Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

planner: add missing exchange between hash-partition window and single-partition window (#36025) #36052

Merged
merged 3 commits into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions planner/core/exhaust_physical_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion planner/core/testdata/window_push_down_suite_in.json
Original file line number Diff line number Diff line change
Expand Up @@ -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);"
]
}
]
18 changes: 18 additions & 0 deletions planner/core/testdata/window_push_down_suite_out.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
" └─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
}
]
}
Expand Down