From cd527d5988a721511028b344ae73dc4294aecd1e Mon Sep 17 00:00:00 2001 From: Zhi Qi <30543181+LittleFall@users.noreply.github.com> Date: Fri, 8 Jul 2022 17:21:03 +0800 Subject: [PATCH 1/2] cherry pick #36025 to release-6.1 Signed-off-by: ti-srebot --- planner/core/exhaust_physical_plans.go | 8 ++++++-- .../testdata/window_push_down_suite_in.json | 3 ++- .../testdata/window_push_down_suite_out.json | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/planner/core/exhaust_physical_plans.go b/planner/core/exhaust_physical_plans.go index b4670f1146c2b..cbbc770fdf985 100644 --- a/planner/core/exhaust_physical_plans.go +++ b/planner/core/exhaust_physical_plans.go @@ -2291,7 +2291,7 @@ func (lw *LogicalWindow) tryToGetMppWindows(prop *property.PhysicalProperty) []P if len(lw.PartitionBy) > 0 { partitionCols := lw.GetPartitionKeys() - // trying to match the required parititions. + // trying to match the required partitions. if prop.MPPPartitionTp == property.HashType { if matches := prop.IsSubsetOf(partitionCols); len(matches) != 0 { partitionCols = choosePartitionKeys(partitionCols, matches) @@ -2306,6 +2306,10 @@ func (lw *LogicalWindow) tryToGetMppWindows(prop *property.PhysicalProperty) []P childProperty.MPPPartitionTp = property.SinglePartitionType } + if prop.MPPPartitionTp == property.SinglePartitionType && childProperty.MPPPartitionTp != property.SinglePartitionType { + return nil + } + window := PhysicalWindow{ WindowFuncDescs: lw.WindowFuncDescs, PartitionBy: lw.PartitionBy, @@ -2596,7 +2600,7 @@ func (la *LogicalAggregation) tryToGetMppHashAggs(prop *property.PhysicalPropert if len(la.GroupByItems) > 0 { partitionCols := la.GetPotentialPartitionKeys() - // trying to match the required parititions. + // trying to match the required partitions. if prop.MPPPartitionTp == property.HashType { if matches := prop.IsSubsetOf(partitionCols); len(matches) != 0 { partitionCols = choosePartitionKeys(partitionCols, matches) diff --git a/planner/core/testdata/window_push_down_suite_in.json b/planner/core/testdata/window_push_down_suite_in.json index 3f228f5b6a476..27f12930a4cdd 100644 --- a/planner/core/testdata/window_push_down_suite_in.json +++ b/planner/core/testdata/window_push_down_suite_in.json @@ -46,7 +46,8 @@ "explain select count(distinct empid) from (select *, row_number() over () from employee) t", "explain select count(distinct empid) from (select *, row_number() over (partition by deptid) from employee) t", "explain select count(empid) from (select *, row_number() over () a from employee) t group by a", - "explain select count(empid) from (select *, row_number() over (partition by deptid) a from employee) t group by a" + "explain select count(empid) from (select *, row_number() over (partition by deptid) a from employee) t group by a", + "explain select row_number() over w2, row_number() over w1 from employee window w2 as (order by deptid), w1 as (partition by deptid);" ] } ] diff --git a/planner/core/testdata/window_push_down_suite_out.json b/planner/core/testdata/window_push_down_suite_out.json index 2b7b7b893cda4..44cd954c9b076 100644 --- a/planner/core/testdata/window_push_down_suite_out.json +++ b/planner/core/testdata/window_push_down_suite_out.json @@ -443,6 +443,24 @@ " └─TableFullScan_18 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo" ], "Warn": null + }, + { + "SQL": "explain select row_number() over w2, row_number() over w1 from employee window w2 as (order by deptid), w1 as (partition by deptid);", + "Plan": [ + "TableReader_37 10000.00 root data:ExchangeSender_36", + "└─ExchangeSender_36 10000.00 mpp[tiflash] ExchangeType: PassThrough", + " └─Projection_10 10000.00 mpp[tiflash] Column#8, Column#7", + " └─Window_35 10000.00 mpp[tiflash] row_number()->Column#8 over(order by test.employee.deptid rows between current row and current row)", + " └─Sort_20 10000.00 mpp[tiflash] test.employee.deptid", + " └─ExchangeReceiver_19 10000.00 mpp[tiflash] ", + " └─ExchangeSender_18 10000.00 mpp[tiflash] ExchangeType: PassThrough", + " └─Window_13 10000.00 mpp[tiflash] row_number()->Column#7 over(partition by test.employee.deptid rows between current row and current row), stream_count: 8", + " └─Sort_17 10000.00 mpp[tiflash] test.employee.deptid, stream_count: 8", + " └─ExchangeReceiver_16 10000.00 mpp[tiflash] stream_count: 8", + " └─ExchangeSender_15 10000.00 mpp[tiflash] ExchangeType: HashPartition, Hash Cols: [name: test.employee.deptid, collate: binary], stream_count: 8", + " └─TableFullScan_14 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo" + ], + "Warn": null } ] } From b3611317d06959154e8b84f0039c9e509be72413 Mon Sep 17 00:00:00 2001 From: Zhi Qi <30543181+LittleFall@users.noreply.github.com> Date: Mon, 22 Aug 2022 15:48:30 +0800 Subject: [PATCH 2/2] fix ut --- planner/core/testdata/window_push_down_suite_out.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/planner/core/testdata/window_push_down_suite_out.json b/planner/core/testdata/window_push_down_suite_out.json index 44cd954c9b076..f769a6b1a4544 100644 --- a/planner/core/testdata/window_push_down_suite_out.json +++ b/planner/core/testdata/window_push_down_suite_out.json @@ -454,10 +454,10 @@ " └─Sort_20 10000.00 mpp[tiflash] test.employee.deptid", " └─ExchangeReceiver_19 10000.00 mpp[tiflash] ", " └─ExchangeSender_18 10000.00 mpp[tiflash] ExchangeType: PassThrough", - " └─Window_13 10000.00 mpp[tiflash] row_number()->Column#7 over(partition by test.employee.deptid rows between current row and current row), stream_count: 8", - " └─Sort_17 10000.00 mpp[tiflash] test.employee.deptid, stream_count: 8", - " └─ExchangeReceiver_16 10000.00 mpp[tiflash] stream_count: 8", - " └─ExchangeSender_15 10000.00 mpp[tiflash] ExchangeType: HashPartition, Hash Cols: [name: test.employee.deptid, collate: binary], stream_count: 8", + " └─Window_13 10000.00 mpp[tiflash] row_number()->Column#7 over(partition by test.employee.deptid rows between current row and current row)", + " └─Sort_17 10000.00 mpp[tiflash] test.employee.deptid", + " └─ExchangeReceiver_16 10000.00 mpp[tiflash] ", + " └─ExchangeSender_15 10000.00 mpp[tiflash] ExchangeType: HashPartition, Hash Cols: [name: test.employee.deptid, collate: binary]", " └─TableFullScan_14 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo" ], "Warn": null