-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
The spot taken by the *-bucket row in the results of a query can vary from query to query (and sometimes for the same query issued before or after ANALYZE;!).
In a nutshell, the Sort plan node may or may not be pushed down by the planner, to a spot before the Agg / BucketScan nodes. If it is then the ORDER BY sorting will not impact it, meaning it will come first. In other circumstances, if the Sort node comes last, it is impacted by ORDER BY.
Example query where it didn't get pushed down:
SELECT age, count(*), diffix.is_suppress_bin(*) FROM customers GROUP BY 1 ORDER BY 1 NULLS FIRST
Sort
Sort Key: age
-> Custom Scan (BucketScan)
-> HashAggregate
Group Key: age
-> Seq Scan on customers
And where it did (because id has many unique columns per ANALYZE;, and the HashAggregate has been changed to Sort -> GroupAggregate:
prop_test=# explain SELECT id, count(*), diffix.is_suppress_bin(*) FROM customers GROUP BY 1 ORDER BY 1 NULLS LAST;
Custom Scan (BucketScan)
-> GroupAggregate
Group Key: id
-> Sort
Sort Key: id
-> Seq Scan on customers
Ideas from slack thread:
- ORDER BY volatile_func(id) where that function does nothing but is marked as VOLATILE
- Extract the ORDER BY clause from the query plan and insert the *-bucket conformant to this order. As in, whilst we emit the buckets, we "wait" for the first bucket which doesn't satisfy the sorting criteria, and then emit the *-bucket
prependAppend anORDER BY is_suppress_bin(*)and let the planner figure it out
Metadata
Metadata
Assignees
Labels
No labels