Repository navigation
Conversation
Query_Statement::apply_all_filters runs metadata-only filters first and
the others in query order. An (if:) filter builds what its expression
needs for every element it evaluates (Set_With_Context::prefetch); for
geometry that is a way or relation geometry store over all candidates.
Written before a spatial filter, as in wr(if:length()>10)(around:10,...),
it computed the geometry of every relation in the coarse candidate ranges,
which the exact around test then nearly all dropped.
Query_Constraint gains filter_needs_geometry(). Filter_Constraint answers
it from its criterion's request_context() (Set_Usage::GEOMETRY), and
apply_all_filters runs such filters in a last pass. (if:) filters on tags,
ids or metadata keep their place, so they still drop candidates before an
expensive spatial test. The filters only remove elements, so the order
doesn't change the result.
On a US northeast full-history extract (Geofabrik), warm cache, 4-core VM,
median of 5 alternating runs:
[out:json]; wr(if:length()>10)(around:10,40.580976,-75.522374)->.s0; way(r.s0:"house")->.s1; rel.s0(39.638451,-80.311484,39.819817,-80.194662)->.s2; .s2 <<->.s3; .s2 out meta center qt 20;
CPU 5.44 s -> 0.14 s, peak RSS 187 MB -> 23 MB
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01736kJWpJaGbt8ML6jz9N35
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.
Stacked on #43 (
metadata-filters-first): it extends the filter ordering that PR introduces. The tables compare against #43's branch.Fixes #238.
Change
Query_Constraint(statements/statement.h) gainsfilter_needs_geometry(), false by default.Filter_Constraint(statements/filter.cc) returns true when its criterion'srequest_context()asks for geometry (Set_Usage::GEOMETRY).Query_Statement::apply_all_filters(statements/query.cc) now runs three passes: metadata-only filters, then the other filters except those needing geometry, then those. Within a pass the query order is kept.Three files, 15 lines added, 2 removed. No change to the database format, the query API or the results.
Impact
US northeast full-history extract (Geofabrik), warm cache, 4-core VM. Builds run alternately; median user+sys CPU and peak RSS per query. Base is #43's branch (b5e4a92).
Queries with a geometry
(if:)before a spatial filter, 5 alternating runs:f4e212 and f4e304 are controls. f4e304 is
way(if:version()>2)(poly:...): a metadata(if:)before an expensive polygon test. An earlier version of this change moved every(if:)filter last and made that query about 15% slower, so filters that need no geometry now keep their place. f4e212 has a geometry(if:)that the polygon filter doesn't narrow much.The 20 production-shaped queries (the 20 heaviest query templates on the public servers in June 2026, moved to Boston and New England coordinates), 3 runs each. None has an
(if:)filter, so the only difference is one virtual call per constraint; the total moved , within noise. Identical output on all 20.Fuzzing, against
all-changes. Identical output on 2,500 queries with theevaluatorsfeature: seed 4, 1,500 queries, run on the first version; seed 5, 1,000 queries, on this version. Total CPU fell 9.3% over seed 4's 1,478 completed queries (4.20 → 0.13 s and 5.39 → 0.41 s among them) and 3.2% over seed 5's 988, which has no case this large and ran 4 jobs in parallel.Queries
User names and user ids drawn from the extract are replaced with
(user)andN.f3p285
f3p695
f4e1209
f4e1380
f4e212
f4e304
Testing
fuzz.pyagainstall-changes, seeds 4 and 5 withevaluators,complete: 2,500 queries, no difference.fuzz,historyandpropsrun on this PR.Limitations and open questions
(if:)filters needing geometry move. One that needs tags only is cheap per element but still loads tags; it keeps its place.around,poly,bbox) still run in query order among themselves. Ordering them by cost is a separate, larger question.Generated by Claude Code