Indian-boult opened a new issue, #20329:
URL: https://github.com/apache/pinot/issues/20329
With `usePhysicalOptimizer=true`, a DISTINCT or GROUP BY with ORDER BY and
LIMIT can return the wrong rows. The leaf aggregate keeps the right top rows,
but the final aggregate trims to LIMIT groups with no ordering and keeps the
first groups its iterator returns.
SET usePhysicalOptimizer=true;
SELECT DISTINCT doubleCol FROM tbl ORDER BY doubleCol LIMIT 3
On the `general_distinct` table in `Distincts.json`, with values 300, 400,
100, 1, 1.01, 1.5 and 1.75, this returns 1.0, 1.01 and 100.0 instead of 1.0,
1.01 and 1.5. The logical planner returns the right rows. For `SELECT DISTINCT
col3 FROM a ORDER BY col3 DESC LIMIT 10` the plan shows the problem.
PhysicalAggregate(group=[{0}], aggType=[FINAL], limit=[10])
PhysicalExchange(exchangeStrategy=[PARTITIONING_EXCHANGE],
distKeys=[[0]])
PhysicalAggregate(group=[{2}], aggType=[LEAF], collations=[[0
DESC]], limit=[10])
`AggregatePushdownRule.addPartialAggregate` gives the final aggregate
`PinotDistMapping.apply(RelCollations.of(o0.getCollations()),
mapFromInputToPartialAgg)`. Those collations index the aggregate output, but
the mapping goes from the aggregate input to the partial aggregate.
`PinotDistMapping.apply` stops at the first index it cannot map. So the
collation is dropped when input field N is not group key N, and it points at
the wrong key when input field N is another group key. `AggregateOperator` then
sets the trim size to the limit with no ordering. The logical planner passes
the same collations to the leaf and the final aggregate.
Aggregations with `is_enable_group_trim='true'` and ORDER BY on an aggregate
are affected the same way. Three expected plans in
`PhysicalOptimizerPlans.json` show the final aggregate with a limit and no
collation for `ORDER BY cnt DESC LIMIT 10`.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]