Repository navigation
fix(spatial): infer relation triples inside EXISTS - #57
Merged
Merged
Conversation
The spatial rewrite walked graph patterns but not the patterns inside
expressions, so `FILTER EXISTS { ?g geo:sfWithin ?rg }` saw only asserted
relation triples: EXISTS kept no row and NOT EXISTS every row. The
patterns of EXISTS in FILTER, BIND and OPTIONAL's condition are now
rewritten as any other.
Closes #56
Inside EXISTS the rewritten relation was planned as at top level: its geometry lookups and index candidates ran for the whole store once per outer row (about 4.5 ms a row; 25 x 6,000 rows timed out). Now, inside EXISTS, the relation is joined LATERAL after the rest of its group, its filters are not index-planned, and a feature's default geometry is tested with a lookup, so each row's values are bound.
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.
Closes #56.
Cause
The spatial rewrite walked graph patterns, but not the patterns inside expressions. A relation triple inside
FILTER EXISTS { ?x geo:hasGeometry ?g . ?g geo:sfWithin ?rg }therefore matched only assertedgeo:sfWithintriples. With none in the data,EXISTSkept no rows (0 instead of 648 on the review probe) andNOT EXISTSkept every row.Fix
Rewriter::walk_existsrewrites the pattern of eachEXISTSin aFILTER, aBINDand anOPTIONAL's condition, the same way as any other pattern.Tests
tests/spatial_paths.rsgainsrelation_triples_inside_exists_are_inferred. It runs 4 bodies (plain, sequence path, alternative path, feature-to-feature) through each ofFILTER EXISTS,FILTER NOT EXISTSandBIND(EXISTS …) FILTER(?in). It compares the results with the join written out, and the complement for NOT EXISTS. The test fails without the fix.The spatial crate's tests and the tripletrail spatial test files pass. fmt and clippy are clean.
Docs