Sort NULLs the way Postgres does on the SQL front end (ATSCALE-52093) - #2
Open
dave-mariani-atscale wants to merge 1 commit into
Open
dave-mariani-atscale wants to merge 1 commit into
dave-mariani-atscale wants to merge 1 commit into
Conversation
Turns on query.language.sql.ordering.postgresNullPlacement, added in engine PR #9968. The engine normalises every warehouse to "NULL sorts smallest" -- nulls first ascending, last descending. That is Hive's rule and it is deliberate, so that a cube gives one answer whatever the backend sits underneath. It is also the opposite of Postgres in both directions: Postgres sorts NULL as the largest value, so nulls come last ascending and first descending. That difference is invisible until it isn't. Any ORDER BY, LIMIT or window ranking over a nullable column returns a different set of rows through the SQL front end than the same query run against Postgres directly, with nothing in the result to say so. This setting makes the front end emit Postgres's own placement when a query states none. It is scoped to the SQL front end, so MDX and DAX are unaffected, and a NULLS FIRST/LAST written into the query still wins over it. Turning it on changes the row order of existing queries that sort over nullable columns, which is the point, but worth knowing before it lands somewhere with saved reports. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Turns on
query.language.sql.ordering.postgresNullPlacement, added in engine PR #9968 for ATSCALE-52093.Why
The engine normalises every warehouse to "NULL sorts smallest" — nulls first ascending, last descending. That is Hive's rule, and it is deliberate: a cube gives one answer whatever backend sits underneath.
It is also the opposite of Postgres in both directions.
The difference is invisible until it isn't. Any
ORDER BY,LIMITor window ranking over a nullable column returns a different set of rows through the SQL front end than the same query run against Postgres directly, with nothing in the result to say so.What this changes
With the setting on, an
ORDER BYon the SQL front end that states no placement gets Postgres's. Scoped to the SQL front end, so MDX and DAX are unaffected. ANULLS FIRST/NULLS LASTwritten into the query still wins over it.Verified on a local engine carrying the fix:
NULLS LASTwrittenORDER BY tei ASC[null, null, null]ORDER BY tei ASC NULLS LAST[null, null, null](clause was inert)[0.092, 0.0924, 0.1058]Caveat
Turning this on changes the row order of existing queries that sort over nullable columns. That is the point, but worth knowing before it lands somewhere with saved reports built on the current order.
Requires an engine carrying PR #9968; on an older engine the key is simply unknown and ignored.