Skip to content

[Bug] The result is not as expected when there are empty groups in group sets #55413

@xiedeyantu

Description

@xiedeyantu

Search before asking

  • I had searched in the issues and found no similar issues.

Version

master branch

What's Wrong?

CREATE TABLE `emp` (
  `empno` int NULL,
  `ename` varchar(10) NOT NULL,
  `job` varchar(9) NULL,
  `mgr` int NULL,
  `hiredate` date NULL,
  `sal` decimal(7,2) NULL,
  `comm` decimal(7,2) NULL,
  `deptno` int NULL
) ENGINE=OLAP
DUPLICATE KEY(`empno`)
DISTRIBUTED BY HASH(`empno`) BUCKETS 10
PROPERTIES (
"replication_allocation" = "tag.location.default: 1"
); 

Plan and result:

mysql> explain logical plan select sum(empno) from EMP where false group by grouping sets((),());                                                         
+--------------------------------------------------------------------------------------------------------------------------------------------+            
| Explain String(Nereids Planner)                                                                                                            |            
+--------------------------------------------------------------------------------------------------------------------------------------------+            
| LogicalResultSink[105] ( outputExprs=[__sum_0#10] )                                                                                        |            
| +--LogicalProject[104] ( distinct=false, projects=[sum(empno)#10] )                                                                        |            
|    +--LogicalAggregate[103] ( groupByExpr=[GROUPING_ID#11], outputExpr=[GROUPING_ID#11, sum(empno#0) AS `sum(empno)`#10], hasRepeat=true ) |            
|       +--LogicalRepeat ( groupingSets=[[], []], outputExpressions=[empno#0, GROUPING_ID#11] )                                              |            
|          +--LogicalEmptyRelation ( projects=[empno#0] )                                                                                    |            
+--------------------------------------------------------------------------------------------------------------------------------------------+            
5 rows in set (0.00 sec)                                                                                                                                  
                                                                                                                                                          
mysql> explain logical plan select sum(empno) from EMP where false group by grouping sets(());                                                            
+-----------------------------------------------------------------------------------------------------------+                                             
| Explain String(Nereids Planner)                                                                           |                                             
+-----------------------------------------------------------------------------------------------------------+                                             
| LogicalResultSink[56] ( outputExprs=[__sum_0#10] )                                                        |                                             
| +--LogicalAggregate[55] ( groupByExpr=[], outputExpr=[sum(empno#0) AS `sum(empno)`#10], hasRepeat=false ) |                                             
|    +--LogicalEmptyRelation ( projects=[empno#0] )                                                         |                                             
+-----------------------------------------------------------------------------------------------------------+                                             
3 rows in set (0.01 sec)                                                                                                                                  
                                                                                                                                                          
mysql> select sum(empno) from EMP where false group by grouping sets((),());                                                                              
Empty set (0.04 sec)   <------- If executed using pgsql, a NULL value should be returned.                                                                                                                                 
                                                                                                                                                          
mysql> select sum(empno) from EMP where false group by grouping sets(());                                                                                 
+------------+                                                                                                                                            
| sum(empno) |                                                                                                                                            
+------------+                                                                                                                                            
|       NULL |                                                                                                                                            
+------------+                                                                                                                                            
1 row in set (0.02 sec)  

What You Expected?

mysql> select sum(empno) from EMP where false group by grouping sets((),()); 
+------------+                                                                                                                                            
| sum(empno) |                                                                                                                                            
+------------+                                                                                                                                            
|       NULL | 
|       NULL |                                                                                                                                                
+------------+ 

How to Reproduce?

No response

Anything Else?

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions