Skip to content

Commit ea0211f

Browse files
time-and-fateti-chi-bot
authored andcommitted
This is an automated cherry-pick of pingcap#48984
Signed-off-by: ti-chi-bot <[email protected]>
1 parent 3aa520f commit ea0211f

File tree

6 files changed

+4168
-4
lines changed

6 files changed

+4168
-4
lines changed

pkg/planner/core/casetest/physicalplantest/testdata/plan_suite_out.json

Lines changed: 3625 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 315 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,315 @@
1+
CREATE TABLE aa311c3c (
2+
57fd8d09 year(4) DEFAULT '1913',
3+
afbdd7c3 char(220) DEFAULT 'gakkl6occ0yd2jmhi2qxog8szibtcqwxyxmga3hp4ktszjplmg3rjvu8v6lgn9q6hva2lekhw6napjejbut6svsr8q2j8w8rc551e5vq',
4+
43b06e99 date NOT NULL DEFAULT '3403-10-08',
5+
b80b3746 tinyint(4) NOT NULL DEFAULT '34',
6+
6302d8ac timestamp DEFAULT '2004-04-01 18:21:18',
7+
PRIMARY KEY (43b06e99,b80b3746) /*T![clustered_index] CLUSTERED */,
8+
KEY 3080c821 (57fd8d09,43b06e99,b80b3746),
9+
KEY a9af33a4 (57fd8d09,b80b3746,43b06e99),
10+
KEY 464b386e (b80b3746),
11+
KEY 19dc3c2d (57fd8d09)
12+
) ENGINE=InnoDB DEFAULT CHARSET=ascii COLLATE=ascii_bin COMMENT='320f8401';
13+
explain select /*+ use_index_merge( `aa311c3c` ) */ `aa311c3c`.`43b06e99` as r0 , `aa311c3c`.`6302d8ac` as r1 from `aa311c3c` where IsNull( `aa311c3c`.`b80b3746` ) or not( `aa311c3c`.`57fd8d09` >= '2008' ) order by r0,r1 limit 95;
14+
id estRows task access object operator info
15+
Projection_7 95.00 root planner__core__issuetest__planner_issue.aa311c3c.43b06e99, planner__core__issuetest__planner_issue.aa311c3c.6302d8ac
16+
└─TopN_9 95.00 root planner__core__issuetest__planner_issue.aa311c3c.43b06e99, planner__core__issuetest__planner_issue.aa311c3c.6302d8ac, offset:0, count:95
17+
└─IndexMerge_17 95.00 root type: union
18+
├─TableFullScan_13(Build) 0.00 cop[tikv] table:aa311c3c keep order:false, stats:pseudo
19+
├─IndexRangeScan_14(Build) 3323.33 cop[tikv] table:aa311c3c, index:3080c821(57fd8d09, 43b06e99, b80b3746) range:[-inf,2008), keep order:false, stats:pseudo
20+
└─TopN_16(Probe) 95.00 cop[tikv] planner__core__issuetest__planner_issue.aa311c3c.43b06e99, planner__core__issuetest__planner_issue.aa311c3c.6302d8ac, offset:0, count:95
21+
└─TableRowIDScan_15 3323.33 cop[tikv] table:aa311c3c keep order:false, stats:pseudo
22+
CREATE TABLE t1(id int,col1 varchar(10),col2 varchar(10),col3 varchar(10));
23+
CREATE TABLE t2(id int,col1 varchar(10),col2 varchar(10),col3 varchar(10));
24+
INSERT INTO t1 values(1,NULL,NULL,null),(2,NULL,NULL,null),(3,NULL,NULL,null);
25+
INSERT INTO t2 values(1,'a','aa','aaa'),(2,'b','bb','bbb'),(3,'c','cc','ccc');
26+
WITH tmp AS (SELECT t2.* FROM t2) select (SELECT tmp.col1 FROM tmp WHERE tmp.id=t1.id ) col1, (SELECT tmp.col2 FROM tmp WHERE tmp.id=t1.id ) col2, (SELECT tmp.col3 FROM tmp WHERE tmp.id=t1.id ) col3 from t1;
27+
col1 col2 col3
28+
a aa aaa
29+
b bb bbb
30+
c cc ccc
31+
set tidb_enable_index_merge=on;
32+
drop table if exists t;
33+
create table t(a int, b int, index idx_a(a), index idx_b(b));
34+
set @@session.sql_select_limit=3;
35+
explain format = 'brief' select * from t where a = 1 or b = 1;
36+
id estRows task access object operator info
37+
IndexMerge 3.00 root type: union, limit embedded(offset:0, count:3)
38+
├─Limit(Build) 1.50 cop[tikv] offset:0, count:3
39+
│ └─IndexRangeScan 1.50 cop[tikv] table:t, index:idx_a(a) range:[1,1], keep order:false, stats:pseudo
40+
├─Limit(Build) 1.50 cop[tikv] offset:0, count:3
41+
│ └─IndexRangeScan 1.50 cop[tikv] table:t, index:idx_b(b) range:[1,1], keep order:false, stats:pseudo
42+
└─TableRowIDScan(Probe) 3.00 cop[tikv] table:t keep order:false, stats:pseudo
43+
explain format = 'brief' select /*+ use_index_merge(t) */ * from t where a = 1 or b = 1;
44+
id estRows task access object operator info
45+
IndexMerge 3.00 root type: union, limit embedded(offset:0, count:3)
46+
├─Limit(Build) 1.50 cop[tikv] offset:0, count:3
47+
│ └─IndexRangeScan 1.50 cop[tikv] table:t, index:idx_a(a) range:[1,1], keep order:false, stats:pseudo
48+
├─Limit(Build) 1.50 cop[tikv] offset:0, count:3
49+
│ └─IndexRangeScan 1.50 cop[tikv] table:t, index:idx_b(b) range:[1,1], keep order:false, stats:pseudo
50+
└─TableRowIDScan(Probe) 3.00 cop[tikv] table:t keep order:false, stats:pseudo
51+
set @@session.sql_select_limit=18446744073709551615;
52+
explain format = 'brief' select * from t where a = 1 or b = 1;
53+
id estRows task access object operator info
54+
IndexMerge 19.99 root type: union
55+
├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx_a(a) range:[1,1], keep order:false, stats:pseudo
56+
├─IndexRangeScan(Build) 10.00 cop[tikv] table:t, index:idx_b(b) range:[1,1], keep order:false, stats:pseudo
57+
└─TableRowIDScan(Probe) 19.99 cop[tikv] table:t keep order:false, stats:pseudo
58+
explain format = 'brief' select * from t where a = 1 or b = 1 limit 3;
59+
id estRows task access object operator info
60+
IndexMerge 3.00 root type: union, limit embedded(offset:0, count:3)
61+
├─Limit(Build) 1.50 cop[tikv] offset:0, count:3
62+
│ └─IndexRangeScan 1.50 cop[tikv] table:t, index:idx_a(a) range:[1,1], keep order:false, stats:pseudo
63+
├─Limit(Build) 1.50 cop[tikv] offset:0, count:3
64+
│ └─IndexRangeScan 1.50 cop[tikv] table:t, index:idx_b(b) range:[1,1], keep order:false, stats:pseudo
65+
└─TableRowIDScan(Probe) 3.00 cop[tikv] table:t keep order:false, stats:pseudo
66+
drop table if exists t1, t2;
67+
CREATE TABLE t1(id int,col1 varchar(10),col2 varchar(10),col3 varchar(10));
68+
CREATE TABLE t2(id int,col1 varchar(10),col2 varchar(10),col3 varchar(10));
69+
INSERT INTO t1 values(1,NULL,NULL,null),(2,NULL,NULL,null),(3,NULL,NULL,null);
70+
INSERT INTO t2 values(1,'a','aa','aaa'),(2,'b','bb','bbb'),(3,'c','cc','ccc');
71+
WITH tmp AS (SELECT t2.* FROM t2) SELECT * FROM t1 WHERE t1.id = (select id from tmp where id = 1) or t1.id = (select id from tmp where id = 2) or t1.id = (select id from tmp where id = 3);
72+
id col1 col2 col3
73+
1 NULL NULL NULL
74+
2 NULL NULL NULL
75+
3 NULL NULL NULL
76+
drop table if exists t1, t2;
77+
CREATE TABLE t1 (a INT, b INT);
78+
CREATE TABLE t2 (a INT, b INT);
79+
INSERT INTO t1 VALUES (1, 1);
80+
INSERT INTO t2 VALUES (1, 1);
81+
SELECT one.a, one.b as b2 FROM t1 one ORDER BY (SELECT two.b FROM t2 two WHERE two.a = one.b);
82+
a b2
83+
1 1
84+
CREATE TABLE ads_txn (
85+
`cusno` varchar(10) NOT NULL,
86+
`txn_dt` varchar(8) NOT NULL,
87+
`unn_trno` decimal(22,0) NOT NULL,
88+
`aml_cntpr_accno` varchar(64) DEFAULT NULL,
89+
`acpayr_accno` varchar(35) DEFAULT NULL,
90+
PRIMARY KEY (`cusno`,`txn_dt`,`unn_trno`) NONCLUSTERED
91+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
92+
PARTITION BY LIST COLUMNS(`txn_dt`)
93+
(PARTITION `p20000101` VALUES IN ('20000101'),
94+
PARTITION `p20220101` VALUES IN ('20220101'),
95+
PARTITION `p20230516` VALUES IN ('20230516'));
96+
analyze table ads_txn;
97+
set autocommit=OFF;
98+
explain update ads_txn s set aml_cntpr_accno = trim(acpayr_accno) where s._tidb_rowid between 1 and 100000;
99+
id estRows task access object operator info
100+
Update_5 N/A root N/A
101+
└─Projection_6 8000.00 root planner__core__issuetest__planner_issue.ads_txn.cusno, planner__core__issuetest__planner_issue.ads_txn.txn_dt, planner__core__issuetest__planner_issue.ads_txn.unn_trno, planner__core__issuetest__planner_issue.ads_txn.aml_cntpr_accno, planner__core__issuetest__planner_issue.ads_txn.acpayr_accno, planner__core__issuetest__planner_issue.ads_txn._tidb_rowid
102+
└─SelectLock_7 8000.00 root for update 0
103+
└─TableReader_9 10000.00 root partition:all data:TableRangeScan_8
104+
└─TableRangeScan_8 10000.00 cop[tikv] table:s range:[1,100000], keep order:false, stats:pseudo
105+
CREATE TABLE tb1 (cid INT, code INT, class VARCHAR(10));
106+
CREATE TABLE tb2 (cid INT, code INT, class VARCHAR(10));
107+
UPDATE tb1, (SELECT code AS cid, code, MAX(class) AS class FROM tb2 GROUP BY code) tb3 SET tb1.cid = tb3.cid, tb1.code = tb3.code, tb1.class = tb3.class;
108+
CREATE TEMPORARY TABLE v0(v1 int);
109+
INSERT INTO v0 WITH ta2 AS (TABLE v0) TABLE ta2 FOR UPDATE OF ta2;
110+
create table tbl_39(col_239 year(4) not null default '2009', primary key(col_239), unique key idx_223(col_239), key idx_224(col_239));
111+
insert into tbl_39 values (1994),(1995),(1996),(1997);
112+
explain select /*+ use_index_merge( tbl_39) */ col_239 from tbl_39 where not( tbl_39.col_239 not in ( '1994' ) ) and tbl_39.col_239 not in ( '2004' , '2010' , '2010' ) or not( tbl_39.col_239 <= '1996' ) and not( tbl_39.col_239 between '2026' and '2011' ) order by tbl_39.col_239 limit 382;
113+
id estRows task access object operator info
114+
Projection_8 382.00 root planner__core__issuetest__planner_issue.tbl_39.col_239
115+
└─Limit_15 382.00 root offset:0, count:382
116+
└─UnionScan_26 382.00 root or(and(not(not(eq(planner__core__issuetest__planner_issue.tbl_39.col_239, 1994))), not(in(planner__core__issuetest__planner_issue.tbl_39.col_239, 2004, 2010, 2010))), and(not(le(planner__core__issuetest__planner_issue.tbl_39.col_239, 1996)), not(and(ge(cast(planner__core__issuetest__planner_issue.tbl_39.col_239, double UNSIGNED BINARY), 2026), le(cast(planner__core__issuetest__planner_issue.tbl_39.col_239, double UNSIGNED BINARY), 2011)))))
117+
└─IndexReader_29 382.00 root index:Selection_28
118+
└─Selection_28 382.00 cop[tikv] or(and(eq(planner__core__issuetest__planner_issue.tbl_39.col_239, 1994), not(in(planner__core__issuetest__planner_issue.tbl_39.col_239, 2004, 2010, 2010))), and(gt(planner__core__issuetest__planner_issue.tbl_39.col_239, 1996), or(lt(cast(planner__core__issuetest__planner_issue.tbl_39.col_239, double UNSIGNED BINARY), 2026), gt(cast(planner__core__issuetest__planner_issue.tbl_39.col_239, double UNSIGNED BINARY), 2011))))
119+
└─IndexRangeScan_27 477.50 cop[tikv] table:tbl_39, index:PRIMARY(col_239) range:[1994,1994], (1996,+inf], keep order:true, stats:pseudo
120+
select /*+ use_index_merge( tbl_39) */ col_239 from tbl_39 where not( tbl_39.col_239 not in ( '1994' ) ) and tbl_39.col_239 not in ( '2004' , '2010' , '2010' ) or not( tbl_39.col_239 <= '1996' ) and not( tbl_39.col_239 between '2026' and '2011' ) order by tbl_39.col_239 limit 382;
121+
col_239
122+
1994
123+
1997
124+
drop table if exists t, t1, t2;
125+
create table t (id int,name varchar(10));
126+
insert into t values(1,'tt');
127+
create table t1(id int,name varchar(10),name1 varchar(10),name2 varchar(10));
128+
insert into t1 values(1,'tt','ttt','tttt'),(2,'dd','ddd','dddd');
129+
create table t2(id int,name varchar(10),name1 varchar(10),name2 varchar(10),`date1` date);
130+
insert into t2 values(1,'tt','ttt','tttt','2099-12-31'),(2,'dd','ddd','dddd','2099-12-31');
131+
WITH bzzs AS (
132+
SELECT
133+
count(1) AS bzn
134+
FROM
135+
t c
136+
),
137+
tmp1 AS (
138+
SELECT
139+
t1.*
140+
FROM
141+
t1
142+
LEFT JOIN bzzs ON 1 = 1
143+
WHERE
144+
name IN ('tt')
145+
AND bzn <> 1
146+
),
147+
tmp2 AS (
148+
SELECT
149+
tmp1.*,
150+
date('2099-12-31') AS endate
151+
FROM
152+
tmp1
153+
),
154+
tmp3 AS (
155+
SELECT
156+
*
157+
FROM
158+
tmp2
159+
WHERE
160+
endate > CURRENT_DATE
161+
UNION ALL
162+
SELECT
163+
'1' AS id,
164+
'ss' AS name,
165+
'sss' AS name1,
166+
'ssss' AS name2,
167+
date('2099-12-31') AS endate
168+
FROM
169+
bzzs t1
170+
WHERE
171+
bzn = 1
172+
)
173+
SELECT
174+
c2.id,
175+
c3.id
176+
FROM
177+
t2 db
178+
LEFT JOIN tmp3 c2 ON c2.id = '1'
179+
LEFT JOIN tmp3 c3 ON c3.id = '1';
180+
id id
181+
1 1
182+
1 1
183+
drop table if exists t;
184+
create table t(a int, b int);
185+
set @@tidb_max_chunk_size = 32;
186+
insert into t values(1, 1);
187+
insert into t select a+1, a+1 from t;
188+
insert into t select a+2, a+2 from t;
189+
insert into t select a+4, a+4 from t;
190+
insert into t select a+8, a+8 from t;
191+
insert into t select a+16, a+16 from t;
192+
insert into t select a+32, a+32 from t;
193+
select a from (select 100 as a, 100 as b union all select * from t) t where b != 0;
194+
a
195+
100
196+
1
197+
2
198+
3
199+
4
200+
5
201+
6
202+
7
203+
8
204+
9
205+
10
206+
11
207+
12
208+
13
209+
14
210+
15
211+
16
212+
17
213+
18
214+
19
215+
20
216+
21
217+
22
218+
23
219+
24
220+
25
221+
26
222+
27
223+
28
224+
29
225+
30
226+
31
227+
32
228+
33
229+
34
230+
35
231+
36
232+
37
233+
38
234+
39
235+
40
236+
41
237+
42
238+
43
239+
44
240+
45
241+
46
242+
47
243+
48
244+
49
245+
50
246+
51
247+
52
248+
53
249+
54
250+
55
251+
56
252+
57
253+
58
254+
59
255+
60
256+
61
257+
62
258+
63
259+
64
260+
set @@tidb_max_chunk_size = default;
261+
drop table if exists t1, t2;
262+
create table t1(a varchar(20) collate utf8mb4_bin, index ia(a));
263+
insert into t1 value('测试'),('测试 '),('xxx ');
264+
explain format = brief select *,length(a) from t1 where a like '测试 %';
265+
id estRows task access object operator info
266+
Projection 250.00 root planner__core__issuetest__planner_issue.t1.a, length(planner__core__issuetest__planner_issue.t1.a)->Column#3
267+
└─UnionScan 250.00 root like(planner__core__issuetest__planner_issue.t1.a, "测试 %", 92)
268+
└─IndexReader 250.00 root index:Selection
269+
└─Selection 250.00 cop[tikv] like(planner__core__issuetest__planner_issue.t1.a, "测试 %", 92)
270+
└─IndexRangeScan 250.00 cop[tikv] table:t1, index:ia(a) range:["测试 ","测试!"), keep order:false, stats:pseudo
271+
explain format = brief select *,length(a) from t1 where a like '测试';
272+
id estRows task access object operator info
273+
Projection 10.00 root planner__core__issuetest__planner_issue.t1.a, length(planner__core__issuetest__planner_issue.t1.a)->Column#3
274+
└─UnionScan 10.00 root like(planner__core__issuetest__planner_issue.t1.a, "测试", 92)
275+
└─IndexReader 10.00 root index:Selection
276+
└─Selection 10.00 cop[tikv] like(planner__core__issuetest__planner_issue.t1.a, "测试", 92)
277+
└─IndexRangeScan 10.00 cop[tikv] table:t1, index:ia(a) range:["测试","测试"], keep order:false, stats:pseudo
278+
select *,length(a) from t1 where a like '测试 %';
279+
a length(a)
280+
测试 8
281+
select *,length(a) from t1 where a like '测试';
282+
a length(a)
283+
测试 6
284+
explain format = brief select * from t1 use index (ia) where a like 'xxx_';
285+
id estRows task access object operator info
286+
Projection 250.00 root planner__core__issuetest__planner_issue.t1.a
287+
└─UnionScan 250.00 root like(planner__core__issuetest__planner_issue.t1.a, "xxx_", 92)
288+
└─IndexReader 250.00 root index:Selection
289+
└─Selection 250.00 cop[tikv] like(planner__core__issuetest__planner_issue.t1.a, "xxx_", 92)
290+
└─IndexRangeScan 250.00 cop[tikv] table:t1, index:ia(a) range:["xxx","xxy"), keep order:false, stats:pseudo
291+
select * from t1 use index (ia) where a like 'xxx_';
292+
a
293+
xxx
294+
create table t2(a varchar(20) collate gbk_chinese_ci, index ia(a));
295+
insert into t2 value('测试'),('测试 ');
296+
explain format = brief select *,length(a) from t2 where a like '测试 %';
297+
id estRows task access object operator info
298+
Projection 8000.00 root planner__core__issuetest__planner_issue.t2.a, length(to_binary(planner__core__issuetest__planner_issue.t2.a))->Column#3
299+
└─UnionScan 8000.00 root like(planner__core__issuetest__planner_issue.t2.a, "测试 %", 92)
300+
└─TableReader 8000.00 root data:Selection
301+
└─Selection 8000.00 cop[tikv] like(planner__core__issuetest__planner_issue.t2.a, "测试 %", 92)
302+
└─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo
303+
explain format = brief select *,length(a) from t2 where a like '测试';
304+
id estRows task access object operator info
305+
Projection 8000.00 root planner__core__issuetest__planner_issue.t2.a, length(to_binary(planner__core__issuetest__planner_issue.t2.a))->Column#3
306+
└─UnionScan 8000.00 root like(planner__core__issuetest__planner_issue.t2.a, "测试", 92)
307+
└─TableReader 8000.00 root data:Selection
308+
└─Selection 8000.00 cop[tikv] like(planner__core__issuetest__planner_issue.t2.a, "测试", 92)
309+
└─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo
310+
select *,length(a) from t2 where a like '测试 %';
311+
a length(a)
312+
测试 6
313+
select *,length(a) from t2 where a like '测试';
314+
a length(a)
315+
测试 4

0 commit comments

Comments
 (0)