planner: add missing exchange between hash-partition agg and single-partition window (#43981)

close pingcap/tidb#43922
This commit is contained in:
Liqi Geng
2023-05-22 22:21:38 +08:00
committed by GitHub
parent 38254fe2c6
commit d14644bfe6
3 changed files with 32 additions and 10 deletions

View File

@ -13,7 +13,8 @@
"explain select *, rank() over () FROM (select *, row_number() over () a from employee) tmp -- 6. multi window from sub query",
"explain select *, rank() over (partition by deptid) FROM (select *, row_number() over () a from employee) tmp -- 6.1 multi window from sub query",
// "explain select *, max(salary) over (), max(salary) over (partition by deptid order by salary), row_number() over (partition by deptid order by salary), max(salary) over (partition by deptid order by empid), row_number() over (partition by deptid order by empid), count(empid) over (partition by salary order by deptid) from employee; -- 7. complex",
"explain select *, sum(a) over (partition by deptid) FROM (select *, row_number() over (order by md5(deptid)) a from employee) tmp; -- 8. some scalar function not supported."
"explain select *, sum(a) over (partition by deptid) FROM (select *, row_number() over (order by md5(deptid)) a from employee) tmp; -- 8. some scalar function not supported.",
"explain select deptid, row_number() OVER() from (select deptid from employee group by deptid) t;"
]
},
{

View File

@ -149,6 +149,23 @@
"Scalar function 'md5'(signature: MD5, return type: var_string(32)) is not supported to push down to tiflash now.",
"MPP mode may be blocked because window function `sum` or its arguments are not supported now."
]
},
{
"SQL": "explain select deptid, row_number() OVER() from (select deptid from employee group by deptid) t;",
"Plan": [
"TableReader_77 8000.00 root MppVersion: 1, data:ExchangeSender_76",
"└─ExchangeSender_76 8000.00 mpp[tiflash] ExchangeType: PassThrough",
" └─Window_75 8000.00 mpp[tiflash] row_number()->Column#6 over(rows between current row and current row)",
" └─ExchangeReceiver_26 8000.00 mpp[tiflash] ",
" └─ExchangeSender_25 8000.00 mpp[tiflash] ExchangeType: PassThrough, Compression: FAST",
" └─Projection_21 8000.00 mpp[tiflash] test.employee.deptid",
" └─HashAgg_22 8000.00 mpp[tiflash] group by:test.employee.deptid, funcs:firstrow(test.employee.deptid)->test.employee.deptid",
" └─ExchangeReceiver_24 8000.00 mpp[tiflash] ",
" └─ExchangeSender_23 8000.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: test.employee.deptid, collate: binary]",
" └─HashAgg_13 8000.00 mpp[tiflash] group by:test.employee.deptid, ",
" └─TableFullScan_20 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo"
],
"Warn": null
}
]
},
@ -340,15 +357,17 @@
{
"SQL": "explain select *, row_number() over () from (select count(empid) from employee group by deptid) t",
"Plan": [
"TableReader_84 8000.00 root MppVersion: 1, data:ExchangeSender_83",
"└─ExchangeSender_83 8000.00 mpp[tiflash] ExchangeType: PassThrough",
" └─Window_82 8000.00 mpp[tiflash] row_number()->Column#7 over(rows between current row and current row)",
" └─Projection_21 8000.00 mpp[tiflash] Column#5",
" └─HashAgg_22 8000.00 mpp[tiflash] group by:test.employee.deptid, funcs:sum(Column#8)->Column#5",
" └─ExchangeReceiver_24 8000.00 mpp[tiflash] ",
" └─ExchangeSender_23 8000.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: test.employee.deptid, collate: binary]",
" └─HashAgg_13 8000.00 mpp[tiflash] group by:test.employee.deptid, funcs:count(test.employee.empid)->Column#8",
" └─TableFullScan_20 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo"
"TableReader_77 8000.00 root MppVersion: 1, data:ExchangeSender_76",
"└─ExchangeSender_76 8000.00 mpp[tiflash] ExchangeType: PassThrough",
" └─Window_75 8000.00 mpp[tiflash] row_number()->Column#7 over(rows between current row and current row)",
" └─ExchangeReceiver_26 8000.00 mpp[tiflash] ",
" └─ExchangeSender_25 8000.00 mpp[tiflash] ExchangeType: PassThrough, Compression: FAST",
" └─Projection_21 8000.00 mpp[tiflash] Column#5",
" └─HashAgg_22 8000.00 mpp[tiflash] group by:test.employee.deptid, funcs:sum(Column#8)->Column#5",
" └─ExchangeReceiver_24 8000.00 mpp[tiflash] ",
" └─ExchangeSender_23 8000.00 mpp[tiflash] ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: test.employee.deptid, collate: binary]",
" └─HashAgg_13 8000.00 mpp[tiflash] group by:test.employee.deptid, funcs:count(test.employee.empid)->Column#8",
" └─TableFullScan_20 10000.00 mpp[tiflash] table:employee keep order:false, stats:pseudo"
],
"Warn": null
},

View File

@ -3115,6 +3115,8 @@ func (la *LogicalAggregation) tryToGetMppHashAggs(prop *property.PhysicalPropert
// do not satisfy the property of its parent, so return empty
return nil
}
} else if prop.MPPPartitionTp != property.AnyType {
return nil
}
// TODO: permute various partition columns from group-by columns
// 1-phase agg