Repository navigation
Conversation
Query_Statement::apply_all_filters runs each constraint's expensive filter in the order the constraints appear in the query. newer and the user filters (uid, user, uid_touched, user_touched) are expensive filters too, but they only read metadata. When a bbox, around or area constraint came first, its filter built geometry for every candidate, and only then did the metadata filter discard most of them. A new Query_Constraint::filter_reads_only_metadata() marks such filters, and apply_all_filters runs them first. Every filter only removes elements, so the order does not change the result. On the Nova Scotia history database: [out:csv(::count)]; way(43.3,-66.5,47.1,-59.6)(newer:"2026-11-08T00:00:00Z"); out count; drops from 6.3 s to 1.3 s, the time the same query already took with newer written first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01736kJUqyDw9zM3Bkh2W2QT
Owner
Author
|
Colin's thoughts: low risk, medium confidence, high benefit. The thrust is simple - rule things out cheaply before doing more expensive checks. The medium confidence comes from the case hypothesized in the PR -- where a bbox filter would rule out most things and a metadata filter few things. I suspect that's probably rare: many edits build up over time, many users edit the same area. |
This was referenced Nov 26, 2026
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.
Fixes #40.
Change
Query_Statement::apply_all_filtersruns each constraint's expensive filter,filter(query, rman, into), in the order the constraints appear in the query.newerand the user filters (uid,user,uid_touched,user_touched) are expensive filters too, but they only read metadata. When a bbox,aroundor area constraint came first, its filter built geometry for every candidate, and only then did the metadata filter discard most of them.Query_Constraint::filter_reads_only_metadata(), false by default and true forNewer_ConstraintandUser_Constraint, marks such filters.apply_all_filtersruns the marked filters first, then the rest in their usual order.Every filter only removes elements, so the order doesn't change the result.
Four files, about 20 lines. Based on fossgis
master. No change to the database format or the query API.Impact
CPU time on the Nova Scotia history database (#2), warm cache, 4-core VM, against fossgis
master(8edf11b). Output is identical. Other jobs shared the VM during these runs, so treat small differences as noise.master[out:csv(::count)]; way(43.3,-66.5,47.1,-59.6)(newer:"2026-11-08T00:00:00Z"); out count;[out:csv(::count)]; way(newer:"2026-11-08T00:00:00Z")(43.3,-66.5,47.1,-59.6); out count;(already in the fast order)[out:csv(::count)]; nwr(44.60,-63.66,44.70,-63.52)(uid:N); out count;(N: the top local user)[out:csv(::count)]; way(43.3,-66.5,47.1,-59.6)(uid_touched:N); out count;Peak memory for the first query drops from 1,119.7 MB to 237.4 MB, because geometry is no longer built for 882,729 ways.
Testing
Differential fuzzer against
master:areas,complete: 1,000 queriesusers,history,complete: 1,500 queries0 differences in all three (13 timeouts skipped in total). This PR against itself: 300 queries, all identical.
Targeted check: 400 queries applying the user filters with boxes before and after them, on input sets and in loops (53 returned data). 0 differences.
No mutation test: this change reorders filters rather than skipping work, so a mutant would have to drop or duplicate a filter, which the fuzzer's ordinary coverage already exercises.
Memory
No new allocation. Peak memory falls when the metadata filter is selective (see above).
Limitations and open questions
changed, for example) could be marked too, but aren't yet.Generated by Claude Code