siddharthteotia commented on code in PR #10248: URL: https://github.com/apache/pinot/pull/10248#discussion_r1114005651
########## pinot-query-planner/src/test/resources/queries/GroupByPlans.json: ########## @@ -91,6 +91,92 @@ "\n LogicalTableScan(table=[[a]])", "\n" ] + }, + { + "description": "SQL hint based group by optimization with select and aggregate column", + "sql": "EXPLAIN PLAN FOR SELECT /*+ SKIP_LEAF_STAGE_GROUP_BY_AGGREGATION */ a.col1, SUM(a.col3) FROM a GROUP BY a.col1", + "output": [ + "Execution Plan", + "\nLogicalAggregate(group=[{0}], EXPR$1=[$SUM0($1)])", + "\n LogicalExchange(distribution=[hash[0]])", + "\n LogicalProject(col1=[$2], col3=[$1])", + "\n LogicalTableScan(table=[[a]])", + "\n" + ] + }, + { + "description": "SQL hint based group by optimization with filter", + "sql": "EXPLAIN PLAN FOR SELECT /*+ SKIP_LEAF_STAGE_GROUP_BY_AGGREGATION */ a.col1, SUM(a.col3) FROM a WHERE a.col3 >= 0 AND a.col2 = 'a' GROUP BY a.col1", + "output": [ + "Execution Plan", + "\nLogicalAggregate(group=[{2}], EXPR$1=[$SUM0($1)])", + "\n LogicalExchange(distribution=[hash[2]])", + "\n LogicalProject(col2=[$0], col3=[$1], col1=[$2])", + "\n LogicalFilter(condition=[AND(>=($1, 0), =($0, 'a'))])", + "\n LogicalTableScan(table=[[a]])", + "\n" + ] + }, + { + "description": "SQL hint based group by optimization count(*) with filter", + "sql": "EXPLAIN PLAN FOR SELECT /*+ SKIP_LEAF_STAGE_GROUP_BY_AGGREGATION */ a.col1, COUNT(*) FROM a WHERE a.col3 >= 0 AND a.col2 = 'a' GROUP BY a.col1", + "notes": "TODO: Needs follow up. Project should only keep a.col1 since the other columns are pushed to the filter, but it currently keeps them all", + "output": [ + "Execution Plan", + "\nLogicalAggregate(group=[{2}], EXPR$1=[COUNT()])", + "\n LogicalExchange(distribution=[hash[2]])", + "\n LogicalProject(col2=[$0], col3=[$1], col1=[$2])", + "\n LogicalFilter(condition=[AND(>=($1, 0), =($0, 'a'))])", + "\n LogicalTableScan(table=[[a]])", + "\n" + ] + }, + { + "description": "SQL hint based group by optimization on 2 columns with filter", + "sql": "EXPLAIN PLAN FOR SELECT /*+ SKIP_LEAF_STAGE_GROUP_BY_AGGREGATION */ a.col2, a.col1, SUM(a.col3) FROM a WHERE a.col3 >= 0 AND a.col1 = 'a' GROUP BY a.col1, a.col2", + "output": [ + "Execution Plan", + "\nLogicalAggregate(group=[{0, 2}], EXPR$2=[$SUM0($1)])", + "\n LogicalExchange(distribution=[hash[0, 2]])", + "\n LogicalProject(col2=[$0], col3=[$1], col1=[$2])", + "\n LogicalFilter(condition=[AND(>=($1, 0), =($2, 'a'))])", + "\n LogicalTableScan(table=[[a]])", + "\n" + ] + }, + { + "description": "SQL hint based group by optimization with having clause", + "sql": "EXPLAIN PLAN FOR SELECT /*+ SKIP_LEAF_STAGE_GROUP_BY_AGGREGATION */ a.col1, COUNT(*), SUM(a.col3) FROM a WHERE a.col3 >= 0 AND a.col2 = 'a' GROUP BY a.col1 HAVING COUNT(*) > 10 AND MAX(a.col3) >= 0 AND MIN(a.col3) < 20 AND SUM(a.col3) <= 10 AND AVG(a.col3) = 5", + "output": [ + "Execution Plan", + "\nLogicalProject(col1=[$0], EXPR$1=[$1], EXPR$2=[$2])", + "\n LogicalFilter(condition=[AND(>($1, 10), >=($3, 0), <($4, 20), <=($2, 10), =($5, 5))])", + "\n LogicalProject(col1=[$0], EXPR$1=[$1], EXPR$2=[$2], $f3=[$3], $f4=[$4], $f5=[CAST(/($5, $1)):INTEGER NOT NULL])", + "\n LogicalProject(col1=[$0], EXPR$1=[$1], EXPR$2=[$2], $f3=[$3], $f4=[$4], $f5=[$2])", + "\n LogicalAggregate(group=[{2}], EXPR$1=[COUNT()], EXPR$2=[$SUM0($1)], agg#2=[MAX($1)], agg#3=[MIN($1)])", Review Comment: Can you add a test for the scenario where `COUNT(*)` is not used in the aggregation set but `AVG()` is still used in the `HAVING` clause ? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org