@@ -69,3 +69,137 @@ func TestIndexAdvise(t *testing.T) {
69
69
require .Equal (t , uint64 (4 ), ia .MaxIndexNum .PerTable )
70
70
require .Equal (t , uint64 (5 ), ia .MaxIndexNum .PerDB )
71
71
}
72
+ << << << < HEAD
73
+ == == == =
74
+
75
+ func TestIndexJoinProjPattern (t * testing.T ) {
76
+ store := testkit .CreateMockStore (t )
77
+ tk := testkit .NewTestKit (t , store )
78
+ tk .MustExec ("use test" )
79
+ tk .MustExec (`create table t1(
80
+ pnbrn_cnaps varchar(5) not null,
81
+ new_accno varchar(18) not null,
82
+ primary key(pnbrn_cnaps,new_accno) nonclustered
83
+ );` )
84
+ tk .MustExec (`create table t2(
85
+ pnbrn_cnaps varchar(5) not null,
86
+ txn_accno varchar(18) not null,
87
+ txn_dt date not null,
88
+ yn_frz varchar(1) default null
89
+ );` )
90
+ tk .MustExec (`insert into t1(pnbrn_cnaps,new_accno) values ("40001","123")` )
91
+ tk .MustExec (`insert into t2(pnbrn_cnaps, txn_accno, txn_dt, yn_frz) values ("40001","123","20221201","0");` )
92
+
93
+ sql := `update
94
+ /*+ inl_join(a) */
95
+ t2 b,
96
+ (
97
+ select t1.pnbrn_cnaps,
98
+ t1.new_accno
99
+ from t1
100
+ where t1.pnbrn_cnaps = '40001'
101
+ ) a
102
+ set b.yn_frz = '1'
103
+ where b.txn_dt = str_to_date('20221201', '%Y%m%d')
104
+ and b.pnbrn_cnaps = a.pnbrn_cnaps
105
+ and b.txn_accno = a.new_accno;`
106
+ rows := [][]interface {}{
107
+ {"Update_8" },
108
+ {"└─IndexJoin_14" },
109
+ {" ├─TableReader_25(Build)" },
110
+ {" │ └─Selection_24" },
111
+ {" │ └─TableFullScan_23" },
112
+ {" └─IndexReader_12(Probe)" },
113
+ {" └─Selection_11" },
114
+ {" └─IndexRangeScan_10" },
115
+ }
116
+ tk .MustExec ("set @@session.tidb_enable_inl_join_inner_multi_pattern='ON'" )
117
+ tk .MustQuery ("explain " + sql ).CheckAt ([]int {0 }, rows )
118
+ rows = [][]interface {}{
119
+ {"Update_8" },
120
+ {"└─HashJoin_10" },
121
+ {" ├─IndexReader_17(Build)" },
122
+ {" │ └─IndexRangeScan_16" },
123
+ {" └─TableReader_14(Probe)" },
124
+ {" └─Selection_13" },
125
+ {" └─TableFullScan_12" },
126
+ }
127
+ tk .MustExec ("set @@session.tidb_enable_inl_join_inner_multi_pattern='OFF'" )
128
+ tk .MustQuery ("explain " + sql ).CheckAt ([]int {0 }, rows )
129
+
130
+ tk .MustExec ("set @@session.tidb_enable_inl_join_inner_multi_pattern='ON'" )
131
+ tk .MustExec (sql )
132
+ tk .MustQuery ("select yn_frz from t2" ).Check (testkit .Rows ("1" ))
133
+ }
134
+
135
+ func TestIndexJoinSelPattern (t * testing.T ) {
136
+ store := testkit .CreateMockStore (t )
137
+ tk := testkit .NewTestKit (t , store )
138
+ tk .MustExec ("use test" )
139
+ tk .MustExec (` create table tbl_miss(
140
+ id bigint(20) unsigned not null
141
+ ,txn_dt date default null
142
+ ,perip_sys_uuid varchar(32) not null
143
+ ,rvrs_idr varchar(1) not null
144
+ ,primary key(id) clustered
145
+ ,key idx1 (txn_dt, perip_sys_uuid, rvrs_idr)
146
+ );
147
+ ` )
148
+ tk .MustExec (`insert into tbl_miss (id,txn_dt,perip_sys_uuid,rvrs_idr) values (1,"20221201","123","1");` )
149
+ tk .MustExec (`create table tbl_src(
150
+ txn_dt date default null
151
+ ,uuid varchar(32) not null
152
+ ,rvrs_idr char(1)
153
+ ,expd_inf varchar(5000)
154
+ ,primary key(uuid,rvrs_idr) nonclustered
155
+ );
156
+ ` )
157
+ tk .MustExec (`insert into tbl_src (txn_dt,uuid,rvrs_idr) values ("20221201","123","1");` )
158
+ sql := `select /*+ use_index(mis,) inl_join(src) */
159
+ *
160
+ from tbl_miss mis
161
+ ,tbl_src src
162
+ where src.txn_dt >= str_to_date('20221201', '%Y%m%d')
163
+ and mis.id between 1 and 10000
164
+ and mis.perip_sys_uuid = src.uuid
165
+ and mis.rvrs_idr = src.rvrs_idr
166
+ and mis.txn_dt = src.txn_dt
167
+ and (
168
+ case when isnull(src.expd_inf) = 1 then ''
169
+ else
170
+ substr(concat_ws('',src.expd_inf,'~~'),
171
+ instr(concat_ws('',src.expd_inf,'~~'),'~~a4') + 4,
172
+ instr(substr(concat_ws('',src.expd_inf,'~~'),
173
+ instr(concat_ws('',src.expd_inf,'~~'),'~~a4') + 4, length(concat_ws('',src.expd_inf,'~~'))),'~~') -1)
174
+ end
175
+ ) != '01';`
176
+ rows := [][]interface {}{
177
+ {"HashJoin_9" },
178
+ {"├─TableReader_12(Build)" },
179
+ {"│ └─Selection_11" },
180
+ {"│ └─TableRangeScan_10" },
181
+ {"└─Selection_13(Probe)" },
182
+ {" └─TableReader_16" },
183
+ {" └─Selection_15" },
184
+ {" └─TableFullScan_14" },
185
+ }
186
+ tk .MustExec ("set @@session.tidb_enable_inl_join_inner_multi_pattern='OFF'" )
187
+ tk .MustQuery ("explain " + sql ).CheckAt ([]int {0 }, rows )
188
+ rows = [][]interface {}{
189
+ {"IndexJoin_13" },
190
+ {"├─TableReader_25(Build)" },
191
+ {"│ └─Selection_24" },
192
+ {"│ └─TableRangeScan_23" },
193
+ {"└─Selection_12(Probe)" },
194
+ {" └─IndexLookUp_11" },
195
+ {" ├─IndexRangeScan_8(Build)" },
196
+ {" └─Selection_10(Probe)" },
197
+ {" └─TableRowIDScan_9" },
198
+ }
199
+ tk .MustExec ("set @@session.tidb_enable_inl_join_inner_multi_pattern='ON'" )
200
+ tk .MustQuery ("explain " + sql ).CheckAt ([]int {0 }, rows )
201
+ tk .MustQuery (sql ).Check (testkit .Rows ("1 2022-12-01 123 1 2022-12-01 123 1 <nil>" ))
202
+ tk .MustExec ("set @@session.tidb_enable_inl_join_inner_multi_pattern='OFF'" )
203
+ tk .MustQuery (sql ).Check (testkit .Rows ("1 2022-12-01 123 1 2022-12-01 123 1 <nil>" ))
204
+ }
205
+ >> >> >> > 982 a6163a1 (sysvar : introduce variable tidb_enable_inl_join_inner_multi_pattern (#41319 ))
0 commit comments