diff --git a/cmd/explaintest/r/access_path_selection.result b/cmd/explaintest/r/access_path_selection.result index f66444389bf3c..6761099570558 100644 --- a/cmd/explaintest/r/access_path_selection.result +++ b/cmd/explaintest/r/access_path_selection.result @@ -38,7 +38,7 @@ StreamAgg_13 1.00 root funcs:max(Column#3) └─TableScan_25 1.25 cop[tikv] table:access_path_selection, range:[-inf,+inf], keep order:true, desc, stats:pseudo explain select count(1) from access_path_selection; id count task operator info -StreamAgg_28 1.00 root funcs:count(Column#19) +StreamAgg_28 1.00 root funcs:count(Column#18) └─TableReader_29 1.00 root data:StreamAgg_8 └─StreamAgg_8 1.00 cop[tikv] funcs:count(1) └─TableScan_24 10000.00 cop[tikv] table:access_path_selection, range:[-inf,+inf], keep order:false, stats:pseudo diff --git a/cmd/explaintest/r/access_tiflash.result b/cmd/explaintest/r/access_tiflash.result index 83ddb18eee8d5..f5bd4cace4dff 100644 --- a/cmd/explaintest/r/access_tiflash.result +++ b/cmd/explaintest/r/access_tiflash.result @@ -2,31 +2,31 @@ drop table if exists t, tt; create table t(a int, b int, index ia(a)); desc select avg(a) from t; id count task operator info -StreamAgg_20 1.00 root funcs:avg(Column#8, Column#9) +StreamAgg_20 1.00 root funcs:avg(Column#7, Column#8) └─IndexReader_21 1.00 root index:StreamAgg_8 └─StreamAgg_8 1.00 cop[tikv] funcs:avg(Column#1) └─IndexScan_19 10000.00 cop[tikv] table:t, index:a, range:[NULL,+inf], keep order:false, stats:pseudo desc select /*+ read_from_storage(tiflash[t]) */ avg(a) from t; id count task operator info -StreamAgg_16 1.00 root funcs:avg(Column#8, Column#9) +StreamAgg_16 1.00 root funcs:avg(Column#7, Column#8) └─TableReader_17 1.00 root data:StreamAgg_8 └─StreamAgg_8 1.00 cop[tiflash] funcs:count(Column#1), sum(Column#1) └─TableScan_15 10000.00 cop[tiflash] table:t, range:[-inf,+inf], keep order:false, stats:pseudo desc select /*+ read_from_storage(tiflash[t]) */ sum(a) from t; id count task operator info -StreamAgg_16 1.00 root funcs:sum(Column#7) +StreamAgg_16 1.00 root funcs:sum(Column#6) └─TableReader_17 1.00 root data:StreamAgg_8 └─StreamAgg_8 1.00 cop[tiflash] funcs:sum(Column#1) └─TableScan_15 10000.00 cop[tiflash] table:t, range:[-inf,+inf], keep order:false, stats:pseudo desc select /*+ read_from_storage(tiflash[t]) */ sum(a+1) from t; id count task operator info -StreamAgg_16 1.00 root funcs:sum(Column#7) +StreamAgg_16 1.00 root funcs:sum(Column#6) └─TableReader_17 1.00 root data:StreamAgg_8 └─StreamAgg_8 1.00 cop[tiflash] funcs:sum(plus(Column#1, 1)) └─TableScan_15 10000.00 cop[tiflash] table:t, range:[-inf,+inf], keep order:false, stats:pseudo desc select /*+ read_from_storage(tiflash[t]) */ sum(isnull(a)) from t; id count task operator info -StreamAgg_16 1.00 root funcs:sum(Column#7) +StreamAgg_16 1.00 root funcs:sum(Column#6) └─TableReader_17 1.00 root data:StreamAgg_8 └─StreamAgg_8 1.00 cop[tiflash] funcs:sum(isnull(Column#1)) └─TableScan_15 10000.00 cop[tiflash] table:t, range:[-inf,+inf], keep order:false, stats:pseudo diff --git a/cmd/explaintest/r/explain.result b/cmd/explaintest/r/explain.result index b3fba38ed2002..a4cc012e707b9 100644 --- a/cmd/explaintest/r/explain.result +++ b/cmd/explaintest/r/explain.result @@ -28,13 +28,13 @@ set session tidb_hashagg_partial_concurrency = 1; set session tidb_hashagg_final_concurrency = 1; explain select group_concat(a) from t group by id; id count task operator info -StreamAgg_8 8000.00 root group by:Column#7, funcs:group_concat(Column#6, ",") +StreamAgg_8 8000.00 root group by:Column#6, funcs:group_concat(Column#5, ",") └─Projection_18 10000.00 root cast(Column#2), Column#1 └─TableReader_15 10000.00 root data:TableScan_14 └─TableScan_14 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:true, stats:pseudo explain select group_concat(a, b) from t group by id; id count task operator info -StreamAgg_8 8000.00 root group by:Column#8, funcs:group_concat(Column#6, Column#7, ",") +StreamAgg_8 8000.00 root group by:Column#7, funcs:group_concat(Column#5, Column#6, ",") └─Projection_18 10000.00 root cast(Column#2), cast(Column#3), Column#1 └─TableReader_15 10000.00 root data:TableScan_14 └─TableScan_14 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:true, stats:pseudo diff --git a/cmd/explaintest/r/explain_complex.result b/cmd/explaintest/r/explain_complex.result index d5ea0dc8ede60..bc49cfa9e5de8 100644 --- a/cmd/explaintest/r/explain_complex.result +++ b/cmd/explaintest/r/explain_complex.result @@ -107,7 +107,7 @@ explain SELECT `ds`, `p1`, `p2`, `p3`, `p4`, `p5`, `p6_md5`, `p7_md5`, count(dic id count task operator info Projection_7 53.00 root Column#7, Column#11, Column#12, Column#13, Column#14, Column#15, Column#16, Column#17, Column#21 └─Sort_8 53.00 root Column#8:desc - └─HashAgg_16 53.00 root group by:Column#52, Column#53, Column#54, Column#55, Column#56, Column#57, Column#58, Column#59, funcs:count(Column#42), firstrow(Column#52), firstrow(Column#44), firstrow(Column#53), firstrow(Column#54), firstrow(Column#55), firstrow(Column#56), firstrow(Column#57), firstrow(Column#58), firstrow(Column#59) + └─HashAgg_16 53.00 root group by:Column#42, Column#43, Column#44, Column#45, Column#46, Column#47, Column#48, Column#49, funcs:count(Column#32), firstrow(Column#42), firstrow(Column#34), firstrow(Column#43), firstrow(Column#44), firstrow(Column#45), firstrow(Column#46), firstrow(Column#47), firstrow(Column#48), firstrow(Column#49) └─IndexLookUp_17 53.00 root ├─IndexScan_13 2650.00 cop[tikv] table:dt, index:cm, range:[1062,1062], [1086,1086], [1423,1423], [1424,1424], [1425,1425], [1426,1426], [1427,1427], [1428,1428], [1429,1429], [1430,1430], [1431,1431], [1432,1432], [1433,1433], [1434,1434], [1435,1435], [1436,1436], [1437,1437], [1438,1438], [1439,1439], [1440,1440], [1441,1441], [1442,1442], [1443,1443], [1444,1444], [1445,1445], [1446,1446], [1447,1447], [1448,1448], [1449,1449], [1450,1450], [1451,1451], [1452,1452], [1488,1488], [1489,1489], [1490,1490], [1491,1491], [1492,1492], [1493,1493], [1494,1494], [1495,1495], [1496,1496], [1497,1497], [1550,1550], [1551,1551], [1552,1552], [1553,1553], [1554,1554], [1555,1555], [1556,1556], [1557,1557], [1558,1558], [1559,1559], [1597,1597], [1598,1598], [1599,1599], [1600,1600], [1601,1601], [1602,1602], [1603,1603], [1604,1604], [1605,1605], [1606,1606], [1607,1607], [1608,1608], [1609,1609], [1610,1610], [1611,1611], [1612,1612], [1613,1613], [1614,1614], [1615,1615], [1616,1616], [1623,1623], [1624,1624], [1625,1625], [1626,1626], [1627,1627], [1628,1628], [1629,1629], [1630,1630], [1631,1631], [1632,1632], [1709,1709], [1719,1719], [1720,1720], [1843,1843], [2813,2813], [2814,2814], [2815,2815], [2816,2816], [2817,2817], [2818,2818], [2819,2819], [2820,2820], [2821,2821], [2822,2822], [2823,2823], [2824,2824], [2825,2825], [2826,2826], [2827,2827], [2828,2828], [2829,2829], [2830,2830], [2831,2831], [2832,2832], [2833,2833], [2834,2834], [2835,2835], [2836,2836], [2837,2837], [2838,2838], [2839,2839], [2840,2840], [2841,2841], [2842,2842], [2843,2843], [2844,2844], [2845,2845], [2846,2846], [2847,2847], [2848,2848], [2849,2849], [2850,2850], [2851,2851], [2852,2852], [2853,2853], [2854,2854], [2855,2855], [2856,2856], [2857,2857], [2858,2858], [2859,2859], [2860,2860], [2861,2861], [2862,2862], [2863,2863], [2864,2864], [2865,2865], [2866,2866], [2867,2867], [2868,2868], [2869,2869], [2870,2870], [2871,2871], [2872,2872], [3139,3139], [3140,3140], [3141,3141], [3142,3142], [3143,3143], [3144,3144], [3145,3145], [3146,3146], [3147,3147], [3148,3148], [3149,3149], [3150,3150], [3151,3151], [3152,3152], [3153,3153], [3154,3154], [3155,3155], [3156,3156], [3157,3157], [3158,3158], [3386,3386], [3387,3387], [3388,3388], [3389,3389], [3390,3390], [3391,3391], [3392,3392], [3393,3393], [3394,3394], [3395,3395], [3664,3664], [3665,3665], [3666,3666], [3667,3667], [3668,3668], [3670,3670], [3671,3671], [3672,3672], [3673,3673], [3674,3674], [3676,3676], [3677,3677], [3678,3678], [3679,3679], [3680,3680], [3681,3681], [3682,3682], [3683,3683], [3684,3684], [3685,3685], [3686,3686], [3687,3687], [3688,3688], [3689,3689], [3690,3690], [3691,3691], [3692,3692], [3693,3693], [3694,3694], [3695,3695], [3696,3696], [3697,3697], [3698,3698], [3699,3699], [3700,3700], [3701,3701], [3702,3702], [3703,3703], [3704,3704], [3705,3705], [3706,3706], [3707,3707], [3708,3708], [3709,3709], [3710,3710], [3711,3711], [3712,3712], [3713,3713], [3714,3714], [3715,3715], [3960,3960], [3961,3961], [3962,3962], [3963,3963], [3964,3964], [3965,3965], [3966,3966], [3967,3967], [3968,3968], [3978,3978], [3979,3979], [3980,3980], [3981,3981], [3982,3982], [3983,3983], [3984,3984], [3985,3985], [3986,3986], [3987,3987], [4208,4208], [4209,4209], [4210,4210], [4211,4211], [4212,4212], [4304,4304], [4305,4305], [4306,4306], [4307,4307], [4308,4308], [4866,4866], [4867,4867], [4868,4868], [4869,4869], [4870,4870], [4871,4871], [4872,4872], [4873,4873], [4874,4874], [4875,4875], keep order:false, stats:pseudo └─HashAgg_11 53.00 cop[tikv] group by:Column#11, Column#12, Column#13, Column#14, Column#15, Column#16, Column#17, Column#7, funcs:count(Column#5), firstrow(Column#8) @@ -179,8 +179,8 @@ CREATE TABLE `tbl_008` (`a` int, `b` int); CREATE TABLE `tbl_009` (`a` int, `b` int); explain 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 count task operator info -HashAgg_34 72000.00 root group by:Column#51, funcs:sum(Column#50) -└─Projection_63 90000.00 root cast(Column#46), Column#47 +HashAgg_34 72000.00 root group by:Column#32, funcs:sum(Column#31) +└─Projection_63 90000.00 root cast(Column#28), Column#29 └─Union_35 90000.00 root ├─TableReader_38 10000.00 root data:TableScan_37 │ └─TableScan_37 10000.00 cop[tikv] table:tbl_001, range:[-inf,+inf], keep order:false, stats:pseudo @@ -242,7 +242,7 @@ UNIQUE KEY org_employee_position_pk (hotel_id,user_id,position_id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; explain SELECT d.id, d.ctx, d.name, d.left_value, d.right_value, d.depth, d.leader_id, d.status, d.created_on, d.updated_on FROM org_department AS d LEFT JOIN org_position AS p ON p.department_id = d.id AND p.status = 1000 LEFT JOIN org_employee_position AS ep ON ep.position_id = p.id AND ep.status = 1000 WHERE (d.ctx = 1 AND (ep.user_id = 62 OR d.id = 20 OR d.id = 20) AND d.status = 1000) GROUP BY d.id ORDER BY d.left_value; id count task operator info -Sort_10 1.00 root Column#31:asc +Sort_10 1.00 root Column#4:asc └─HashAgg_15 1.00 root group by:Column#1, funcs:firstrow(Column#1), firstrow(Column#2), firstrow(Column#3), firstrow(Column#4), firstrow(Column#5), firstrow(Column#6), firstrow(Column#7), firstrow(Column#8), firstrow(Column#9), firstrow(Column#10) └─Selection_22 0.01 root or(eq(Column#22, 62), or(eq(Column#1, 20), eq(Column#1, 20))) └─HashLeftJoin_24 0.02 root left outer join, inner:IndexMergeJoin_40 (REVERSED), equal:[eq(Column#11, Column#23)] diff --git a/cmd/explaintest/r/explain_complex_stats.result b/cmd/explaintest/r/explain_complex_stats.result index 6b996c44cd352..4685cc996d7b1 100644 --- a/cmd/explaintest/r/explain_complex_stats.result +++ b/cmd/explaintest/r/explain_complex_stats.result @@ -117,7 +117,7 @@ explain SELECT ds, p1, p2, p3, p4, p5, p6_md5, p7_md5, count(dic) as install_dev id count task operator info Projection_7 21.53 root Column#7, Column#11, Column#12, Column#13, Column#14, Column#15, Column#16, Column#17, Column#21 └─Sort_8 21.53 root Column#8:desc - └─HashAgg_16 21.53 root group by:Column#52, Column#53, Column#54, Column#55, Column#56, Column#57, Column#58, Column#59, funcs:count(Column#42), firstrow(Column#52), firstrow(Column#44), firstrow(Column#53), firstrow(Column#54), firstrow(Column#55), firstrow(Column#56), firstrow(Column#57), firstrow(Column#58), firstrow(Column#59) + └─HashAgg_16 21.53 root group by:Column#42, Column#43, Column#44, Column#45, Column#46, Column#47, Column#48, Column#49, funcs:count(Column#32), firstrow(Column#42), firstrow(Column#34), firstrow(Column#43), firstrow(Column#44), firstrow(Column#45), firstrow(Column#46), firstrow(Column#47), firstrow(Column#48), firstrow(Column#49) └─IndexLookUp_17 21.53 root ├─IndexScan_13 128.32 cop[tikv] table:dt, index:cm, range:[1062,1062], [1086,1086], [1423,1423], [1424,1424], [1425,1425], [1426,1426], [1427,1427], [1428,1428], [1429,1429], [1430,1430], [1431,1431], [1432,1432], [1433,1433], [1434,1434], [1435,1435], [1436,1436], [1437,1437], [1438,1438], [1439,1439], [1440,1440], [1441,1441], [1442,1442], [1443,1443], [1444,1444], [1445,1445], [1446,1446], [1447,1447], [1448,1448], [1449,1449], [1450,1450], [1451,1451], [1452,1452], [1488,1488], [1489,1489], [1490,1490], [1491,1491], [1492,1492], [1493,1493], [1494,1494], [1495,1495], [1496,1496], [1497,1497], [1550,1550], [1551,1551], [1552,1552], [1553,1553], [1554,1554], [1555,1555], [1556,1556], [1557,1557], [1558,1558], [1559,1559], [1597,1597], [1598,1598], [1599,1599], [1600,1600], [1601,1601], [1602,1602], [1603,1603], [1604,1604], [1605,1605], [1606,1606], [1607,1607], [1608,1608], [1609,1609], [1610,1610], [1611,1611], [1612,1612], [1613,1613], [1614,1614], [1615,1615], [1616,1616], [1623,1623], [1624,1624], [1625,1625], [1626,1626], [1627,1627], [1628,1628], [1629,1629], [1630,1630], [1631,1631], [1632,1632], [1709,1709], [1719,1719], [1720,1720], [1843,1843], [2813,2813], [2814,2814], [2815,2815], [2816,2816], [2817,2817], [2818,2818], [2819,2819], [2820,2820], [2821,2821], [2822,2822], [2823,2823], [2824,2824], [2825,2825], [2826,2826], [2827,2827], [2828,2828], [2829,2829], [2830,2830], [2831,2831], [2832,2832], [2833,2833], [2834,2834], [2835,2835], [2836,2836], [2837,2837], [2838,2838], [2839,2839], [2840,2840], [2841,2841], [2842,2842], [2843,2843], [2844,2844], [2845,2845], [2846,2846], [2847,2847], [2848,2848], [2849,2849], [2850,2850], [2851,2851], [2852,2852], [2853,2853], [2854,2854], [2855,2855], [2856,2856], [2857,2857], [2858,2858], [2859,2859], [2860,2860], [2861,2861], [2862,2862], [2863,2863], [2864,2864], [2865,2865], [2866,2866], [2867,2867], [2868,2868], [2869,2869], [2870,2870], [2871,2871], [2872,2872], [3139,3139], [3140,3140], [3141,3141], [3142,3142], [3143,3143], [3144,3144], [3145,3145], [3146,3146], [3147,3147], [3148,3148], [3149,3149], [3150,3150], [3151,3151], [3152,3152], [3153,3153], [3154,3154], [3155,3155], [3156,3156], [3157,3157], [3158,3158], [3386,3386], [3387,3387], [3388,3388], [3389,3389], [3390,3390], [3391,3391], [3392,3392], [3393,3393], [3394,3394], [3395,3395], [3664,3664], [3665,3665], [3666,3666], [3667,3667], [3668,3668], [3670,3670], [3671,3671], [3672,3672], [3673,3673], [3674,3674], [3676,3676], [3677,3677], [3678,3678], [3679,3679], [3680,3680], [3681,3681], [3682,3682], [3683,3683], [3684,3684], [3685,3685], [3686,3686], [3687,3687], [3688,3688], [3689,3689], [3690,3690], [3691,3691], [3692,3692], [3693,3693], [3694,3694], [3695,3695], [3696,3696], [3697,3697], [3698,3698], [3699,3699], [3700,3700], [3701,3701], [3702,3702], [3703,3703], [3704,3704], [3705,3705], [3706,3706], [3707,3707], [3708,3708], [3709,3709], [3710,3710], [3711,3711], [3712,3712], [3713,3713], [3714,3714], [3715,3715], [3960,3960], [3961,3961], [3962,3962], [3963,3963], [3964,3964], [3965,3965], [3966,3966], [3967,3967], [3968,3968], [3978,3978], [3979,3979], [3980,3980], [3981,3981], [3982,3982], [3983,3983], [3984,3984], [3985,3985], [3986,3986], [3987,3987], [4208,4208], [4209,4209], [4210,4210], [4211,4211], [4212,4212], [4304,4304], [4305,4305], [4306,4306], [4307,4307], [4308,4308], [4866,4866], [4867,4867], [4868,4868], [4869,4869], [4870,4870], [4871,4871], [4872,4872], [4873,4873], [4874,4874], [4875,4875], keep order:false └─HashAgg_11 21.53 cop[tikv] group by:Column#11, Column#12, Column#13, Column#14, Column#15, Column#16, Column#17, Column#7, funcs:count(Column#5), firstrow(Column#8) @@ -205,8 +205,8 @@ CREATE TABLE tbl_009 (a int, b int); load stats 's/explain_complex_stats_tbl_009.json'; explain 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 count task operator info -HashAgg_34 18000.00 root group by:Column#51, funcs:sum(Column#50) -└─Projection_63 18000.00 root cast(Column#46), Column#47 +HashAgg_34 18000.00 root group by:Column#32, funcs:sum(Column#31) +└─Projection_63 18000.00 root cast(Column#28), Column#29 └─Union_35 18000.00 root ├─TableReader_38 2000.00 root data:TableScan_37 │ └─TableScan_37 2000.00 cop[tikv] table:tbl_001, range:[-inf,+inf], keep order:false diff --git a/cmd/explaintest/r/explain_easy.result b/cmd/explaintest/r/explain_easy.result index 9c2273719aba0..e5aedf3360823 100644 --- a/cmd/explaintest/r/explain_easy.result +++ b/cmd/explaintest/r/explain_easy.result @@ -12,11 +12,11 @@ set @@session.tidb_hashagg_final_concurrency = 1; explain select * from t3 where exists (select s.a from t3 s having sum(s.a) = t3.a ); id count task operator info Projection_11 8000.00 root Column#1, Column#2, Column#3, Column#4 -└─HashLeftJoin_12 8000.00 root semi join, inner:StreamAgg_27, equal:[eq(Column#19, Column#11)] +└─HashLeftJoin_12 8000.00 root semi join, inner:StreamAgg_27, equal:[eq(Column#13, Column#11)] ├─Projection_13 10000.00 root Column#1, Column#2, Column#3, Column#4, cast(Column#1) │ └─TableReader_15 10000.00 root data:TableScan_14 │ └─TableScan_14 10000.00 cop[tikv] table:t3, range:[-inf,+inf], keep order:false, stats:pseudo - └─StreamAgg_27 1.00 root funcs:sum(Column#22) + └─StreamAgg_27 1.00 root funcs:sum(Column#16) └─TableReader_28 1.00 root data:StreamAgg_19 └─StreamAgg_19 1.00 cop[tikv] funcs:sum(Column#6) └─TableScan_26 10000.00 cop[tikv] table:s, range:[-inf,+inf], keep order:false, stats:pseudo @@ -31,7 +31,7 @@ IndexLookUp_12 10000.00 root └─TableScan_11 10000.00 cop[tikv] table:t1, keep order:false, stats:pseudo explain select * from t2 order by c2; id count task operator info -Sort_4 10000.00 root Column#5:asc +Sort_4 10000.00 root Column#2:asc └─TableReader_8 10000.00 root data:TableScan_7 └─TableScan_7 10000.00 cop[tikv] table:t2, range:[-inf,+inf], keep order:false, stats:pseudo explain select * from t1 where t1.c1 > 0; @@ -62,11 +62,11 @@ Delete_4 N/A root N/A └─TableScan_10 10.00 cop[tikv] table:t1, keep order:false, stats:pseudo explain select count(b.c2) from t1 a, t2 b where a.c1 = b.c2 group by a.c1; id count task operator info -Projection_11 9990.00 root cast(Column#9) +Projection_11 9990.00 root cast(Column#8) └─HashLeftJoin_21 9990.00 root inner join, inner:HashAgg_28, equal:[eq(Column#1, Column#5)] ├─TableReader_34 10000.00 root data:TableScan_33 │ └─TableScan_33 10000.00 cop[tikv] table:a, range:[-inf,+inf], keep order:false, stats:pseudo - └─HashAgg_28 7992.00 root group by:Column#12, funcs:count(Column#10), firstrow(Column#12) + └─HashAgg_28 7992.00 root group by:Column#11, funcs:count(Column#9), firstrow(Column#11) └─TableReader_29 7992.00 root data:HashAgg_23 └─HashAgg_23 7992.00 cop[tikv] group by:Column#5, funcs:count(Column#5) └─Selection_27 9990.00 cop[tikv] not(isnull(Column#5)) @@ -90,8 +90,8 @@ TableReader_7 0.33 root data:Selection_6 └─TableScan_5 1.00 cop[tikv] table:t1, range:[1,1], keep order:false, stats:pseudo explain select sum(t1.c1 in (select c1 from t2)) from t1; id count task operator info -StreamAgg_12 1.00 root funcs:sum(Column#12) -└─Projection_23 10000.00 root cast(Column#8) +StreamAgg_12 1.00 root funcs:sum(Column#10) +└─Projection_23 10000.00 root cast(Column#7) └─HashLeftJoin_22 10000.00 root CARTESIAN left outer semi join, inner:IndexReader_21, other cond:eq(Column#1, Column#4) ├─TableReader_15 10000.00 root data:TableScan_14 │ └─TableScan_14 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false, stats:pseudo @@ -163,24 +163,24 @@ TableReader_5 10000.00 root data:TableScan_4 explain select c1 from t2 union select c1 from t2 union all select c1 from t2; id count task operator info Union_17 26000.00 root -├─HashAgg_21 16000.00 root group by:Column#13, funcs:firstrow(Column#15) +├─HashAgg_21 16000.00 root group by:Column#10, funcs:firstrow(Column#12) │ └─Union_22 16000.00 root -│ ├─StreamAgg_27 8000.00 root group by:Column#9, funcs:firstrow(Column#9), firstrow(Column#9) +│ ├─StreamAgg_27 8000.00 root group by:Column#7, funcs:firstrow(Column#7), firstrow(Column#7) │ │ └─IndexReader_40 10000.00 root index:IndexScan_39 │ │ └─IndexScan_39 10000.00 cop[tikv] table:t2, index:c1, range:[NULL,+inf], keep order:true, stats:pseudo -│ └─StreamAgg_45 8000.00 root group by:Column#5, funcs:firstrow(Column#5), firstrow(Column#5) +│ └─StreamAgg_45 8000.00 root group by:Column#4, funcs:firstrow(Column#4), firstrow(Column#4) │ └─IndexReader_58 10000.00 root index:IndexScan_57 │ └─IndexScan_57 10000.00 cop[tikv] table:t2, index:c1, range:[NULL,+inf], keep order:true, stats:pseudo └─IndexReader_63 10000.00 root index:IndexScan_62 └─IndexScan_62 10000.00 cop[tikv] table:t2, index:c1, range:[NULL,+inf], keep order:false, stats:pseudo explain select c1 from t2 union all select c1 from t2 union select c1 from t2; id count task operator info -HashAgg_18 24000.00 root group by:Column#13, funcs:firstrow(Column#14) +HashAgg_18 24000.00 root group by:Column#10, funcs:firstrow(Column#11) └─Union_19 24000.00 root - ├─StreamAgg_24 8000.00 root group by:Column#9, funcs:firstrow(Column#9), firstrow(Column#9) + ├─StreamAgg_24 8000.00 root group by:Column#7, funcs:firstrow(Column#7), firstrow(Column#7) │ └─IndexReader_37 10000.00 root index:IndexScan_36 │ └─IndexScan_36 10000.00 cop[tikv] table:t2, index:c1, range:[NULL,+inf], keep order:true, stats:pseudo - ├─StreamAgg_42 8000.00 root group by:Column#5, funcs:firstrow(Column#5), firstrow(Column#5) + ├─StreamAgg_42 8000.00 root group by:Column#4, funcs:firstrow(Column#4), firstrow(Column#4) │ └─IndexReader_55 10000.00 root index:IndexScan_54 │ └─IndexScan_54 10000.00 cop[tikv] table:t2, index:c1, range:[NULL,+inf], keep order:true, stats:pseudo └─StreamAgg_60 8000.00 root group by:Column#1, funcs:firstrow(Column#1), firstrow(Column#1) @@ -189,7 +189,7 @@ HashAgg_18 24000.00 root group by:Column#13, funcs:firstrow(Column#14) explain select count(1) from (select count(1) from (select * from t1 where c3 = 100) k) k2; id count task operator info StreamAgg_13 1.00 root funcs:count(1) -└─StreamAgg_28 1.00 root funcs:firstrow(Column#13) +└─StreamAgg_28 1.00 root funcs:firstrow(Column#8) └─TableReader_29 1.00 root data:StreamAgg_17 └─StreamAgg_17 1.00 cop[tikv] funcs:firstrow(1) └─Selection_27 10.00 cop[tikv] eq(Column#3, 100) @@ -197,14 +197,14 @@ StreamAgg_13 1.00 root funcs:count(1) explain select 1 from (select count(c2), count(c3) from t1) k; id count task operator info Projection_5 1.00 root 1 -└─StreamAgg_21 1.00 root funcs:firstrow(Column#15) +└─StreamAgg_21 1.00 root funcs:firstrow(Column#13) └─TableReader_22 1.00 root data:StreamAgg_9 └─StreamAgg_9 1.00 cop[tikv] funcs:firstrow(1) └─TableScan_19 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false, stats:pseudo explain select count(1) from (select max(c2), count(c3) as m from t1) k; id count task operator info StreamAgg_11 1.00 root funcs:count(1) -└─StreamAgg_27 1.00 root funcs:firstrow(Column#15) +└─StreamAgg_27 1.00 root funcs:firstrow(Column#12) └─TableReader_28 1.00 root data:StreamAgg_15 └─StreamAgg_15 1.00 cop[tikv] funcs:firstrow(1) └─TableScan_25 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false, stats:pseudo @@ -217,8 +217,8 @@ StreamAgg_11 1.00 root funcs:count(1) set @@session.tidb_opt_insubq_to_join_and_agg=0; explain select sum(t1.c1 in (select c1 from t2)) from t1; id count task operator info -StreamAgg_12 1.00 root funcs:sum(Column#12) -└─Projection_23 10000.00 root cast(Column#8) +StreamAgg_12 1.00 root funcs:sum(Column#10) +└─Projection_23 10000.00 root cast(Column#7) └─HashLeftJoin_22 10000.00 root CARTESIAN left outer semi join, inner:IndexReader_21, other cond:eq(Column#1, Column#4) ├─TableReader_15 10000.00 root data:TableScan_14 │ └─TableScan_14 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false, stats:pseudo @@ -226,7 +226,7 @@ StreamAgg_12 1.00 root funcs:sum(Column#12) └─IndexScan_20 10000.00 cop[tikv] table:t2, index:c1, range:[NULL,+inf], keep order:false, stats:pseudo explain select 1 in (select c2 from t2) from t1; id count task operator info -Projection_6 10000.00 root Column#8 +Projection_6 10000.00 root Column#7 └─HashLeftJoin_7 10000.00 root CARTESIAN left outer semi join, inner:TableReader_14 ├─TableReader_9 10000.00 root data:TableScan_8 │ └─TableScan_8 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false, stats:pseudo @@ -235,8 +235,8 @@ Projection_6 10000.00 root Column#8 └─TableScan_12 10000.00 cop[tikv] table:t2, range:[-inf,+inf], keep order:false, stats:pseudo explain select sum(6 in (select c2 from t2)) from t1; id count task operator info -StreamAgg_12 1.00 root funcs:sum(Column#12) -└─Projection_22 10000.00 root cast(Column#8) +StreamAgg_12 1.00 root funcs:sum(Column#10) +└─Projection_22 10000.00 root cast(Column#7) └─HashLeftJoin_21 10000.00 root CARTESIAN left outer semi join, inner:TableReader_20 ├─TableReader_15 10000.00 root data:TableScan_14 │ └─TableScan_14 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false, stats:pseudo @@ -305,7 +305,7 @@ drop table if exists t; create table t(a int primary key, b int, c int, index idx(b)); explain select t.c in (select count(*) from t s ignore index(idx), t t1 where s.a = t.a and s.a = t1.a) from t; id count task operator info -Projection_11 10000.00 root Column#12 +Projection_11 10000.00 root Column#11 └─Apply_13 10000.00 root CARTESIAN left outer semi join, inner:StreamAgg_20, other cond:eq(Column#3, Column#10) ├─TableReader_15 10000.00 root data:TableScan_14 │ └─TableScan_14 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo @@ -317,7 +317,7 @@ Projection_11 10000.00 root Column#12 └─TableScan_48 1.00 cop[tikv] table:t1, range: decided by [eq(Column#7, Column#1)], keep order:true, stats:pseudo explain select t.c in (select count(*) from t s use index(idx), t t1 where s.b = t.a and s.a = t1.a) from t; id count task operator info -Projection_11 10000.00 root Column#12 +Projection_11 10000.00 root Column#11 └─Apply_13 10000.00 root CARTESIAN left outer semi join, inner:StreamAgg_20, other cond:eq(Column#3, Column#10) ├─TableReader_15 10000.00 root data:TableScan_14 │ └─TableScan_14 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo @@ -329,7 +329,7 @@ Projection_11 10000.00 root Column#12 └─TableScan_41 1.00 cop[tikv] table:t1, range: decided by [Column#4], keep order:true, stats:pseudo explain select t.c in (select count(*) from t s use index(idx), t t1 where s.b = t.a and s.c = t1.a) from t; id count task operator info -Projection_11 10000.00 root Column#12 +Projection_11 10000.00 root Column#11 └─Apply_13 10000.00 root CARTESIAN left outer semi join, inner:StreamAgg_20, other cond:eq(Column#3, Column#10) ├─TableReader_15 10000.00 root data:TableScan_14 │ └─TableScan_14 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo @@ -345,7 +345,7 @@ insert into t values(1, 1, 1), (2, 2 ,2), (3, 3, 3), (4, 3, 4),(5,3,5); analyze table t; explain select t.c in (select count(*) from t s, t t1 where s.b = t.a and s.b = 3 and s.a = t1.a) from t; id count task operator info -Projection_11 5.00 root Column#12 +Projection_11 5.00 root Column#11 └─Apply_13 5.00 root CARTESIAN left outer semi join, inner:StreamAgg_20, other cond:eq(Column#3, Column#10) ├─TableReader_15 5.00 root data:TableScan_14 │ └─TableScan_14 5.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false @@ -359,7 +359,7 @@ Projection_11 5.00 root Column#12 └─TableScan_39 5.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:true explain select t.c in (select count(*) from t s left join t t1 on s.a = t1.a where 3 = t.a and s.b = 3) from t; id count task operator info -Projection_10 5.00 root Column#12 +Projection_10 5.00 root Column#11 └─Apply_12 5.00 root CARTESIAN left outer semi join, inner:StreamAgg_19, other cond:eq(Column#3, Column#10) ├─TableReader_14 5.00 root data:TableScan_13 │ └─TableScan_13 5.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false @@ -373,7 +373,7 @@ Projection_10 5.00 root Column#12 └─TableScan_38 5.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:true explain select t.c in (select count(*) from t s right join t t1 on s.a = t1.a where 3 = t.a and t1.b = 3) from t; id count task operator info -Projection_10 5.00 root Column#12 +Projection_10 5.00 root Column#11 └─Apply_12 5.00 root CARTESIAN left outer semi join, inner:StreamAgg_19, other cond:eq(Column#3, Column#10) ├─TableReader_14 5.00 root data:TableScan_13 │ └─TableScan_13 5.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false @@ -551,16 +551,16 @@ HashRightJoin_9 4166.67 root inner join, inner:TableReader_12, equal:[eq(Column# └─TableScan_13 10000.00 cop[tikv] table:tb, range:[-inf,+inf], keep order:false, stats:pseudo explain select ifnull(t.nc, 1) in (select count(*) from t s , t t1 where s.a = t.a and s.a = t1.a) from t; id count task operator info -Projection_12 10000.00 root Column#15 +Projection_12 10000.00 root Column#14 └─Apply_14 10000.00 root CARTESIAN left outer semi join, inner:HashAgg_19, other cond:eq(Column#3, Column#13) ├─TableReader_16 10000.00 root data:TableScan_15 │ └─TableScan_15 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo - └─HashAgg_19 1.00 root funcs:count(Column#17) + └─HashAgg_19 1.00 root funcs:count(Column#15) └─HashLeftJoin_20 9.99 root inner join, inner:HashAgg_30, equal:[eq(Column#5, Column#9)] ├─TableReader_24 9.99 root data:Selection_23 │ └─Selection_23 9.99 cop[tikv] eq(Column#5, Column#1), not(isnull(Column#5)) │ └─TableScan_22 10000.00 cop[tikv] table:s, range:[-inf,+inf], keep order:false, stats:pseudo - └─HashAgg_30 7.99 root group by:Column#20, funcs:count(Column#18), firstrow(Column#20) + └─HashAgg_30 7.99 root group by:Column#18, funcs:count(Column#16), firstrow(Column#18) └─TableReader_31 7.99 root data:HashAgg_25 └─HashAgg_25 7.99 cop[tikv] group by:Column#9, funcs:count(1) └─Selection_29 9.99 cop[tikv] eq(Column#9, Column#1), not(isnull(Column#9)) @@ -584,16 +584,16 @@ HashRightJoin_7 8000.00 root right outer join, inner:TableReader_11, equal:[eq(C └─TableScan_12 10000.00 cop[tikv] table:tb, range:[-inf,+inf], keep order:false, stats:pseudo explain select ifnull(t.a, 1) in (select count(*) from t s , t t1 where s.a = t.a and s.a = t1.a) from t; id count task operator info -Projection_12 10000.00 root Column#15 +Projection_12 10000.00 root Column#14 └─Apply_14 10000.00 root CARTESIAN left outer semi join, inner:HashAgg_19, other cond:eq(ifnull(Column#1, 1), Column#13) ├─TableReader_16 10000.00 root data:TableScan_15 │ └─TableScan_15 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo - └─HashAgg_19 1.00 root funcs:count(Column#17) + └─HashAgg_19 1.00 root funcs:count(Column#15) └─HashLeftJoin_20 9.99 root inner join, inner:HashAgg_30, equal:[eq(Column#5, Column#9)] ├─TableReader_24 9.99 root data:Selection_23 │ └─Selection_23 9.99 cop[tikv] eq(Column#5, Column#1), not(isnull(Column#5)) │ └─TableScan_22 10000.00 cop[tikv] table:s, range:[-inf,+inf], keep order:false, stats:pseudo - └─HashAgg_30 7.99 root group by:Column#20, funcs:count(Column#18), firstrow(Column#20) + └─HashAgg_30 7.99 root group by:Column#18, funcs:count(Column#16), firstrow(Column#18) └─TableReader_31 7.99 root data:HashAgg_25 └─HashAgg_25 7.99 cop[tikv] group by:Column#9, funcs:count(1) └─Selection_29 9.99 cop[tikv] eq(Column#9, Column#1), not(isnull(Column#9)) @@ -623,12 +623,12 @@ drop table if exists t; create table t(a int, b int, c int); explain select * from (select * from t order by (select 2)) t order by a, b; id count task operator info -Sort_12 10000.00 root Column#9:asc, Column#10:asc +Sort_12 10000.00 root Column#1:asc, Column#2:asc └─TableReader_18 10000.00 root data:TableScan_17 └─TableScan_17 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo explain select * from (select * from t order by c) t order by a, b; id count task operator info -Sort_6 10000.00 root Column#8:asc, Column#9:asc +Sort_6 10000.00 root Column#1:asc, Column#2:asc └─Sort_9 10000.00 root Column#3:asc └─TableReader_12 10000.00 root data:TableScan_11 └─TableScan_11 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo @@ -715,7 +715,7 @@ create table t(a int, b int); explain select a, b from (select a, b, avg(b) over (partition by a)as avg_b from t) as tt where a > 10 and b < 10 and a > avg_b; id count task operator info Projection_8 2666.67 root Column#1, Column#2 -└─Selection_9 2666.67 root gt(cast(Column#1), Column#7), lt(Column#2, 10) +└─Selection_9 2666.67 root gt(cast(Column#1), Column#5), lt(Column#2, 10) └─Window_10 3333.33 root avg(cast(Column#2)) over(partition by Column#1) └─Sort_14 3333.33 root Column#1:asc └─TableReader_13 3333.33 root data:Selection_12 diff --git a/cmd/explaintest/r/explain_easy_stats.result b/cmd/explaintest/r/explain_easy_stats.result index d379349559627..8857754ae38b2 100644 --- a/cmd/explaintest/r/explain_easy_stats.result +++ b/cmd/explaintest/r/explain_easy_stats.result @@ -15,11 +15,11 @@ set @@session.tidb_hashagg_final_concurrency = 1; explain select * from t3 where exists (select s.a from t3 s having sum(s.a) = t3.a ); id count task operator info Projection_11 1600.00 root Column#1, Column#2, Column#3, Column#4 -└─HashLeftJoin_12 1600.00 root semi join, inner:StreamAgg_27, equal:[eq(Column#19, Column#11)] +└─HashLeftJoin_12 1600.00 root semi join, inner:StreamAgg_27, equal:[eq(Column#13, Column#11)] ├─Projection_13 2000.00 root Column#1, Column#2, Column#3, Column#4, cast(Column#1) │ └─TableReader_15 2000.00 root data:TableScan_14 │ └─TableScan_14 2000.00 cop[tikv] table:t3, range:[-inf,+inf], keep order:false - └─StreamAgg_27 1.00 root funcs:sum(Column#22) + └─StreamAgg_27 1.00 root funcs:sum(Column#16) └─TableReader_28 1.00 root data:StreamAgg_19 └─StreamAgg_19 1.00 cop[tikv] funcs:sum(Column#6) └─TableScan_26 2000.00 cop[tikv] table:s, range:[-inf,+inf], keep order:false @@ -34,7 +34,7 @@ IndexLookUp_12 1999.00 root └─TableScan_11 1999.00 cop[tikv] table:t1, keep order:false explain select * from t2 order by c2; id count task operator info -Sort_4 1985.00 root Column#5:asc +Sort_4 1985.00 root Column#2:asc └─TableReader_8 1985.00 root data:TableScan_7 └─TableScan_7 1985.00 cop[tikv] table:t2, range:[-inf,+inf], keep order:false explain select * from t1 where t1.c1 > 0; @@ -65,7 +65,7 @@ Delete_4 N/A root N/A └─TableScan_10 0.00 cop[tikv] table:t1, keep order:false explain select count(b.c2) from t1 a, t2 b where a.c1 = b.c2 group by a.c1; id count task operator info -Projection_11 1985.00 root cast(Column#9) +Projection_11 1985.00 root cast(Column#8) └─HashLeftJoin_21 1985.00 root inner join, inner:HashAgg_25, equal:[eq(Column#1, Column#5)] ├─TableReader_34 1999.00 root data:TableScan_33 │ └─TableScan_33 1999.00 cop[tikv] table:a, range:[-inf,+inf], keep order:false @@ -123,7 +123,7 @@ Limit_10 1.00 root offset:0, count:1 set @@session.tidb_opt_insubq_to_join_and_agg=0; explain select 1 in (select c2 from t2) from t1; id count task operator info -Projection_6 1999.00 root Column#8 +Projection_6 1999.00 root Column#7 └─HashLeftJoin_7 1999.00 root CARTESIAN left outer semi join, inner:TableReader_14 ├─TableReader_9 1999.00 root data:TableScan_8 │ └─TableScan_8 1999.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false diff --git a/cmd/explaintest/r/select.result b/cmd/explaintest/r/select.result index 46308b4f4e9df..bf3ce77b2303a 100644 --- a/cmd/explaintest/r/select.result +++ b/cmd/explaintest/r/select.result @@ -256,7 +256,7 @@ drop table if exists t; create table t (a int, b int, c int, key idx(a, b, c)); explain select count(a) from t; id count task operator info -StreamAgg_20 1.00 root funcs:count(Column#14) +StreamAgg_20 1.00 root funcs:count(Column#13) └─TableReader_21 1.00 root data:StreamAgg_8 └─StreamAgg_8 1.00 cop[tikv] funcs:count(Column#1) └─TableScan_18 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo @@ -267,7 +267,7 @@ insert t values(0,0,0); explain select distinct b from t group by a; id count task operator info HashAgg_7 8000.00 root group by:Column#2, funcs:firstrow(Column#2) -└─StreamAgg_22 8000.00 root group by:Column#12, funcs:firstrow(Column#11) +└─StreamAgg_22 8000.00 root group by:Column#11, funcs:firstrow(Column#10) └─IndexReader_23 8000.00 root index:StreamAgg_11 └─StreamAgg_11 8000.00 cop[tikv] group by:Column#1, funcs:firstrow(Column#2) └─IndexScan_21 10000.00 cop[tikv] table:t, index:a, b, c, range:[NULL,+inf], keep order:true, stats:pseudo @@ -276,7 +276,7 @@ b 0 explain select count(b) from t group by a; id count task operator info -StreamAgg_19 8000.00 root group by:Column#13, funcs:count(Column#12) +StreamAgg_19 8000.00 root group by:Column#12, funcs:count(Column#11) └─IndexReader_20 8000.00 root index:StreamAgg_8 └─StreamAgg_8 8000.00 cop[tikv] group by:Column#1, funcs:count(Column#2) └─IndexScan_18 10000.00 cop[tikv] table:t, index:a, b, c, range:[NULL,+inf], keep order:true, stats:pseudo @@ -286,7 +286,7 @@ count(b) insert t values(1,1,1),(3,3,6),(3,2,5),(2,1,4),(1,1,3),(1,1,2); explain select count(a) from t where b>0 group by a, b; id count task operator info -StreamAgg_25 2666.67 root group by:Column#14, Column#15, funcs:count(Column#13) +StreamAgg_25 2666.67 root group by:Column#13, Column#14, funcs:count(Column#12) └─IndexReader_26 2666.67 root index:StreamAgg_9 └─StreamAgg_9 2666.67 cop[tikv] group by:Column#1, Column#2, funcs:count(Column#1) └─Selection_24 3333.33 cop[tikv] gt(Column#2, 0) @@ -300,7 +300,7 @@ count(a) explain select count(a) from t where b>0 group by a, b order by a; id count task operator info Projection_7 2666.67 root Column#5 -└─StreamAgg_36 2666.67 root group by:Column#23, Column#24, funcs:count(Column#21), firstrow(Column#23) +└─StreamAgg_36 2666.67 root group by:Column#21, Column#22, funcs:count(Column#19), firstrow(Column#21) └─IndexReader_37 2666.67 root index:StreamAgg_34 └─StreamAgg_34 2666.67 cop[tikv] group by:Column#1, Column#2, funcs:count(Column#1) └─Selection_28 3333.33 cop[tikv] gt(Column#2, 0) @@ -315,7 +315,7 @@ explain select count(a) from t where b>0 group by a, b order by a limit 1; id count task operator info Projection_9 1.00 root Column#5 └─Limit_15 1.00 root offset:0, count:1 - └─StreamAgg_44 1.00 root group by:Column#24, Column#25, funcs:count(Column#22), firstrow(Column#24) + └─StreamAgg_44 1.00 root group by:Column#22, Column#23, funcs:count(Column#20), firstrow(Column#22) └─IndexReader_45 1.00 root index:StreamAgg_40 └─StreamAgg_40 1.00 cop[tikv] group by:Column#1, Column#2, funcs:count(Column#1) └─Selection_43 1.25 cop[tikv] gt(Column#2, 0) @@ -382,21 +382,21 @@ drop table if exists t; create table t(a int, b int); explain select a != any (select a from t t2) from t t1; id count task operator info -Projection_8 10000.00 root and(or(or(gt(Column#9, 1), ne(Column#1, Column#8)), if(ne(Column#10, 0), NULL, 0)), and(ne(Column#11, 0), if(isnull(Column#1), NULL, 1))) +Projection_8 10000.00 root and(or(or(gt(Column#8, 1), ne(Column#1, Column#7)), if(ne(Column#9, 0), NULL, 0)), and(ne(Column#10, 0), if(isnull(Column#1), NULL, 1))) └─HashLeftJoin_9 10000.00 root CARTESIAN inner join, inner:StreamAgg_16 ├─TableReader_12 10000.00 root data:TableScan_11 │ └─TableScan_11 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false, stats:pseudo - └─StreamAgg_16 1.00 root funcs:firstrow(Column#15), count(distinct Column#16), sum(Column#17), count(1) + └─StreamAgg_16 1.00 root funcs:firstrow(Column#13), count(distinct Column#14), sum(Column#15), count(1) └─Projection_26 10000.00 root Column#4, Column#4, cast(isnull(Column#4)) └─TableReader_23 10000.00 root data:TableScan_22 └─TableScan_22 10000.00 cop[tikv] table:t2, range:[-inf,+inf], keep order:false, stats:pseudo explain select a = all (select a from t t2) from t t1; id count task operator info -Projection_8 10000.00 root or(and(and(le(Column#9, 1), eq(Column#1, Column#8)), if(ne(Column#10, 0), NULL, 1)), or(eq(Column#11, 0), if(isnull(Column#1), NULL, 0))) +Projection_8 10000.00 root or(and(and(le(Column#8, 1), eq(Column#1, Column#7)), if(ne(Column#9, 0), NULL, 1)), or(eq(Column#10, 0), if(isnull(Column#1), NULL, 0))) └─HashLeftJoin_9 10000.00 root CARTESIAN inner join, inner:StreamAgg_16 ├─TableReader_12 10000.00 root data:TableScan_11 │ └─TableScan_11 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false, stats:pseudo - └─StreamAgg_16 1.00 root funcs:firstrow(Column#15), count(distinct Column#16), sum(Column#17), count(1) + └─StreamAgg_16 1.00 root funcs:firstrow(Column#13), count(distinct Column#14), sum(Column#15), count(1) └─Projection_26 10000.00 root Column#4, Column#4, cast(isnull(Column#4)) └─TableReader_23 10000.00 root data:TableScan_22 └─TableScan_22 10000.00 cop[tikv] table:t2, range:[-inf,+inf], keep order:false, stats:pseudo @@ -406,8 +406,8 @@ drop table if exists s; create table s(a varchar(20), b varchar(20)); explain select a in (select a from s where s.b = t.b) from t; id count task operator info -Projection_9 10000.00 root Column#8 -└─HashLeftJoin_10 10000.00 root left outer semi join, inner:Projection_14, equal:[eq(Column#10, Column#11)], other cond:eq(cast(Column#1), cast(Column#4)) +Projection_9 10000.00 root Column#7 +└─HashLeftJoin_10 10000.00 root left outer semi join, inner:Projection_14, equal:[eq(Column#8, Column#9)], other cond:eq(cast(Column#1), cast(Column#4)) ├─Projection_11 10000.00 root Column#1, Column#2, cast(Column#2) │ └─TableReader_13 10000.00 root data:TableScan_12 │ └─TableScan_12 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo @@ -426,7 +426,7 @@ drop table t; create table t(a int not null, b int); explain select a in (select a from t t2 where t2.b = t1.b) from t t1; id count task operator info -Projection_7 10000.00 root Column#8 +Projection_7 10000.00 root Column#7 └─HashLeftJoin_8 10000.00 root left outer semi join, inner:TableReader_12, equal:[eq(Column#2, Column#5) eq(Column#1, Column#4)] ├─TableReader_10 10000.00 root data:TableScan_9 │ └─TableScan_9 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false, stats:pseudo @@ -442,7 +442,7 @@ create table t(a int, b int); explain select a from t order by rand(); id count task operator info Projection_8 10000.00 root Column#1 -└─Sort_4 10000.00 root Column#5:asc +└─Sort_4 10000.00 root Column#4:asc └─Projection_9 10000.00 root Column#1, rand() └─TableReader_7 10000.00 root data:TableScan_6 └─TableScan_6 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo @@ -453,7 +453,7 @@ TableReader_8 10000.00 root data:TableScan_7 explain select a from t order by abs(rand())+1; id count task operator info Projection_8 10000.00 root Column#1 -└─Sort_4 10000.00 root Column#5:asc +└─Sort_4 10000.00 root Column#4:asc └─Projection_9 10000.00 root Column#1, plus(abs(rand()), 1) └─TableReader_7 10000.00 root data:TableScan_6 └─TableScan_6 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo @@ -478,7 +478,7 @@ PRIMARY KEY (`id`) ); explain select row_number() over( partition by i ) - x as rnk from t; id count task operator info -Projection_7 10000.00 root minus(Column#7, Column#3) +Projection_7 10000.00 root minus(Column#5, Column#3) └─Window_8 10000.00 root row_number() over(partition by Column#2) └─Sort_11 10000.00 root Column#2:asc └─TableReader_10 10000.00 root data:TableScan_9 diff --git a/cmd/explaintest/r/subquery.result b/cmd/explaintest/r/subquery.result index a7d881badaac6..b2d762a0d425f 100644 --- a/cmd/explaintest/r/subquery.result +++ b/cmd/explaintest/r/subquery.result @@ -17,7 +17,7 @@ insert into t values(1,1,1,1),(2,2,2,2),(3,2,2,2),(4,2,2,2),(5,2,2,2); analyze table t; explain select t.c in (select count(*) from t s use index(idx), t t1 where s.b = 1 and s.c = 1 and s.d = t.a and s.a = t1.a) from t; id count task operator info -Projection_11 5.00 root Column#15 +Projection_11 5.00 root Column#14 └─Apply_13 5.00 root CARTESIAN left outer semi join, inner:StreamAgg_22, other cond:eq(Column#3, Column#13) ├─TableReader_15 5.00 root data:TableScan_14 │ └─TableScan_14 5.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false @@ -37,7 +37,7 @@ Projection_11 7992.00 root Column#1 │ └─Selection_15 9970.03 cop[tikv] not(isnull(Column#1)), not(isnull(Column#2)), not(isnull(Column#3)) │ └─TableScan_14 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false, stats:pseudo └─Selection_17 6393.60 root not(isnull(Column#9)) - └─HashAgg_23 7992.00 root group by:Column#14, funcs:max(Column#12), firstrow(Column#14) + └─HashAgg_23 7992.00 root group by:Column#12, funcs:max(Column#10), firstrow(Column#12) └─TableReader_24 7992.00 root data:HashAgg_18 └─HashAgg_18 7992.00 cop[tikv] group by:Column#6, funcs:max(Column#5) └─Selection_22 9990.00 cop[tikv] not(isnull(Column#6)) diff --git a/cmd/explaintest/r/topn_push_down.result b/cmd/explaintest/r/topn_push_down.result index 97101d3dcfad2..0dbcf2b06760a 100644 --- a/cmd/explaintest/r/topn_push_down.result +++ b/cmd/explaintest/r/topn_push_down.result @@ -201,11 +201,11 @@ Apply_15 9990.00 root semi join, inner:Selection_19, equal:[eq(Column#1, Column# └─TableScan_23 1.25 cop[tikv] table:t2, range:[-inf,+inf], keep order:false, stats:pseudo desc select * from t1 where t1.a in (select a from (select t2.a as a, t1.b as b from t2 where t2.b > t1.b) x order by b limit 1); id count task operator info -Apply_17 9990.00 root semi join, inner:Selection_21, equal:[eq(Column#1, Column#9)] +Apply_17 9990.00 root semi join, inner:Selection_21, equal:[eq(Column#1, Column#4)] ├─TableReader_20 9990.00 root data:Selection_19 │ └─Selection_19 9990.00 cop[tikv] not(isnull(Column#1)) │ └─TableScan_18 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false, stats:pseudo -└─Selection_21 0.80 root not(isnull(Column#9)) +└─Selection_21 0.80 root not(isnull(Column#4)) └─Projection_22 1.00 root Column#4, Column#2 └─Limit_23 1.00 root offset:0, count:1 └─TableReader_29 1.00 root data:Limit_28 diff --git a/cmd/explaintest/r/tpch.result b/cmd/explaintest/r/tpch.result index e5220c8265d68..de0054b639390 100644 --- a/cmd/explaintest/r/tpch.result +++ b/cmd/explaintest/r/tpch.result @@ -119,9 +119,9 @@ order by l_returnflag, l_linestatus; id count task operator info -Sort_6 2.94 root Column#26:asc, Column#27:asc +Sort_6 2.94 root Column#9:asc, Column#10:asc └─Projection_8 2.94 root Column#9, Column#10, Column#18, Column#19, Column#20, Column#21, Column#22, Column#23, Column#24, Column#25 - └─HashAgg_14 2.94 root group by:Column#49, Column#50, funcs:sum(Column#36), sum(Column#37), sum(Column#38), sum(Column#39), avg(Column#40, Column#41), avg(Column#42, Column#43), avg(Column#44, Column#45), count(Column#46), firstrow(Column#49), firstrow(Column#50) + └─HashAgg_14 2.94 root group by:Column#39, Column#40, funcs:sum(Column#26), sum(Column#27), sum(Column#28), sum(Column#29), avg(Column#30, Column#31), avg(Column#32, Column#33), avg(Column#34, Column#35), count(Column#36), firstrow(Column#39), firstrow(Column#40) └─TableReader_15 2.94 root data:HashAgg_9 └─HashAgg_9 2.94 cop[tikv] group by:Column#10, Column#9, funcs:sum(Column#5), sum(Column#6), sum(mul(Column#6, minus(1, Column#7))), sum(mul(mul(Column#6, minus(1, Column#7)), plus(1, Column#8))), count(Column#5), sum(Column#5), count(Column#6), sum(Column#6), count(Column#7), sum(Column#7), count(1) └─Selection_13 293795345.00 cop[tikv] le(Column#11, 1998-08-15) @@ -251,7 +251,7 @@ limit 10; id count task operator info Projection_14 10.00 root Column#18, Column#35, Column#13, Column#16 └─TopN_17 10.00 root Column#35:desc, Column#13:asc, offset:0, count:10 - └─HashAgg_23 40252367.98 root group by:Column#52, Column#53, Column#54, funcs:sum(Column#48), firstrow(Column#49), firstrow(Column#50), firstrow(Column#51) + └─HashAgg_23 40252367.98 root group by:Column#48, Column#49, Column#50, funcs:sum(Column#44), firstrow(Column#45), firstrow(Column#46), firstrow(Column#47) └─Projection_81 91515927.49 root mul(Column#23, minus(1, Column#24)), Column#13, Column#16, Column#18, Column#18, Column#13, Column#16 └─IndexHashJoin_38 91515927.49 root inner join, inner:IndexLookUp_28, outer key:Column#9, inner key:Column#18 ├─HashRightJoin_71 22592975.51 root inner join, inner:TableReader_77, equal:[eq(Column#1, Column#10)] @@ -295,8 +295,8 @@ o_orderpriority order by o_orderpriority; id count task operator info -Sort_10 1.00 root Column#44:asc -└─Projection_12 1.00 root Column#6, Column#43 +Sort_10 1.00 root Column#6:asc +└─Projection_12 1.00 root Column#6, Column#27 └─HashAgg_15 1.00 root group by:Column#6, funcs:count(1), firstrow(Column#6) └─IndexHashJoin_30 2340750.00 root semi join, inner:IndexLookUp_20, outer key:Column#1, inner key:Column#10 ├─TableReader_42 2925937.50 root data:Selection_41 @@ -343,9 +343,9 @@ n_name order by revenue desc; id count task operator info -Sort_23 5.00 root Column#51:desc +Sort_23 5.00 root Column#49:desc └─Projection_25 5.00 root Column#43, Column#49 - └─HashAgg_28 5.00 root group by:Column#54, funcs:sum(Column#52), firstrow(Column#53) + └─HashAgg_28 5.00 root group by:Column#52, funcs:sum(Column#50), firstrow(Column#51) └─Projection_86 11822812.50 root mul(Column#23, minus(1, Column#24)), Column#43, Column#43 └─HashLeftJoin_38 11822812.50 root inner join, inner:TableReader_84, equal:[eq(Column#38, Column#4) eq(Column#10, Column#1)] ├─IndexMergeJoin_49 11822812.50 root inner join, inner:TableReader_47, outer key:Column#18, inner key:Column#9 @@ -388,7 +388,7 @@ and l_shipdate < date_add('1994-01-01', interval '1' year) and l_discount between 0.06 - 0.01 and 0.06 + 0.01 and l_quantity < 24; id count task operator info -StreamAgg_20 1.00 root funcs:sum(Column#21) +StreamAgg_20 1.00 root funcs:sum(Column#20) └─TableReader_21 1.00 root data:StreamAgg_9 └─StreamAgg_9 1.00 cop[tikv] funcs:sum(mul(Column#6, Column#7)) └─Selection_19 3713857.91 cop[tikv] ge(Column#11, 1994-01-01 00:00:00.000000), ge(Column#7, 0.05), le(Column#7, 0.07), lt(Column#11, 1995-01-01), lt(Column#5, 24) @@ -444,9 +444,9 @@ supp_nation, cust_nation, l_year; id count task operator info -Sort_22 769.96 root Column#55:asc, Column#56:asc, Column#57:asc -└─Projection_24 769.96 root Column#50, Column#51, Column#52, Column#54 - └─HashAgg_27 769.96 root group by:Column#50, Column#51, Column#52, funcs:sum(Column#53), firstrow(Column#50), firstrow(Column#51), firstrow(Column#52) +Sort_22 769.96 root Column#43:asc, Column#47:asc, Column#50:asc +└─Projection_24 769.96 root Column#43, Column#47, Column#50, Column#52 + └─HashAgg_27 769.96 root group by:Column#43, Column#47, Column#50, funcs:sum(Column#51), firstrow(Column#43), firstrow(Column#47), firstrow(Column#50) └─Projection_28 1957240.42 root Column#43, Column#47, extract("YEAR", Column#18), mul(Column#13, minus(1, Column#14)) └─HashLeftJoin_40 1957240.42 root inner join, inner:TableReader_94, equal:[eq(Column#37, Column#46)], other cond:or(and(eq(Column#43, "JAPAN"), eq(Column#47, "INDIA")), and(eq(Column#43, "INDIA"), eq(Column#47, "JAPAN"))) ├─HashLeftJoin_51 24465505.20 root inner join, inner:TableReader_91, equal:[eq(Column#26, Column#34)] @@ -516,10 +516,10 @@ o_year order by o_year; id count task operator info -Sort_29 719.02 root Column#67:asc -└─Projection_31 719.02 root Column#62, div(Column#65, Column#66) - └─HashAgg_34 719.02 root group by:Column#80, funcs:sum(Column#77), sum(Column#78), firstrow(Column#79) - └─Projection_123 563136.02 root case(eq(Column#64, "INDIA"), Column#63, 0), Column#63, Column#62, Column#62 +Sort_29 719.02 root Column#62:asc +└─Projection_31 719.02 root Column#62, div(Column#64, Column#65) + └─HashAgg_34 719.02 root group by:Column#78, funcs:sum(Column#75), sum(Column#76), firstrow(Column#77) + └─Projection_123 563136.02 root case(eq(Column#56, "INDIA"), Column#63, 0), Column#63, Column#62, Column#62 └─Projection_35 563136.02 root extract("YEAR", Column#38), mul(Column#22, minus(1, Column#23)), Column#56 └─HashLeftJoin_45 563136.02 root inner join, inner:TableReader_121, equal:[eq(Column#13, Column#55)] ├─HashLeftJoin_56 563136.02 root inner join, inner:TableReader_119, equal:[eq(Column#19, Column#10)] @@ -592,9 +592,9 @@ order by nation, o_year desc; id count task operator info -Sort_25 2406.00 root Column#57:asc, Column#58:desc -└─Projection_27 2406.00 root Column#53, Column#54, Column#56 - └─HashAgg_30 2406.00 root group by:Column#53, Column#54, funcs:sum(Column#55), firstrow(Column#53), firstrow(Column#54) +Sort_25 2406.00 root Column#50:asc, Column#53:desc +└─Projection_27 2406.00 root Column#50, Column#53, Column#55 + └─HashAgg_30 2406.00 root group by:Column#50, Column#53, funcs:sum(Column#54), firstrow(Column#50), firstrow(Column#53) └─Projection_31 971049283.51 root Column#50, extract("YEAR", Column#44), minus(mul(Column#22, minus(1, Column#23)), mul(Column#37, Column#21)) └─HashLeftJoin_44 971049283.51 root inner join, inner:TableReader_106, equal:[eq(Column#19, Column#35) eq(Column#18, Column#34)] ├─HashLeftJoin_56 241379546.70 root inner join, inner:TableReader_104, equal:[eq(Column#17, Column#40)] @@ -660,7 +660,7 @@ limit 20; id count task operator info Projection_17 20.00 root Column#1, Column#2, Column#39, Column#6, Column#36, Column#3, Column#5, Column#8 └─TopN_20 20.00 root Column#39:desc, offset:0, count:20 - └─HashAgg_26 3017307.69 root group by:Column#61, Column#62, Column#63, Column#64, Column#65, Column#66, Column#67, funcs:sum(Column#53), firstrow(Column#54), firstrow(Column#55), firstrow(Column#56), firstrow(Column#57), firstrow(Column#58), firstrow(Column#59), firstrow(Column#60) + └─HashAgg_26 3017307.69 root group by:Column#53, Column#54, Column#55, Column#56, Column#57, Column#58, Column#59, funcs:sum(Column#45), firstrow(Column#46), firstrow(Column#47), firstrow(Column#48), firstrow(Column#49), firstrow(Column#50), firstrow(Column#51), firstrow(Column#52) └─Projection_67 12222016.17 root mul(Column#23, minus(1, Column#24)), Column#1, Column#2, Column#3, Column#5, Column#6, Column#8, Column#36, Column#1, Column#2, Column#6, Column#5, Column#36, Column#3, Column#8 └─IndexMergeJoin_39 12222016.17 root inner join, inner:Projection_37, outer key:Column#9, inner key:Column#18 ├─HashLeftJoin_44 3017307.69 root inner join, inner:TableReader_63, equal:[eq(Column#1, Column#10)] @@ -716,7 +716,7 @@ id count task operator info Projection_57 1304801.67 root Column#1, Column#18 └─Sort_58 1304801.67 root Column#18:desc └─Selection_60 1304801.67 root gt(Column#18, NULL) - └─HashAgg_63 1631002.09 root group by:Column#49, funcs:sum(Column#47), firstrow(Column#48) + └─HashAgg_63 1631002.09 root group by:Column#44, funcs:sum(Column#42), firstrow(Column#43) └─Projection_89 1631002.09 root mul(Column#4, cast(Column#3)), Column#1, Column#1 └─HashRightJoin_67 1631002.09 root inner join, inner:HashRightJoin_80, equal:[eq(Column#7, Column#2)] ├─HashRightJoin_80 20000.00 root inner join, inner:TableReader_85, equal:[eq(Column#14, Column#10)] @@ -767,9 +767,9 @@ l_shipmode order by l_shipmode; id count task operator info -Sort_9 1.00 root Column#29:asc +Sort_9 1.00 root Column#24:asc └─Projection_11 1.00 root Column#24, Column#27, Column#28 - └─HashAgg_14 1.00 root group by:Column#38, funcs:sum(Column#35), sum(Column#36), firstrow(Column#37) + └─HashAgg_14 1.00 root group by:Column#35, funcs:sum(Column#32), sum(Column#33), firstrow(Column#34) └─Projection_40 10023369.01 root cast(case(or(eq(Column#6, "1-URGENT"), eq(Column#6, "2-HIGH")), 1, 0)), cast(case(and(ne(Column#6, "1-URGENT"), ne(Column#6, "2-HIGH")), 1, 0)), Column#24, Column#24 └─IndexMergeJoin_22 10023369.01 root inner join, inner:TableReader_20, outer key:Column#10, inner key:Column#1 ├─TableReader_36 10023369.01 root data:Selection_35 @@ -807,8 +807,8 @@ order by custdist desc, c_count desc; id count task operator info -Sort_9 7500000.00 root Column#23:desc, Column#22:desc -└─Projection_11 7500000.00 root Column#18, Column#21 +Sort_9 7500000.00 root Column#19:desc, Column#18:desc +└─Projection_11 7500000.00 root Column#18, Column#19 └─HashAgg_14 7500000.00 root group by:Column#18, funcs:count(1), firstrow(Column#18) └─HashAgg_17 7500000.00 root group by:Column#1, funcs:count(Column#9) └─HashLeftJoin_21 60000000.00 root left outer join, inner:TableReader_23 (REVERSED), equal:[eq(Column#1, Column#10)] @@ -928,8 +928,8 @@ p_brand, p_type, p_size; id count task operator info -Sort_13 3863988.24 root Column#28:desc, Column#25:asc, Column#26:asc, Column#27:asc -└─Projection_15 3863988.24 root Column#10, Column#11, Column#12, Column#24 +Sort_13 3863988.24 root Column#23:desc, Column#10:asc, Column#11:asc, Column#12:asc +└─Projection_15 3863988.24 root Column#10, Column#11, Column#12, Column#23 └─HashAgg_18 3863988.24 root group by:Column#10, Column#11, Column#12, funcs:count(distinct Column#2), firstrow(Column#10), firstrow(Column#11), firstrow(Column#12) └─HashLeftJoin_30 3863988.24 root anti semi join, inner:TableReader_57, equal:[eq(Column#2, Column#16)] ├─IndexMergeJoin_38 4829985.30 root inner join, inner:IndexReader_36, outer key:Column#7, inner key:Column#1 @@ -1027,7 +1027,7 @@ o_totalprice desc, o_orderdate limit 100; id count task operator info -Projection_24 100.00 root Column#2, Column#1, Column#9, Column#13, Column#12, Column#57 +Projection_24 100.00 root Column#2, Column#1, Column#9, Column#13, Column#12, Column#54 └─TopN_27 100.00 root Column#12:desc, Column#13:asc, offset:0, count:100 └─HashAgg_33 59251097.60 root group by:Column#1, Column#12, Column#13, Column#2, Column#9, funcs:sum(Column#22), firstrow(Column#1), firstrow(Column#2), firstrow(Column#9), firstrow(Column#12), firstrow(Column#13) └─HashRightJoin_48 240004648.80 root inner join, inner:HashLeftJoin_49, equal:[eq(Column#9, Column#18)] @@ -1038,7 +1038,7 @@ Projection_24 100.00 root Column#2, Column#1, Column#9, Column#13, Column#12, Co │ │ └─TableReader_63 75000000.00 root data:TableScan_62 │ │ └─TableScan_62 75000000.00 cop[tikv] table:orders, range:[-inf,+inf], keep order:false │ └─Selection_66 59251097.60 root gt(Column#52, 314) - │ └─HashAgg_73 74063872.00 root group by:Column#71, funcs:sum(Column#69), firstrow(Column#71) + │ └─HashAgg_73 74063872.00 root group by:Column#62, funcs:sum(Column#60), firstrow(Column#62) │ └─TableReader_74 74063872.00 root data:HashAgg_67 │ └─HashAgg_67 74063872.00 cop[tikv] group by:Column#35, funcs:sum(Column#39) │ └─TableScan_72 300005811.00 cop[tikv] table:lineitem, range:[-inf,+inf], keep order:false @@ -1090,7 +1090,7 @@ and l_shipmode in ('AIR', 'AIR REG') and l_shipinstruct = 'DELIVER IN PERSON' ); id count task operator info -StreamAgg_13 1.00 root funcs:sum(Column#29) +StreamAgg_13 1.00 root funcs:sum(Column#28) └─Projection_46 6286493.79 root mul(Column#6, minus(1, Column#7)) └─IndexMergeJoin_41 6286493.79 root inner join, inner:TableReader_39, outer key:Column#2, inner key:Column#18, other cond:or(and(and(eq(Column#21, "Brand#52"), in(Column#24, "SM CASE", "SM BOX", "SM PACK", "SM PKG")), and(ge(Column#5, 4), and(le(Column#5, 14), le(Column#23, 5)))), or(and(and(eq(Column#21, "Brand#11"), in(Column#24, "MED BAG", "MED BOX", "MED PKG", "MED PACK")), and(ge(Column#5, 18), and(le(Column#5, 28), le(Column#23, 10)))), and(and(eq(Column#21, "Brand#51"), in(Column#24, "LG CASE", "LG BOX", "LG PACK", "LG PKG")), and(ge(Column#5, 29), and(le(Column#5, 39), le(Column#23, 15)))))) ├─TableReader_29 6286493.79 root data:Selection_28 @@ -1146,7 +1146,7 @@ and n_name = 'ALGERIA' order by s_name; id count task operator info -Sort_28 20000.00 root Column#48:asc +Sort_28 20000.00 root Column#2:asc └─Projection_30 20000.00 root Column#2, Column#3 └─HashRightJoin_32 20000.00 root inner join, inner:HashRightJoin_45, equal:[eq(Column#1, Column#13)] ├─HashRightJoin_45 20000.00 root inner join, inner:TableReader_50, equal:[eq(Column#8, Column#4)] @@ -1156,10 +1156,10 @@ Sort_28 20000.00 root Column#48:asc │ └─TableReader_47 500000.00 root data:TableScan_46 │ └─TableScan_46 500000.00 cop[tikv] table:supplier, range:[-inf,+inf], keep order:false └─HashAgg_53 64006.34 root group by:Column#13, funcs:firstrow(Column#13) - └─Projection_54 64006.34 root Column#12, Column#13, Column#14, Column#18, mul(0.5, Column#45) - └─Selection_55 64006.34 root gt(cast(Column#14), mul(0.5, Column#45)) - └─HashAgg_58 80007.93 root group by:Column#12, Column#13, funcs:firstrow(Column#12), firstrow(Column#13), firstrow(Column#14), firstrow(Column#18), sum(Column#32) - └─HashLeftJoin_62 9711455.06 root left outer join, inner:IndexHashJoin_75 (REVERSED), equal:[eq(Column#12, Column#29) eq(Column#13, Column#30)] + └─Projection_54 64006.34 root Column#12, Column#13, Column#14, Column#18, mul(0.5, Column#44) + └─Selection_55 64006.34 root gt(cast(Column#14), mul(0.5, Column#44)) + └─HashAgg_58 80007.93 root group by:Column#12, Column#13, funcs:firstrow(Column#12), firstrow(Column#13), firstrow(Column#14), firstrow(Column#18), sum(Column#31) + └─HashLeftJoin_62 9711455.06 root left outer join, inner:IndexHashJoin_75 (REVERSED), equal:[eq(Column#12, Column#28) eq(Column#13, Column#29)] ├─IndexHashJoin_75 321865.05 root inner join, inner:IndexLookUp_66, outer key:Column#18, inner key:Column#12 │ ├─TableReader_87 80007.93 root data:Selection_86 │ │ └─Selection_86 80007.93 cop[tikv] like(Column#19, "green%", 92) @@ -1168,7 +1168,7 @@ Sort_28 20000.00 root Column#48:asc │ ├─IndexScan_64 4.02 cop[tikv] table:partsupp, index:PS_PARTKEY, PS_SUPPKEY, range: decided by [eq(Column#12, Column#18)], keep order:false │ └─TableScan_65 4.02 cop[tikv] table:partsupp, keep order:false └─TableReader_92 44189356.65 root data:Selection_91 - └─Selection_91 44189356.65 cop[tikv] ge(Column#38, 1993-01-01 00:00:00.000000), lt(Column#38, 1994-01-01) + └─Selection_91 44189356.65 cop[tikv] ge(Column#37, 1993-01-01 00:00:00.000000), lt(Column#37, 1994-01-01) └─TableScan_90 300005811.00 cop[tikv] table:lineitem, range:[-inf,+inf], keep order:false /* Q21 Suppliers Who Kept Orders Waiting Query @@ -1219,10 +1219,10 @@ numwait desc, s_name limit 100; id count task operator info -Projection_25 1.00 root Column#2, Column#104 -└─TopN_28 1.00 root Column#104:desc, Column#2:asc, offset:0, count:100 +Projection_25 1.00 root Column#2, Column#72 +└─TopN_28 1.00 root Column#72:desc, Column#2:asc, offset:0, count:100 └─HashAgg_34 1.00 root group by:Column#2, funcs:count(1), firstrow(Column#2) - └─IndexHashJoin_49 7828961.66 root anti semi join, inner:IndexLookUp_39, outer key:Column#8, inner key:Column#71, other cond:ne(Column#73, Column#10) + └─IndexHashJoin_49 7828961.66 root anti semi join, inner:IndexLookUp_39, outer key:Column#8, inner key:Column#55, other cond:ne(Column#57, Column#10) ├─IndexHashJoin_88 9786202.08 root semi join, inner:IndexLookUp_79, outer key:Column#8, inner key:Column#38, other cond:ne(Column#40, Column#1), ne(Column#40, Column#10) │ ├─IndexMergeJoin_99 12232752.60 root inner join, inner:TableReader_97, outer key:Column#8, inner key:Column#25 │ │ ├─HashRightJoin_105 12232752.60 root inner join, inner:HashRightJoin_118, equal:[eq(Column#1, Column#10)] @@ -1242,8 +1242,8 @@ Projection_25 1.00 root Column#2, Column#104 │ ├─IndexScan_77 4.05 cop[tikv] table:l2, index:L_ORDERKEY, L_LINENUMBER, range: decided by [eq(Column#38, Column#8)], keep order:false │ └─TableScan_78 4.05 cop[tikv] table:l2, keep order:false └─IndexLookUp_39 3.24 root - ├─IndexScan_36 4.05 cop[tikv] table:l3, index:L_ORDERKEY, L_LINENUMBER, range: decided by [eq(Column#71, Column#8)], keep order:false - └─Selection_38 3.24 cop[tikv] gt(Column#83, Column#82) + ├─IndexScan_36 4.05 cop[tikv] table:l3, index:L_ORDERKEY, L_LINENUMBER, range: decided by [eq(Column#55, Column#8)], keep order:false + └─Selection_38 3.24 cop[tikv] gt(Column#67, Column#66) └─TableScan_37 4.05 cop[tikv] table:l3, keep order:false /* Q22 Global Sales Opportunity Query @@ -1292,11 +1292,11 @@ cntrycode order by cntrycode; id count task operator info -Sort_32 1.00 root Column#41:asc -└─Projection_34 1.00 root Column#37, Column#39, Column#40 - └─HashAgg_37 1.00 root group by:Column#37, funcs:count(1), sum(Column#38), firstrow(Column#37) +Sort_32 1.00 root Column#27:asc +└─Projection_34 1.00 root Column#27, Column#28, Column#29 + └─HashAgg_37 1.00 root group by:Column#27, funcs:count(1), sum(Column#6), firstrow(Column#27) └─Projection_38 0.00 root substring(Column#5, 1, 2), Column#6 - └─HashLeftJoin_39 0.00 root anti semi join, inner:TableReader_45, equal:[eq(Column#1, Column#20)] + └─HashLeftJoin_39 0.00 root anti semi join, inner:TableReader_45, equal:[eq(Column#1, Column#19)] ├─Selection_40 0.00 root in(substring(Column#5, 1, 2), "20", "40", "22", "30", "39", "42", "21") │ └─TableReader_43 0.00 root data:Selection_42 │ └─Selection_42 0.00 cop[tikv] gt(Column#6, NULL) diff --git a/cmd/explaintest/r/window_function.result b/cmd/explaintest/r/window_function.result index 42cafee53fce2..5791735771ced 100644 --- a/cmd/explaintest/r/window_function.result +++ b/cmd/explaintest/r/window_function.result @@ -4,47 +4,47 @@ create table t (a int, b int, c timestamp, index idx(a)); set @@tidb_enable_window_function = 1; explain select sum(a) over() from t; id count task operator info -Projection_7 10000.00 root Column#7 +Projection_7 10000.00 root Column#6 └─Window_8 10000.00 root sum(cast(Column#1)) over() └─IndexReader_12 10000.00 root index:IndexScan_11 └─IndexScan_11 10000.00 cop[tikv] table:t, index:a, range:[NULL,+inf], keep order:false, stats:pseudo explain select sum(a) over(partition by a) from t; id count task operator info -Projection_7 10000.00 root Column#7 +Projection_7 10000.00 root Column#6 └─Window_8 10000.00 root sum(cast(Column#1)) over(partition by Column#1) └─IndexReader_10 10000.00 root index:IndexScan_9 └─IndexScan_9 10000.00 cop[tikv] table:t, index:a, range:[NULL,+inf], keep order:true, stats:pseudo explain select sum(a) over(partition by a order by b) from t; id count task operator info -Projection_7 10000.00 root Column#8 +Projection_7 10000.00 root Column#6 └─Window_8 10000.00 root sum(cast(Column#1)) over(partition by Column#1 order by Column#2 asc range between unbounded preceding and current row) └─Sort_11 10000.00 root Column#1:asc, Column#2:asc └─TableReader_10 10000.00 root data:TableScan_9 └─TableScan_9 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo explain select sum(a) over(partition by a order by b rows unbounded preceding) from t; id count task operator info -Projection_7 10000.00 root Column#8 +Projection_7 10000.00 root Column#6 └─Window_8 10000.00 root sum(cast(Column#1)) over(partition by Column#1 order by Column#2 asc rows between unbounded preceding and current row) └─Sort_11 10000.00 root Column#1:asc, Column#2:asc └─TableReader_10 10000.00 root data:TableScan_9 └─TableScan_9 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo explain select sum(a) over(partition by a order by b rows between 1 preceding and 1 following) from t; id count task operator info -Projection_7 10000.00 root Column#8 +Projection_7 10000.00 root Column#6 └─Window_8 10000.00 root sum(cast(Column#1)) over(partition by Column#1 order by Column#2 asc rows between 1 preceding and 1 following) └─Sort_11 10000.00 root Column#1:asc, Column#2:asc └─TableReader_10 10000.00 root data:TableScan_9 └─TableScan_9 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo explain select sum(a) over(partition by a order by b range between 1 preceding and 1 following) from t; id count task operator info -Projection_7 10000.00 root Column#8 +Projection_7 10000.00 root Column#6 └─Window_8 10000.00 root sum(cast(Column#1)) over(partition by Column#1 order by Column#2 asc range between 1 preceding and 1 following) └─Sort_11 10000.00 root Column#1:asc, Column#2:asc └─TableReader_10 10000.00 root data:TableScan_9 └─TableScan_9 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo explain select sum(a) over(partition by a order by c range between interval '2:30' minute_second preceding and interval '2:30' minute_second following) from t; id count task operator info -Projection_7 10000.00 root Column#8 +Projection_7 10000.00 root Column#6 └─Window_8 10000.00 root sum(cast(Column#1)) over(partition by Column#1 order by Column#3 asc range between interval "2:30" "MINUTE_SECOND" preceding and interval "2:30" "MINUTE_SECOND" following) └─Sort_11 10000.00 root Column#1:asc, Column#3:asc └─TableReader_10 10000.00 root data:TableScan_9 diff --git a/executor/aggregate_test.go b/executor/aggregate_test.go index 917de994a6b89..94de5565715de 100644 --- a/executor/aggregate_test.go +++ b/executor/aggregate_test.go @@ -633,8 +633,8 @@ func (s *testSuiteAgg) TestInjectProjBelowTopN(c *C) { tk.MustExec("insert into t values (1), (1), (1),(2),(3),(2),(3),(2),(3);") tk.MustQuery("explain select * from t order by i + 1").Check(testkit.Rows( "Projection_8 10000.00 root Column#1", - "└─Sort_4 10000.00 root Column#4:asc", - " └─Projection_9 10000.00 root Column#1, plus(Column#3, 1)", + "└─Sort_4 10000.00 root Column#3:asc", + " └─Projection_9 10000.00 root Column#1, plus(Column#1, 1)", " └─TableReader_7 10000.00 root data:TableScan_6", " └─TableScan_6 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo")) rs := tk.MustQuery("select * from t order by i + 1 ") @@ -642,7 +642,7 @@ func (s *testSuiteAgg) TestInjectProjBelowTopN(c *C) { "1", "1", "1", "2", "2", "2", "3", "3", "3")) tk.MustQuery("explain select * from t order by i + 1 limit 2").Check(testkit.Rows( "Projection_15 2.00 root Column#1", - "└─TopN_7 2.00 root Column#4:asc, offset:0, count:2", + "└─TopN_7 2.00 root Column#3:asc, offset:0, count:2", " └─Projection_16 2.00 root Column#1, plus(Column#1, 1)", " └─TableReader_12 2.00 root data:TopN_11", " └─TopN_11 2.00 cop[tikv] plus(Column#1, 1):asc, offset:0, count:2", @@ -755,11 +755,11 @@ func (s *testSuiteAgg) TestIssue12759HashAggCalledByApply(c *C) { // make sure the plan is Apply -> Apply -> Apply -> HashAgg, and the count of Apply is equal to HashAggFinalConcurrency-1. tk.MustQuery("explain select /*+ hash_agg() */ sum(a), (select NULL from test where tt.a = test.a limit 1),(select NULL from test where tt.a = test.a limit 1),(select NULL from test where tt.a = test.a limit 1) from test tt;").Check(testkit.Rows("" + - "Projection_28 1.00 root Column#3, Column#7, Column#11, Column#15]\n" + + "Projection_28 1.00 root Column#3, Column#6, Column#9, Column#12]\n" + "[└─Apply_30 1.00 root CARTESIAN left outer join, inner:Projection_65]\n" + "[ ├─Apply_32 1.00 root CARTESIAN left outer join, inner:Projection_54]\n" + "[ │ ├─Apply_34 1.00 root CARTESIAN left outer join, inner:Projection_43]\n" + - "[ │ │ ├─HashAgg_39 1.00 root funcs:sum(Column#26), firstrow(Column#27)]\n" + + "[ │ │ ├─HashAgg_39 1.00 root funcs:sum(Column#22), firstrow(Column#23)]\n" + "[ │ │ │ └─TableReader_40 1.00 root data:HashAgg_35]\n" + "[ │ │ │ └─HashAgg_35 1.00 cop[tikv] funcs:sum(Column#1), firstrow(Column#1)]\n" + "[ │ │ │ └─TableScan_38 10000.00 cop[tikv] table:tt, range:[-inf,+inf], keep order:false, stats:pseudo]\n" + @@ -767,18 +767,18 @@ func (s *testSuiteAgg) TestIssue12759HashAggCalledByApply(c *C) { "[ │ │ └─Limit_44 1.00 root offset:0, count:1]\n" + "[ │ │ └─TableReader_50 1.00 root data:Limit_49]\n" + "[ │ │ └─Limit_49 1.00 cop[tikv] offset:0, count:1]\n" + - "[ │ │ └─Selection_48 1.00 cop[tikv] eq(Column#1, Column#5)]\n" + + "[ │ │ └─Selection_48 1.00 cop[tikv] eq(Column#1, Column#4)]\n" + "[ │ │ └─TableScan_47 1000.00 cop[tikv] table:test, range:[-inf,+inf], keep order:false, stats:pseudo]\n" + "[ │ └─Projection_54 1.00 root NULL]\n" + "[ │ └─Limit_55 1.00 root offset:0, count:1]\n" + "[ │ └─TableReader_61 1.00 root data:Limit_60]\n" + "[ │ └─Limit_60 1.00 cop[tikv] offset:0, count:1]\n" + - "[ │ └─Selection_59 1.00 cop[tikv] eq(Column#1, Column#9)]\n" + + "[ │ └─Selection_59 1.00 cop[tikv] eq(Column#1, Column#7)]\n" + "[ │ └─TableScan_58 1000.00 cop[tikv] table:test, range:[-inf,+inf], keep order:false, stats:pseudo]\n" + "[ └─Projection_65 1.00 root NULL]\n" + "[ └─Limit_66 1.00 root offset:0, count:1]\n" + "[ └─TableReader_72 1.00 root data:Limit_71]\n" + "[ └─Limit_71 1.00 cop[tikv] offset:0, count:1]\n" + - "[ └─Selection_70 1.00 cop[tikv] eq(Column#1, Column#13)]\n" + + "[ └─Selection_70 1.00 cop[tikv] eq(Column#1, Column#10)]\n" + "[ └─TableScan_69 1000.00 cop[tikv] table:test, range:[-inf,+inf], keep order:false, stats:pseudo")) } diff --git a/executor/merge_join_test.go b/executor/merge_join_test.go index 0a32a8eb92d73..5530a955a0b73 100644 --- a/executor/merge_join_test.go +++ b/executor/merge_join_test.go @@ -328,7 +328,7 @@ func (s *testSuite2) TestMergeJoin(c *C) { tk.MustExec("create table t(a int)") tk.MustExec("insert into t value(1),(2)") tk.MustQuery("explain select /*+ TIDB_SMJ(t1, t2) */ * from t t1 join t t2 order by t1.a, t2.a").Check(testkit.Rows( - "Sort_6 100000000.00 root Column#5:asc, Column#6:asc", + "Sort_6 100000000.00 root Column#1:asc, Column#3:asc", "└─MergeJoin_9 100000000.00 root inner join", " ├─TableReader_11 10000.00 root data:TableScan_10", " │ └─TableScan_10 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false, stats:pseudo", @@ -349,7 +349,7 @@ func (s *testSuite2) TestMergeJoin(c *C) { tk.MustExec("create table s(a int, b int)") tk.MustExec("insert into s values(1,1)") tk.MustQuery("explain select /*+ TIDB_SMJ(t, s) */ a in (select a from s where s.b >= t.b) from t").Check(testkit.Rows( - "Projection_7 10000.00 root Column#8", + "Projection_7 10000.00 root Column#7", "└─MergeJoin_8 10000.00 root left outer semi join, other cond:eq(Column#1, Column#4), ge(Column#5, Column#2)", " ├─TableReader_10 10000.00 root data:TableScan_9", " │ └─TableScan_9 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo", diff --git a/expression/testdata/expression_suite_out.json b/expression/testdata/expression_suite_out.json index 1d885cada532c..96b04380bec42 100644 --- a/expression/testdata/expression_suite_out.json +++ b/expression/testdata/expression_suite_out.json @@ -267,7 +267,7 @@ "SQL": "explain select * from t1 where t1.b > 1 or t1.b in (select b from t2)", "Result": [ "Projection_7 8000.00 root Column#1, Column#2, Column#3", - "└─Selection_8 8000.00 root or(gt(Column#3, 1), Column#8)", + "└─Selection_8 8000.00 root or(gt(Column#3, 1), Column#7)", " └─HashLeftJoin_9 10000.00 root CARTESIAN left outer semi join, inner:TableReader_13, other cond:eq(Column#3, Column#6)", " ├─TableReader_11 10000.00 root data:TableScan_10", " │ └─TableScan_10 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false, stats:pseudo", diff --git a/planner/cascades/testdata/integration_suite_out.json b/planner/cascades/testdata/integration_suite_out.json index 391abcf12b85b..ea66d1de56b4f 100644 --- a/planner/cascades/testdata/integration_suite_out.json +++ b/planner/cascades/testdata/integration_suite_out.json @@ -50,10 +50,10 @@ { "SQL": "select a from t group by a having sum(b) > 4", "Plan": [ - "Projection_11 6400.00 root Column#4", + "Projection_11 6400.00 root Column#1", "└─Projection_12 6400.00 root Column#1, Column#3", " └─Selection_13 6400.00 root gt(Column#3, 4)", - " └─HashAgg_18 8000.00 root group by:Column#10, funcs:sum(Column#8), firstrow(Column#10)", + " └─HashAgg_18 8000.00 root group by:Column#7, funcs:sum(Column#5), firstrow(Column#7)", " └─TableReader_19 8000.00 root data:HashAgg_20", " └─HashAgg_20 8000.00 cop[tikv] group by:Column#1, funcs:sum(Column#2)", " └─TableScan_16 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo" @@ -99,10 +99,10 @@ { "SQL": "select b from t order by a+b", "Plan": [ - "Projection_7 10000.00 root Column#3", - "└─Projection_12 10000.00 root Column#3, Column#4", - " └─Sort_8 10000.00 root Column#6:asc", - " └─Projection_13 10000.00 root Column#3, Column#4, plus(Column#4, Column#3)", + "Projection_7 10000.00 root Column#2", + "└─Projection_12 10000.00 root Column#2, Column#1", + " └─Sort_8 10000.00 root Column#4:asc", + " └─Projection_13 10000.00 root Column#2, Column#1, plus(Column#1, Column#2)", " └─Projection_9 10000.00 root Column#2, Column#1", " └─TableReader_10 10000.00 root data:TableScan_11", " └─TableScan_11 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo" @@ -117,10 +117,10 @@ { "SQL": "select b from t order by b, a+b, a", "Plan": [ - "Projection_7 10000.00 root Column#3", - "└─Projection_12 10000.00 root Column#3, Column#4", - " └─Sort_8 10000.00 root Column#3:asc, Column#6:asc, Column#4:asc", - " └─Projection_13 10000.00 root Column#3, Column#4, plus(Column#4, Column#3)", + "Projection_7 10000.00 root Column#2", + "└─Projection_12 10000.00 root Column#2, Column#1", + " └─Sort_8 10000.00 root Column#2:asc, Column#4:asc, Column#1:asc", + " └─Projection_13 10000.00 root Column#2, Column#1, plus(Column#1, Column#2)", " └─Projection_9 10000.00 root Column#2, Column#1", " └─TableReader_10 10000.00 root data:TableScan_11", " └─TableScan_11 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo" @@ -141,7 +141,7 @@ "SQL": "select sum(a) from t", "Plan": [ "Projection_8 1.00 root Column#3", - "└─HashAgg_13 1.00 root funcs:sum(Column#5)", + "└─HashAgg_13 1.00 root funcs:sum(Column#4)", " └─TableReader_14 1.00 root data:HashAgg_15", " └─HashAgg_15 1.00 cop[tikv] funcs:sum(Column#1)", " └─TableScan_11 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo" @@ -154,7 +154,7 @@ "SQL": "select max(a), min(b) from t", "Plan": [ "Projection_8 1.00 root Column#3, Column#4", - "└─HashAgg_12 1.00 root funcs:max(Column#7), min(Column#8)", + "└─HashAgg_12 1.00 root funcs:max(Column#5), min(Column#6)", " └─TableReader_13 1.00 root data:HashAgg_14", " └─HashAgg_14 1.00 cop[tikv] funcs:max(Column#1), min(Column#2)", " └─TableScan_11 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo" @@ -168,7 +168,7 @@ "Plan": [ "Projection_10 8000.00 root Column#2, Column#3", "└─Sort_19 8000.00 root Column#2:asc", - " └─HashAgg_12 8000.00 root group by:Column#12, funcs:avg(Column#10), firstrow(Column#11)", + " └─HashAgg_12 8000.00 root group by:Column#10, funcs:avg(Column#8), firstrow(Column#9)", " └─Projection_15 10000.00 root cast(Column#1), Column#2, Column#2", " └─TableReader_13 10000.00 root data:TableScan_14", " └─TableScan_14 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo" @@ -185,7 +185,7 @@ "Plan": [ "Projection_10 8000.00 root Column#2, Column#3", "└─Sort_19 8000.00 root Column#2:asc", - " └─HashAgg_16 8000.00 root group by:Column#8, funcs:sum(Column#6), firstrow(Column#8)", + " └─HashAgg_16 8000.00 root group by:Column#6, funcs:sum(Column#4), firstrow(Column#6)", " └─TableReader_17 8000.00 root data:HashAgg_18", " └─HashAgg_18 8000.00 cop[tikv] group by:Column#2, funcs:sum(Column#1)", " └─TableScan_14 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo" @@ -200,11 +200,11 @@ { "SQL": "select b, avg(a) from t group by b having sum(a) > 1 order by b", "Plan": [ - "Projection_12 6400.00 root Column#5, Column#6", + "Projection_12 6400.00 root Column#2, Column#3", "└─Projection_14 6400.00 root Column#2, Column#3, Column#4", " └─Sort_27 6400.00 root Column#2:asc", " └─Selection_26 6400.00 root gt(Column#4, 1)", - " └─HashAgg_17 8000.00 root group by:Column#19, funcs:avg(Column#16), sum(Column#17), firstrow(Column#18)", + " └─HashAgg_17 8000.00 root group by:Column#15, funcs:avg(Column#12), sum(Column#13), firstrow(Column#14)", " └─Projection_20 10000.00 root cast(Column#1), cast(Column#1), Column#2, Column#2", " └─TableReader_18 10000.00 root data:TableScan_19", " └─TableScan_19 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo" @@ -219,7 +219,7 @@ "SQL": "select max(a+b) from t", "Plan": [ "Projection_8 1.00 root Column#3", - "└─HashAgg_13 1.00 root funcs:max(Column#5)", + "└─HashAgg_13 1.00 root funcs:max(Column#4)", " └─TableReader_14 1.00 root data:HashAgg_15", " └─HashAgg_15 1.00 cop[tikv] funcs:max(plus(Column#1, Column#2))", " └─TableScan_11 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo" @@ -231,10 +231,10 @@ { "SQL": "select sum(a) from t group by a, a+b order by a", "Plan": [ - "Projection_10 8000.00 root Column#4", + "Projection_10 8000.00 root Column#3", "└─Projection_12 8000.00 root Column#3, Column#1", " └─Sort_21 8000.00 root Column#1:asc", - " └─HashAgg_14 8000.00 root group by:Column#13, Column#14, funcs:sum(Column#11), firstrow(Column#12)", + " └─HashAgg_14 8000.00 root group by:Column#11, Column#12, funcs:sum(Column#9), firstrow(Column#10)", " └─Projection_17 10000.00 root cast(Column#1), Column#1, Column#1, plus(Column#1, Column#2)", " └─TableReader_15 10000.00 root data:TableScan_16", " └─TableScan_16 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo" @@ -279,7 +279,7 @@ { "SQL": "select b from t order by b limit 3", "Plan": [ - "TopN_8 3.00 root Column#3:asc, offset:0, count:3", + "TopN_8 3.00 root Column#2:asc, offset:0, count:3", "└─Projection_10 10000.00 root Column#2", " └─TableReader_11 10000.00 root data:TableScan_12", " └─TableScan_12 10000.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false, stats:pseudo" diff --git a/planner/cascades/testdata/stringer_suite_out.json b/planner/cascades/testdata/stringer_suite_out.json index 42b4b95474f0b..08fc32039d2d0 100644 --- a/planner/cascades/testdata/stringer_suite_out.json +++ b/planner/cascades/testdata/stringer_suite_out.json @@ -5,7 +5,7 @@ { "SQL": "select b from t where a > 1 and b < 1", "Result": [ - "Group#0 Schema:[Column#13]", + "Group#0 Schema:[Column#2]", " Projection_3 input:[Group#1], Column#2", "Group#1 Schema:[Column#1,Column#2], UniqueKey:[Column#1]", " TableGather_5 input:[Group#2]", @@ -27,7 +27,7 @@ { "SQL": "select t1.b from t t1, t t2 where t2.a=t1.b and t1.a > 10", "Result": [ - "Group#0 Schema:[Column#25]", + "Group#0 Schema:[Column#2]", " Projection_5 input:[Group#1], Column#2", "Group#1 Schema:[Column#1,Column#2,Column#13]", " Selection_4 input:[Group#2], eq(Column#13, Column#2), gt(Column#1, 10)", @@ -46,7 +46,7 @@ { "SQL": "select max(b), sum(a) from t where c > 10 group by d", "Result": [ - "Group#0 Schema:[Column#15,Column#16]", + "Group#0 Schema:[Column#13,Column#14]", " Projection_4 input:[Group#1], Column#13, Column#14", "Group#1 Schema:[Column#13,Column#14]", " Aggregation_3 input:[Group#2], group by:Column#4, funcs:max(Column#2), sum(Column#1)", @@ -61,7 +61,7 @@ { "SQL": "select avg(b) from t where b > 10", "Result": [ - "Group#0 Schema:[Column#14]", + "Group#0 Schema:[Column#13]", " Projection_4 input:[Group#1], Column#13", "Group#1 Schema:[Column#13]", " Aggregation_3 input:[Group#2], funcs:avg(Column#2)", @@ -76,7 +76,7 @@ { "SQL": "select a from t t1 where exists(select 1 from t t2 where t2.a < t1.b) and a < 5", "Result": [ - "Group#0 Schema:[Column#26], UniqueKey:[Column#26]", + "Group#0 Schema:[Column#1], UniqueKey:[Column#1]", " Projection_7 input:[Group#1], Column#1", "Group#1 Schema:[Column#1,Column#2], UniqueKey:[Column#1]", " Selection_2 input:[Group#2], lt(Column#1, 5)", @@ -97,7 +97,7 @@ { "SQL": "select sum(t1.a) from t t1, t t2 where t1.a = t2.b", "Result": [ - "Group#0 Schema:[Column#26]", + "Group#0 Schema:[Column#25]", " Projection_6 input:[Group#1], Column#25", "Group#1 Schema:[Column#25]", " Aggregation_5 input:[Group#2], funcs:sum(Column#1)", @@ -118,9 +118,9 @@ { "SQL": "select a from t where a > 10 limit 3", "Result": [ - "Group#0 Schema:[Column#13], UniqueKey:[Column#13]", + "Group#0 Schema:[Column#1], UniqueKey:[Column#1]", " Limit_4 input:[Group#1], offset:0, count:3", - "Group#1 Schema:[Column#13], UniqueKey:[Column#13]", + "Group#1 Schema:[Column#1], UniqueKey:[Column#1]", " Projection_3 input:[Group#2], Column#1", "Group#2 Schema:[Column#1], UniqueKey:[Column#1]", " TableGather_6 input:[Group#3]", @@ -131,11 +131,11 @@ { "SQL": "select a from t where b > 1 order by c", "Result": [ - "Group#0 Schema:[Column#15], UniqueKey:[Column#15]", - " Projection_5 input:[Group#1], Column#13", - "Group#1 Schema:[Column#13,Column#14], UniqueKey:[Column#13]", - " Sort_4 input:[Group#2], Column#14:asc", - "Group#2 Schema:[Column#13,Column#14], UniqueKey:[Column#13]", + "Group#0 Schema:[Column#13], UniqueKey:[Column#13]", + " Projection_5 input:[Group#1], Column#1", + "Group#1 Schema:[Column#1,Column#3], UniqueKey:[Column#1]", + " Sort_4 input:[Group#2], Column#3:asc", + "Group#2 Schema:[Column#1,Column#3], UniqueKey:[Column#1]", " Projection_3 input:[Group#3], Column#1, Column#3", "Group#3 Schema:[Column#1,Column#2,Column#3], UniqueKey:[Column#1]", " TableGather_7 input:[Group#4]", @@ -148,21 +148,21 @@ { "SQL": "select avg(a) from t union all select avg(b) from t", "Result": [ - "Group#0 Schema:[Column#29]", + "Group#0 Schema:[Column#27]", " Union_7 input:[Group#1,Group#2]", - "Group#1 Schema:[Column#29]", - " Projection_8 input:[Group#3], Column#28", - "Group#3 Schema:[Column#28]", - " Projection_6 input:[Group#4], Column#27", - "Group#4 Schema:[Column#27]", - " Aggregation_5 input:[Group#5], funcs:avg(Column#15)", - "Group#5 Schema:[Column#15], UniqueKey:[Column#15]", + "Group#1 Schema:[Column#27]", + " Projection_8 input:[Group#3], Column#26", + "Group#3 Schema:[Column#26]", + " Projection_6 input:[Group#4], Column#26", + "Group#4 Schema:[Column#26]", + " Aggregation_5 input:[Group#5], funcs:avg(Column#14)", + "Group#5 Schema:[Column#14], UniqueKey:[Column#14]", " TableGather_11 input:[Group#6]", - "Group#6 Schema:[Column#15], UniqueKey:[Column#15]", - " TableScan_10 table:t, pk col:Column#15", - "Group#2 Schema:[Column#29]", - " Projection_9 input:[Group#7], Column#14", - "Group#7 Schema:[Column#14]", + "Group#6 Schema:[Column#14], UniqueKey:[Column#14]", + " TableScan_10 table:t, pk col:Column#14", + "Group#2 Schema:[Column#27]", + " Projection_9 input:[Group#7], Column#13", + "Group#7 Schema:[Column#13]", " Projection_3 input:[Group#8], Column#13", "Group#8 Schema:[Column#13]", " Aggregation_2 input:[Group#9], funcs:avg(Column#2)", diff --git a/planner/cascades/testdata/transformation_rules_suite_out.json b/planner/cascades/testdata/transformation_rules_suite_out.json index d7450bef25f8b..547c9d166c1d6 100644 --- a/planner/cascades/testdata/transformation_rules_suite_out.json +++ b/planner/cascades/testdata/transformation_rules_suite_out.json @@ -5,11 +5,11 @@ { "SQL": "select a, b from (select a, b from t as t1 order by a) as t2 where t2.b > 10", "Result": [ - "Group#0 Schema:[Column#15,Column#16], UniqueKey:[Column#15]", - " Projection_5 input:[Group#1], Column#13, Column#14", - "Group#1 Schema:[Column#13,Column#14], UniqueKey:[Column#13]", - " Sort_3 input:[Group#2], Column#13:asc", - "Group#2 Schema:[Column#13,Column#14], UniqueKey:[Column#13]", + "Group#0 Schema:[Column#1,Column#2], UniqueKey:[Column#1]", + " Projection_5 input:[Group#1], Column#1, Column#2", + "Group#1 Schema:[Column#1,Column#2], UniqueKey:[Column#1]", + " Sort_3 input:[Group#2], Column#1:asc", + "Group#2 Schema:[Column#1,Column#2], UniqueKey:[Column#1]", " Projection_2 input:[Group#3], Column#1, Column#2", "Group#3 Schema:[Column#1,Column#2], UniqueKey:[Column#1]", " TableGather_7 input:[Group#4]", @@ -22,11 +22,11 @@ { "SQL": "select a, b from (select a, b from t as t1 order by a) as t2 where t2.a > 10", "Result": [ - "Group#0 Schema:[Column#15,Column#16], UniqueKey:[Column#15]", - " Projection_5 input:[Group#1], Column#13, Column#14", - "Group#1 Schema:[Column#13,Column#14], UniqueKey:[Column#13]", - " Sort_3 input:[Group#2], Column#13:asc", - "Group#2 Schema:[Column#13,Column#14], UniqueKey:[Column#13]", + "Group#0 Schema:[Column#1,Column#2], UniqueKey:[Column#1]", + " Projection_5 input:[Group#1], Column#1, Column#2", + "Group#1 Schema:[Column#1,Column#2], UniqueKey:[Column#1]", + " Sort_3 input:[Group#2], Column#1:asc", + "Group#2 Schema:[Column#1,Column#2], UniqueKey:[Column#1]", " Projection_2 input:[Group#3], Column#1, Column#2", "Group#3 Schema:[Column#1,Column#2], UniqueKey:[Column#1]", " TableGather_7 input:[Group#4]", @@ -37,9 +37,9 @@ { "SQL": "select a, b from (select a, b, a+b as a_b from t as t1) as t2 where a_b > 10 and b = 1", "Result": [ - "Group#0 Schema:[Column#16,Column#17], UniqueKey:[Column#16]", - " Projection_4 input:[Group#1], Column#13, Column#14", - "Group#1 Schema:[Column#13,Column#14,Column#15], UniqueKey:[Column#13]", + "Group#0 Schema:[Column#1,Column#2], UniqueKey:[Column#1]", + " Projection_4 input:[Group#1], Column#1, Column#2", + "Group#1 Schema:[Column#1,Column#2,Column#13], UniqueKey:[Column#1]", " Projection_2 input:[Group#2], Column#1, Column#2, plus(Column#1, Column#2)", "Group#2 Schema:[Column#1,Column#2], UniqueKey:[Column#1]", " TableGather_6 input:[Group#3]", @@ -52,11 +52,11 @@ { "SQL": "select a, @i:=@i+1 as ii from (select a, @i:=0 from t as t1) as t2 where @i < 10", "Result": [ - "Group#0 Schema:[Column#15,Column#16], UniqueKey:[Column#15]", - " Projection_4 input:[Group#1], Column#13, setvar(\"i\", cast(plus(cast(getvar(\"i\")), 1)))", - "Group#1 Schema:[Column#13,Column#14], UniqueKey:[Column#13]", + "Group#0 Schema:[Column#1,Column#14], UniqueKey:[Column#1]", + " Projection_4 input:[Group#1], Column#1, setvar(\"i\", cast(plus(cast(getvar(\"i\")), 1)))", + "Group#1 Schema:[Column#1,Column#13], UniqueKey:[Column#1]", " Selection_3 input:[Group#2], lt(cast(getvar(\"i\")), 10)", - "Group#2 Schema:[Column#13,Column#14], UniqueKey:[Column#13]", + "Group#2 Schema:[Column#1,Column#13], UniqueKey:[Column#1]", " Projection_2 input:[Group#3], Column#1, setvar(\"i\", \"0\")", "Group#3 Schema:[Column#1], UniqueKey:[Column#1]", " TableGather_6 input:[Group#4]", @@ -67,11 +67,11 @@ { "SQL": "select a, @i:=@i+1 as ii from (select a, @i:=0 from t as t1) as t2 where @i < 10 and a > 10", "Result": [ - "Group#0 Schema:[Column#15,Column#16], UniqueKey:[Column#15]", - " Projection_4 input:[Group#1], Column#13, setvar(\"i\", cast(plus(cast(getvar(\"i\")), 1)))", - "Group#1 Schema:[Column#13,Column#14], UniqueKey:[Column#13]", + "Group#0 Schema:[Column#1,Column#14], UniqueKey:[Column#1]", + " Projection_4 input:[Group#1], Column#1, setvar(\"i\", cast(plus(cast(getvar(\"i\")), 1)))", + "Group#1 Schema:[Column#1,Column#13], UniqueKey:[Column#1]", " Selection_8 input:[Group#2], lt(cast(getvar(\"i\")), 10)", - "Group#2 Schema:[Column#13,Column#14], UniqueKey:[Column#13]", + "Group#2 Schema:[Column#1,Column#13], UniqueKey:[Column#1]", " Projection_2 input:[Group#3], Column#1, setvar(\"i\", \"0\")", "Group#3 Schema:[Column#1], UniqueKey:[Column#1]", " TableGather_6 input:[Group#4]", @@ -82,7 +82,7 @@ { "SQL": "select a, max(b) from t group by a having a > 1", "Result": [ - "Group#0 Schema:[Column#14,Column#15], UniqueKey:[Column#14,Column#14]", + "Group#0 Schema:[Column#1,Column#13], UniqueKey:[Column#1,Column#1]", " Projection_3 input:[Group#1], Column#1, Column#13", "Group#1 Schema:[Column#13,Column#1], UniqueKey:[Column#1,Column#1]", " Aggregation_2 input:[Group#2], group by:Column#1, funcs:max(Column#2), firstrow(Column#1)", @@ -95,9 +95,9 @@ { "SQL": "select a, avg(b) from t group by a having a > 1 and max(b) > 10", "Result": [ - "Group#0 Schema:[Column#19,Column#20], UniqueKey:[Column#19,Column#19]", - " Projection_5 input:[Group#1], Column#15, Column#16", - "Group#1 Schema:[Column#15,Column#16,Column#18], UniqueKey:[Column#15,Column#15]", + "Group#0 Schema:[Column#15,Column#16], UniqueKey:[Column#15,Column#15]", + " Projection_5 input:[Group#1], Column#1, Column#13", + "Group#1 Schema:[Column#1,Column#13,Column#14], UniqueKey:[Column#1,Column#1]", " Projection_3 input:[Group#2], Column#1, Column#13, Column#14", "Group#2 Schema:[Column#13,Column#14,Column#1], UniqueKey:[Column#1,Column#1]", " Selection_10 input:[Group#3], gt(Column#14, 10)", @@ -117,43 +117,43 @@ { "SQL": "select a, sum(b) from t group by a", "Result": [ - "Group#0 Schema:[Column#14,Column#15], UniqueKey:[Column#14,Column#14]", + "Group#0 Schema:[Column#1,Column#13], UniqueKey:[Column#1,Column#1]", " Projection_3 input:[Group#1], Column#1, Column#13", "Group#1 Schema:[Column#13,Column#1], UniqueKey:[Column#1,Column#1]", " Aggregation_2 input:[Group#2], group by:Column#1, funcs:sum(Column#2), firstrow(Column#1)", - " Aggregation_7 input:[Group#3], group by:Column#18, funcs:sum(Column#16), firstrow(Column#18)", + " Aggregation_7 input:[Group#3], group by:Column#16, funcs:sum(Column#14), firstrow(Column#16)", "Group#2 Schema:[Column#1,Column#2], UniqueKey:[Column#1]", " TableGather_5 input:[Group#4]", "Group#4 Schema:[Column#1,Column#2], UniqueKey:[Column#1]", " TableScan_4 table:t, pk col:Column#1", - "Group#3 Schema:[Column#16,Column#18]", + "Group#3 Schema:[Column#14,Column#16]", " TableGather_5 input:[Group#5]", - "Group#5 Schema:[Column#16,Column#18]", + "Group#5 Schema:[Column#14,Column#16]", " Aggregation_6 input:[Group#4], group by:Column#1, funcs:sum(Column#2)" ] }, { "SQL": "select a, sum(b) from t group by a+c, a", "Result": [ - "Group#0 Schema:[Column#14,Column#15], UniqueKey:[Column#14]", + "Group#0 Schema:[Column#1,Column#13], UniqueKey:[Column#1]", " Projection_3 input:[Group#1], Column#1, Column#13", "Group#1 Schema:[Column#13,Column#1], UniqueKey:[Column#1]", " Aggregation_2 input:[Group#2], group by:Column#1, plus(Column#1, Column#3), funcs:sum(Column#2), firstrow(Column#1)", - " Aggregation_7 input:[Group#3], group by:Column#18, Column#19, funcs:sum(Column#16), firstrow(Column#19)", + " Aggregation_7 input:[Group#3], group by:Column#16, Column#17, funcs:sum(Column#14), firstrow(Column#17)", "Group#2 Schema:[Column#1,Column#2,Column#3], UniqueKey:[Column#1]", " TableGather_5 input:[Group#4]", "Group#4 Schema:[Column#1,Column#2,Column#3], UniqueKey:[Column#1]", " TableScan_4 table:t, pk col:Column#1", - "Group#3 Schema:[Column#16,Column#18,Column#19]", + "Group#3 Schema:[Column#14,Column#16,Column#17]", " TableGather_5 input:[Group#5]", - "Group#5 Schema:[Column#16,Column#18,Column#19]", + "Group#5 Schema:[Column#14,Column#16,Column#17]", " Aggregation_6 input:[Group#4], group by:Column#1, plus(Column#1, Column#3), funcs:sum(Column#2)" ] }, { "SQL": "select a, sum(b) from t group by sin(a)+sin(c)", "Result": [ - "Group#0 Schema:[Column#14,Column#15], UniqueKey:[Column#14]", + "Group#0 Schema:[Column#1,Column#13], UniqueKey:[Column#1]", " Projection_3 input:[Group#1], Column#1, Column#13", "Group#1 Schema:[Column#13,Column#1], UniqueKey:[Column#1]", " Aggregation_2 input:[Group#2], group by:plus(sin(cast(Column#1)), sin(cast(Column#3))), funcs:sum(Column#2), firstrow(Column#1)", @@ -171,11 +171,11 @@ { "SQL": "select b from t order by a limit 2", "Result": [ - "Group#0 Schema:[Column#15]", - " Projection_5 input:[Group#1], Column#13", - "Group#1 Schema:[Column#13,Column#14], UniqueKey:[Column#14]", - " TopN_8 input:[Group#2], Column#14:asc, offset:0, count:2", - "Group#2 Schema:[Column#13,Column#14], UniqueKey:[Column#14]", + "Group#0 Schema:[Column#13]", + " Projection_5 input:[Group#1], Column#2", + "Group#1 Schema:[Column#2,Column#1], UniqueKey:[Column#1]", + " TopN_8 input:[Group#2], Column#1:asc, offset:0, count:2", + "Group#2 Schema:[Column#2,Column#1], UniqueKey:[Column#1]", " Projection_2 input:[Group#3], Column#2, Column#1", "Group#3 Schema:[Column#1,Column#2], UniqueKey:[Column#1]", " TableGather_7 input:[Group#4]", @@ -186,11 +186,11 @@ { "SQL": "select a+b from t order by a limit 1 offset 2", "Result": [ - "Group#0 Schema:[Column#15]", + "Group#0 Schema:[Column#14]", " Projection_5 input:[Group#1], Column#13", - "Group#1 Schema:[Column#13,Column#14], UniqueKey:[Column#14]", - " TopN_8 input:[Group#2], Column#14:asc, offset:2, count:1", - "Group#2 Schema:[Column#13,Column#14], UniqueKey:[Column#14]", + "Group#1 Schema:[Column#13,Column#1], UniqueKey:[Column#1]", + " TopN_8 input:[Group#2], Column#1:asc, offset:2, count:1", + "Group#2 Schema:[Column#13,Column#1], UniqueKey:[Column#1]", " Projection_2 input:[Group#3], plus(Column#1, Column#2), Column#1", "Group#3 Schema:[Column#1,Column#2], UniqueKey:[Column#1]", " TableGather_7 input:[Group#4]", diff --git a/planner/core/cbo_test.go b/planner/core/cbo_test.go index 2bf5f5190f3f7..ab95fdb48b2d1 100644 --- a/planner/core/cbo_test.go +++ b/planner/core/cbo_test.go @@ -248,7 +248,7 @@ func (s *testAnalyzeSuite) TestEstimation(c *C) { c.Assert(h.DumpStatsDeltaToKV(handle.DumpAll), IsNil) c.Assert(h.Update(dom.InfoSchema()), IsNil) testKit.MustQuery("explain select count(*) from t group by a").Check(testkit.Rows( - "HashAgg_9 2.00 root group by:Column#6, funcs:count(Column#5)", + "HashAgg_9 2.00 root group by:Column#5, funcs:count(Column#4)", "└─TableReader_10 2.00 root data:HashAgg_5", " └─HashAgg_5 2.00 cop[tikv] group by:Column#1, funcs:count(1)", " └─TableScan_8 8.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false", @@ -700,7 +700,7 @@ func (s *testAnalyzeSuite) TestCorrelatedEstimation(c *C) { tk.MustExec("analyze table t") tk.MustQuery("explain select t.c in (select count(*) from t s , t t1 where s.a = t.a and s.a = t1.a) from t;"). Check(testkit.Rows( - "Projection_11 10.00 root Column#15", + "Projection_11 10.00 root Column#14", "└─Apply_13 10.00 root CARTESIAN left outer semi join, inner:StreamAgg_22, other cond:eq(Column#3, Column#13)", " ├─TableReader_15 10.00 root data:TableScan_14", " │ └─TableScan_14 10.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false", diff --git a/planner/core/logical_plan_builder.go b/planner/core/logical_plan_builder.go index c901e695c112f..c09fa3ced5aa6 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -824,10 +824,6 @@ func (b *PlanBuilder) buildProjectionField(ctx context.Context, p LogicalPlan, f return nil, nil, err } } - newCol := &expression.Column{ - UniqueID: b.ctx.GetSessionVars().AllocPlanColumnID(), - RetType: expr.GetType(), - } name := &types.FieldName{ TblName: tblName, OrigTblName: origTblName, @@ -835,6 +831,13 @@ func (b *PlanBuilder) buildProjectionField(ctx context.Context, p LogicalPlan, f OrigColName: origColName, DBName: dbName, } + if isCol { + return col, name, nil + } + newCol := &expression.Column{ + UniqueID: b.ctx.GetSessionVars().AllocPlanColumnID(), + RetType: expr.GetType(), + } return newCol, name, nil } diff --git a/planner/core/logical_plan_test.go b/planner/core/logical_plan_test.go index e927ab3af2042..43130441ea04b 100644 --- a/planner/core/logical_plan_test.go +++ b/planner/core/logical_plan_test.go @@ -32,6 +32,7 @@ import ( "github.com/pingcap/tidb/planner/property" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/util/testleak" + "github.com/pingcap/tidb/util/testutil" ) var _ = Suite(&testPlanSuite{}) @@ -46,184 +47,43 @@ type testPlanSuite struct { is infoschema.InfoSchema ctx sessionctx.Context + + testData testutil.TestData } func (s *testPlanSuite) SetUpSuite(c *C) { s.is = infoschema.MockInfoSchema([]*model.TableInfo{MockSignedTable(), MockUnsignedTable(), MockView()}) s.ctx = MockContext() + s.ctx.GetSessionVars().EnableWindowFunction = true s.Parser = parser.New() + s.Parser.EnableWindowFunc(true) + + var err error + s.testData, err = testutil.LoadTestSuiteData("testdata", "plan_suite_unexported") + c.Assert(err, IsNil) +} + +func (s *testPlanSuite) TearDownSuite(c *C) { + c.Assert(s.testData.GenerateOutputIfNeeded(), IsNil) } func (s *testPlanSuite) TestPredicatePushDown(c *C) { defer testleak.AfterTest(c)() - tests := []struct { - sql string - best string - }{ - { - sql: "select count(*) from t a, t b where a.a = b.a", - best: "Join{DataScan(a)->DataScan(b)}(Column#1,Column#13)->Aggr(count(1))->Projection", - }, - { - sql: "select a from (select a from t where d = 0) k where k.a = 5", - best: "DataScan(t)->Projection->Projection", - }, - { - sql: "select a from (select a+1 as a from t) k where k.a = 5", - best: "DataScan(t)->Projection->Projection", - }, - { - sql: "select a from (select 1+2 as a from t where d = 0) k where k.a = 5", - best: "DataScan(t)->Projection->Projection", - }, - { - sql: "select a from (select d as a from t where d = 0) k where k.a = 5", - best: "DataScan(t)->Projection->Projection", - }, - { - sql: "select * from t ta, t tb where (ta.d, ta.a) = (tb.b, tb.c)", - best: "Join{DataScan(ta)->DataScan(tb)}(Column#4,Column#14)(Column#1,Column#15)->Projection", - }, - { - sql: "select * from t t1, t t2 where t1.a = t2.b and t2.b > 0 and t1.a = t1.c and t1.d like 'abc' and t2.d = t1.d", - best: "Join{DataScan(t1)->Sel([like(cast(Column#4), abc, 92)])->DataScan(t2)->Sel([like(cast(Column#16), abc, 92)])}(Column#1,Column#14)(Column#4,Column#16)->Projection", - }, - { - sql: "select * from t ta join t tb on ta.d = tb.d and ta.d > 1 where tb.a = 0", - best: "Join{DataScan(ta)->DataScan(tb)}(Column#4,Column#16)->Projection", - }, - { - sql: "select * from t ta join t tb on ta.d = tb.d where ta.d > 1 and tb.a = 0", - best: "Join{DataScan(ta)->DataScan(tb)}(Column#4,Column#16)->Projection", - }, - { - sql: "select * from t ta left outer join t tb on ta.d = tb.d and ta.d > 1 where tb.a = 0", - best: "Join{DataScan(ta)->DataScan(tb)}(Column#4,Column#16)->Projection", - }, - { - sql: "select * from t ta right outer join t tb on ta.d = tb.d and ta.a > 1 where tb.a = 0", - best: "Join{DataScan(ta)->DataScan(tb)}(Column#4,Column#16)->Projection", - }, - { - sql: "select * from t ta left outer join t tb on ta.d = tb.d and ta.a > 1 where ta.d = 0", - best: "Join{DataScan(ta)->DataScan(tb)}->Projection", - }, - { - sql: "select * from t ta left outer join t tb on ta.d = tb.d and ta.a > 1 where tb.d = 0", - best: "Join{DataScan(ta)->DataScan(tb)}->Projection", - }, - { - sql: "select * from t ta left outer join t tb on ta.d = tb.d and ta.a > 1 where tb.c is not null and tb.c = 0 and ifnull(tb.d, 1)", - best: "Join{DataScan(ta)->DataScan(tb)}(Column#4,Column#16)->Projection", - }, - { - sql: "select * from t ta left outer join t tb on ta.a = tb.a left outer join t tc on tb.b = tc.b where tc.c > 0", - best: "Join{Join{DataScan(ta)->DataScan(tb)}(Column#1,Column#13)->DataScan(tc)}(Column#14,Column#26)->Projection", - }, - { - sql: "select * from t ta left outer join t tb on ta.a = tb.a left outer join t tc on tc.b = ta.b where tb.c > 0", - best: "Join{Join{DataScan(ta)->DataScan(tb)}(Column#1,Column#13)->DataScan(tc)}(Column#2,Column#26)->Projection", - }, - { - sql: "select * from t as ta left outer join (t as tb left join t as tc on tc.b = tb.b) on tb.a = ta.a where tc.c > 0", - best: "Join{DataScan(ta)->Join{DataScan(tb)->DataScan(tc)}(Column#14,Column#26)}(Column#1,Column#13)->Projection", - }, - { - sql: "select * from ( t as ta left outer join t as tb on ta.a = tb.a) join ( t as tc left join t as td on tc.b = td.b) on ta.c = td.c where tb.c = 2 and td.a = 1", - best: "Join{Join{DataScan(ta)->DataScan(tb)}(Column#1,Column#13)->Join{DataScan(tc)->DataScan(td)}(Column#26,Column#38)}(Column#3,Column#39)->Projection", - }, - { - sql: "select * from t ta left outer join (t tb left outer join t tc on tc.b = tb.b) on tb.a = ta.a and tc.c = ta.c where tc.d > 0 or ta.d > 0", - best: "Join{DataScan(ta)->Join{DataScan(tb)->DataScan(tc)}(Column#14,Column#26)}(Column#1,Column#13)(Column#3,Column#27)->Sel([or(gt(Column#28, 0), gt(Column#4, 0))])->Projection", - }, - { - sql: "select * from t ta left outer join t tb on ta.d = tb.d and ta.a > 1 where ifnull(tb.d, 1) or tb.d is null", - best: "Join{DataScan(ta)->DataScan(tb)}(Column#4,Column#16)->Sel([or(ifnull(Column#16, 1), isnull(Column#16))])->Projection", - }, - { - sql: "select a, d from (select * from t union all select * from t union all select * from t) z where a < 10", - best: "UnionAll{DataScan(t)->Projection->Projection->DataScan(t)->Projection->Projection->DataScan(t)->Projection->Projection}->Projection", - }, - { - sql: "select (select count(*) from t where t.a = k.a) from t k", - best: "Apply{DataScan(k)->DataScan(t)->Aggr(count(1))->Projection->MaxOneRow}->Projection", - }, { - sql: "select a from t where exists(select 1 from t as x where x.a < t.a)", - best: "Join{DataScan(t)->DataScan(x)}->Projection", - }, - { - sql: "select a from t where exists(select 1 from t as x where x.a = t.a and t.a < 1 and x.a < 1)", - best: "Join{DataScan(t)->DataScan(x)}(Column#1,Column#13)->Projection", - }, - { - sql: "select a from t where exists(select 1 from t as x where x.a = t.a and x.a < 1) and a < 1", - best: "Join{DataScan(t)->DataScan(x)}(Column#1,Column#13)->Projection", - }, - { - sql: "select a from t where exists(select 1 from t as x where x.a = t.a) and exists(select 1 from t as x where x.a = t.a)", - best: "Join{Join{DataScan(t)->DataScan(x)}(Column#1,Column#13)->DataScan(x)}(Column#1,Column#26)->Projection", - }, - { - sql: "select * from (select a, b, sum(c) as s from t group by a, b) k where k.a > k.b * 2 + 1", - best: "DataScan(t)->Aggr(sum(Column#3),firstrow(Column#1),firstrow(Column#2))->Projection->Projection", - }, - { - sql: "select * from (select a, b, sum(c) as s from t group by a, b) k where k.a > 1 and k.b > 2", - best: "DataScan(t)->Aggr(sum(Column#3),firstrow(Column#1),firstrow(Column#2))->Projection->Projection", - }, - { - sql: "select * from (select k.a, sum(k.s) as ss from (select a, sum(b) as s from t group by a) k group by k.a) l where l.a > 2", - best: "DataScan(t)->Aggr(sum(Column#2),firstrow(Column#1))->Projection->Aggr(sum(Column#15),firstrow(Column#14))->Projection->Projection", - }, - { - sql: "select * from (select a, sum(b) as s from t group by a) k where a > s", - best: "DataScan(t)->Aggr(sum(Column#2),firstrow(Column#1))->Sel([gt(cast(Column#1), Column#13)])->Projection->Projection", - }, - { - sql: "select * from (select a, sum(b) as s from t group by a + 1) k where a > 1", - best: "DataScan(t)->Aggr(sum(Column#2),firstrow(Column#1))->Sel([gt(Column#1, 1)])->Projection->Projection", - }, - { - sql: "select * from (select a, sum(b) as s from t group by a having 1 = 0) k where a > 1", - best: "Dual->Sel([gt(Column#14, 1)])->Projection", - }, - { - sql: "select a, count(a) cnt from t group by a having cnt < 1", - best: "DataScan(t)->Aggr(count(Column#1),firstrow(Column#1))->Sel([lt(Column#13, 1)])->Projection", - }, - // issue #3873 - { - sql: "select t1.a, t2.a from t as t1 left join t as t2 on t1.a = t2.a where t1.a < 1.0", - best: "Join{DataScan(t1)->DataScan(t2)}(Column#1,Column#13)->Projection", - }, - // issue #7728 - { - sql: "select * from t t1 join t t2 on t1.a = t2.a where t2.a = null", - best: "Dual->Projection", - }, - { - sql: "select a, b from (select a, b, min(a) over(partition by b) as min_a from t)as tt where a < 10 and b > 10 and b = min_a", - best: "DataScan(t)->Projection->Projection->Window(min(Column#13))->Sel([lt(Column#13, 10) eq(Column#14, Column#16)])->Projection->Projection", - }, - { - sql: "select a, b from (select a, b, c, d, sum(a) over(partition by b, c) as sum_a from t)as tt where b + c > 10 and b in (1, 2) and sum_a > b", - best: "DataScan(t)->Projection->Projection->Window(sum(cast(Column#13)))->Sel([gt(Column#18, cast(Column#14))])->Projection->Projection", - }, - } - s.Parser.EnableWindowFunc(true) - defer func() { - s.Parser.EnableWindowFunc(false) - }() + var input, output []string + s.testData.GetTestCases(c, &input, &output) ctx := context.Background() - for ith, ca := range tests { - comment := Commentf("for %s", ca.sql) - stmt, err := s.ParseOneStmt(ca.sql, "", "") + for ith, ca := range input { + comment := Commentf("for %s", ca) + stmt, err := s.ParseOneStmt(ca, "", "") c.Assert(err, IsNil, comment) p, _, err := BuildLogicalPlan(ctx, s.ctx, stmt, s.is) c.Assert(err, IsNil) p, err = logicalOptimize(context.TODO(), flagPredicatePushDown|flagDecorrelate|flagPrunColumns, p.(LogicalPlan)) c.Assert(err, IsNil) - c.Assert(ToString(p), Equals, ca.best, Commentf("for %s %d", ca.sql, ith)) + s.testData.OnRecord(func() { + output[ith] = ToString(p) + }) + c.Assert(ToString(p), Equals, output[ith], Commentf("for %s %d", ca, ith)) } } @@ -787,99 +647,13 @@ func (s *testPlanSuite) TestTablePartition(c *C) { func (s *testPlanSuite) TestSubquery(c *C) { defer testleak.AfterTest(c)() - tests := []struct { - sql string - best string - }{ - { - // This will be resolved as in sub query. - sql: "select * from t where 10 in (select b from t s where s.a = t.a)", - best: "Join{DataScan(t)->DataScan(s)}(Column#1,Column#13)->Projection", - }, - { - sql: "select count(c) ,(select b from t s where s.a = t.a) from t", - best: "Join{DataScan(t)->Aggr(count(Column#3),firstrow(Column#1))->DataScan(s)}(Column#1,Column#15)->Projection->Projection", - }, - { - sql: "select count(c) ,(select count(s.b) from t s where s.a = t.a) from t", - best: "Join{DataScan(t)->Aggr(count(Column#3),firstrow(Column#1))->DataScan(s)}(Column#1,Column#15)->Aggr(firstrow(Column#13),firstrow(Column#1),count(Column#16))->Projection->Projection", - }, - { - // Semi-join with agg cannot decorrelate. - sql: "select t.c in (select count(s.b) from t s where s.a = t.a) from t", - best: "Apply{DataScan(t)->DataScan(s)->Sel([eq(Column#13, Column#1)])->Aggr(count(Column#14))}->Projection", - }, - { - sql: "select (select count(s.b) k from t s where s.a = t.a having k != 0) from t", - best: "Join{DataScan(t)->DataScan(s)->Aggr(count(Column#14),firstrow(Column#13))}(Column#1,Column#13)->Projection->Projection->Projection", - }, - { - sql: "select (select count(s.b) k from t s where s.a = t1.a) from t t1, t t2", - best: "Join{Join{DataScan(t1)->DataScan(t2)}->DataScan(s)->Aggr(count(Column#26),firstrow(Column#25))}(Column#1,Column#25)->Projection->Projection->Projection", - }, - { - sql: "select (select count(1) k from t s where s.a = t.a having k != 0) from t", - best: "Join{DataScan(t)->DataScan(s)->Aggr(count(1),firstrow(Column#13))}(Column#1,Column#13)->Projection->Projection->Projection", - }, - { - sql: "select a from t where a in (select a from t s group by t.b)", - best: "Join{DataScan(t)->DataScan(s)->Aggr(firstrow(Column#13))->Projection}(Column#1,Column#25)->Projection", - }, - { - // This will be resolved as in sub query. - sql: "select * from t where 10 in (((select b from t s where s.a = t.a)))", - best: "Join{DataScan(t)->DataScan(s)}(Column#1,Column#13)->Projection", - }, - { - // This will be resolved as in function. - sql: "select * from t where 10 in (((select b from t s where s.a = t.a)), 10)", - best: "Join{DataScan(t)->DataScan(s)}(Column#1,Column#13)->Projection->Sel([in(10, Column#25, 10)])->Projection", - }, - { - sql: "select * from t where exists (select s.a from t s having sum(s.a) = t.a )", - best: "Join{DataScan(t)->DataScan(s)->Aggr(sum(Column#13))->Projection}->Projection", - }, - { - // Test MaxOneRow for limit. - sql: "select (select * from (select b from t limit 1) x where x.b = t1.b) from t t1", - best: "Join{DataScan(t1)->DataScan(t)->Projection->Limit}(Column#2,Column#25)->Projection->Projection", - }, - { - // Test Nested sub query. - sql: "select * from t where exists (select s.a from t s where s.c in (select c from t as k where k.d = s.d) having sum(s.a) = t.a )", - best: "Join{DataScan(t)->Join{DataScan(s)->DataScan(k)}(Column#16,Column#28)(Column#15,Column#27)->Aggr(sum(Column#13))->Projection}->Projection", - }, - { - sql: "select t1.b from t t1 where t1.b = (select max(t2.a) from t t2 where t1.b=t2.b)", - best: "Join{DataScan(t1)->DataScan(t2)->Aggr(max(Column#13),firstrow(Column#14))}(Column#2,Column#14)->Projection->Sel([eq(Column#2, Column#26)])->Projection", - }, - { - sql: "select t1.b from t t1 where t1.b = (select avg(t2.a) from t t2 where t1.g=t2.g and (t1.b = 4 or t2.b = 2))", - best: "Apply{DataScan(t1)->DataScan(t2)->Sel([eq(Column#10, Column#22) or(eq(Column#2, 4), eq(Column#14, 2))])->Aggr(avg(Column#13))}->Projection->Sel([eq(cast(Column#2), Column#26)])->Projection", - }, - { - sql: "select t1.b from t t1 where t1.b = (select max(t2.a) from t t2 where t1.b=t2.b order by t1.a)", - best: "Join{DataScan(t1)->DataScan(t2)->Aggr(max(Column#13),firstrow(Column#14))}(Column#2,Column#14)->Projection->Sel([eq(Column#2, Column#26)])->Projection", - }, - { - sql: "select t1.b from t t1 where t1.b in (select t2.b from t t2 where t2.a = t1.a order by t2.a)", - best: "Join{DataScan(t1)->DataScan(t2)}(Column#1,Column#13)(Column#2,Column#14)->Projection", - }, - { - sql: "select t1.b from t t1 where exists(select t2.b from t t2 where t2.a = t1.a order by t2.a)", - best: "Join{DataScan(t1)->DataScan(t2)}(Column#1,Column#13)->Projection", - }, - { - // `Sort` will not be eliminated, if it is not the top level operator. - sql: "select t1.b from t t1 where t1.b = (select t2.b from t t2 where t2.a = t1.a order by t2.a limit 1)", - best: "Apply{DataScan(t1)->DataScan(t2)->Sel([eq(Column#13, Column#1)])->Projection->Sort->Limit}->Projection->Sel([eq(Column#2, Column#27)])->Projection", - }, - } + var input, output []string + s.testData.GetTestCases(c, &input, &output) ctx := context.Background() - for ith, ca := range tests { - comment := Commentf("for %s", ca.sql) - stmt, err := s.ParseOneStmt(ca.sql, "", "") + for ith, ca := range input { + comment := Commentf("for %s", ca) + stmt, err := s.ParseOneStmt(ca, "", "") c.Assert(err, IsNil, comment) Preprocess(s.ctx, stmt, s.is) @@ -889,107 +663,21 @@ func (s *testPlanSuite) TestSubquery(c *C) { p, err = logicalOptimize(context.TODO(), flagBuildKeyInfo|flagDecorrelate|flagPrunColumns, lp) c.Assert(err, IsNil) } - c.Assert(ToString(p), Equals, ca.best, Commentf("for %s %d", ca.sql, ith)) + s.testData.OnRecord(func() { + output[ith] = ToString(p) + }) + c.Assert(ToString(p), Equals, output[ith], Commentf("for %s %d", ca, ith)) } } func (s *testPlanSuite) TestPlanBuilder(c *C) { defer testleak.AfterTest(c)() - tests := []struct { - sql string - plan string - }{ - { - sql: "select * from t for update", - plan: "DataScan(t)->Lock->Projection", - }, - { - sql: "update t set t.a = t.a * 1.5 where t.a >= 1000 order by t.a desc limit 10", - plan: "TableReader(Table(t)->Limit)->Limit->Update", - }, - { - sql: "delete from t where t.a >= 1000 order by t.a desc limit 10", - plan: "TableReader(Table(t)->Limit)->Limit->Delete", - }, - { - sql: "explain select * from t union all select * from t limit 1, 1", - plan: "*core.Explain", - }, - // The correctness of explain result is checked at integration test. There is to improve coverage. - { - sql: "explain select /*+ TIDB_INLJ(t1, t2) */ * from t t1 left join t t2 on t1.a=t2.a where t1.b=1 and t2.b=1 and (t1.c=1 or t2.c=1)", - plan: "*core.Explain", - }, - { - sql: "explain select /*+ TIDB_HJ(t1, t2) */ * from t t1 left join t t2 on t1.a=t2.a where t1.b=1 and t2.b=1 and (t1.c=1 or t2.c=1)", - plan: "*core.Explain", - }, - { - sql: "explain select /*+ TIDB_SMJ(t1, t2) */ * from t t1 right join t t2 on t1.a=t2.a where t1.b=1 and t2.b=1 and (t1.c=1 or t2.c=1)", - plan: "*core.Explain", - }, - { - sql: `explain format="dot" select /*+ TIDB_SMJ(t1, t2) */ * from t t1, t t2 where t1.a=t2.a`, - plan: "*core.Explain", - }, - { - sql: "explain select * from t order by b", - plan: "*core.Explain", - }, - { - sql: "explain select * from t order by b limit 1", - plan: "*core.Explain", - }, - { - sql: `explain format="dot" select * from t order by a`, - plan: "*core.Explain", - }, - { - sql: "insert into t select * from t", - plan: "TableReader(Table(t))->Insert", - }, - { - sql: "show columns from t where `Key` = 'pri' like 't*'", - plan: "Show->Sel([eq(cast(Column#4), 0)])->Projection", - }, - { - sql: "do sleep(5)", - plan: "Dual->Projection", - }, - { - sql: "select substr(\"abc\", 1)", - plan: "Dual->Projection", - }, - { - sql: "select * from t t1, t t2 where 1 = 0", - plan: "Dual->Projection", - }, - { - sql: "select * from t t1 join t t2 using(a)", - plan: "Join{DataScan(t1)->DataScan(t2)}->Projection", - }, - { - sql: "select * from t t1 natural join t t2", - plan: "Join{DataScan(t1)->DataScan(t2)}->Projection", - }, - { - sql: "delete from t where a in (select b from t where c = 666) or b in (select a from t where c = 42)", - // Note the Projection before Delete: the final schema should be the schema of - // table t rather than Join. - // If this schema is not set correctly, table.RemoveRecord would fail when adding - // binlog columns, because the schema and data are not consistent. - plan: "LeftHashJoin{LeftHashJoin{TableReader(Table(t))->IndexLookUp(Index(t.c_d_e)[[666,666]], Table(t))}(Column#1,Column#14)->IndexReader(Index(t.c_d_e)[[42,42]])}(Column#2,Column#27)->Sel([or(Column#26, Column#40)])->Projection->Delete", - }, - { - sql: "update t set a = 2 where b in (select c from t)", - plan: "LeftHashJoin{TableReader(Table(t))->IndexReader(Index(t.c_d_e)[[NULL,+inf]])->HashAgg}(Column#2,Column#25)->Projection->Update", - }, - } - + var input, output []string + s.testData.GetTestCases(c, &input, &output) ctx := context.Background() - for _, ca := range tests { - comment := Commentf("for %s", ca.sql) - stmt, err := s.ParseOneStmt(ca.sql, "", "") + for i, ca := range input { + comment := Commentf("for %s", ca) + stmt, err := s.ParseOneStmt(ca, "", "") c.Assert(err, IsNil, comment) s.ctx.GetSessionVars().HashJoinConcurrency = 1 @@ -1000,7 +688,10 @@ func (s *testPlanSuite) TestPlanBuilder(c *C) { p, err = logicalOptimize(context.TODO(), flagPrunColumns, lp) c.Assert(err, IsNil) } - c.Assert(ToString(p), Equals, ca.plan, Commentf("for %s", ca.sql)) + s.testData.OnRecord(func() { + output[i] = ToString(p) + }) + c.Assert(ToString(p), Equals, output[i], Commentf("for %s", ca)) } } @@ -1052,104 +743,24 @@ func (s *testPlanSuite) TestJoinReOrder(c *C) { func (s *testPlanSuite) TestEagerAggregation(c *C) { defer testleak.AfterTest(c)() - tests := []struct { - sql string - best string - }{ - { - sql: "select sum(t.a), sum(t.a+1), sum(t.a), count(t.a), sum(t.a) + count(t.a) from t", - best: "DataScan(t)->Aggr(sum(Column#1),sum(plus(Column#1, 1)),count(Column#1))->Projection", - }, - { - sql: "select sum(t.a + t.b), sum(t.a + t.c), sum(t.a + t.b), count(t.a) from t having sum(t.a + t.b) > 0 order by sum(t.a + t.c)", - best: "DataScan(t)->Aggr(sum(plus(Column#1, Column#2)),sum(plus(Column#1, Column#3)),count(Column#1))->Sel([gt(Column#13, 0)])->Projection->Sort->Projection", - }, - { - sql: "select sum(a.a) from t a, t b where a.c = b.c", - best: "Join{DataScan(a)->Aggr(sum(Column#1),firstrow(Column#3))->DataScan(b)}(Column#3,Column#15)->Aggr(sum(Column#27))->Projection", - }, - { - sql: "select sum(b.a) from t a, t b where a.c = b.c", - best: "Join{DataScan(a)->DataScan(b)->Aggr(sum(Column#13),firstrow(Column#15))}(Column#3,Column#15)->Aggr(sum(Column#27))->Projection", - }, - { - sql: "select sum(b.a), a.a from t a, t b where a.c = b.c", - best: "Join{DataScan(a)->DataScan(b)->Aggr(sum(Column#13),firstrow(Column#15))}(Column#3,Column#15)->Aggr(sum(Column#28),firstrow(Column#1))->Projection", - }, - { - sql: "select sum(a.a), b.a from t a, t b where a.c = b.c", - best: "Join{DataScan(a)->Aggr(sum(Column#1),firstrow(Column#3))->DataScan(b)}(Column#3,Column#15)->Aggr(sum(Column#28),firstrow(Column#13))->Projection", - }, - { - sql: "select sum(a.a), sum(b.a) from t a, t b where a.c = b.c", - best: "Join{DataScan(a)->DataScan(b)}(Column#3,Column#15)->Aggr(sum(Column#1),sum(Column#13))->Projection", - }, - { - sql: "select sum(a.a), max(b.a) from t a, t b where a.c = b.c", - best: "Join{DataScan(a)->Aggr(sum(Column#1),firstrow(Column#3))->DataScan(b)}(Column#3,Column#15)->Aggr(sum(Column#29),max(Column#13))->Projection", - }, - { - sql: "select max(a.a), sum(b.a) from t a, t b where a.c = b.c", - best: "Join{DataScan(a)->DataScan(b)->Aggr(sum(Column#13),firstrow(Column#15))}(Column#3,Column#15)->Aggr(max(Column#1),sum(Column#29))->Projection", - }, - { - sql: "select sum(a.a) from t a, t b, t c where a.c = b.c and b.c = c.c", - best: "Join{Join{DataScan(a)->DataScan(b)}(Column#3,Column#15)->DataScan(c)}(Column#15,Column#27)->Aggr(sum(Column#1))->Projection", - }, - { - sql: "select sum(b.a) from t a left join t b on a.c = b.c", - best: "Join{DataScan(a)->DataScan(b)->Aggr(sum(Column#13),firstrow(Column#15))}(Column#3,Column#15)->Aggr(sum(Column#27))->Projection", - }, - { - sql: "select sum(a.a) from t a left join t b on a.c = b.c", - best: "Join{DataScan(a)->Aggr(sum(Column#1),firstrow(Column#3))->DataScan(b)}(Column#3,Column#15)->Aggr(sum(Column#27))->Projection", - }, - { - sql: "select sum(a.a) from t a right join t b on a.c = b.c", - best: "Join{DataScan(a)->Aggr(sum(Column#1),firstrow(Column#3))->DataScan(b)}(Column#3,Column#15)->Aggr(sum(Column#27))->Projection", - }, - { - sql: "select sum(a) from (select * from t) x", - best: "DataScan(t)->Aggr(sum(Column#1))->Projection", - }, - { - sql: "select sum(c1) from (select c c1, d c2 from t a union all select a c1, b c2 from t b union all select b c1, e c2 from t c) x group by c2", - best: "UnionAll{DataScan(a)->Projection->Aggr(sum(Column#41),firstrow(Column#42))->DataScan(b)->Projection->Aggr(sum(Column#27),firstrow(Column#28))->DataScan(c)->Projection->Aggr(sum(Column#13),firstrow(Column#14))}->Aggr(sum(Column#47))->Projection", - }, - { - sql: "select max(a.b), max(b.b) from t a join t b on a.c = b.c group by a.a", - best: "Join{DataScan(a)->DataScan(b)->Aggr(max(Column#14),firstrow(Column#15))}(Column#3,Column#15)->Projection->Projection", - }, - { - sql: "select max(a.b), max(b.b) from t a join t b on a.a = b.a group by a.c", - best: "Join{DataScan(a)->DataScan(b)}(Column#1,Column#13)->Aggr(max(Column#2),max(Column#14))->Projection", - }, - { - sql: "select max(c.b) from (select * from t a union all select * from t b) c group by c.a", - best: "UnionAll{DataScan(a)->Projection->Projection->Projection->DataScan(b)->Projection->Projection->Projection}->Aggr(max(Column#63))->Projection", - }, - { - sql: "select max(a.c) from t a join t b on a.a=b.a and a.b=b.b group by a.b", - best: "Join{DataScan(a)->DataScan(b)}(Column#1,Column#13)(Column#2,Column#14)->Aggr(max(Column#3))->Projection", - }, - { - sql: "select t1.a, count(t2.b) from t t1, t t2 where t1.a = t2.a group by t1.a", - best: "Join{DataScan(t1)->DataScan(t2)}(Column#1,Column#13)->Projection->Projection", - }, - } - + var input []string + var output []string + s.testData.GetTestCases(c, &input, &output) ctx := context.Background() s.ctx.GetSessionVars().AllowAggPushDown = true - for ith, tt := range tests { - comment := Commentf("for %s", tt.sql) - stmt, err := s.ParseOneStmt(tt.sql, "", "") + for ith, tt := range input { + comment := Commentf("for %s", tt) + stmt, err := s.ParseOneStmt(tt, "", "") c.Assert(err, IsNil, comment) p, _, err := BuildLogicalPlan(ctx, s.ctx, stmt, s.is) c.Assert(err, IsNil) p, err = logicalOptimize(context.TODO(), flagBuildKeyInfo|flagPredicatePushDown|flagPrunColumns|flagPushDownAgg, p.(LogicalPlan)) c.Assert(err, IsNil) - c.Assert(ToString(p), Equals, tt.best, Commentf("for %s %d", tt.sql, ith)) + s.testData.OnRecord(func() { + output[ith] = ToString(p) + }) + c.Assert(ToString(p), Equals, output[ith], Commentf("for %s %d", tt, ith)) } s.ctx.GetSessionVars().AllowAggPushDown = false } @@ -1272,11 +883,11 @@ func (s *testPlanSuite) TestColumnPruning(c *C) { sql: "select t01.a from (select a from t t21 union all select a from t t22) t2 join t t01 on 1 left outer join t t3 on 1 join t t4 on 1", ans: map[int][]string{ 1: {"Column#1"}, - 3: {"Column#14"}, - 5: {"Column#27"}, - 8: {"Column#28"}, - 10: {"Column#40"}, - 12: {"Column#52"}, + 3: {"Column#13"}, + 5: {"Column#25"}, + 8: {"Column#26"}, + 10: {"Column#38"}, + 12: {"Column#50"}, }, }, { @@ -1536,100 +1147,56 @@ func (s *testPlanSuite) TestValidate(c *C) { } } -func checkUniqueKeys(p LogicalPlan, c *C, ans map[int][][]string, sql string) { +func (s *testPlanSuite) checkUniqueKeys(p LogicalPlan, c *C, ans map[int][][]string, sql string) { + s.testData.OnRecord(func() { + ans[p.ID()] = make([][]string, len(p.Schema().Keys)) + }) keyList, ok := ans[p.ID()] c.Assert(ok, IsTrue, Commentf("for %s, %v not found", sql, p.ID())) c.Assert(len(p.Schema().Keys), Equals, len(keyList), Commentf("for %s, %v, the number of key doesn't match, the schema is %s", sql, p.ID(), p.Schema())) - for i, key := range keyList { - c.Assert(len(p.Schema().Keys[i]), Equals, len(key), Commentf("for %s, %v %v, the number of column doesn't match", sql, p.ID(), key)) - for j, colName := range key { - c.Assert(p.Schema().Keys[i][j].String(), Equals, colName, Commentf("for %s, %v %v, column dosen't match", sql, p.ID(), key)) + for i := range keyList { + s.testData.OnRecord(func() { + keyList[i] = make([]string, len(p.Schema().Keys[i])) + }) + c.Assert(len(p.Schema().Keys[i]), Equals, len(keyList[i]), Commentf("for %s, %v %v, the number of column doesn't match", sql, p.ID(), keyList[i])) + for j := range keyList[i] { + s.testData.OnRecord(func() { + keyList[i][j] = p.Schema().Keys[i][j].String() + }) + c.Assert(p.Schema().Keys[i][j].String(), Equals, keyList[i][j], Commentf("for %s, %v %v, column dosen't match", sql, p.ID(), keyList[i])) } } + s.testData.OnRecord(func() { + ans[p.ID()] = keyList + }) for _, child := range p.Children() { - checkUniqueKeys(child, c, ans, sql) + s.checkUniqueKeys(child, c, ans, sql) } } func (s *testPlanSuite) TestUniqueKeyInfo(c *C) { defer testleak.AfterTest(c)() - tests := []struct { - sql string - ans map[int][][]string - }{ - { - sql: "select a, sum(e) from t group by b", - ans: map[int][][]string{ - 1: {{"Column#1"}}, - 2: {{"Column#1"}}, - 3: {{"Column#14"}}, - }, - }, - { - sql: "select a, b, sum(f) from t group by b", - ans: map[int][][]string{ - 1: {{"Column#9"}, {"Column#1"}}, - 2: {{"Column#1"}, {"Column#2"}}, - 3: {{"Column#14"}, {"Column#15"}}, - }, - }, - { - sql: "select c, d, e, sum(a) from t group by c, d, e", - ans: map[int][][]string{ - 1: {{"Column#1"}}, - 2: {{"Column#3", "Column#4", "Column#5"}}, - 3: {{"Column#14", "Column#15", "Column#16"}}, - }, - }, - { - sql: "select f, g, sum(a) from t", - ans: map[int][][]string{ - 1: {{"Column#9"}, {"Column#9", "Column#10"}, {"Column#1"}}, - 2: {{"Column#9"}, {"Column#9", "Column#10"}}, - 3: {{"Column#14"}, {"Column#14", "Column#15"}}, - }, - }, - { - sql: "select * from t t1 join t t2 on t1.a = t2.e", - ans: map[int][][]string{ - 1: {{"Column#9"}, {"Column#9", "Column#10"}, {"Column#1"}}, - 2: {{"Column#21"}, {"Column#21", "Column#22"}, {"Column#13"}}, - 3: {{"Column#21"}, {"Column#21", "Column#22"}, {"Column#13"}}, - 4: {{"Column#45"}, {"Column#45", "Column#46"}, {"Column#37"}}, - }, - }, - { - sql: "select f from t having sum(a) > 0", - ans: map[int][][]string{ - 1: {{"Column#9"}, {"Column#1"}}, - 2: {{"Column#9"}}, - 6: {{"Column#9"}}, - 3: {{"Column#14"}}, - 5: {{"Column#17"}}, - }, - }, - { - sql: "select * from t t1 left join t t2 on t1.a = t2.a", - ans: map[int][][]string{ - 1: {{"Column#9"}, {"Column#9", "Column#10"}, {"Column#1"}}, - 2: {{"Column#21"}, {"Column#21", "Column#22"}, {"Column#13"}}, - 3: {{"Column#9"}, {"Column#9", "Column#10"}, {"Column#1"}}, - 4: {{"Column#33"}, {"Column#33", "Column#34"}, {"Column#25"}}, - }, - }, - } + var input []string + var output []map[int][][]string + s.testData.GetTestCases(c, &input, &output) + s.testData.OnRecord(func() { + output = make([]map[int][][]string, len(input)) + }) ctx := context.Background() - for ith, tt := range tests { - comment := Commentf("for %s %d", tt.sql, ith) - stmt, err := s.ParseOneStmt(tt.sql, "", "") + for ith, tt := range input { + comment := Commentf("for %s %d", tt, ith) + stmt, err := s.ParseOneStmt(tt, "", "") c.Assert(err, IsNil, comment) p, _, err := BuildLogicalPlan(ctx, s.ctx, stmt, s.is) c.Assert(err, IsNil) lp, err := logicalOptimize(context.TODO(), flagPredicatePushDown|flagPrunColumns|flagBuildKeyInfo, p.(LogicalPlan)) c.Assert(err, IsNil) - checkUniqueKeys(lp, c, tt.ans, tt.sql) + s.testData.OnRecord(func() { + output[ith] = make(map[int][][]string) + }) + s.checkUniqueKeys(lp, c, output[ith], tt) } } @@ -1946,64 +1513,35 @@ func (s *testPlanSuite) TestUnion(c *C) { defer func() { testleak.AfterTest(c)() }() - tests := []struct { - sql string - best string - err bool - }{ - { - sql: "select a from t union select a from t", - best: "UnionAll{DataScan(t)->Projection->DataScan(t)->Projection}->Aggr(firstrow(Column#27))", - err: false, - }, - { - sql: "select a from t union all select a from t", - best: "UnionAll{DataScan(t)->Projection->DataScan(t)->Projection}", - err: false, - }, - { - sql: "select a from t union select a from t union all select a from t", - best: "UnionAll{UnionAll{DataScan(t)->Projection->DataScan(t)->Projection}->Aggr(firstrow(Column#40))->Projection->DataScan(t)->Projection}", - err: false, - }, - { - sql: "select a from t union select a from t union all select a from t union select a from t union select a from t", - best: "UnionAll{DataScan(t)->Projection->DataScan(t)->Projection->DataScan(t)->Projection->DataScan(t)->Projection->DataScan(t)->Projection}->Aggr(firstrow(Column#66))", - err: false, - }, - { - sql: "select a from t union select a, b from t", - best: "", - err: true, - }, - { - sql: "select * from (select 1 as a union select 1 union all select 2) t order by a", - best: "UnionAll{UnionAll{Dual->Projection->Dual->Projection}->Aggr(firstrow(Column#4))->Projection->Dual->Projection}->Projection->Sort", - err: false, - }, - { - sql: "select * from (select 1 as a union select 1 union all select 2) t order by (select a)", - best: "Apply{UnionAll{UnionAll{Dual->Projection->Dual->Projection}->Aggr(firstrow(Column#4))->Projection->Dual->Projection}->Dual->Projection->MaxOneRow}->Sort->Projection", - err: false, - }, + var input []string + var output []struct { + Best string + Err bool } + s.testData.GetTestCases(c, &input, &output) ctx := context.TODO() - for i, tt := range tests { - comment := Commentf("case:%v sql:%s", i, tt.sql) - stmt, err := s.ParseOneStmt(tt.sql, "", "") + for i, tt := range input { + comment := Commentf("case:%v sql:%s", i, tt) + stmt, err := s.ParseOneStmt(tt, "", "") c.Assert(err, IsNil, comment) Preprocess(s.ctx, stmt, s.is) builder := NewPlanBuilder(MockContext(), s.is, &BlockHintProcessor{}) plan, err := builder.Build(ctx, stmt) - if tt.err { + s.testData.OnRecord(func() { + output[i].Err = err != nil + }) + if output[i].Err { c.Assert(err, NotNil) continue } c.Assert(err, IsNil) p := plan.(LogicalPlan) p, err = logicalOptimize(ctx, builder.optFlag, p.(LogicalPlan)) + s.testData.OnRecord(func() { + output[i].Best = ToString(p) + }) c.Assert(err, IsNil) - c.Assert(ToString(p), Equals, tt.best, comment) + c.Assert(ToString(p), Equals, output[i].Best, comment) } } @@ -2011,115 +1549,12 @@ func (s *testPlanSuite) TestTopNPushDown(c *C) { defer func() { testleak.AfterTest(c)() }() - tests := []struct { - sql string - best string - }{ - // Test TopN + Selection. - { - sql: "select * from t where a < 1 order by b limit 5", - best: "DataScan(t)->TopN([Column#2],0,5)->Projection", - }, - // Test Limit + Selection. - { - sql: "select * from t where a < 1 limit 5", - best: "DataScan(t)->Limit->Projection", - }, - // Test Limit + Agg + Proj . - { - sql: "select a, count(b) from t group by b limit 5", - best: "DataScan(t)->Aggr(count(Column#2),firstrow(Column#1))->Limit->Projection", - }, - // Test TopN + Agg + Proj . - { - sql: "select a, count(b) from t group by b order by c limit 5", - best: "DataScan(t)->Aggr(count(Column#2),firstrow(Column#1),firstrow(Column#3))->TopN([Column#3],0,5)->Projection", - }, - // Test TopN + Join + Proj. - { - sql: "select * from t, t s order by t.a limit 5", - best: "Join{DataScan(t)->DataScan(s)}->TopN([Column#1],0,5)->Projection", - }, - // Test Limit + Join + Proj. - { - sql: "select * from t, t s limit 5", - best: "Join{DataScan(t)->DataScan(s)}->Limit->Projection", - }, - // Test TopN + Left Join + Proj. - { - sql: "select * from t left outer join t s on t.a = s.a order by t.a limit 5", - best: "Join{DataScan(t)->TopN([Column#1],0,5)->DataScan(s)}(Column#1,Column#13)->TopN([Column#1],0,5)->Projection", - }, - // Test TopN + Left Join + Proj. - { - sql: "select * from t left outer join t s on t.a = s.a order by t.a limit 5, 5", - best: "Join{DataScan(t)->TopN([Column#1],0,10)->DataScan(s)}(Column#1,Column#13)->TopN([Column#1],5,5)->Projection", - }, - // Test Limit + Left Join + Proj. - { - sql: "select * from t left outer join t s on t.a = s.a limit 5", - best: "Join{DataScan(t)->Limit->DataScan(s)}(Column#1,Column#13)->Limit->Projection", - }, - // Test Limit + Left Join Apply + Proj. - { - sql: "select (select s.a from t s where t.a = s.a) from t limit 5", - best: "Join{DataScan(t)->Limit->DataScan(s)}(Column#1,Column#13)->Limit->Projection", - }, - // Test TopN + Left Join Apply + Proj. - { - sql: "select (select s.a from t s where t.a = s.a) from t order by t.a limit 5", - best: "Join{DataScan(t)->TopN([Column#1],0,5)->DataScan(s)}(Column#1,Column#13)->TopN([Column#1],0,5)->Projection", - }, - // Test TopN + Left Semi Join Apply + Proj. - { - sql: "select exists (select s.a from t s where t.a = s.a) from t order by t.a limit 5", - best: "Join{DataScan(t)->TopN([Column#1],0,5)->DataScan(s)}(Column#1,Column#13)->TopN([Column#1],0,5)->Projection", - }, - // Test TopN + Semi Join Apply + Proj. - { - sql: "select * from t where exists (select s.a from t s where t.a = s.a) order by t.a limit 5", - best: "Join{DataScan(t)->DataScan(s)}(Column#1,Column#13)->TopN([Column#1],0,5)->Projection", - }, - // Test TopN + Right Join + Proj. - { - sql: "select * from t right outer join t s on t.a = s.a order by s.a limit 5", - best: "Join{DataScan(t)->DataScan(s)->TopN([Column#13],0,5)}(Column#1,Column#13)->TopN([Column#13],0,5)->Projection", - }, - // Test Limit + Right Join + Proj. - { - sql: "select * from t right outer join t s on t.a = s.a order by s.a,t.b limit 5", - best: "Join{DataScan(t)->DataScan(s)}(Column#1,Column#13)->TopN([Column#13 Column#2],0,5)->Projection", - }, - // Test TopN + UA + Proj. - { - sql: "select * from t union all (select * from t s) order by a,b limit 5", - best: "UnionAll{DataScan(t)->TopN([Column#25 Column#26],0,5)->Projection->DataScan(s)->TopN([Column#1 Column#2],0,5)->Projection}->TopN([Column#49 Column#50],0,5)", - }, - // Test TopN + UA + Proj. - { - sql: "select * from t union all (select * from t s) order by a,b limit 5, 5", - best: "UnionAll{DataScan(t)->TopN([Column#25 Column#26],0,10)->Projection->DataScan(s)->TopN([Column#1 Column#2],0,10)->Projection}->TopN([Column#49 Column#50],5,5)", - }, - // Test Limit + UA + Proj + Sort. - { - sql: "select * from t union all (select * from t s order by a) limit 5", - best: "UnionAll{DataScan(t)->Limit->Projection->DataScan(s)->TopN([Column#1],0,5)->Projection}->Limit", - }, - // Test `ByItem` containing column from both sides. - { - sql: "select ifnull(t1.b, t2.a) from t t1 left join t t2 on t1.e=t2.e order by ifnull(t1.b, t2.a) limit 5", - best: "Join{DataScan(t1)->TopN([Column#2],0,5)->DataScan(t2)}(Column#5,Column#17)->TopN([Column#2],0,5)->Projection", - }, - // Test ifnull cannot be eliminated - { - sql: "select ifnull(t1.h, t2.b) from t t1 left join t t2 on t1.e=t2.e order by ifnull(t1.h, t2.b) limit 5", - best: "Join{DataScan(t1)->DataScan(t2)}(Column#5,Column#17)->TopN([ifnull(Column#11, Column#14)],0,5)->Projection->Projection", - }, - } + var input, output []string + s.testData.GetTestCases(c, &input, &output) ctx := context.TODO() - for i, tt := range tests { - comment := Commentf("case:%v sql:%s", i, tt.sql) - stmt, err := s.ParseOneStmt(tt.sql, "", "") + for i, tt := range input { + comment := Commentf("case:%v sql:%s", i, tt) + stmt, err := s.ParseOneStmt(tt, "", "") c.Assert(err, IsNil, comment) Preprocess(s.ctx, stmt, s.is) builder := NewPlanBuilder(MockContext(), s.is, &BlockHintProcessor{}) @@ -2127,7 +1562,10 @@ func (s *testPlanSuite) TestTopNPushDown(c *C) { c.Assert(err, IsNil) p, err = logicalOptimize(ctx, builder.optFlag, p.(LogicalPlan)) c.Assert(err, IsNil) - c.Assert(ToString(p), Equals, tt.best, comment) + s.testData.OnRecord(func() { + output[i] = ToString(p) + }) + c.Assert(ToString(p), Equals, output[i], comment) } } @@ -2284,300 +1722,24 @@ func (s *testPlanSuite) TestSelectView(c *C) { func (s *testPlanSuite) TestWindowFunction(c *C) { defer testleak.AfterTest(c)() - tests := []struct { - sql string - result string - }{ - { - sql: "select a, avg(a) over(partition by a) from t", - result: "TableReader(Table(t))->Window(avg(cast(Column#1)) over(partition by Column#1))->Projection", - }, - { - sql: "select a, avg(a) over(partition by b) from t", - result: "TableReader(Table(t))->Sort->Window(avg(cast(Column#1)) over(partition by Column#2))->Projection", - }, - { - sql: "select a, avg(a+1) over(partition by (a+1)) from t", - result: "IndexReader(Index(t.f)[[NULL,+inf]])->Projection->Sort->Window(avg(cast(Column#17)) over(partition by Column#16))->Projection", - }, - { - sql: "select a, avg(a) over(order by a asc, b desc) from t order by a asc, b desc", - result: "TableReader(Table(t))->Sort->Window(avg(cast(Column#1)) over(order by Column#1 asc, Column#2 desc range between unbounded preceding and current row))->Projection", - }, - { - sql: "select a, b as a, avg(a) over(partition by a) from t", - result: "TableReader(Table(t))->Window(avg(cast(Column#1)) over(partition by Column#1))->Projection", - }, - { - sql: "select a, b as z, sum(z) over() from t", - result: "[planner:1054]Unknown column 'z' in 'field list'", - }, - { - sql: "select a, b as z from t order by (sum(z) over())", - result: "TableReader(Table(t))->Window(sum(cast(Column#2)) over())->Sort->Projection", - }, - { - sql: "select sum(avg(a)) over() from t", - result: "IndexReader(Index(t.f)[[NULL,+inf]]->StreamAgg)->StreamAgg->Window(sum(Column#13) over())->Projection", - }, - { - sql: "select b from t order by(sum(a) over())", - result: "TableReader(Table(t))->Window(sum(cast(Column#1)) over())->Sort->Projection", - }, - { - sql: "select b from t order by(sum(a) over(partition by a))", - result: "TableReader(Table(t))->Window(sum(cast(Column#1)) over(partition by Column#1))->Sort->Projection", - }, - { - sql: "select b from t order by(sum(avg(a)) over())", - result: "TableReader(Table(t)->StreamAgg)->StreamAgg->Window(sum(Column#13) over())->Sort->Projection", - }, - { - sql: "select a from t having (select sum(a) over() as w from t tt where a > t.a)", - result: "Apply{IndexReader(Index(t.f)[[NULL,+inf]])->IndexReader(Index(t.f)[[NULL,+inf]]->Sel([gt(Column#14, Column#1)]))->Window(sum(cast(Column#14)) over())->MaxOneRow->Sel([Column#28])}->Projection", - }, - { - sql: "select avg(a) over() as w from t having w > 1", - result: "[planner:3594]You cannot use the alias 'w' of an expression containing a window function in this context.'", - }, - { - sql: "select sum(a) over() as sum_a from t group by sum_a", - result: "[planner:1247]Reference 'sum_a' not supported (reference to window function)", - }, - { - sql: "select sum(a) over() from t window w1 as (w2)", - result: "[planner:3579]Window name 'w2' is not defined.", - }, - { - sql: "select sum(a) over(w) from t", - result: "[planner:3579]Window name 'w' is not defined.", - }, - { - sql: "select sum(a) over() from t window w1 as (w2), w2 as (w1)", - result: "[planner:3580]There is a circularity in the window dependency graph.", - }, - { - sql: "select sum(a) over(w partition by a) from t window w as ()", - result: "[planner:3581]A window which depends on another cannot define partitioning.", - }, - { - sql: "SELECT FIRST_VALUE(a) RESPECT NULLS OVER (w1 PARTITION BY b ORDER BY b ASC, a DESC ROWS 2 PRECEDING) AS 'first_value', a, b FROM ( SELECT a, b FROM `t` ) as t WINDOW w1 AS (PARTITION BY b ORDER BY b ASC, a ASC );", - result: "[planner:3581]A window which depends on another cannot define partitioning.", - }, - { - sql: "select sum(a) over(w) from t window w as (rows between 1 preceding AND 1 following)", - result: "[planner:3582]Window 'w' has a frame definition, so cannot be referenced by another window.", - }, - { - sql: "select sum(a) over w from t window w as (rows between 1 preceding AND 1 following)", - result: "IndexReader(Index(t.f)[[NULL,+inf]])->Window(sum(cast(Column#1)) over(rows between 1 preceding and 1 following))->Projection", - }, - { - sql: "select sum(a) over(w order by b) from t window w as (order by a)", - result: "[planner:3583]Window '' cannot inherit 'w' since both contain an ORDER BY clause.", - }, - { - sql: "select sum(a) over() from t window w1 as (), w1 as ()", - result: "[planner:3591]Window 'w1' is defined twice.", - }, - { - sql: "select avg(a) over(w2) from t window w1 as (partition by a), w2 as (w1)", - result: "TableReader(Table(t))->Window(avg(cast(Column#1)) over(partition by Column#1))->Projection", - }, - { - sql: "select a from t window w1 as (partition by a) order by (sum(a) over(w1))", - result: "TableReader(Table(t))->Window(sum(cast(Column#1)) over(partition by Column#1))->Sort->Projection", - }, - { - sql: "select sum(a) over(groups 1 preceding) from t", - result: "[planner:1235]This version of TiDB doesn't yet support 'GROUPS'", - }, - { - sql: "select sum(a) over(rows between unbounded following and 1 preceding) from t", - result: "[planner:3584]Window '': frame start cannot be UNBOUNDED FOLLOWING.", - }, - { - sql: "select sum(a) over(rows between current row and unbounded preceding) from t", - result: "[planner:3585]Window '': frame end cannot be UNBOUNDED PRECEDING.", - }, - { - sql: "select sum(a) over(rows interval 1 MINUTE_SECOND preceding) from t", - result: "[planner:3596]Window '': INTERVAL can only be used with RANGE frames.", - }, - { - sql: "select sum(a) over(rows between 1.0 preceding and 1 following) from t", - result: "[planner:3586]Window '': frame start or end is negative, NULL or of non-integral type", - }, - { - sql: "select sum(a) over(range between 1 preceding and 1 following) from t", - result: "[planner:3587]Window '' with RANGE N PRECEDING/FOLLOWING frame requires exactly one ORDER BY expression, of numeric or temporal type", - }, - { - sql: "select sum(a) over(order by c_str range between 1 preceding and 1 following) from t", - result: "[planner:3587]Window '' with RANGE N PRECEDING/FOLLOWING frame requires exactly one ORDER BY expression, of numeric or temporal type", - }, - { - sql: "select sum(a) over(order by a range interval 1 MINUTE_SECOND preceding) from t", - result: "[planner:3589]Window '' with RANGE frame has ORDER BY expression of numeric type, INTERVAL bound value not allowed.", - }, - { - sql: "select sum(a) over(order by i_date range interval a MINUTE_SECOND preceding) from t", - result: "[planner:3590]Window '' has a non-constant frame bound.", - }, - { - sql: "select sum(a) over(order by i_date range interval -1 MINUTE_SECOND preceding) from t", - result: "[planner:3586]Window '': frame start or end is negative, NULL or of non-integral type", - }, - { - sql: "select sum(a) over(order by i_date range 1 preceding) from t", - result: "[planner:3588]Window '' with RANGE frame has ORDER BY expression of datetime type. Only INTERVAL bound value allowed.", - }, - { - sql: "select sum(a) over(order by a range between 1.0 preceding and 1 following) from t", - result: "TableReader(Table(t))->Window(sum(cast(Column#1)) over(order by Column#1 asc range between 1.0 preceding and 1 following))->Projection", - }, - { - sql: "select row_number() over(rows between 1 preceding and 1 following) from t", - result: "IndexReader(Index(t.f)[[NULL,+inf]])->Window(row_number() over())->Projection", - }, - { - sql: "select avg(b), max(avg(b)) over(rows between 1 preceding and 1 following) max from t group by c", - result: "TableReader(Table(t))->HashAgg->Window(max(Column#13) over(rows between 1 preceding and 1 following))->Projection", - }, - { - sql: "select nth_value(a, 1.0) over() from t", - result: "[planner:1210]Incorrect arguments to nth_value", - }, - { - sql: "SELECT NTH_VALUE(a, 1.0) OVER() FROM t", - result: "[planner:1210]Incorrect arguments to nth_value", - }, - { - sql: "select nth_value(a, 0) over() from t", - result: "[planner:1210]Incorrect arguments to nth_value", - }, - { - sql: "select ntile(0) over() from t", - result: "[planner:1210]Incorrect arguments to ntile", - }, - { - sql: "select ntile(null) over() from t", - result: "IndexReader(Index(t.f)[[NULL,+inf]])->Window(ntile() over())->Projection", - }, - { - sql: "select avg(a) over w from t window w as(partition by b)", - result: "TableReader(Table(t))->Sort->Window(avg(cast(Column#1)) over(partition by Column#2))->Projection", - }, - { - sql: "select nth_value(i_date, 1) over() from t", - result: "TableReader(Table(t))->Window(nth_value(Column#12, 1) over())->Projection", - }, - { - sql: "select sum(b) over w, sum(c) over w from t window w as (order by a)", - result: "TableReader(Table(t))->Window(sum(cast(Column#2)), sum(cast(Column#3)) over(order by Column#1 asc range between unbounded preceding and current row))->Projection", - }, - { - sql: "delete from t order by (sum(a) over())", - result: "[planner:3593]You cannot use the window function 'sum' in this context.'", - }, - { - sql: "delete from t order by (SUM(a) over())", - result: "[planner:3593]You cannot use the window function 'sum' in this context.'", - }, - { - sql: "SELECT * from t having ROW_NUMBER() over()", - result: "[planner:3593]You cannot use the window function 'row_number' in this context.'", - }, - { - // The best execution order should be (a,c), (a, b, c), (a, b), (), it requires only 2 sort operations. - sql: "select sum(a) over (partition by a order by b), sum(b) over (order by a, b, c), sum(c) over(partition by a order by c), sum(d) over() from t", - result: "TableReader(Table(t))->Sort->Window(sum(cast(Column#3)) over(partition by Column#1 order by Column#3 asc range between unbounded preceding and current row))->Sort->Window(sum(cast(Column#2)) over(order by Column#1 asc, Column#2 asc, Column#3 asc range between unbounded preceding and current row))->Window(sum(cast(Column#1)) over(partition by Column#1 order by Column#2 asc range between unbounded preceding and current row))->Window(sum(cast(Column#4)) over())->Projection", - }, - // Test issue 11010. - { - sql: "select dense_rank() over w1, a, b from t window w1 as (partition by t.b order by t.a desc, t.b desc range between current row and 1 following)", - result: "[planner:3587]Window 'w1' with RANGE N PRECEDING/FOLLOWING frame requires exactly one ORDER BY expression, of numeric or temporal type", - }, - { - sql: "select dense_rank() over w1, a, b from t window w1 as (partition by t.b order by t.a desc, t.b desc range between current row and unbounded following)", - result: "TableReader(Table(t))->Sort->Window(dense_rank() over(partition by Column#2 order by Column#1 desc, Column#2 desc))->Projection", - }, - { - sql: "select dense_rank() over w1, a, b from t window w1 as (partition by t.b order by t.a desc, t.b desc range between 1 preceding and 1 following)", - result: "[planner:3587]Window 'w1' with RANGE N PRECEDING/FOLLOWING frame requires exactly one ORDER BY expression, of numeric or temporal type", - }, - // Test issue 11001. - { - sql: "SELECT PERCENT_RANK() OVER w1 AS 'percent_rank', fieldA, fieldB FROM ( SELECT a AS fieldA, b AS fieldB FROM t ) t1 WINDOW w1 AS ( ROWS BETWEEN 0 FOLLOWING AND UNBOUNDED PRECEDING)", - result: "[planner:3585]Window 'w1': frame end cannot be UNBOUNDED PRECEDING.", - }, - // Test issue 11002. - { - sql: "SELECT PERCENT_RANK() OVER w1 AS 'percent_rank', fieldA, fieldB FROM ( SELECT a AS fieldA, b AS fieldB FROM t ) as t1 WINDOW w1 AS ( ROWS BETWEEN UNBOUNDED FOLLOWING AND UNBOUNDED FOLLOWING)", - result: "[planner:3584]Window 'w1': frame start cannot be UNBOUNDED FOLLOWING.", - }, - // Test issue 11011. - { - sql: "select dense_rank() over w1, a, b from t window w1 as (partition by t.b order by t.a asc range between 1250951168 following AND 1250951168 preceding)", - result: "[planner:3586]Window 'w1': frame start or end is negative, NULL or of non-integral type", - }, - // Test issue 10556. - { - sql: "SELECT FIRST_VALUE(a) IGNORE NULLS OVER () FROM t", - result: "[planner:1235]This version of TiDB doesn't yet support 'IGNORE NULLS'", - }, - { - sql: "SELECT SUM(DISTINCT a) OVER () FROM t", - result: "[planner:1235]This version of TiDB doesn't yet support '(DISTINCT ..)'", - }, - { - sql: "SELECT NTH_VALUE(a, 1) FROM LAST over (partition by b order by b), a FROM t", - result: "[planner:1235]This version of TiDB doesn't yet support 'FROM LAST'", - }, - { - sql: "SELECT NTH_VALUE(a, 1) FROM LAST IGNORE NULLS over (partition by b order by b), a FROM t", - result: "[planner:1235]This version of TiDB doesn't yet support 'IGNORE NULLS'", - }, - { - sql: "SELECT NTH_VALUE(fieldA, ATAN(-1)) OVER (w1) AS 'ntile', fieldA, fieldB FROM ( SELECT a AS fieldA, b AS fieldB FROM t ) as te WINDOW w1 AS ( ORDER BY fieldB ASC, fieldA DESC )", - result: "[planner:1210]Incorrect arguments to nth_value", - }, - { - sql: "SELECT NTH_VALUE(fieldA, -1) OVER (w1 PARTITION BY fieldB ORDER BY fieldB , fieldA ) AS 'ntile', fieldA, fieldB FROM ( SELECT a AS fieldA, b AS fieldB FROM t ) as temp WINDOW w1 AS ( ORDER BY fieldB ASC, fieldA DESC )", - result: "[planner:1210]Incorrect arguments to nth_value", - }, - { - sql: "SELECT SUM(a) OVER w AS 'sum' FROM t WINDOW w AS (ROWS BETWEEN 1 FOLLOWING AND CURRENT ROW )", - result: "[planner:3586]Window 'w': frame start or end is negative, NULL or of non-integral type", - }, - { - sql: "SELECT SUM(a) OVER w AS 'sum' FROM t WINDOW w AS (ROWS BETWEEN CURRENT ROW AND 1 PRECEDING )", - result: "[planner:3586]Window 'w': frame start or end is negative, NULL or of non-integral type", - }, - { - sql: "SELECT SUM(a) OVER w AS 'sum' FROM t WINDOW w AS (ROWS BETWEEN 1 FOLLOWING AND 1 PRECEDING )", - result: "[planner:3586]Window 'w': frame start or end is negative, NULL or of non-integral type", - }, - // Test issue 11943 - { - sql: "SELECT ROW_NUMBER() OVER (partition by b) + a FROM t", - result: "TableReader(Table(t))->Sort->Window(row_number() over(partition by Column#2))->Projection", - }, - } + var input, output []string + s.testData.GetTestCases(c, &input, &output) - s.Parser.EnableWindowFunc(true) - defer func() { - s.Parser.EnableWindowFunc(false) - }() ctx := context.TODO() - for i, tt := range tests { - comment := Commentf("case:%v sql:%s", i, tt.sql) - p, stmt, err := s.optimize(ctx, tt.sql) + for i, tt := range input { + comment := Commentf("case:%v sql:%s", i, tt) + p, stmt, err := s.optimize(ctx, tt) if err != nil { - c.Assert(err.Error(), Equals, tt.result, comment) + s.testData.OnRecord(func() { + output[i] = err.Error() + }) + c.Assert(err.Error(), Equals, output[i], comment) continue } - c.Assert(ToString(p), Equals, tt.result, comment) + s.testData.OnRecord(func() { + output[i] = ToString(p) + }) + c.Assert(ToString(p), Equals, output[i], comment) var sb strings.Builder // After restore, the result should be the same. @@ -2585,10 +1747,10 @@ func (s *testPlanSuite) TestWindowFunction(c *C) { c.Assert(err, IsNil) p, _, err = s.optimize(ctx, sb.String()) if err != nil { - c.Assert(err.Error(), Equals, tt.result, comment) + c.Assert(err.Error(), Equals, output[i], comment) continue } - c.Assert(ToString(p), Equals, tt.result, comment) + c.Assert(ToString(p), Equals, output[i], comment) } } @@ -2774,7 +1936,7 @@ func (s *testPlanSuite) TestUpdateEQCond(c *C) { }{ { sql: "select t1.a from t t1, t t2 where t1.a = t2.a+1", - best: "Join{DataScan(t1)->DataScan(t2)->Projection}(Column#1,Column#26)->Projection", + best: "Join{DataScan(t1)->DataScan(t2)->Projection}(Column#1,Column#25)->Projection", }, } ctx := context.TODO() diff --git a/planner/core/rule_column_pruning.go b/planner/core/rule_column_pruning.go index d99322c9a6600..297acd8f8b48e 100644 --- a/planner/core/rule_column_pruning.go +++ b/planner/core/rule_column_pruning.go @@ -16,8 +16,6 @@ package core import ( "context" - "github.com/pingcap/errors" - "github.com/pingcap/failpoint" "github.com/pingcap/parser/ast" "github.com/pingcap/parser/model" "github.com/pingcap/parser/mysql" @@ -35,22 +33,13 @@ func (s *columnPruner) optimize(ctx context.Context, lp LogicalPlan) (LogicalPla return lp, err } -func getUsedList(usedCols []*expression.Column, schema *expression.Schema) ([]bool, error) { - failpoint.Inject("enableGetUsedListErr", func(val failpoint.Value) { - if val.(bool) { - failpoint.Return(nil, errors.New("getUsedList failed, triggered by gofail enableGetUsedListErr")) - } - }) - +func getUsedList(usedCols []*expression.Column, schema *expression.Schema) []bool { + tmpSchema := expression.NewSchema(usedCols...) used := make([]bool, schema.Len()) - for _, col := range usedCols { - idx := schema.ColumnIndex(col) - if idx == -1 { - return nil, errors.Errorf("Can't find column %s from schema %s.", col, schema) - } - used[idx] = true + for i, col := range schema.Columns { + used[i] = tmpSchema.Contains(col) } - return used, nil + return used } // exprsHasSideEffects checks if any of the expressions has side effects. @@ -84,10 +73,7 @@ func exprHasSetVarOrSleep(expr expression.Expression) bool { // If any expression has SetVar function or Sleep function, we do not prune it. func (p *LogicalProjection) PruneColumns(parentUsedCols []*expression.Column) error { child := p.children[0] - used, err := getUsedList(parentUsedCols, p.schema) - if err != nil { - return err - } + used := getUsedList(parentUsedCols, p.schema) for i := len(used) - 1; i >= 0; i-- { if !used[i] && !exprHasSetVarOrSleep(p.Exprs[i]) { @@ -110,10 +96,7 @@ func (p *LogicalSelection) PruneColumns(parentUsedCols []*expression.Column) err // PruneColumns implements LogicalPlan interface. func (la *LogicalAggregation) PruneColumns(parentUsedCols []*expression.Column) error { child := la.children[0] - used, err := getUsedList(parentUsedCols, la.Schema()) - if err != nil { - return err - } + used := getUsedList(parentUsedCols, la.Schema()) for i := len(used) - 1; i >= 0; i-- { if !used[i] { @@ -180,10 +163,7 @@ func (ls *LogicalSort) PruneColumns(parentUsedCols []*expression.Column) error { // PruneColumns implements LogicalPlan interface. func (p *LogicalUnionAll) PruneColumns(parentUsedCols []*expression.Column) error { - used, err := getUsedList(parentUsedCols, p.schema) - if err != nil { - return err - } + used := getUsedList(parentUsedCols, p.schema) hasBeenUsed := false for i := range used { @@ -220,10 +200,7 @@ func (p *LogicalUnionScan) PruneColumns(parentUsedCols []*expression.Column) err // PruneColumns implements LogicalPlan interface. func (ds *DataSource) PruneColumns(parentUsedCols []*expression.Column) error { - used, err := getUsedList(parentUsedCols, ds.schema) - if err != nil { - return err - } + used := getUsedList(parentUsedCols, ds.schema) var ( handleCol *expression.Column @@ -257,10 +234,7 @@ func (ds *DataSource) PruneColumns(parentUsedCols []*expression.Column) error { // PruneColumns implements LogicalPlan interface. func (p *LogicalTableDual) PruneColumns(parentUsedCols []*expression.Column) error { - used, err := getUsedList(parentUsedCols, p.Schema()) - if err != nil { - return err - } + used := getUsedList(parentUsedCols, p.Schema()) for i := len(used) - 1; i >= 0; i-- { if !used[i] { diff --git a/planner/core/rule_inject_extra_projection.go b/planner/core/rule_inject_extra_projection.go index 24f867f1431b2..593732f26fef3 100644 --- a/planner/core/rule_inject_extra_projection.go +++ b/planner/core/rule_inject_extra_projection.go @@ -167,9 +167,9 @@ func InjectProjBelowSort(p PhysicalPlan, orderByItems []*ByItems) PhysicalPlan { childPlan := p.Children()[0] bottomProjSchemaCols := make([]*expression.Column, 0, len(childPlan.Schema().Columns)+numOrderByItems) bottomProjExprs := make([]expression.Expression, 0, len(childPlan.Schema().Columns)+numOrderByItems) - for i, col := range childPlan.Schema().Columns { + for _, col := range childPlan.Schema().Columns { newCol := col.Clone().(*expression.Column) - newCol.Index = i + newCol.Index = childPlan.Schema().ColumnIndex(newCol) bottomProjSchemaCols = append(bottomProjSchemaCols, newCol) bottomProjExprs = append(bottomProjExprs, newCol) } diff --git a/planner/core/testdata/analyze_suite_out.json b/planner/core/testdata/analyze_suite_out.json index 22bc60ca4e7ef..1a8f07f43ab6f 100644 --- a/planner/core/testdata/analyze_suite_out.json +++ b/planner/core/testdata/analyze_suite_out.json @@ -47,13 +47,13 @@ ], "Plan": [ "Limit_17 1.00 root offset:0, count:1", - "└─IndexMergeJoin_70 1.00 root left outer semi join, inner:IndexReader_68, outer key:Column#1, inner key:Column#8", + "└─IndexMergeJoin_70 1.00 root left outer semi join, inner:IndexReader_68, outer key:Column#1, inner key:Column#5", " ├─TopN_29 1.00 root Column#1:asc, offset:0, count:1", " │ └─IndexReader_37 1.00 root index:TopN_36", " │ └─TopN_36 1.00 cop[tikv] Column#1:asc, offset:0, count:1", " │ └─IndexScan_35 6.00 cop[tikv] table:t1, index:b, c, range:[-inf,6], keep order:false", " └─IndexReader_68 1.04 root index:IndexScan_67", - " └─IndexScan_67 1.04 cop[tikv] table:t2, index:b, c, range: decided by [eq(Column#8, Column#1)], keep order:true" + " └─IndexScan_67 1.04 cop[tikv] table:t2, index:b, c, range: decided by [eq(Column#5, Column#1)], keep order:true" ] }, { diff --git a/planner/core/testdata/plan_suite_out.json b/planner/core/testdata/plan_suite_out.json index fe7be7d3927ff..b6b53bf28ba62 100644 --- a/planner/core/testdata/plan_suite_out.json +++ b/planner/core/testdata/plan_suite_out.json @@ -52,7 +52,7 @@ }, { "SQL": "select /*+ HASH_JOIN(@sel_2 t1@sel_2, t2@sel_2), SM_JOIN(@sel_1 t1@sel_1, t2@sel_1) */ * from (select t1.a, t1.b from t t1, t t2 where t1.a = t2.a) t1, t t2 where t1.b = t2.b", - "Best": "MergeInnerJoin{LeftHashJoin{TableReader(Table(t))->IndexReader(Index(t.f)[[NULL,+inf]])}(Column#1,Column#13)->Sort->TableReader(Table(t))->Sort}(Column#2,Column#28)->Projection" + "Best": "MergeInnerJoin{LeftHashJoin{TableReader(Table(t))->IndexReader(Index(t.f)[[NULL,+inf]])}(Column#1,Column#13)->Sort->TableReader(Table(t))->Sort}(Column#2,Column#26)->Projection" }, { "SQL": "select /*+ STREAM_AGG() */ s, count(s) from (select /*+ HASH_AGG() */ sum(t1.a) as s from t t1, t t2 where t1.a = t2.b group by t1.a) p group by s", @@ -238,7 +238,7 @@ }, { "SQL": "select c from t order by t.a + t.b limit 1", - "Best": "TableReader(Table(t)->TopN([plus(Column#1, Column#2)],0,1))->Projection->TopN([Column#17],0,1)->Projection->Projection" + "Best": "TableReader(Table(t)->TopN([plus(Column#1, Column#2)],0,1))->Projection->TopN([Column#14],0,1)->Projection->Projection" }, { "SQL": "select c from t limit 1", @@ -298,7 +298,7 @@ }, { "SQL": "select * from (select * from t use index() order by b) t left join t t1 on t.a=t1.a limit 10", - "Best": "IndexMergeJoin{TableReader(Table(t)->TopN([Column#2],0,10))->TopN([Column#2],0,10)->TableReader(Table(t))}(Column#1,Column#25)->Limit" + "Best": "IndexMergeJoin{TableReader(Table(t)->TopN([Column#2],0,10))->TopN([Column#2],0,10)->TableReader(Table(t))}(Column#1,Column#13)->Limit" }, { "SQL": "select * from ((SELECT 1 a,3 b) UNION (SELECT 2,1) ORDER BY (SELECT 2)) t order by a,b", @@ -331,7 +331,7 @@ "Cases": [ { "SQL": "select * from t t1 join t t2 on t1.a = t2.c_str", - "Best": "LeftHashJoin{TableReader(Table(t))->Projection->TableReader(Table(t))->Projection}(Column#49,Column#50)->Projection" + "Best": "LeftHashJoin{TableReader(Table(t))->Projection->TableReader(Table(t))->Projection}(Column#25,Column#26)->Projection" }, { "SQL": "select * from t t1 join t t2 on t1.b = t2.a", @@ -528,11 +528,11 @@ "Cases": [ { "SQL": "select * from t where exists (select s.a from t s having sum(s.a) = t.a )", - "Best": "LeftHashJoin{TableReader(Table(t))->Projection->IndexReader(Index(t.f)[[NULL,+inf]]->StreamAgg)->StreamAgg}(Column#41,Column#25)->Projection" + "Best": "LeftHashJoin{TableReader(Table(t))->Projection->IndexReader(Index(t.f)[[NULL,+inf]]->StreamAgg)->StreamAgg}(Column#27,Column#25)->Projection" }, { "SQL": "select * from t where exists (select s.a from t s having sum(s.a) = t.a ) order by t.a", - "Best": "LeftHashJoin{TableReader(Table(t))->Projection->IndexReader(Index(t.f)[[NULL,+inf]]->StreamAgg)->StreamAgg}(Column#41,Column#25)->Projection->Sort" + "Best": "LeftHashJoin{TableReader(Table(t))->Projection->IndexReader(Index(t.f)[[NULL,+inf]]->StreamAgg)->StreamAgg}(Column#27,Column#25)->Projection->Sort" }, { "SQL": "select * from t where a in (select s.a from t s) order by t.a", @@ -540,7 +540,7 @@ }, { "SQL": "select * from t where exists (select s.a from t s where s.c in (select c from t as k where k.d = s.d) having sum(s.a) = t.a )", - "Best": "LeftHashJoin{TableReader(Table(t))->Projection->MergeSemiJoin{IndexReader(Index(t.c_d_e)[[NULL,+inf]])->IndexReader(Index(t.c_d_e)[[NULL,+inf]])}(Column#15,Column#27)(Column#16,Column#28)->Projection->StreamAgg}(Column#54,Column#38)->Projection" + "Best": "LeftHashJoin{TableReader(Table(t))->Projection->MergeSemiJoin{IndexReader(Index(t.c_d_e)[[NULL,+inf]])->IndexReader(Index(t.c_d_e)[[NULL,+inf]])}(Column#15,Column#27)(Column#16,Column#28)->Projection->StreamAgg}(Column#39,Column#37)->Projection" }, { "SQL": "select * from t where a in (select a from t) order by b", @@ -690,7 +690,7 @@ }, { "SQL": "select a from t union all (select c from t) order by a limit 1", - "Best": "UnionAll{TableReader(Table(t)->Limit)->Limit->IndexReader(Index(t.c_d_e)[[NULL,+inf]]->Limit)->Limit}->TopN([Column#27],0,1)" + "Best": "UnionAll{TableReader(Table(t)->Limit)->Limit->IndexReader(Index(t.c_d_e)[[NULL,+inf]]->Limit)->Limit}->TopN([Column#25],0,1)" } ] }, @@ -1041,7 +1041,7 @@ }, { "SQL": "select max(a+1) from t;", - "Best": "IndexReader(Index(t.f)[[NULL,+inf]]->Sel([not(isnull(plus(Column#1, 1)))])->TopN([plus(Column#1, 1) true],0,1))->Projection->TopN([Column#41 true],0,1)->Projection->Projection->StreamAgg" + "Best": "IndexReader(Index(t.f)[[NULL,+inf]]->Sel([not(isnull(plus(Column#1, 1)))])->TopN([plus(Column#1, 1) true],0,1))->Projection->TopN([Column#40 true],0,1)->Projection->Projection->StreamAgg" }, { "SQL": "select max(a), min(a) from t;", @@ -1145,7 +1145,7 @@ }, { "SQL": "select count(t1.a) from t t1, t t2 where t1.a = t2.a*2 group by t1.a", - "Best": "LeftHashJoin{IndexReader(Index(t.f)[[NULL,+inf]])->IndexReader(Index(t.f)[[NULL,+inf]])->Projection}(Column#1,Column#27)->HashAgg", + "Best": "LeftHashJoin{IndexReader(Index(t.f)[[NULL,+inf]])->IndexReader(Index(t.f)[[NULL,+inf]])->Projection}(Column#1,Column#26)->HashAgg", "Warning": "" }, { @@ -1155,7 +1155,7 @@ }, { "SQL": "select /*+ STREAM_AGG() */ count(t1.a) from t t1, t t2 where t1.a = t2.a*2 group by t1.a", - "Best": "LeftHashJoin{IndexReader(Index(t.f)[[NULL,+inf]])->IndexReader(Index(t.f)[[NULL,+inf]])->Projection}(Column#1,Column#27)->Sort->StreamAgg", + "Best": "LeftHashJoin{IndexReader(Index(t.f)[[NULL,+inf]])->IndexReader(Index(t.f)[[NULL,+inf]])->Projection}(Column#1,Column#26)->Sort->StreamAgg", "Warning": "" }, { @@ -1170,12 +1170,12 @@ }, { "SQL": "select /*+ HASH_AGG() */ t1.a from t t1 where t1.a < any(select t2.b from t t2)", - "Best": "LeftHashJoin{IndexReader(Index(t.f)[[NULL,+inf]]->Sel([if(isnull(Column#1), , 1)]))->TableReader(Table(t)->HashAgg)->HashAgg->Sel([ne(Column#28, 0)])}->Projection->Projection", + "Best": "LeftHashJoin{IndexReader(Index(t.f)[[NULL,+inf]]->Sel([if(isnull(Column#1), , 1)]))->TableReader(Table(t)->HashAgg)->HashAgg->Sel([ne(Column#27, 0)])}->Projection->Projection", "Warning": "" }, { "SQL": "select /*+ hash_agg() */ t1.a from t t1 where t1.a != any(select t2.b from t t2)", - "Best": "LeftHashJoin{IndexReader(Index(t.f)[[NULL,+inf]]->Sel([if(isnull(Column#1), , 1)]))->TableReader(Table(t))->Projection->HashAgg->Sel([ne(Column#29, 0)])}->Projection->Projection", + "Best": "LeftHashJoin{IndexReader(Index(t.f)[[NULL,+inf]]->Sel([if(isnull(Column#1), , 1)]))->TableReader(Table(t))->Projection->HashAgg->Sel([ne(Column#28, 0)])}->Projection->Projection", "Warning": "" }, { @@ -1240,7 +1240,7 @@ }, { "SQL": "select /*+ HASH_AGG(@sel_2) */ a, (select count(*) from t t1 where t1.b > t.a) from t where b > (select b from t t2 where t2.b = t.a limit 1)", - "Plan": "Apply{Apply{TableReader(Table(t))->TableReader(Table(t)->Sel([eq(Column#14, Column#1)])->Limit)->Limit}->TableReader(Table(t)->Sel([gt(Column#28, Column#1)])->HashAgg)->HashAgg}->Projection", + "Plan": "Apply{Apply{TableReader(Table(t))->TableReader(Table(t)->Sel([eq(Column#14, Column#1)])->Limit)->Limit}->TableReader(Table(t)->Sel([gt(Column#26, Column#1)])->HashAgg)->HashAgg}->Projection", "Hints": "USE_INDEX(@`sel_1` `test`.`t` ), USE_INDEX(@`sel_3` `test`.`t2` ), USE_INDEX(@`sel_2` `test`.`t1` ), HASH_AGG(@`sel_2`)" }, { @@ -1250,7 +1250,7 @@ }, { "SQL": "select /*+ HASH_JOIN(@sel_2 t1@sel_2, t2@sel_2), SM_JOIN(@sel_1 t1@sel_1, t2@sel_1) */ * from (select t1.a, t1.b from t t1, t t2 where t1.a = t2.a) t1, t t2 where t1.b = t2.b", - "Plan": "MergeInnerJoin{LeftHashJoin{TableReader(Table(t))->IndexReader(Index(t.f)[[NULL,+inf]])}(Column#1,Column#13)->Sort->TableReader(Table(t))->Sort}(Column#2,Column#28)->Projection", + "Plan": "MergeInnerJoin{LeftHashJoin{TableReader(Table(t))->IndexReader(Index(t.f)[[NULL,+inf]])}(Column#1,Column#13)->Sort->TableReader(Table(t))->Sort}(Column#2,Column#26)->Projection", "Hints": "USE_INDEX(@`sel_2` `test`.`t1` ), USE_INDEX(@`sel_2` `test`.`t2` `f`), HASH_JOIN(@`sel_2` `test`.`t1`), USE_INDEX(@`sel_1` `test`.`t2` ), SM_JOIN(@`sel_1` `test`.`t1`)" } ] @@ -1277,7 +1277,7 @@ "Cases": [ { "SQL": "select t1.a, (select count(t2.a) from t t2 where t2.g in (select t3.d from t t3 where t3.c = t1.a)) as agg_col from t t1;", - "Best": "Apply{IndexReader(Index(t.f)[[NULL,+inf]])->IndexMergeJoin{IndexReader(Index(t.c_d_e)[[NULL,+inf]]->HashAgg)->HashAgg->IndexReader(Index(t.g)[[NULL,+inf]])}(Column#29,Column#23)}->HashAgg" + "Best": "Apply{IndexReader(Index(t.f)[[NULL,+inf]])->IndexMergeJoin{IndexReader(Index(t.c_d_e)[[NULL,+inf]]->HashAgg)->HashAgg->IndexReader(Index(t.g)[[NULL,+inf]])}(Column#28,Column#22)}->HashAgg" } ] }, diff --git a/planner/core/testdata/plan_suite_unexported_in.json b/planner/core/testdata/plan_suite_unexported_in.json new file mode 100644 index 0000000000000..f4e4d1eddc8fc --- /dev/null +++ b/planner/core/testdata/plan_suite_unexported_in.json @@ -0,0 +1,280 @@ +[ + { + "name": "TestEagerAggregation", + "cases": [ + "select sum(t.a), sum(t.a+1), sum(t.a), count(t.a), sum(t.a) + count(t.a) from t", + "select sum(t.a + t.b), sum(t.a + t.c), sum(t.a + t.b), count(t.a) from t having sum(t.a + t.b) > 0 order by sum(t.a + t.c)", + "select sum(a.a) from t a, t b where a.c = b.c", + "select sum(b.a) from t a, t b where a.c = b.c", + "select sum(b.a), a.a from t a, t b where a.c = b.c", + "select sum(a.a), b.a from t a, t b where a.c = b.c", + "select sum(a.a), sum(b.a) from t a, t b where a.c = b.c", + "select sum(a.a), max(b.a) from t a, t b where a.c = b.c", + "select max(a.a), sum(b.a) from t a, t b where a.c = b.c", + "select sum(a.a) from t a, t b, t c where a.c = b.c and b.c = c.c", + "select sum(b.a) from t a left join t b on a.c = b.c", + "select sum(a.a) from t a left join t b on a.c = b.c", + "select sum(a.a) from t a right join t b on a.c = b.c", + "select sum(a) from (select * from t) x", + "select sum(c1) from (select c c1, d c2 from t a union all select a c1, b c2 from t b union all select b c1, e c2 from t c) x group by c2", + "select max(a.b), max(b.b) from t a join t b on a.c = b.c group by a.a", + "select max(a.b), max(b.b) from t a join t b on a.a = b.a group by a.c", + "select max(c.b) from (select * from t a union all select * from t b) c group by c.a", + "select max(a.c) from t a join t b on a.a=b.a and a.b=b.b group by a.b", + "select t1.a, count(t2.b) from t t1, t t2 where t1.a = t2.a group by t1.a" + ] + }, + { + "name": "TestPlanBuilder", + "cases": [ + "select * from t for update", + "update t set t.a = t.a * 1.5 where t.a >= 1000 order by t.a desc limit 10", + "delete from t where t.a >= 1000 order by t.a desc limit 10", + "explain select * from t union all select * from t limit 1, 1", + // The correctness of explain result is checked at integration test. There is to improve coverage. + "explain select /*+ TIDB_INLJ(t1, t2) */ * from t t1 left join t t2 on t1.a=t2.a where t1.b=1 and t2.b=1 and (t1.c=1 or t2.c=1)", + "explain select /*+ TIDB_HJ(t1, t2) */ * from t t1 left join t t2 on t1.a=t2.a where t1.b=1 and t2.b=1 and (t1.c=1 or t2.c=1)", + "explain select /*+ TIDB_SMJ(t1, t2) */ * from t t1 right join t t2 on t1.a=t2.a where t1.b=1 and t2.b=1 and (t1.c=1 or t2.c=1)", + "explain format=\"dot\" select /*+ TIDB_SMJ(t1, t2) */ * from t t1, t t2 where t1.a=t2.a", + "explain select * from t order by b", + "explain select * from t order by b limit 1", + "explain format=\"dot\" select * from t order by a", + "insert into t select * from t", + "show columns from t where `Key` = 'pri' like 't*'", + "do sleep(5)", + "select substr(\"abc\", 1)", + "select * from t t1, t t2 where 1 = 0", + "select * from t t1 join t t2 using(a)", + "select * from t t1 natural join t t2", + // Note the Projection before Delete: the final schema should be the schema of + // table t rather than Join. + // If this schema is not set correctly, table.RemoveRecord would fail when adding + // binlog columns, because the schema and data are not consistent. + "delete from t where a in (select b from t where c = 666) or b in (select a from t where c = 42)", + "update t set a = 2 where b in (select c from t)" + ] + }, + { + "name": "TestPredicatePushDown", + "cases": [ + "select count(*) from t a, t b where a.a = b.a", + "select a from (select a from t where d = 0) k where k.a = 5", + "select a from (select a+1 as a from t) k where k.a = 5", + "select a from (select 1+2 as a from t where d = 0) k where k.a = 5", + "select a from (select d as a from t where d = 0) k where k.a = 5", + "select * from t ta, t tb where (ta.d, ta.a) = (tb.b, tb.c)", + "select * from t t1, t t2 where t1.a = t2.b and t2.b > 0 and t1.a = t1.c and t1.d like 'abc' and t2.d = t1.d", + "select * from t ta join t tb on ta.d = tb.d and ta.d > 1 where tb.a = 0", + "select * from t ta join t tb on ta.d = tb.d where ta.d > 1 and tb.a = 0", + "select * from t ta left outer join t tb on ta.d = tb.d and ta.d > 1 where tb.a = 0", + "select * from t ta right outer join t tb on ta.d = tb.d and ta.a > 1 where tb.a = 0", + "select * from t ta left outer join t tb on ta.d = tb.d and ta.a > 1 where ta.d = 0", + "select * from t ta left outer join t tb on ta.d = tb.d and ta.a > 1 where tb.d = 0", + "select * from t ta left outer join t tb on ta.d = tb.d and ta.a > 1 where tb.c is not null and tb.c = 0 and ifnull(tb.d, 1)", + "select * from t ta left outer join t tb on ta.a = tb.a left outer join t tc on tb.b = tc.b where tc.c > 0", + "select * from t ta left outer join t tb on ta.a = tb.a left outer join t tc on tc.b = ta.b where tb.c > 0", + "select * from t as ta left outer join (t as tb left join t as tc on tc.b = tb.b) on tb.a = ta.a where tc.c > 0", + "select * from ( t as ta left outer join t as tb on ta.a = tb.a) join ( t as tc left join t as td on tc.b = td.b) on ta.c = td.c where tb.c = 2 and td.a = 1", + "select * from t ta left outer join (t tb left outer join t tc on tc.b = tb.b) on tb.a = ta.a and tc.c = ta.c where tc.d > 0 or ta.d > 0", + "select * from t ta left outer join t tb on ta.d = tb.d and ta.a > 1 where ifnull(tb.d, 1) or tb.d is null", + "select a, d from (select * from t union all select * from t union all select * from t) z where a < 10", + "select (select count(*) from t where t.a = k.a) from t k", + "select a from t where exists(select 1 from t as x where x.a < t.a)", + "select a from t where exists(select 1 from t as x where x.a = t.a and t.a < 1 and x.a < 1)", + "select a from t where exists(select 1 from t as x where x.a = t.a and x.a < 1) and a < 1", + "select a from t where exists(select 1 from t as x where x.a = t.a) and exists(select 1 from t as x where x.a = t.a)", + "select * from (select a, b, sum(c) as s from t group by a, b) k where k.a > k.b * 2 + 1", + "select * from (select a, b, sum(c) as s from t group by a, b) k where k.a > 1 and k.b > 2", + "select * from (select k.a, sum(k.s) as ss from (select a, sum(b) as s from t group by a) k group by k.a) l where l.a > 2", + "select * from (select a, sum(b) as s from t group by a) k where a > s", + "select * from (select a, sum(b) as s from t group by a + 1) k where a > 1", + "select * from (select a, sum(b) as s from t group by a having 1 = 0) k where a > 1", + "select a, count(a) cnt from t group by a having cnt < 1", + // issue #3873 + "select t1.a, t2.a from t as t1 left join t as t2 on t1.a = t2.a where t1.a < 1.0", + // issue #7728 + "select * from t t1 join t t2 on t1.a = t2.a where t2.a = null", + "select a, b from (select a, b, min(a) over(partition by b) as min_a from t)as tt where a < 10 and b > 10 and b = min_a", + "select a, b from (select a, b, c, d, sum(a) over(partition by b, c) as sum_a from t)as tt where b + c > 10 and b in (1, 2) and sum_a > b" + ] + }, + { + "name": "TestSubquery", + "cases": [ + // This will be resolved as in sub query. + "select * from t where 10 in (select b from t s where s.a = t.a)", + "select count(c) ,(select b from t s where s.a = t.a) from t", + "select count(c) ,(select count(s.b) from t s where s.a = t.a) from t", + // Semi-join with agg cannot decorrelate. + "select t.c in (select count(s.b) from t s where s.a = t.a) from t", + "select (select count(s.b) k from t s where s.a = t.a having k != 0) from t", + "select (select count(s.b) k from t s where s.a = t1.a) from t t1, t t2", + "select (select count(1) k from t s where s.a = t.a having k != 0) from t", + "select a from t where a in (select a from t s group by t.b)", + // This will be resolved as in sub query. + "select * from t where 10 in (((select b from t s where s.a = t.a)))", + // This will be resolved as in function. + "select * from t where 10 in (((select b from t s where s.a = t.a)), 10)", + "select * from t where exists (select s.a from t s having sum(s.a) = t.a )", + // Test MaxOneRow for limit. + "select (select * from (select b from t limit 1) x where x.b = t1.b) from t t1", + // Test Nested sub query. + "select * from t where exists (select s.a from t s where s.c in (select c from t as k where k.d = s.d) having sum(s.a) = t.a )", + "select t1.b from t t1 where t1.b = (select max(t2.a) from t t2 where t1.b=t2.b)", + "select t1.b from t t1 where t1.b = (select avg(t2.a) from t t2 where t1.g=t2.g and (t1.b = 4 or t2.b = 2))", + "select t1.b from t t1 where t1.b = (select max(t2.a) from t t2 where t1.b=t2.b order by t1.a)", + "select t1.b from t t1 where t1.b in (select t2.b from t t2 where t2.a = t1.a order by t2.a)", + "select t1.b from t t1 where exists(select t2.b from t t2 where t2.a = t1.a order by t2.a)", + // `Sort` will not be eliminated, if it is not the top level operator. + "select t1.b from t t1 where t1.b = (select t2.b from t t2 where t2.a = t1.a order by t2.a limit 1)" + ] + }, + { + "name": "TestTopNPushDown", + "cases": [ + // Test TopN + Selection. + "select * from t where a < 1 order by b limit 5", + // Test Limit + Selection. + "select * from t where a < 1 limit 5", + // Test Limit + Agg + Proj . + "select a, count(b) from t group by b limit 5", + // Test TopN + Agg + Proj . + "select a, count(b) from t group by b order by c limit 5", + // Test TopN + Join + Proj. + "select * from t, t s order by t.a limit 5", + // Test Limit + Join + Proj. + "select * from t, t s limit 5", + // Test TopN + Left Join + Proj. + "select * from t left outer join t s on t.a = s.a order by t.a limit 5", + // Test TopN + Left Join + Proj. + "select * from t left outer join t s on t.a = s.a order by t.a limit 5, 5", + // Test Limit + Left Join + Proj. + "select * from t left outer join t s on t.a = s.a limit 5", + // Test Limit + Left Join Apply + Proj. + "select (select s.a from t s where t.a = s.a) from t limit 5", + // Test TopN + Left Join Apply + Proj. + "select (select s.a from t s where t.a = s.a) from t order by t.a limit 5", + // Test TopN + Left Semi Join Apply + Proj. + "select exists (select s.a from t s where t.a = s.a) from t order by t.a limit 5", + // Test TopN + Semi Join Apply + Proj. + "select * from t where exists (select s.a from t s where t.a = s.a) order by t.a limit 5", + // Test TopN + Right Join + Proj. + "select * from t right outer join t s on t.a = s.a order by s.a limit 5", + // Test Limit + Right Join + Proj. + "select * from t right outer join t s on t.a = s.a order by s.a,t.b limit 5", + // Test TopN + UA + Proj. + "select * from t union all (select * from t s) order by a,b limit 5", + // Test TopN + UA + Proj. + "select * from t union all (select * from t s) order by a,b limit 5, 5", + // Test Limit + UA + Proj + Sort. + "select * from t union all (select * from t s order by a) limit 5", + // Test `ByItem` containing column from both sides. + "select ifnull(t1.b, t2.a) from t t1 left join t t2 on t1.e=t2.e order by ifnull(t1.b, t2.a) limit 5", + // Test ifnull cannot be eliminated + "select ifnull(t1.h, t2.b) from t t1 left join t t2 on t1.e=t2.e order by ifnull(t1.h, t2.b) limit 5" + ] + }, + { + "name": "TestUnion", + "cases": [ + "select a from t union select a from t", + "select a from t union all select a from t", + "select a from t union select a from t union all select a from t", + "select a from t union select a from t union all select a from t union select a from t union select a from t", + "select a from t union select a, b from t", + "select * from (select 1 as a union select 1 union all select 2) t order by a", + "select * from (select 1 as a union select 1 union all select 2) t order by (select a)" + ] + }, + { + "name": "TestWindowFunction", + "cases": [ + "select a, avg(a) over(partition by a) from t", + "select a, avg(a) over(partition by b) from t", + "select a, avg(a+1) over(partition by (a+1)) from t", + "select a, avg(a) over(order by a asc, b desc) from t order by a asc, b desc", + "select a, b as a, avg(a) over(partition by a) from t", + "select a, b as z, sum(z) over() from t", + "select a, b as z from t order by (sum(z) over())", + "select sum(avg(a)) over() from t", + "select b from t order by(sum(a) over())", + "select b from t order by(sum(a) over(partition by a))", + "select b from t order by(sum(avg(a)) over())", + "select a from t having (select sum(a) over() as w from t tt where a > t.a)", + "select avg(a) over() as w from t having w > 1", + "select sum(a) over() as sum_a from t group by sum_a", + "select sum(a) over() from t window w1 as (w2)", + "select sum(a) over(w) from t", + "select sum(a) over() from t window w1 as (w2), w2 as (w1)", + "select sum(a) over(w partition by a) from t window w as ()", + "SELECT FIRST_VALUE(a) RESPECT NULLS OVER (w1 PARTITION BY b ORDER BY b ASC, a DESC ROWS 2 PRECEDING) AS 'first_value', a, b FROM ( SELECT a, b FROM `t` ) as t WINDOW w1 AS (PARTITION BY b ORDER BY b ASC, a ASC );", + "select sum(a) over(w) from t window w as (rows between 1 preceding AND 1 following)", + "select sum(a) over w from t window w as (rows between 1 preceding AND 1 following)", + "select sum(a) over(w order by b) from t window w as (order by a)", + "select sum(a) over() from t window w1 as (), w1 as ()", + "select avg(a) over(w2) from t window w1 as (partition by a), w2 as (w1)", + "select a from t window w1 as (partition by a) order by (sum(a) over(w1))", + "select sum(a) over(groups 1 preceding) from t", + "select sum(a) over(rows between unbounded following and 1 preceding) from t", + "select sum(a) over(rows between current row and unbounded preceding) from t", + "select sum(a) over(rows interval 1 MINUTE_SECOND preceding) from t", + "select sum(a) over(rows between 1.0 preceding and 1 following) from t", + "select sum(a) over(range between 1 preceding and 1 following) from t", + "select sum(a) over(order by c_str range between 1 preceding and 1 following) from t", + "select sum(a) over(order by a range interval 1 MINUTE_SECOND preceding) from t", + "select sum(a) over(order by i_date range interval a MINUTE_SECOND preceding) from t", + "select sum(a) over(order by i_date range interval -1 MINUTE_SECOND preceding) from t", + "select sum(a) over(order by i_date range 1 preceding) from t", + "select sum(a) over(order by a range between 1.0 preceding and 1 following) from t", + "select row_number() over(rows between 1 preceding and 1 following) from t", + "select avg(b), max(avg(b)) over(rows between 1 preceding and 1 following) max from t group by c", + "select nth_value(a, 1.0) over() from t", + "SELECT NTH_VALUE(a, 1.0) OVER() FROM t", + "select nth_value(a, 0) over() from t", + "select ntile(0) over() from t", + "select ntile(null) over() from t", + "select avg(a) over w from t window w as(partition by b)", + "select nth_value(i_date, 1) over() from t", + "select sum(b) over w, sum(c) over w from t window w as (order by a)", + "delete from t order by (sum(a) over())", + "delete from t order by (SUM(a) over())", + "SELECT * from t having ROW_NUMBER() over()", + // The best execution order should be (a,c), (a, b, c), (a, b), (), it requires only 2 sort operations. + "select sum(a) over (partition by a order by b), sum(b) over (order by a, b, c), sum(c) over(partition by a order by c), sum(d) over() from t", + // Test issue 11010. + "select dense_rank() over w1, a, b from t window w1 as (partition by t.b order by t.a desc, t.b desc range between current row and 1 following)", + "select dense_rank() over w1, a, b from t window w1 as (partition by t.b order by t.a desc, t.b desc range between current row and unbounded following)", + "select dense_rank() over w1, a, b from t window w1 as (partition by t.b order by t.a desc, t.b desc range between 1 preceding and 1 following)", + // Test issue 11001. + "SELECT PERCENT_RANK() OVER w1 AS 'percent_rank', fieldA, fieldB FROM ( SELECT a AS fieldA, b AS fieldB FROM t ) t1 WINDOW w1 AS ( ROWS BETWEEN 0 FOLLOWING AND UNBOUNDED PRECEDING)", + // Test issue 11002. + "SELECT PERCENT_RANK() OVER w1 AS 'percent_rank', fieldA, fieldB FROM ( SELECT a AS fieldA, b AS fieldB FROM t ) as t1 WINDOW w1 AS ( ROWS BETWEEN UNBOUNDED FOLLOWING AND UNBOUNDED FOLLOWING)", + // Test issue 11011. + "select dense_rank() over w1, a, b from t window w1 as (partition by t.b order by t.a asc range between 1250951168 following AND 1250951168 preceding)", + // Test issue 10556. + "SELECT FIRST_VALUE(a) IGNORE NULLS OVER () FROM t", + "SELECT SUM(DISTINCT a) OVER () FROM t", + "SELECT NTH_VALUE(a, 1) FROM LAST over (partition by b order by b), a FROM t", + "SELECT NTH_VALUE(a, 1) FROM LAST IGNORE NULLS over (partition by b order by b), a FROM t", + "SELECT NTH_VALUE(fieldA, ATAN(-1)) OVER (w1) AS 'ntile', fieldA, fieldB FROM ( SELECT a AS fieldA, b AS fieldB FROM t ) as te WINDOW w1 AS ( ORDER BY fieldB ASC, fieldA DESC )", + "SELECT NTH_VALUE(fieldA, -1) OVER (w1 PARTITION BY fieldB ORDER BY fieldB , fieldA ) AS 'ntile', fieldA, fieldB FROM ( SELECT a AS fieldA, b AS fieldB FROM t ) as temp WINDOW w1 AS ( ORDER BY fieldB ASC, fieldA DESC )", + "SELECT SUM(a) OVER w AS 'sum' FROM t WINDOW w AS (ROWS BETWEEN 1 FOLLOWING AND CURRENT ROW )", + "SELECT SUM(a) OVER w AS 'sum' FROM t WINDOW w AS (ROWS BETWEEN CURRENT ROW AND 1 PRECEDING )", + "SELECT SUM(a) OVER w AS 'sum' FROM t WINDOW w AS (ROWS BETWEEN 1 FOLLOWING AND 1 PRECEDING )", + // Test issue 11943 + "SELECT ROW_NUMBER() OVER (partition by b) + a FROM t" + ] + }, + { + "name": "TestUniqueKeyInfo", + "cases": [ + "select a, sum(e) from t group by b", + "select a, b, sum(f) from t group by b", + "select c, d, e, sum(a) from t group by c, d, e", + "select f, g, sum(a) from t", + "select * from t t1 join t t2 on t1.a = t2.e", + "select f from t having sum(a) > 0", + "select * from t t1 left join t t2 on t1.a = t2.a" + ] + } +] diff --git a/planner/core/testdata/plan_suite_unexported_out.json b/planner/core/testdata/plan_suite_unexported_out.json new file mode 100644 index 0000000000000..5ee455ab4950d --- /dev/null +++ b/planner/core/testdata/plan_suite_unexported_out.json @@ -0,0 +1,479 @@ +[ + { + "Name": "TestEagerAggregation", + "Cases": [ + "DataScan(t)->Aggr(sum(Column#1),sum(plus(Column#1, 1)),count(Column#1))->Projection", + "DataScan(t)->Aggr(sum(plus(Column#1, Column#2)),sum(plus(Column#1, Column#3)),count(Column#1))->Sel([gt(Column#13, 0)])->Projection->Sort->Projection", + "Join{DataScan(a)->Aggr(sum(Column#1),firstrow(Column#3))->DataScan(b)}(Column#3,Column#15)->Aggr(sum(Column#26))->Projection", + "Join{DataScan(a)->DataScan(b)->Aggr(sum(Column#13),firstrow(Column#15))}(Column#3,Column#15)->Aggr(sum(Column#26))->Projection", + "Join{DataScan(a)->DataScan(b)->Aggr(sum(Column#13),firstrow(Column#15))}(Column#3,Column#15)->Aggr(sum(Column#26),firstrow(Column#1))->Projection", + "Join{DataScan(a)->Aggr(sum(Column#1),firstrow(Column#3))->DataScan(b)}(Column#3,Column#15)->Aggr(sum(Column#26),firstrow(Column#13))->Projection", + "Join{DataScan(a)->DataScan(b)}(Column#3,Column#15)->Aggr(sum(Column#1),sum(Column#13))->Projection", + "Join{DataScan(a)->Aggr(sum(Column#1),firstrow(Column#3))->DataScan(b)}(Column#3,Column#15)->Aggr(sum(Column#27),max(Column#13))->Projection", + "Join{DataScan(a)->DataScan(b)->Aggr(sum(Column#13),firstrow(Column#15))}(Column#3,Column#15)->Aggr(max(Column#1),sum(Column#27))->Projection", + "Join{Join{DataScan(a)->DataScan(b)}(Column#3,Column#15)->DataScan(c)}(Column#15,Column#27)->Aggr(sum(Column#1))->Projection", + "Join{DataScan(a)->DataScan(b)->Aggr(sum(Column#13),firstrow(Column#15))}(Column#3,Column#15)->Aggr(sum(Column#26))->Projection", + "Join{DataScan(a)->Aggr(sum(Column#1),firstrow(Column#3))->DataScan(b)}(Column#3,Column#15)->Aggr(sum(Column#26))->Projection", + "Join{DataScan(a)->Aggr(sum(Column#1),firstrow(Column#3))->DataScan(b)}(Column#3,Column#15)->Aggr(sum(Column#26))->Projection", + "DataScan(t)->Aggr(sum(Column#1))->Projection", + "UnionAll{DataScan(a)->Projection->Aggr(sum(Column#27),firstrow(Column#28))->DataScan(b)->Projection->Aggr(sum(Column#13),firstrow(Column#14))->DataScan(c)->Projection->Aggr(sum(Column#2),firstrow(Column#5))}->Aggr(sum(Column#40))->Projection", + "Join{DataScan(a)->DataScan(b)->Aggr(max(Column#14),firstrow(Column#15))}(Column#3,Column#15)->Projection->Projection", + "Join{DataScan(a)->DataScan(b)}(Column#1,Column#13)->Aggr(max(Column#2),max(Column#14))->Projection", + "UnionAll{DataScan(a)->Projection->Projection->Projection->DataScan(b)->Projection->Projection->Projection}->Aggr(max(Column#38))->Projection", + "Join{DataScan(a)->DataScan(b)}(Column#1,Column#13)(Column#2,Column#14)->Aggr(max(Column#3))->Projection", + "Join{DataScan(t1)->DataScan(t2)}(Column#1,Column#13)->Projection->Projection" + ] + }, + { + "Name": "TestPlanBuilder", + "Cases": [ + "DataScan(t)->Lock->Projection", + "TableReader(Table(t)->Limit)->Limit->Update", + "TableReader(Table(t)->Limit)->Limit->Delete", + "*core.Explain", + "*core.Explain", + "*core.Explain", + "*core.Explain", + "*core.Explain", + "*core.Explain", + "*core.Explain", + "*core.Explain", + "TableReader(Table(t))->Insert", + "Show->Sel([eq(cast(Column#4), 0)])->Projection", + "Dual->Projection", + "Dual->Projection", + "Dual->Projection", + "Join{DataScan(t1)->DataScan(t2)}->Projection", + "Join{DataScan(t1)->DataScan(t2)}->Projection", + "LeftHashJoin{LeftHashJoin{TableReader(Table(t))->IndexLookUp(Index(t.c_d_e)[[666,666]], Table(t))}(Column#1,Column#14)->IndexReader(Index(t.c_d_e)[[42,42]])}(Column#2,Column#26)->Sel([or(Column#25, Column#38)])->Projection->Delete", + "LeftHashJoin{TableReader(Table(t))->IndexReader(Index(t.c_d_e)[[NULL,+inf]])->HashAgg}(Column#2,Column#15)->Projection->Update" + ] + }, + { + "Name": "TestPredicatePushDown", + "Cases": [ + "Join{DataScan(a)->DataScan(b)}(Column#1,Column#13)->Aggr(count(1))->Projection", + "DataScan(t)->Projection->Projection", + "DataScan(t)->Projection->Projection", + "DataScan(t)->Projection->Projection", + "DataScan(t)->Projection->Projection", + "Join{DataScan(ta)->DataScan(tb)}(Column#4,Column#14)(Column#1,Column#15)->Projection", + "Join{DataScan(t1)->Sel([like(cast(Column#4), abc, 92)])->DataScan(t2)->Sel([like(cast(Column#16), abc, 92)])}(Column#1,Column#14)(Column#4,Column#16)->Projection", + "Join{DataScan(ta)->DataScan(tb)}(Column#4,Column#16)->Projection", + "Join{DataScan(ta)->DataScan(tb)}(Column#4,Column#16)->Projection", + "Join{DataScan(ta)->DataScan(tb)}(Column#4,Column#16)->Projection", + "Join{DataScan(ta)->DataScan(tb)}(Column#4,Column#16)->Projection", + "Join{DataScan(ta)->DataScan(tb)}->Projection", + "Join{DataScan(ta)->DataScan(tb)}->Projection", + "Join{DataScan(ta)->DataScan(tb)}(Column#4,Column#16)->Projection", + "Join{Join{DataScan(ta)->DataScan(tb)}(Column#1,Column#13)->DataScan(tc)}(Column#14,Column#26)->Projection", + "Join{Join{DataScan(ta)->DataScan(tb)}(Column#1,Column#13)->DataScan(tc)}(Column#2,Column#26)->Projection", + "Join{DataScan(ta)->Join{DataScan(tb)->DataScan(tc)}(Column#14,Column#26)}(Column#1,Column#13)->Projection", + "Join{Join{DataScan(ta)->DataScan(tb)}(Column#1,Column#13)->Join{DataScan(tc)->DataScan(td)}(Column#26,Column#38)}(Column#3,Column#39)->Projection", + "Join{DataScan(ta)->Join{DataScan(tb)->DataScan(tc)}(Column#14,Column#26)}(Column#1,Column#13)(Column#3,Column#27)->Sel([or(gt(Column#28, 0), gt(Column#4, 0))])->Projection", + "Join{DataScan(ta)->DataScan(tb)}(Column#4,Column#16)->Sel([or(ifnull(Column#16, 1), isnull(Column#16))])->Projection", + "UnionAll{DataScan(t)->Projection->Projection->DataScan(t)->Projection->Projection->DataScan(t)->Projection->Projection}->Projection", + "Apply{DataScan(k)->DataScan(t)->Aggr(count(1))->Projection->MaxOneRow}->Projection", + "Join{DataScan(t)->DataScan(x)}->Projection", + "Join{DataScan(t)->DataScan(x)}(Column#1,Column#13)->Projection", + "Join{DataScan(t)->DataScan(x)}(Column#1,Column#13)->Projection", + "Join{Join{DataScan(t)->DataScan(x)}(Column#1,Column#13)->DataScan(x)}(Column#1,Column#26)->Projection", + "DataScan(t)->Aggr(sum(Column#3),firstrow(Column#1),firstrow(Column#2))->Projection->Projection", + "DataScan(t)->Aggr(sum(Column#3),firstrow(Column#1),firstrow(Column#2))->Projection->Projection", + "DataScan(t)->Aggr(sum(Column#2),firstrow(Column#1))->Projection->Aggr(sum(Column#13),firstrow(Column#1))->Projection->Projection", + "DataScan(t)->Aggr(sum(Column#2),firstrow(Column#1))->Sel([gt(cast(Column#1), Column#13)])->Projection->Projection", + "DataScan(t)->Aggr(sum(Column#2),firstrow(Column#1))->Sel([gt(Column#1, 1)])->Projection->Projection", + "Dual->Sel([gt(Column#1, 1)])->Projection", + "DataScan(t)->Aggr(count(Column#1),firstrow(Column#1))->Sel([lt(Column#13, 1)])->Projection", + "Join{DataScan(t1)->DataScan(t2)}(Column#1,Column#13)->Projection", + "Dual->Projection", + "DataScan(t)->Projection->Projection->Window(min(Column#1))->Sel([lt(Column#1, 10) eq(Column#2, Column#14)])->Projection->Projection", + "DataScan(t)->Projection->Projection->Window(sum(cast(Column#1)))->Sel([gt(Column#14, cast(Column#2))])->Projection->Projection" + ] + }, + { + "Name": "TestSubquery", + "Cases": [ + "Join{DataScan(t)->DataScan(s)}(Column#1,Column#13)->Projection", + "Join{DataScan(t)->Aggr(count(Column#3),firstrow(Column#1))->DataScan(s)}(Column#1,Column#14)->Projection->Projection", + "Join{DataScan(t)->Aggr(count(Column#3),firstrow(Column#1))->DataScan(s)}(Column#1,Column#14)->Aggr(firstrow(Column#13),firstrow(Column#1),count(Column#15))->Projection->Projection", + "Apply{DataScan(t)->DataScan(s)->Sel([eq(Column#13, Column#1)])->Aggr(count(Column#14))}->Projection", + "Join{DataScan(t)->DataScan(s)->Aggr(count(Column#14),firstrow(Column#13))}(Column#1,Column#13)->Projection->Projection->Projection", + "Join{Join{DataScan(t1)->DataScan(t2)}->DataScan(s)->Aggr(count(Column#26),firstrow(Column#25))}(Column#1,Column#25)->Projection->Projection->Projection", + "Join{DataScan(t)->DataScan(s)->Aggr(count(1),firstrow(Column#13))}(Column#1,Column#13)->Projection->Projection->Projection", + "Join{DataScan(t)->DataScan(s)->Aggr(firstrow(Column#13))->Projection}(Column#1,Column#13)->Projection", + "Join{DataScan(t)->DataScan(s)}(Column#1,Column#13)->Projection", + "Join{DataScan(t)->DataScan(s)}(Column#1,Column#13)->Projection->Sel([in(10, Column#14, 10)])->Projection", + "Join{DataScan(t)->DataScan(s)->Aggr(sum(Column#13))->Projection}->Projection", + "Join{DataScan(t1)->DataScan(t)->Projection->Limit}(Column#2,Column#14)->Projection->Projection", + "Join{DataScan(t)->Join{DataScan(s)->DataScan(k)}(Column#16,Column#28)(Column#15,Column#27)->Aggr(sum(Column#13))->Projection}->Projection", + "Join{DataScan(t1)->DataScan(t2)->Aggr(max(Column#13),firstrow(Column#14))}(Column#2,Column#14)->Projection->Sel([eq(Column#2, Column#25)])->Projection", + "Apply{DataScan(t1)->DataScan(t2)->Sel([eq(Column#10, Column#22) or(eq(Column#2, 4), eq(Column#14, 2))])->Aggr(avg(Column#13))}->Projection->Sel([eq(cast(Column#2), Column#25)])->Projection", + "Join{DataScan(t1)->DataScan(t2)->Aggr(max(Column#13),firstrow(Column#14))}(Column#2,Column#14)->Projection->Sel([eq(Column#2, Column#25)])->Projection", + "Join{DataScan(t1)->DataScan(t2)}(Column#1,Column#13)(Column#2,Column#14)->Projection", + "Join{DataScan(t1)->DataScan(t2)}(Column#1,Column#13)->Projection", + "Apply{DataScan(t1)->DataScan(t2)->Sel([eq(Column#13, Column#1)])->Projection->Sort->Limit}->Projection->Sel([eq(Column#2, Column#25)])->Projection" + ] + }, + { + "Name": "TestTopNPushDown", + "Cases": [ + "DataScan(t)->TopN([Column#2],0,5)->Projection", + "DataScan(t)->Limit->Projection", + "DataScan(t)->Aggr(count(Column#2),firstrow(Column#1))->Limit->Projection", + "DataScan(t)->Aggr(count(Column#2),firstrow(Column#1),firstrow(Column#3))->TopN([Column#3],0,5)->Projection", + "Join{DataScan(t)->DataScan(s)}->TopN([Column#1],0,5)->Projection", + "Join{DataScan(t)->DataScan(s)}->Limit->Projection", + "Join{DataScan(t)->TopN([Column#1],0,5)->DataScan(s)}(Column#1,Column#13)->TopN([Column#1],0,5)->Projection", + "Join{DataScan(t)->TopN([Column#1],0,10)->DataScan(s)}(Column#1,Column#13)->TopN([Column#1],5,5)->Projection", + "Join{DataScan(t)->Limit->DataScan(s)}(Column#1,Column#13)->Limit->Projection", + "Join{DataScan(t)->Limit->DataScan(s)}(Column#1,Column#13)->Limit->Projection", + "Join{DataScan(t)->TopN([Column#1],0,5)->DataScan(s)}(Column#1,Column#13)->TopN([Column#1],0,5)->Projection", + "Join{DataScan(t)->TopN([Column#1],0,5)->DataScan(s)}(Column#1,Column#13)->TopN([Column#1],0,5)->Projection", + "Join{DataScan(t)->DataScan(s)}(Column#1,Column#13)->TopN([Column#1],0,5)->Projection", + "Join{DataScan(t)->DataScan(s)->TopN([Column#13],0,5)}(Column#1,Column#13)->TopN([Column#13],0,5)->Projection", + "Join{DataScan(t)->DataScan(s)}(Column#1,Column#13)->TopN([Column#13 Column#2],0,5)->Projection", + "UnionAll{DataScan(t)->TopN([Column#13 Column#14],0,5)->Projection->DataScan(s)->TopN([Column#1 Column#2],0,5)->Projection}->TopN([Column#25 Column#26],0,5)", + "UnionAll{DataScan(t)->TopN([Column#13 Column#14],0,10)->Projection->DataScan(s)->TopN([Column#1 Column#2],0,10)->Projection}->TopN([Column#25 Column#26],5,5)", + "UnionAll{DataScan(t)->Limit->Projection->DataScan(s)->TopN([Column#1],0,5)->Projection}->Limit", + "Join{DataScan(t1)->TopN([Column#2],0,5)->DataScan(t2)}(Column#5,Column#17)->TopN([Column#2],0,5)->Projection", + "Join{DataScan(t1)->DataScan(t2)}(Column#5,Column#17)->TopN([ifnull(Column#11, Column#14)],0,5)->Projection->Projection" + ] + }, + { + "Name": "TestUnion", + "Cases": [ + { + "Best": "UnionAll{DataScan(t)->Projection->DataScan(t)->Projection}->Aggr(firstrow(Column#25))", + "Err": false + }, + { + "Best": "UnionAll{DataScan(t)->Projection->DataScan(t)->Projection}", + "Err": false + }, + { + "Best": "UnionAll{UnionAll{DataScan(t)->Projection->DataScan(t)->Projection}->Aggr(firstrow(Column#37))->Projection->DataScan(t)->Projection}", + "Err": false + }, + { + "Best": "UnionAll{DataScan(t)->Projection->DataScan(t)->Projection->DataScan(t)->Projection->DataScan(t)->Projection->DataScan(t)->Projection}->Aggr(firstrow(Column#61))", + "Err": false + }, + { + "Best": "", + "Err": true + }, + { + "Best": "UnionAll{UnionAll{Dual->Projection->Dual->Projection}->Aggr(firstrow(Column#4))->Projection->Dual->Projection}->Projection->Sort", + "Err": false + }, + { + "Best": "Apply{UnionAll{UnionAll{Dual->Projection->Dual->Projection}->Aggr(firstrow(Column#4))->Projection->Dual->Projection}->Dual->Projection->MaxOneRow}->Sort->Projection", + "Err": false + } + ] + }, + { + "Name": "TestWindowFunction", + "Cases": [ + "TableReader(Table(t))->Window(avg(cast(Column#1)) over(partition by Column#1))->Projection", + "TableReader(Table(t))->Sort->Window(avg(cast(Column#1)) over(partition by Column#2))->Projection", + "IndexReader(Index(t.f)[[NULL,+inf]])->Projection->Sort->Window(avg(cast(Column#16)) over(partition by Column#15))->Projection", + "TableReader(Table(t))->Sort->Window(avg(cast(Column#1)) over(order by Column#1 asc, Column#2 desc range between unbounded preceding and current row))->Projection", + "TableReader(Table(t))->Window(avg(cast(Column#1)) over(partition by Column#1))->Projection", + "[planner:1054]Unknown column 'z' in 'field list'", + "TableReader(Table(t))->Window(sum(cast(Column#2)) over())->Sort->Projection", + "IndexReader(Index(t.f)[[NULL,+inf]]->StreamAgg)->StreamAgg->Window(sum(Column#13) over())->Projection", + "TableReader(Table(t))->Window(sum(cast(Column#1)) over())->Sort->Projection", + "TableReader(Table(t))->Window(sum(cast(Column#1)) over(partition by Column#1))->Sort->Projection", + "TableReader(Table(t)->StreamAgg)->StreamAgg->Window(sum(Column#13) over())->Sort->Projection", + "Apply{IndexReader(Index(t.f)[[NULL,+inf]])->IndexReader(Index(t.f)[[NULL,+inf]]->Sel([gt(Column#13, Column#1)]))->Window(sum(cast(Column#13)) over())->MaxOneRow->Sel([Column#26])}->Projection", + "[planner:3594]You cannot use the alias 'w' of an expression containing a window function in this context.'", + "[planner:1247]Reference 'sum_a' not supported (reference to window function)", + "[planner:3579]Window name 'w2' is not defined.", + "[planner:3579]Window name 'w' is not defined.", + "[planner:3580]There is a circularity in the window dependency graph.", + "[planner:3581]A window which depends on another cannot define partitioning.", + "[planner:3581]A window which depends on another cannot define partitioning.", + "[planner:3582]Window 'w' has a frame definition, so cannot be referenced by another window.", + "IndexReader(Index(t.f)[[NULL,+inf]])->Window(sum(cast(Column#1)) over(rows between 1 preceding and 1 following))->Projection", + "[planner:3583]Window '' cannot inherit 'w' since both contain an ORDER BY clause.", + "[planner:3591]Window 'w1' is defined twice.", + "TableReader(Table(t))->Window(avg(cast(Column#1)) over(partition by Column#1))->Projection", + "TableReader(Table(t))->Window(sum(cast(Column#1)) over(partition by Column#1))->Sort->Projection", + "[planner:1235]This version of TiDB doesn't yet support 'GROUPS'", + "[planner:3584]Window '': frame start cannot be UNBOUNDED FOLLOWING.", + "[planner:3585]Window '': frame end cannot be UNBOUNDED PRECEDING.", + "[planner:3596]Window '': INTERVAL can only be used with RANGE frames.", + "[planner:3586]Window '': frame start or end is negative, NULL or of non-integral type", + "[planner:3587]Window '' with RANGE N PRECEDING/FOLLOWING frame requires exactly one ORDER BY expression, of numeric or temporal type", + "[planner:3587]Window '' with RANGE N PRECEDING/FOLLOWING frame requires exactly one ORDER BY expression, of numeric or temporal type", + "[planner:3589]Window '' with RANGE frame has ORDER BY expression of numeric type, INTERVAL bound value not allowed.", + "[planner:3590]Window '' has a non-constant frame bound.", + "[planner:3586]Window '': frame start or end is negative, NULL or of non-integral type", + "[planner:3588]Window '' with RANGE frame has ORDER BY expression of datetime type. Only INTERVAL bound value allowed.", + "TableReader(Table(t))->Window(sum(cast(Column#1)) over(order by Column#1 asc range between 1.0 preceding and 1 following))->Projection", + "IndexReader(Index(t.f)[[NULL,+inf]])->Window(row_number() over())->Projection", + "TableReader(Table(t))->HashAgg->Window(max(Column#13) over(rows between 1 preceding and 1 following))->Projection", + "[planner:1210]Incorrect arguments to nth_value", + "[planner:1210]Incorrect arguments to nth_value", + "[planner:1210]Incorrect arguments to nth_value", + "[planner:1210]Incorrect arguments to ntile", + "IndexReader(Index(t.f)[[NULL,+inf]])->Window(ntile() over())->Projection", + "TableReader(Table(t))->Sort->Window(avg(cast(Column#1)) over(partition by Column#2))->Projection", + "TableReader(Table(t))->Window(nth_value(Column#12, 1) over())->Projection", + "TableReader(Table(t))->Window(sum(cast(Column#2)), sum(cast(Column#3)) over(order by Column#1 asc range between unbounded preceding and current row))->Projection", + "[planner:3593]You cannot use the window function 'sum' in this context.'", + "[planner:3593]You cannot use the window function 'sum' in this context.'", + "[planner:3593]You cannot use the window function 'row_number' in this context.'", + "TableReader(Table(t))->Sort->Window(sum(cast(Column#3)) over(partition by Column#1 order by Column#3 asc range between unbounded preceding and current row))->Sort->Window(sum(cast(Column#2)) over(order by Column#1 asc, Column#2 asc, Column#3 asc range between unbounded preceding and current row))->Window(sum(cast(Column#1)) over(partition by Column#1 order by Column#2 asc range between unbounded preceding and current row))->Window(sum(cast(Column#4)) over())->Projection", + "[planner:3587]Window 'w1' with RANGE N PRECEDING/FOLLOWING frame requires exactly one ORDER BY expression, of numeric or temporal type", + "TableReader(Table(t))->Sort->Window(dense_rank() over(partition by Column#2 order by Column#1 desc, Column#2 desc))->Projection", + "[planner:3587]Window 'w1' with RANGE N PRECEDING/FOLLOWING frame requires exactly one ORDER BY expression, of numeric or temporal type", + "[planner:3585]Window 'w1': frame end cannot be UNBOUNDED PRECEDING.", + "[planner:3584]Window 'w1': frame start cannot be UNBOUNDED FOLLOWING.", + "[planner:3586]Window 'w1': frame start or end is negative, NULL or of non-integral type", + "[planner:1235]This version of TiDB doesn't yet support 'IGNORE NULLS'", + "[planner:1235]This version of TiDB doesn't yet support '(DISTINCT ..)'", + "[planner:1235]This version of TiDB doesn't yet support 'FROM LAST'", + "[planner:1235]This version of TiDB doesn't yet support 'IGNORE NULLS'", + "[planner:1210]Incorrect arguments to nth_value", + "[planner:1210]Incorrect arguments to nth_value", + "[planner:3586]Window 'w': frame start or end is negative, NULL or of non-integral type", + "[planner:3586]Window 'w': frame start or end is negative, NULL or of non-integral type", + "[planner:3586]Window 'w': frame start or end is negative, NULL or of non-integral type", + "TableReader(Table(t))->Sort->Window(row_number() over(partition by Column#2))->Projection" + ] + }, + { + "Name": "TestUniqueKeyInfo", + "Cases": [ + { + "1": [ + [ + "Column#1" + ] + ], + "2": [ + [ + "Column#1" + ] + ], + "3": [ + [ + "Column#1" + ] + ] + }, + { + "1": [ + [ + "Column#9" + ], + [ + "Column#1" + ] + ], + "2": [ + [ + "Column#1" + ], + [ + "Column#2" + ] + ], + "3": [ + [ + "Column#1" + ], + [ + "Column#2" + ] + ] + }, + { + "1": [ + [ + "Column#1" + ] + ], + "2": [ + [ + "Column#3", + "Column#4", + "Column#5" + ] + ], + "3": [ + [ + "Column#3", + "Column#4", + "Column#5" + ] + ] + }, + { + "1": [ + [ + "Column#9" + ], + [ + "Column#9", + "Column#10" + ], + [ + "Column#1" + ] + ], + "2": [ + [ + "Column#9" + ], + [ + "Column#9", + "Column#10" + ] + ], + "3": [ + [ + "Column#9" + ], + [ + "Column#9", + "Column#10" + ] + ] + }, + { + "1": [ + [ + "Column#9" + ], + [ + "Column#9", + "Column#10" + ], + [ + "Column#1" + ] + ], + "2": [ + [ + "Column#21" + ], + [ + "Column#21", + "Column#22" + ], + [ + "Column#13" + ] + ], + "3": [ + [ + "Column#21" + ], + [ + "Column#21", + "Column#22" + ], + [ + "Column#13" + ] + ], + "4": [ + [ + "Column#21" + ], + [ + "Column#21", + "Column#22" + ], + [ + "Column#13" + ] + ] + }, + { + "1": [ + [ + "Column#9" + ], + [ + "Column#1" + ] + ], + "2": [ + [ + "Column#9" + ] + ], + "3": [ + [ + "Column#9" + ] + ], + "5": [ + [ + "Column#14" + ] + ], + "6": [ + [ + "Column#9" + ] + ] + }, + { + "1": [ + [ + "Column#9" + ], + [ + "Column#9", + "Column#10" + ], + [ + "Column#1" + ] + ], + "2": [ + [ + "Column#21" + ], + [ + "Column#21", + "Column#22" + ], + [ + "Column#13" + ] + ], + "3": [ + [ + "Column#9" + ], + [ + "Column#9", + "Column#10" + ], + [ + "Column#1" + ] + ], + "4": [ + [ + "Column#9" + ], + [ + "Column#9", + "Column#10" + ], + [ + "Column#1" + ] + ] + } + ] + } +] diff --git a/planner/failtest/fail_test.go b/planner/failtest/fail_test.go deleted file mode 100644 index 393ac9ae399c9..0000000000000 --- a/planner/failtest/fail_test.go +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2019 PingCAP, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// See the License for the specific language governing permissions and -// limitations under the License. - -package failtest - -import ( - "testing" - - . "github.com/pingcap/check" - "github.com/pingcap/failpoint" - "github.com/pingcap/tidb/domain" - "github.com/pingcap/tidb/kv" - "github.com/pingcap/tidb/session" - "github.com/pingcap/tidb/sessionctx" - "github.com/pingcap/tidb/store/mockstore" - "github.com/pingcap/tidb/util/mock" - "github.com/pingcap/tidb/util/testkit" - "github.com/pingcap/tidb/util/testleak" -) - -func TestT(t *testing.T) { - TestingT(t) -} - -var _ = Suite(&testFailPointSuit{}) - -type testFailPointSuit struct { - store kv.Storage - dom *domain.Domain - ctx sessionctx.Context -} - -func (s *testFailPointSuit) SetUpSuite(c *C) { - store, err := mockstore.NewMockTikvStore() - c.Assert(err, IsNil) - c.Assert(store, NotNil) - - dom, err := session.BootstrapSession(store) - c.Assert(err, IsNil) - c.Assert(dom, NotNil) - - s.store, s.dom, s.ctx = store, dom, mock.NewContext() -} - -func (s *testFailPointSuit) TearDownSuite(c *C) { - s.dom.Close() - err := s.store.Close() - c.Assert(err, IsNil) -} - -func (s *testFailPointSuit) SetUpTest(c *C) { - testleak.BeforeTest() -} - -func (s *testFailPointSuit) TearDownTest(c *C) { - testleak.AfterTest(c)() -} - -func (s *testFailPointSuit) TestColumnPruningError(c *C) { - tk := testkit.NewTestKit(c, s.store) - tk.MustExec(`use test;`) - tk.MustExec(`drop table if exists t;`) - tk.MustExec(`create table t(a int, b int);`) - tk.MustExec(`insert into t values(1,1);`) - - // test normal behavior - tk.MustQuery(`select a from t;`).Check(testkit.Rows(`1`)) - - // test the injected fail point - c.Assert(failpoint.Enable("github.com/pingcap/tidb/planner/core/enableGetUsedListErr", `return(true)`), IsNil) - defer func() { - c.Assert(failpoint.Disable("github.com/pingcap/tidb/planner/core/enableGetUsedListErr"), IsNil) - }() - err := tk.ExecToErr(`select a from t;`) - c.Assert(err.Error(), Equals, "getUsedList failed, triggered by gofail enableGetUsedListErr") -} diff --git a/util/ranger/testdata/ranger_suite_out.json b/util/ranger/testdata/ranger_suite_out.json index dcb3afdd2e7a9..9616c2db53ffc 100644 --- a/util/ranger/testdata/ranger_suite_out.json +++ b/util/ranger/testdata/ranger_suite_out.json @@ -5,7 +5,7 @@ { "SQL": "explain select t.e in (select count(*) from t s use index(idx), t t1 where s.b = 1 and s.c in (1, 2) and s.d = t.a and s.a = t1.a) from t", "Result": [ - "Projection_11 2.00 root Column#18", + "Projection_11 2.00 root Column#17", "└─Apply_13 2.00 root CARTESIAN left outer semi join, inner:StreamAgg_20, other cond:eq(Column#5, Column#16)", " ├─TableReader_15 2.00 root data:TableScan_14", " │ └─TableScan_14 2.00 cop[tikv] table:t, range:[-inf,+inf], keep order:false",