Repository navigation
Declare search cells over a closed derived schema - #332
Conversation
cd4c598 to
9943721
Compare
9943721 to
eeb56bb
Compare
farhan-syah
left a comment
There was a problem hiding this comment.
Request changes.
Checked statically against the branch ref (no checkout):
| Claim | Result |
|---|---|
cargo fmt --all -- --check clean |
Confirmed on every changed file. |
| Comment hygiene | One broken comment (inline). No issue numbers or links. |
| "every trigger and every shape" | Not true. The resolver re-derives routing from the AST and diverges from the planner in both directions (inline, blocker). |
| Commit list | The body cites cdb2e71a1, 4eddcfeb5, 235b7a28b, 994372149. The branch holds bec78889, 15cea2e, ca7baec, eeb56bb. Update the body after the rebase. |
Blockers are the layer finding, the broken comment, and the doc/code contradiction. The registry singleton and the tolerant tests are should-fix; both fall out of the layer change.
What landed correctly: the closed-schema wire case reproduces #305, and _surrogate is now declared beside distance.
|
Addressed and pushed — branch head
Red proof: on |
|
Rebase, and force with release. Rebuild the commits |
The derived-relation inference re-derived search routing from the AST and diverged from the planner in both directions: a WHERE sparse_score(...) or a one-argument ORDER BY vector_distance(...) declared a distance cell the planner never fills (silent NULL where main refused 42703), while SqlPlan::MultiVectorSearch went undeclared (42703 stays). SqlPlan::carries_search_cells() matches the three variants whose rows lower to the vector-hit shape; infer_subquery_relation reads the cells from the subquery's own plan, which the planner call sites already build. TableScope's derived arm plans non-lateral factors for the same input; a correlated LATERAL factor cannot be planned at scope time and routes no cells. The four AST heuristic functions and the third registry singleton are gone.
The tolerant assertions pinned one outcome each: a declared distance parses as f64 with no empty escape, a body routing no search refuses 42703 instead of reading a NULL cell. Guards cover the four divergences the review listed: sparse WHERE, one-argument ORDER BY vector_distance, a body off a derived relation, and WHERE multi_vector_search (declared; the lowering refuses 42601).
2a51f66 to
e0a51d0
Compare
|
Rebased onto The rebuilt tree is identical to the previously audited |
Summary
A derived relation over a closed-schema source refused
s.distancewith42703, while the same projection over an open-schema source ran. The response layer answers a search-shaped query with two synthetic cells the schema cannot name:distance(Float64) and_surrogate(the internal row id, resolved to the user primary key). The declaration follows the plan:SqlPlan::carries_search_cells()matches the three variants whose rows lower to the vector-hit shape (VectorSearch | SparseSearch | MultiVectorSearch), andinfer_subquery_relationreads the cells from the subquery's own plan — the source the planner already uses, never a second AST reading of it.Closes #305.
Behaviour changes
s.distanceover a closed-schema derived relation whose body routes to a search (ORDER BY vector_*and the operator forms<=>/<#>/<->,sparse_score, routingWHEREforms,WHERE multi_vector_search(...))42703s._surrogateover the same shapes42703ORDER BY vector_distance(..), a body whoseFROMis neitherScannorJoin)4270342703— a declared cell is never NULLRoot cause
Derived-relation inference (
resolver/derived.rs) re-derived "is this a search?" from the AST. The planner answers the same question inwhere_search/order_by/triggers, and the two diverged in both directions: declarations for shapes that route no search (silent NULL cells), and no declaration forSqlPlan::MultiVectorSearch.What changed
Rebased onto
a7f597257; two commits.Commit
e9f969f60— the fix:SqlPlan::carries_search_cells()matches the three variants whose rows lower to the vector-hit shape;infer_subquery_relationtakes the subquery's plan (derived_frompassesinner_plan,entrypassescte_plan,TableScope's derived arm plans non-lateral factors for the same input — a correlatedLATERALfactor cannot be planned at scope time and routes no cells). The four AST heuristic functions and the third registry singleton are deleted.Commit
e0a51d035— the tests: the filed case (closed schema plus a vector index,SEARCH … USING VECTOR(…)in the derived body), the pinned outcomes for the previously tolerant assertions, and guards for the four divergences (sparse_scoreinWHERE, one-argumentORDER BY vector_distance, a body off a derived relation, andWHERE multi_vector_search).Regression proof
On
mainwithout the change, the reworked wire case fails 5 of 20 — including the filedSEARCH … USING VECTOR(…)case and the_surrogateprojection. On the branch head all 20 pass.Tested
cargo nextest run -p nodedb-sql --lib— 892 pass (derived-relation andcarries_search_cellsunit tests included)cargo nextest run -p nodedb --test wire -E 'test(cases::sql_search_subquery_composition)'— 20 pass; onmainwith the same tests: 15 pass / 5 failcargo fmt --all -- --check,cargo clippy -p nodedb-sql --all-targets,nodedb-preflight.sh: cleanNotes
synthetic_columndeclares the cells as nullableUnknowntype: the declaration resolves the name; the response layer supplies the value.WHERE multi_vector_search(...)plansSqlPlan::MultiVectorSearch, which the lowering step does not support yet (42601, variant named). The cell declaration is plan-derived, so that refusal is the honest one;42703no longer appears for it.order_by/triggersnoScan/Jointo read, so it routes no search; its projection refuses the cells.