@@ -84,6 +84,72 @@ func TestIssue43311(t *testing.T) {
84
84
tk .MustQuery (`execute st using @a, @b` ).Check (testkit .Rows ()) // empty
85
85
}
86
86
87
+ func TestIssue44830 (t * testing.T ) {
88
+ store := testkit .CreateMockStore (t )
89
+ tk := testkit .NewTestKit (t , store )
90
+ tk .MustExec (`use test` )
91
+ tk .MustExec (`set @@tidb_opt_fix_control = "44830:ON"` )
92
+ tk .MustExec (`create table t (a int, primary key(a))` )
93
+ tk .MustExec (`create table t1 (a int, b int, primary key(a, b))` ) // multiple-column primary key
94
+ tk .MustExec (`insert into t values (1), (2), (3)` )
95
+ tk .MustExec (`insert into t1 values (1, 1), (2, 2), (3, 3)` )
96
+ tk .MustExec (`set @a=1, @b=2, @c=3` )
97
+
98
+ // single-column primary key cases
99
+ tk .MustExec (`prepare st from 'select * from t where 1=1 and a in (?, ?, ?)'` )
100
+ tk .MustQuery (`execute st using @a, @b, @c` ).Sort ().Check (testkit .Rows ("1" , "2" , "3" ))
101
+ tk .MustQuery (`execute st using @a, @b, @c` ).Sort ().Check (testkit .Rows ("1" , "2" , "3" ))
102
+ tk .MustQuery (`select @@last_plan_from_cache` ).Check (testkit .Rows ("1" ))
103
+ tk .MustQuery (`execute st using @a, @b, @b` ).Sort ().Check (testkit .Rows ("1" , "2" ))
104
+ tk .MustQuery (`select @@last_plan_from_cache` ).Check (testkit .Rows ("0" )) // range length changed
105
+ tk .MustQuery (`execute st using @b, @b, @b` ).Sort ().Check (testkit .Rows ("2" ))
106
+ tk .MustQuery (`select @@last_plan_from_cache` ).Check (testkit .Rows ("0" )) // range length changed
107
+ tk .MustQuery (`execute st using @a, @b, @c` ).Sort ().Check (testkit .Rows ("1" , "2" , "3" ))
108
+ tk .MustQuery (`execute st using @a, @b, @b` ).Sort ().Check (testkit .Rows ("1" , "2" ))
109
+ tk .MustQuery (`execute st using @a, @b, @b` ).Sort ().Check (testkit .Rows ("1" , "2" ))
110
+ tk .MustQuery (`select @@last_plan_from_cache` ).Check (testkit .Rows ("0" )) // contain duplicated values in the in-list
111
+
112
+ // multi-column primary key cases
113
+ tk .MustExec (`prepare st from 'select * from t1 where 1=1 and (a, b) in ((?, ?), (?, ?), (?, ?))'` )
114
+ tk .MustQuery (`execute st using @a, @a, @b, @b, @c, @c` ).Sort ().Check (testkit .Rows ("1 1" , "2 2" , "3 3" ))
115
+ tk .MustQuery (`execute st using @a, @a, @b, @b, @c, @c` ).Sort ().Check (testkit .Rows ("1 1" , "2 2" , "3 3" ))
116
+ tk .MustQuery (`select @@last_plan_from_cache` ).Check (testkit .Rows ("1" ))
117
+ tk .MustQuery (`execute st using @a, @a, @b, @b, @b, @b` ).Sort ().Check (testkit .Rows ("1 1" , "2 2" ))
118
+ tk .MustQuery (`select @@last_plan_from_cache` ).Check (testkit .Rows ("0" )) // range length changed
119
+ tk .MustQuery (`execute st using @b, @b, @b, @b, @b, @b` ).Sort ().Check (testkit .Rows ("2 2" ))
120
+ tk .MustQuery (`select @@last_plan_from_cache` ).Check (testkit .Rows ("0" )) // range length changed
121
+ tk .MustQuery (`execute st using @b, @b, @b, @b, @c, @c` ).Sort ().Check (testkit .Rows ("2 2" , "3 3" ))
122
+ tk .MustQuery (`select @@last_plan_from_cache` ).Check (testkit .Rows ("0" )) // range length changed
123
+ tk .MustQuery (`execute st using @a, @a, @a, @a, @a, @a` ).Sort ().Check (testkit .Rows ("1 1" ))
124
+ tk .MustQuery (`execute st using @a, @a, @a, @a, @a, @a` ).Sort ().Check (testkit .Rows ("1 1" ))
125
+ tk .MustQuery (`select @@last_plan_from_cache` ).Check (testkit .Rows ("0" )) // contain duplicated values in the in-list
126
+ tk .MustQuery (`execute st using @a, @a, @b, @b, @b, @b` ).Sort ().Check (testkit .Rows ("1 1" , "2 2" ))
127
+ tk .MustQuery (`execute st using @a, @a, @b, @b, @b, @b` ).Sort ().Check (testkit .Rows ("1 1" , "2 2" ))
128
+ tk .MustQuery (`select @@last_plan_from_cache` ).Check (testkit .Rows ("0" )) // contain duplicated values in the in-list
129
+ }
130
+
131
+ func TestIssue44830NonPrep (t * testing.T ) {
132
+ store := testkit .CreateMockStore (t )
133
+ tk := testkit .NewTestKit (t , store )
134
+ tk .MustExec (`use test` )
135
+ tk .MustExec (`set @@tidb_enable_non_prepared_plan_cache=1` )
136
+ tk .MustExec (`set @@tidb_opt_fix_control = "44830:ON"` )
137
+ tk .MustExec (`create table t1 (a int, b int, primary key(a, b))` ) // multiple-column primary key
138
+ tk .MustExec (`insert into t1 values (1, 1), (2, 2), (3, 3)` )
139
+ tk .MustExec (`set @a=1, @b=2, @c=3` )
140
+
141
+ tk .MustQuery (`select * from t1 where 1=1 and (a, b) in ((1, 1), (2, 2), (3, 3))` ).Sort ().Check (testkit .Rows ("1 1" , "2 2" , "3 3" ))
142
+ tk .MustQuery (`select * from t1 where 1=1 and (a, b) in ((1, 1), (2, 2), (3, 3))` ).Sort ().Check (testkit .Rows ("1 1" , "2 2" , "3 3" ))
143
+ tk .MustQuery (`select @@last_plan_from_cache` ).Check (testkit .Rows ("1" ))
144
+ tk .MustQuery (`select * from t1 where 1=1 and (a, b) in ((1, 1), (2, 2), (2, 2))` ).Sort ().Check (testkit .Rows ("1 1" , "2 2" ))
145
+ tk .MustQuery (`select @@last_plan_from_cache` ).Check (testkit .Rows ("0" ))
146
+ tk .MustQuery (`select * from t1 where 1=1 and (a, b) in ((2, 2), (2, 2), (2, 2))` ).Sort ().Check (testkit .Rows ("2 2" ))
147
+ tk .MustQuery (`select @@last_plan_from_cache` ).Check (testkit .Rows ("0" ))
148
+ tk .MustQuery (`select * from t1 where 1=1 and (a, b) in ((1, 1), (1, 1), (1, 1))` ).Sort ().Check (testkit .Rows ("1 1" ))
149
+ tk .MustQuery (`select * from t1 where 1=1 and (a, b) in ((1, 1), (1, 1), (1, 1))` ).Sort ().Check (testkit .Rows ("1 1" ))
150
+ tk .MustQuery (`select @@last_plan_from_cache` ).Check (testkit .Rows ("0" ))
151
+ }
152
+
87
153
func TestPlanCacheSizeSwitch (t * testing.T ) {
88
154
store := testkit .CreateMockStore (t )
89
155
tk := testkit .NewTestKit (t , store )
0 commit comments