yashmayya opened a new pull request, #18600: URL: https://github.com/apache/pinot/pull/18600
On the physical optimizer path (`usePhysicalOptimizer=true`), the group-trim rule pushed `limit = fetch` into the leaf/final aggregate and ignored the query `OFFSET`. Paginated `DISTINCT` / `GROUP BY` queries that hit group trim then trimmed away rows the outer `OFFSET ... FETCH` window still needed and came back short — silently wrong results, no error. It now pushes `offset + fetch` (clamped to avoid int overflow) so the leaf/final aggregate keeps enough groups. The default/legacy planner isn't affected: its sort-exchange-copy rule already folds the offset into the inner sort's fetch before the aggregate rule runs, so that rule sees `offset + fetch` there. `PINOT_POST_RULES_V2` has no sort-exchange rule, so `PinotLogicalAggregateRule` matches the raw outer sort and has to add the offset itself. ### Tests - Plan-level (`PhysicalOptimizerPlans.json`): no-aggregate `DISTINCT ... LIMIT n OFFSET m` and hinted aggregate, asserting leaf/final `limit=[offset+fetch]`. - Integration (`GroupByOptionsTest`, `usePhysicalOptimizer=true`): paginated DISTINCT and hinted-aggregate paths return a full page. Verified it fails (0 rows) without the fix. Fixes #18592 -- 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]
