Skip to content

Commit

Permalink
planner: enhance projection explain-info when simple column projected…
Browse files Browse the repository at this point in the history
… again with a new unique-id (#44520)

close #44521
  • Loading branch information
AilinKid authored Jun 19, 2023
1 parent 949e925 commit 6e3d0eb
Show file tree
Hide file tree
Showing 33 changed files with 344 additions and 339 deletions.
20 changes: 10 additions & 10 deletions cmd/explaintest/r/agg_predicate_pushdown.result
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,50 @@ create table t(a int, b int, c int);
desc format='brief' select a, b, avg(c) from t group by a, b, c having
(a > 1) and (a > 2) and 1 and (b > 2) and (avg(c) > 3);
id estRows task access object operator info
Projection 711.11 root test.t.a, test.t.b, Column#5
Projection 711.11 root test.t.a, test.t.b, Column#5->Column#8
└─Selection 711.11 root gt(Column#5, 3)
└─HashAgg 888.89 root group by:Column#16, Column#17, Column#18, funcs:avg(Column#13)->Column#5, funcs:firstrow(Column#14)->test.t.a, funcs:firstrow(Column#15)->test.t.b
└─Projection 1111.11 root cast(test.t.c, decimal(10,0) BINARY)->Column#13, test.t.a, test.t.b, test.t.a, test.t.b, test.t.c
└─Projection 1111.11 root cast(test.t.c, decimal(10,0) BINARY)->Column#13, test.t.a->Column#14, test.t.b->Column#15, test.t.a->Column#16, test.t.b->Column#17, test.t.c->Column#18
└─TableReader 1111.11 root data:Selection
└─Selection 1111.11 cop[tikv] gt(test.t.a, 1), gt(test.t.a, 2), gt(test.t.b, 2)
└─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo
desc format='brief' select a, b, avg(c) from t group by a, b, c having
(a > 1 or b > 2) and (a > 2 or b < 1) and 1 and (b > 2) and (avg(c) > 3);
id estRows task access object operator info
Projection 657.65 root test.t.a, test.t.b, Column#5
Projection 657.65 root test.t.a, test.t.b, Column#5->Column#8
└─Selection 657.65 root gt(Column#5, 3)
└─HashAgg 822.06 root group by:Column#16, Column#17, Column#18, funcs:avg(Column#13)->Column#5, funcs:firstrow(Column#14)->test.t.a, funcs:firstrow(Column#15)->test.t.b
└─Projection 1027.57 root cast(test.t.c, decimal(10,0) BINARY)->Column#13, test.t.a, test.t.b, test.t.a, test.t.b, test.t.c
└─Projection 1027.57 root cast(test.t.c, decimal(10,0) BINARY)->Column#13, test.t.a->Column#14, test.t.b->Column#15, test.t.a->Column#16, test.t.b->Column#17, test.t.c->Column#18
└─TableReader 1027.57 root data:Selection
└─Selection 1027.57 cop[tikv] gt(test.t.b, 2), or(gt(test.t.a, 1), gt(test.t.b, 2)), or(gt(test.t.a, 2), lt(test.t.b, 1))
└─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo
desc format='brief' select a, b, avg(c) from t group by a, b, c having
(a > 1 and b > 2) or (a > 2 and b < 1) or (b > 2 and avg(c) > 3);
id estRows task access object operator info
Projection 3027.54 root test.t.a, test.t.b, Column#5
Projection 3027.54 root test.t.a, test.t.b, Column#5->Column#8
└─Selection 3027.54 root or(and(gt(test.t.a, 1), gt(test.t.b, 2)), or(and(gt(test.t.a, 2), lt(test.t.b, 1)), and(gt(test.t.b, 2), gt(Column#5, 3))))
└─HashAgg 3784.43 root group by:Column#16, Column#17, Column#18, funcs:avg(Column#13)->Column#5, funcs:firstrow(Column#14)->test.t.a, funcs:firstrow(Column#15)->test.t.b
└─Projection 4730.53 root cast(test.t.c, decimal(10,0) BINARY)->Column#13, test.t.a, test.t.b, test.t.a, test.t.b, test.t.c
└─Projection 4730.53 root cast(test.t.c, decimal(10,0) BINARY)->Column#13, test.t.a->Column#14, test.t.b->Column#15, test.t.a->Column#16, test.t.b->Column#17, test.t.c->Column#18
└─TableReader 4730.53 root data:Selection
└─Selection 4730.53 cop[tikv] or(and(gt(test.t.a, 1), gt(test.t.b, 2)), or(and(gt(test.t.a, 2), lt(test.t.b, 1)), gt(test.t.b, 2)))
└─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo
desc format='brief' select a, b, avg(c) from t group by a, b, c having
(a > 1 or avg(c) > 1) and (a < 3);
id estRows task access object operator info
Projection 2126.93 root test.t.a, test.t.b, Column#5
Projection 2126.93 root test.t.a, test.t.b, Column#5->Column#8
└─Selection 2126.93 root or(gt(test.t.a, 1), gt(Column#5, 1))
└─HashAgg 2658.67 root group by:Column#16, Column#17, Column#18, funcs:avg(Column#13)->Column#5, funcs:firstrow(Column#14)->test.t.a, funcs:firstrow(Column#15)->test.t.b
└─Projection 3323.33 root cast(test.t.c, decimal(10,0) BINARY)->Column#13, test.t.a, test.t.b, test.t.a, test.t.b, test.t.c
└─Projection 3323.33 root cast(test.t.c, decimal(10,0) BINARY)->Column#13, test.t.a->Column#14, test.t.b->Column#15, test.t.a->Column#16, test.t.b->Column#17, test.t.c->Column#18
└─TableReader 3323.33 root data:Selection
└─Selection 3323.33 cop[tikv] lt(test.t.a, 3)
└─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo
desc format='brief' select a, b, avg(c) from t group by a, b, c having
(a > 1 and avg(c) > 1) or (a < 3);
id estRows task access object operator info
Projection 6393.60 root test.t.a, test.t.b, Column#5
Projection 6393.60 root test.t.a, test.t.b, Column#5->Column#8
└─Selection 6393.60 root or(and(gt(test.t.a, 1), gt(Column#5, 1)), lt(test.t.a, 3))
└─HashAgg 7992.00 root group by:Column#16, Column#17, Column#18, funcs:avg(Column#13)->Column#5, funcs:firstrow(Column#14)->test.t.a, funcs:firstrow(Column#15)->test.t.b
└─Projection 9990.00 root cast(test.t.c, decimal(10,0) BINARY)->Column#13, test.t.a, test.t.b, test.t.a, test.t.b, test.t.c
└─Projection 9990.00 root cast(test.t.c, decimal(10,0) BINARY)->Column#13, test.t.a->Column#14, test.t.b->Column#15, test.t.a->Column#16, test.t.b->Column#17, test.t.c->Column#18
└─TableReader 9990.00 root data:Selection
└─Selection 9990.00 cop[tikv] or(gt(test.t.a, 1), lt(test.t.a, 3))
└─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo
Expand Down
4 changes: 2 additions & 2 deletions cmd/explaintest/r/collation_agg_func_disabled.result
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ count(distinct value, value1)
desc format='brief' select count(distinct value collate utf8mb4_bin, value1) from t;
id estRows task access object operator info
StreamAgg 1.00 root funcs:count(distinct Column#6, Column#7)->Column#5
└─Projection 10000.00 root cast(collation_agg_func.t.value, varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin)->Column#6, collation_agg_func.t.value1
└─Projection 10000.00 root cast(collation_agg_func.t.value, varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin)->Column#6, collation_agg_func.t.value1->Column#7
└─TableReader 10000.00 root data:TableFullScan
└─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo
select count(distinct value collate utf8mb4_bin, value1) from t;
Expand Down Expand Up @@ -124,7 +124,7 @@ approx_count_distinct(value, value1)
desc format='brief' select approx_count_distinct(value collate utf8mb4_bin, value1) from t;
id estRows task access object operator info
HashAgg 1.00 root funcs:approx_count_distinct(Column#6, Column#7)->Column#5
└─Projection 10000.00 root cast(collation_agg_func.t.value, varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin)->Column#6, collation_agg_func.t.value1
└─Projection 10000.00 root cast(collation_agg_func.t.value, varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin)->Column#6, collation_agg_func.t.value1->Column#7
└─TableReader 10000.00 root data:TableFullScan
└─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo
select approx_count_distinct(value collate utf8mb4_bin, value1) from t;
Expand Down
4 changes: 2 additions & 2 deletions cmd/explaintest/r/collation_agg_func_enabled.result
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ count(distinct value, value1)
desc format='brief' select count(distinct value collate utf8mb4_bin, value1) from t;
id estRows task access object operator info
StreamAgg 1.00 root funcs:count(distinct Column#6, Column#7)->Column#5
└─Projection 10000.00 root cast(collation_agg_func.t.value, varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin)->Column#6, collation_agg_func.t.value1
└─Projection 10000.00 root cast(collation_agg_func.t.value, varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin)->Column#6, collation_agg_func.t.value1->Column#7
└─TableReader 10000.00 root data:TableFullScan
└─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo
select count(distinct value collate utf8mb4_bin, value1) from t;
Expand Down Expand Up @@ -124,7 +124,7 @@ approx_count_distinct(value, value1)
desc format='brief' select approx_count_distinct(value collate utf8mb4_bin, value1) from t;
id estRows task access object operator info
HashAgg 1.00 root funcs:approx_count_distinct(Column#6, Column#7)->Column#5
└─Projection 10000.00 root cast(collation_agg_func.t.value, varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin)->Column#6, collation_agg_func.t.value1
└─Projection 10000.00 root cast(collation_agg_func.t.value, varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin)->Column#6, collation_agg_func.t.value1->Column#7
└─TableReader 10000.00 root data:TableFullScan
└─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo
select approx_count_distinct(value collate utf8mb4_bin, value1) from t;
Expand Down
4 changes: 2 additions & 2 deletions cmd/explaintest/r/cte.result
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ Projection_26 10000.00 root test.t1.c1, test.t1.c2
├─TableReader_30(Build) 10000.00 root data:TableFullScan_29
│ └─TableFullScan_29 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo
└─HashAgg_31(Probe) 10000.00 root funcs:max(Column#19)->Column#14, funcs:sum(Column#20)->Column#15, funcs:count(1)->Column#16
└─Projection_35 200000.00 root test.t2.c1, cast(isnull(test.t2.c1), decimal(20,0) BINARY)->Column#20
└─Projection_35 200000.00 root test.t2.c1->Column#19, cast(isnull(test.t2.c1), decimal(20,0) BINARY)->Column#20
└─CTEFullScan_33 200000.00 root CTE:cte1 data:CTE_0
CTE_0 20.00 root Recursive CTE, limit(offset:0, count:1)
├─Projection_19(Seed Part) 10.00 root test.t2.c1
Expand Down Expand Up @@ -664,7 +664,7 @@ Projection_24 10000.00 root test.t1.c1, test.t1.c2
├─TableReader_28(Build) 10000.00 root data:TableFullScan_27
│ └─TableFullScan_27 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo
└─HashAgg_29(Probe) 10000.00 root funcs:max(Column#23)->Column#18, funcs:sum(Column#24)->Column#19, funcs:count(1)->Column#20
└─Projection_33 180000000.00 root test.t2.c1, cast(isnull(test.t2.c1), decimal(20,0) BINARY)->Column#24
└─Projection_33 180000000.00 root test.t2.c1->Column#23, cast(isnull(test.t2.c1), decimal(20,0) BINARY)->Column#24
└─CTEFullScan_31 180000000.00 root CTE:cte1 data:CTE_0
CTE_0 18000.00 root Recursive CTE
├─TableReader_19(Seed Part) 10000.00 root data:TableFullScan_18
Expand Down
8 changes: 4 additions & 4 deletions cmd/explaintest/r/explain.result
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,25 @@ set session tidb_hashagg_final_concurrency = 1;
explain format = 'brief' select group_concat(a) from t group by id;
id estRows task access object operator info
StreamAgg 8000.00 root group by:Column#6, funcs:group_concat(Column#5 separator ",")->Column#4
└─Projection 10000.00 root cast(test.t.a, var_string(20))->Column#5, test.t.id
└─Projection 10000.00 root cast(test.t.a, var_string(20))->Column#5, test.t.id->Column#6
└─TableReader 10000.00 root data:TableFullScan
└─TableFullScan 10000.00 cop[tikv] table:t keep order:true, stats:pseudo
explain format = 'brief' select group_concat(a, b) from t group by id;
id estRows task access object operator info
StreamAgg 8000.00 root group by:Column#7, funcs:group_concat(Column#5, Column#6 separator ",")->Column#4
└─Projection 10000.00 root cast(test.t.a, var_string(20))->Column#5, cast(test.t.b, var_string(20))->Column#6, test.t.id
└─Projection 10000.00 root cast(test.t.a, var_string(20))->Column#5, cast(test.t.b, var_string(20))->Column#6, test.t.id->Column#7
└─TableReader 10000.00 root data:TableFullScan
└─TableFullScan 10000.00 cop[tikv] table:t keep order:true, stats:pseudo
explain format = TRADITIONAL select group_concat(a, b) from t group by id;
id estRows task access object operator info
StreamAgg_8 8000.00 root group by:Column#7, funcs:group_concat(Column#5, Column#6 separator ",")->Column#4
└─Projection_18 10000.00 root cast(test.t.a, var_string(20))->Column#5, cast(test.t.b, var_string(20))->Column#6, test.t.id
└─Projection_18 10000.00 root cast(test.t.a, var_string(20))->Column#5, cast(test.t.b, var_string(20))->Column#6, test.t.id->Column#7
└─TableReader_15 10000.00 root data:TableFullScan_14
└─TableFullScan_14 10000.00 cop[tikv] table:t keep order:true, stats:pseudo
explain format = 'row' select group_concat(a, b) from t group by id;
id estRows task access object operator info
StreamAgg_8 8000.00 root group by:Column#7, funcs:group_concat(Column#5, Column#6 separator ",")->Column#4
└─Projection_18 10000.00 root cast(test.t.a, var_string(20))->Column#5, cast(test.t.b, var_string(20))->Column#6, test.t.id
└─Projection_18 10000.00 root cast(test.t.a, var_string(20))->Column#5, cast(test.t.b, var_string(20))->Column#6, test.t.id->Column#7
└─TableReader_15 10000.00 root data:TableFullScan_14
└─TableFullScan_14 10000.00 cop[tikv] table:t keep order:true, stats:pseudo
drop table t;
Expand Down
4 changes: 2 additions & 2 deletions cmd/explaintest/r/explain_complex.result
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ PRIMARY KEY (`aid`,`dic`)
);
explain format = 'brief' SELECT `ds`, `p1`, `p2`, `p3`, `p4`, `p5`, `p6_md5`, `p7_md5`, count(dic) as install_device FROM `dt` use index (cmi) WHERE (`ds` >= '2016-09-01') AND (`ds` <= '2016-11-03') AND (`cm` IN ('1062', '1086', '1423', '1424', '1425', '1426', '1427', '1428', '1429', '1430', '1431', '1432', '1433', '1434', '1435', '1436', '1437', '1438', '1439', '1440', '1441', '1442', '1443', '1444', '1445', '1446', '1447', '1448', '1449', '1450', '1451', '1452', '1488', '1489', '1490', '1491', '1492', '1493', '1494', '1495', '1496', '1497', '1550', '1551', '1552', '1553', '1554', '1555', '1556', '1557', '1558', '1559', '1597', '1598', '1599', '1600', '1601', '1602', '1603', '1604', '1605', '1606', '1607', '1608', '1609', '1610', '1611', '1612', '1613', '1614', '1615', '1616', '1623', '1624', '1625', '1626', '1627', '1628', '1629', '1630', '1631', '1632', '1709', '1719', '1720', '1843', '2813', '2814', '2815', '2816', '2817', '2818', '2819', '2820', '2821', '2822', '2823', '2824', '2825', '2826', '2827', '2828', '2829', '2830', '2831', '2832', '2833', '2834', '2835', '2836', '2837', '2838', '2839', '2840', '2841', '2842', '2843', '2844', '2845', '2846', '2847', '2848', '2849', '2850', '2851', '2852', '2853', '2854', '2855', '2856', '2857', '2858', '2859', '2860', '2861', '2862', '2863', '2864', '2865', '2866', '2867', '2868', '2869', '2870', '2871', '2872', '3139', '3140', '3141', '3142', '3143', '3144', '3145', '3146', '3147', '3148', '3149', '3150', '3151', '3152', '3153', '3154', '3155', '3156', '3157', '3158', '3386', '3387', '3388', '3389', '3390', '3391', '3392', '3393', '3394', '3395', '3664', '3665', '3666', '3667', '3668', '3670', '3671', '3672', '3673', '3674', '3676', '3677', '3678', '3679', '3680', '3681', '3682', '3683', '3684', '3685', '3686', '3687', '3688', '3689', '3690', '3691', '3692', '3693', '3694', '3695', '3696', '3697', '3698', '3699', '3700', '3701', '3702', '3703', '3704', '3705', '3706', '3707', '3708', '3709', '3710', '3711', '3712', '3713', '3714', '3715', '3960', '3961', '3962', '3963', '3964', '3965', '3966', '3967', '3968', '3978', '3979', '3980', '3981', '3982', '3983', '3984', '3985', '3986', '3987', '4208', '4209', '4210', '4211', '4212', '4304', '4305', '4306', '4307', '4308', '4866', '4867', '4868', '4869', '4870', '4871', '4872', '4873', '4874', '4875')) GROUP BY `ds`, `p1`, `p2`, `p3`, `p4`, `p5`, `p6_md5`, `p7_md5` ORDER BY `ds2` DESC;
id estRows task access object operator info
Projection 53.00 root test.dt.ds, test.dt.p1, test.dt.p2, test.dt.p3, test.dt.p4, test.dt.p5, test.dt.p6_md5, test.dt.p7_md5, Column#21
Projection 53.00 root test.dt.ds, test.dt.p1, test.dt.p2, test.dt.p3, test.dt.p4, test.dt.p5, test.dt.p6_md5, test.dt.p7_md5, Column#21->Column#30
└─Sort 53.00 root test.dt.ds2:desc
└─HashAgg 53.00 root group by:test.dt.ds, test.dt.p1, test.dt.p2, test.dt.p3, test.dt.p4, test.dt.p5, test.dt.p6_md5, test.dt.p7_md5, funcs:count(Column#32)->Column#21, funcs:firstrow(test.dt.ds)->test.dt.ds, funcs:firstrow(Column#34)->test.dt.ds2, funcs:firstrow(test.dt.p1)->test.dt.p1, funcs:firstrow(test.dt.p2)->test.dt.p2, funcs:firstrow(test.dt.p3)->test.dt.p3, funcs:firstrow(test.dt.p4)->test.dt.p4, funcs:firstrow(test.dt.p5)->test.dt.p5, funcs:firstrow(test.dt.p6_md5)->test.dt.p6_md5, funcs:firstrow(test.dt.p7_md5)->test.dt.p7_md5
└─IndexLookUp 53.00 root
Expand Down Expand Up @@ -183,7 +183,7 @@ CREATE TABLE `tbl_009` (`a` int, `b` int);
explain format = 'brief' select sum(a) from (select * from tbl_001 union all select * from tbl_002 union all select * from tbl_003 union all select * from tbl_004 union all select * from tbl_005 union all select * from tbl_006 union all select * from tbl_007 union all select * from tbl_008 union all select * from tbl_009) x group by b;
id estRows task access object operator info
HashAgg 72000.00 root group by:Column#32, funcs:sum(Column#31)->Column#30
└─Projection 90000.00 root cast(Column#28, decimal(10,0) BINARY)->Column#31, Column#29
└─Projection 90000.00 root cast(Column#28, decimal(10,0) BINARY)->Column#31, Column#29->Column#32
└─Union 90000.00 root
├─TableReader 10000.00 root data:TableFullScan
│ └─TableFullScan 10000.00 cop[tikv] table:tbl_001 keep order:false, stats:pseudo
Expand Down
Loading

0 comments on commit 6e3d0eb

Please sign in to comment.