Commit faa2e8f
quantifier: MATERIALIZE non-deterministic CTEs + entity-in-list property access (+18) (#90)
* sql: MATERIALIZE non-deterministic CTEs so rand() WITH values are stable (+18 TCK)
A WITH-projected value computed with rand() (e.g.
`WITH CASE WHEN rand()<0.5 THEN reverse(list) ELSE list END + x AS list`)
changed on every reference. SQLite treats a multiply-referenced CTE as a view
and re-evaluates its body (re-running RANDOM()) per reference, so in a chain of
WITH CTEs the same `list` yielded a DIFFERENT random value at each use. The
quantifier algebraic-identity scenarios then broke: `none(x IN list WHERE p)`,
`any(x IN list WHERE p)`, and `NOT any(...)` over the SAME list each saw a
different random list, so e.g. `none(...) = (NOT any(...))` was false.
sql_cte() and sql_pre_cte() now emit `AS MATERIALIZED (...)` when the CTE body
contains a non-deterministic function (gated on the substring `RANDOM(`),
forcing SQLite to compute the CTE once. Gated to non-recursive CTEs only
(MATERIALIZED is invalid on a recursive CTE) and only when RANDOM() is present,
so recursive/varlen and ordinary deterministic CTEs are unchanged.
Rigorous full pass-set diff: zero regressions, +18 (Quantifier9/11/12 identity
cluster + Quantifier1-4 related). 3758 -> 3776. Unit 944/944, functional clean.
* expr: property access on an entity inside a list reads .properties (groundwork)
`r.name` where r is a node/relationship that is a LIST ELEMENT (e.g. the
quantifier variable in `any(r IN relationships(p) WHERE r.name = 'a')`)
returned null: the projected-JSON property branch used top-level
`json_extract(value, '$.name')`, but an entity stores props under
`.properties`. It now routes through `_gql_dyn_prop`, which picks
`$.properties.<key>` for entity-shaped objects and `$.<key>` for plain maps
(same UDF already used for subscript bases).
Correct + regression-free (rigorous full pass-set diff: zero regressions, zero
newly-passing). Groundwork: the Quantifier1-4 [8]/[9] scenarios additionally
require varlen relationships(p)/nodes(p) through an aggregating WITH and
GROUP-BY-on-list, deferred.
---------
Co-authored-by: Dylan Bobby Storey <dstorey@dstorey-personal-m3.local>1 parent fca8931 commit faa2e8f
3 files changed
Lines changed: 45 additions & 3 deletions
File tree
- docs/testing
- src/backend/transform
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
624 | 624 | | |
625 | 625 | | |
626 | 626 | | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
537 | 537 | | |
538 | 538 | | |
539 | 539 | | |
540 | | - | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
541 | 549 | | |
542 | 550 | | |
543 | 551 | | |
| |||
555 | 563 | | |
556 | 564 | | |
557 | 565 | | |
558 | | - | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
559 | 569 | | |
560 | 570 | | |
561 | 571 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
803 | 803 | | |
804 | 804 | | |
805 | 805 | | |
806 | | - | |
| 806 | + | |
807 | 807 | | |
808 | 808 | | |
809 | 809 | | |
| |||
0 commit comments