Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
Signed-off-by: AilinKid <[email protected]>
  • Loading branch information
AilinKid committed Jul 29, 2024
1 parent 7ffc7c9 commit 74be2aa
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/planner/core/logical_expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ func (p *LogicalExpand) ExhaustPhysicalPlans(prop *property.PhysicalProperty) ([

// ExtractCorrelatedCols implements base.LogicalPlan.<15th> interface.
func (p *LogicalExpand) ExtractCorrelatedCols() []*expression.CorrelatedColumn {
// if p.LevelExprs is nil, it means the GenLevelProjections has not been called yet,
// which is done in logical optimizing phase. While for building correlated subquery
// plan, the ExtractCorrelatedCols will be called once after building, so we should
// distinguish the case here.
if p.LevelExprs == nil {
// since level projections generation don't produce any correlated columns, just
// return nil.
return nil
}
corCols := make([]*expression.CorrelatedColumn, 0, len(p.LevelExprs[0]))
for _, lExpr := range p.LevelExprs {
for _, expr := range lExpr {
Expand Down
23 changes: 23 additions & 0 deletions tests/integrationtest/r/executor/expand.result
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,26 @@ GROUP BY product WITH ROLLUP) AS tmp
WHERE product is null;
product SUM
NULL 7785

SELECT product FROM t1 WHERE EXISTS
(SELECT product, country_id , SUM(profit) FROM t1 AS t2
WHERE t1.product=t2.product GROUP BY product, country_id WITH ROLLUP
HAVING SUM(profit) > 6000);
product
Computer
Computer
Computer
Computer
Computer

SELECT product, country_id , year, SUM(profit) FROM t1
GROUP BY product, country_id, year HAVING country_id is NULL;
product country_id year SUM(profit)
SELECT CONCAT(':',product,':'), SUM(profit), AVG(profit) FROM t1
GROUP BY product WITH ROLLUP;
CONCAT(':',product,':') SUM(profit) AVG(profit)
NULL 7785 519.0000
:TV: 600 120.0000
:Calculator: 275 68.7500
:Phone: 10 10.0000
:Computer: 6900 1380.0000
19 changes: 19 additions & 0 deletions tests/integrationtest/t/executor/expand.test
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,22 @@ t1.country_id=t2.country_id GROUP BY product, country, year WITH ROLLUP;
SELECT product, `SUM` FROM (SELECT product, SUM(profit) AS 'sum' FROM t1
GROUP BY product WITH ROLLUP) AS tmp
WHERE product is null;

--echo
--sorted_result
SELECT product FROM t1 WHERE EXISTS
(SELECT product, country_id , SUM(profit) FROM t1 AS t2
WHERE t1.product=t2.product GROUP BY product, country_id WITH ROLLUP
HAVING SUM(profit) > 6000);

--echo
--sorted_result
# The following does not return the expected answer, but this is a limitation
# in the implementation so we should just document it
SELECT product, country_id , year, SUM(profit) FROM t1
GROUP BY product, country_id, year HAVING country_id is NULL;

--echo
--sorted_result
SELECT CONCAT(':',product,':'), SUM(profit), AVG(profit) FROM t1
GROUP BY product WITH ROLLUP;

0 comments on commit 74be2aa

Please sign in to comment.