Repository navigation
Read a grouping key in an order term over an aggregate as the GROUP BY reads it, so Oracle sorts by me.age + count(you.age) - #283
Open
jasperblues wants to merge 1 commit into
Open
jasperblues wants to merge 1 commit into
jasperblues wants to merge 1 commit into
Conversation
…Y reads it, so Oracle sorts by me.age + count(you.age) On Oracle, ORDER BY me.age + count(you.age) beside me.age AS age failed with ORA-00979. The projection groups by the key read through its text (item_property), and the order term read me.age again from the properties. Where rows are grouped, an order term whose every aggregate and key is an item is now sorted over the items' columns, after the query. Any other term over an aggregate reads each key item as its column value, the same expression the GROUP BY holds (_keys_read). Port of drivine4j#429. Fixes #256
This branch has not been deployed
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.
Fixes #256
Port of liberation-data/drivine4j#429 (merged as bc69834e), the fix for liberation-data/drivine4j#413.
On Oracle, an order term over an aggregate that reads a grouping key failed with ORA-00979:
It failed here
I ran the new test on Oracle (
gvenzl/oracle-free:23-faststart) at main (ac0c979). Each of the first 7 statements failed withORA-00979: "N1"."PROPS": must appear in the GROUP BY clause or be used in an aggregate function, except the 2 that already worked (ORDER BY age + count(you.age)and the node key). The 5 that failed were the issue's RETURN form, its WITH form, DISTINCT, SKIP/LIMIT with a WHERE after it, and an aggregate in the term that is no item. The run then stalled on the 8th, the comprehension case covered below. Offline, main's SQL for the issue's statement read the key 47 times asJSON_VALUE(n1.props, '$.age…'), beside a GROUP BY on its text.Fix
In
_project, as in drivine4j'sproject:_over_items), is sorted over the items' columns after the query._keys_read).The issue's statement compiles to 14 KB, down from 16 KB. Its SQL is drivine4j's byte for byte, except for the
NO_JSON_TABLE_TRANSFORMhint (#275) and the outerKEEP '$'. The temporal case (me.born + duration({days: 10 * count(*)})) compiled to 210 MB on Oracle on main. It is 52 KB now.SQL
Every statement of the spec (v0.6.19, all four files) compiles to the same SQL on Oracle and Postgres before and after: 2,060 compiles, 0 changed. No spec statement has this shape.
Tests
test_an_order_term_over_an_aggregate_that_reads_a_grouping_key_is_sorted_by_the_key_as_it_is_grouped_by(async, plus the sync copy from unasync), on Neo4j, Postgres and Oracle. It is drivine4j'sCypherQueryContracttest, with Neo4j's rows. It covers the issue's statement in RETURN, WITH and DISTINCT forms, an order term made of items (age + count(you.age)), SKIP and LIMIT with a WHERE after the ordered WITH, a node key, an aggregate that is no item, a key in a function, two keys, a key that is an expression, several keys, a variable-length walk and a temporal key.test_oracle_item_property: the issue's statement reads the key through its text twice (once for the item, once for the GROUP BY) and never asJSON_VALUE(n1.props, '$.age…').Differences from drivine4j
ORDER BY me.age + size([me IN [1] | me]) + count(you.age). It compiles to 4.7 MB here, before the fix (4.4 MB) and after, and drivine4j compiles it to 15 KB. The difference is Cypher on SQL stores: text functions or + over an aggregate's result compile unshared to megabytes, past drivine4j#359's fix (port of drivine4j#373) #235 (+ over an aggregate's result written out at every level), not yet ported. Oracle was still parsing it after 20 minutes. It runs on Neo4j and Postgres.Gate
scripts/check_cypher_spec.py,ruff check,ruff format --check,pyright,scripts/unasync.py --check, thenORACLE_TESTS=true uv run pytest -q: 5200 passed, 298 skipped.