Repository navigation
seed connected values through type-anchored stars - #1626
Conversation
bplatz
left a comment
There was a problem hiding this comment.
The diagnosis is right and the fix is in the right place. Two gaps in what's established, both inline.
One more that doesn't anchor to a line: the PR notes this should land after #1624 because "the seeded plan routes some historical-t reads through lanes that #1624 makes correct on rebuilt indexes." Those lanes (batched-subject probes) carry their own constraints — they read base leaflets directly and are latest-t only, with a novelty-overlay bail gate. If the seeded plan can newly reach them, the bail gates deserve a test at a historical t and one with a novelty overlay. Right now the coverage is two plan-shape unit tests plus one indexed result test, all at head with no overlay — none of which would catch a lane that's reachable but not correctly gated.
| .collect(); | ||
| values | ||
| .iter() | ||
| .any(|vp| vp.vars.iter().any(|v| triple_vars.contains(v))) |
There was a problem hiding this comment.
Two issues with any-over-any.
Mixed VALUES lists defeat the gate. This returns true if any VALUES shares any var, but values_after_triples is a single decision for the whole block.values slice. A group holding both a connected VALUES and a disconnected one — legal SPARQL, { VALUES ?a {..} VALUES ?b {..} ?s :p ?a . ?s :q ?r } — now seeds both, and the disconnected one produces exactly the cartesian seed the deferral was written to prevent. The gate is all-or-nothing where the hazard is per-VALUES.
Any shared var, not the star's subject. VALUES ?n { "x" } . ?s a ex:Thing ; ex:name ?n binds a leaf object var and now seeds, which costs the property-join fusion for the whole star — 8 separate joins instead of one fused scan on a wide star. The arity sweep in the PR body only covers the subject-connected shape, so "no crossover where the extent scan wins" isn't established for this one. Narrowing to a VALUES that binds the star's subject would match both the issue and the evidence.
There was a problem hiding this comment.
Both of these are right, and the second one especially — thank you for catching them. I went and reproduced each against the old gate before changing anything, and they both land exactly as you describe.
On the mixed list: your example is the clean repro. With { VALUES ?a {..} VALUES ?b {..} ?s :p ?a . ?s :q ?r } the old gate saw ?a in the triple vars, returned true for the whole slice, and the plan came out [NestedLoopJoin, NestedLoopJoin, ValuesOperator, ValuesOperator, EmptyOperator] — both VALUES seeded at the base, including the disconnected ?b, which is precisely the cartesian seed the deferral was there to stop. So the gate was not just coarse, it was actively re-introducing the thing it was guarding.
On the subject-vs-any-shared-var point: also confirmed, and I think this was the more important of the two. VALUES ?n { "x" } . ?s a ex:Thing ; ex:name ?n under the old gate planned as [NestedLoopJoin, NestedLoopJoin, ValuesOperator, EmptyOperator] — seeded, fusion gone. You're right that the arity sweep in the PR body doesn't cover that shape at all; it only ever varied k on the subject-connected form, so "no crossover where the extent scan wins" was never established for an object-var VALUES and I shouldn't have let the gate cash a cheque the evidence didn't write.
What I did: narrowed the test to the star's subject var, and made the decision per-VALUES rather than per-block. split_values_seeding_star partitions block.values into the ones binding the subject (seed) and everything else (defer), and the call site seeds the first list and applies the second after the triples. I went with the split rather than the defer-all-if-any-disconnected fallback because it turned out to be cheap — apply_values already loops over a Vec<ValuesPattern>, so it's a partition plus passing two lists instead of one, and it keeps the #51 win in the mixed case instead of giving it up. If you'd rather have the blunter defer-all rule for a while on the theory that mixed blocks are rare and not worth the extra branch, I'm happy to swap it — it's a two-line change either way.
One nice side effect of keying on the subject: is_property_join already guarantees every triple in the block shares the first triple's subject var, so the gate no longer has to build a HashSet of all triple vars to answer the question.
Tests added, all three of which fail against the old gate: test_mixed_values_seeds_only_the_subject_binding_one (subject-bound + disconnected in one block — asserts the disconnected one stays at the root and the subject-bound one seeds from the base), test_values_sharing_only_object_vars_all_defer (your exact example — asserts nothing seeds the base), and test_object_var_values_keeps_property_join (asserts PropertyJoinOperator is retained).
| let plan = op.describe(); | ||
| let ops = plan_ops(&plan); | ||
|
|
||
| assert_eq!( |
There was a problem hiding this comment.
Asserting the exact operator vector — including EmptyOperator as a leaf artifact of the test harness — makes this brittle against any planner refactor, and it doesn't actually assert the property under test (that the class extent isn't drained); it asserts one tree shape that happens to have that property today.
The companion test right below gets this right with ops.first() / ops.last(). Same treatment here — "ValuesOperator is not at the root" is the durable claim.
There was a problem hiding this comment.
Agreed, and the EmptyOperator bit in particular is fair — that's a harness artifact I had no business pinning. Rewritten to the durable claims, matching the companion test's first()/last() shape.
The one thing I kept from the old assert, because I think it's the piece that actually speaks to your "it doesn't assert the property under test" point, is !ops.contains("PropertyJoinOperator"). That is the property under test, more or less directly: the whole defect was that the star fused and the driver scan drained the class extent, so "no property join here" is the closest thing to "the extent isn't drained" that a plan-shape assertion can say. So the test now asserts ValuesOperator is not at the root, no PropertyJoinOperator anywhere, and the VALUES is still applied somewhere — no positional coupling beyond the root.
bplatz
left a comment
There was a problem hiding this comment.
Left some feedback below to look at before merge
The values-after-triples deferral fired on any VALUES preceding a 2+-triple star, including one whose variable is the star's subject. That left the subject unbound when the star was planned, so the bound-object rdf:type triple won the driver race and the whole class extent was drained before the deferred VALUES discarded all but the matching row. Gate the deferral on the VALUES being disconnected from the star, which is the case it was written for (a pinned vector-search query vector). A connected VALUES now seeds, and build_scan_or_join picks a bound-driven lane from the real cardinality estimates.
The gate asked whether any VALUES shared any variable with the star, and applied one answer to the whole block. Two consequences. A block holding both a connected and a disconnected VALUES seeded both, putting the disconnected one at the base of the plan — the cartesian seed the deferral exists to prevent. Split the decision per-VALUES instead. A VALUES binding only a leaf object var also seeded, which costs the star its fusion without constraining the driving scan; the arity sweep behind this change only covers the subject-connected shape. Narrow the test to the star's subject var, which is-property-join already guarantees is shared by every triple.
The seeded plan reaches batched-subject probes that read base leaflets directly: latest-t only, with a novelty-overlay bail gate. Neither condition had a test — the existing coverage is all at head with no overlay, so a lane that is reachable but not correctly gated would pass. Both tests assert results, not plan shape: a lane that bails to a slower fallback is fine, one that returns the wrong rows is not. Each first asserts the query still plans as seeded, so the result assertions cannot quietly stop covering the lane they were written for. The historical case changes a value rather than retracting the predicate outright, so the predicate keeps live rows either side of the boundary and the test is a pure replay question — the fully-retracted shape depends on #1624, which is still open.
The shape the seeded plan actually changed the answer to: a predicate a later full rebuild leaves with no live rows is unreachable through PSOT/POST, and deferring used to route it through PropertyJoinOperator, whose replay-aware driver selection kept it correct by accident. Seeding takes it off that lane. #1624 preserves the SPOT history sidecars the probes need, so this is answerable now. Uses a full rebuild rather than an incremental build because that is the path that dropped the partition. The head assertion doubles as proof the predicate really is fully retracted.
989cc44 to
6b38a17
Compare
|
This is a good catch and you're right that the coverage was thin in exactly the place it mattered: two plan-shape unit tests plus one result test, all at head, none of which would notice a lane that's reachable but mis-gated. Both tests added, in
The bit I want to flag rather than bury: each test also asserts the query still plans as seeded ( There's a third test now too — Which lets me say the merge-order note in the PR body more precisely than I originally did, and it was vaguer than it should have been. The reason this wanted #1624 first isn't tidiness: moving these queries onto the seeded lane takes them off |
SELECT ?s ?n WHERE { VALUES ?s { <iri> } ?s a :Thing ; :name ?n }was O(class size) rather than O(VALUES rows): the values-after-triples deferral fired on any VALUES preceding a 2+-triple star, including one whose variable is the star's subject. That left?sunbound at planning time, the bound-objectrdf:typetriple won the driver race, and the whole class extent was drained before the deferred VALUES discarded all but the matching rows. Measured in-process at 1.5ms/17ms/47ms for N=2K/20K/50K against a flat ~0.02ms for the equivalent inlined-IRI query.The gate now checks whether the VALUES shares a variable with the star. Disconnected VALUES (the case the deferral was written for — a pinned vector-search query vector, where seeding would produce a cartesian seed) keep the deferred plan unchanged; connected VALUES seed first, and
build_scan_or_joinpicks a bound-driven lane from real cardinality estimates. No cardinality threshold was added: an arity sweep to k=32,768 against a 50,000-member class found no crossover where the extent scan wins — the old plan pays the full scan and the post-filter, so it never comes out ahead.Plan-shape regression tests pin both directions (the existing disconnected-VALUES vector test passes unchanged), plus result-correctness tests on indexed ledgers. Sequencing note: this should land after #1624 — the seeded plan routes some historical-
treads through lanes that #1624 makes correct on rebuilt indexes.