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