Repository navigation
Conversation
When a query statement checks tags late (a bbox under 1 square degree,
around under 2 km, and other range strategies), it collected every element
in its ranges, decoded each skeleton with its member list, checked the tags
of all of them, and kept the matches. In a dense 0.99999 x 0.99999 degree
box around Worcester, way["maxheight"]["highway"] decoded about two million
ways to keep about a thousand.
Before collecting, Query_Statement::execute now asks ids_from_local_tags for
the ids that carry every positive tag filter (keys, key-values,
key-regexes): it reads only those keys' entries in the local tag index for
the ranges' coarse cells, and intersects the per-filter id lists. Collection
then gets these ids, so it skips the other elements on their raw id without
decoding them. The late tag check still runs on what is collected, so
negated filters and regex keys behave as before.
It applies at the current date, without an id constraint already in place,
and when the ranges span at most 65,536 coarse cells. Uint31_Index orders by
the low 31 bits first, so for ways and relations the cells are taken from
those bits.
On a US northeast full-history extract (Geofabrik), warm cache, 4-core VM,
median CPU and peak RSS of 3 alternating runs:
[out:json][timeout:90]; (way["maxheight"]["highway"](42.0,-72.0,42.99999,-71.00001); way["bridge"]["maxheight"](42.0,-72.0,42.99999,-71.00001); way["tunnel"]["maxheight"](42.0,-72.0,42.99999,-71.00001); node["maxheight"]["highway"](42.0,-72.0,42.99999,-71.00001); ); out center;
6.49 s -> 1.59 s, 608 MB -> 14 MB
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01736kJWpJaGbt8ML6jz9N35
cldellow
force-pushed
the
query-local-tags-first
branch
from
November 27, 2026 02:09
d053c62 to
edbe5e3
Compare
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 #254.
Change
ids_from_local_tags(statements/query.cc): for the ranges' coarse cells, it reads only the local tag index entries of each positive tag filter (keys, key-values and key-regexes, the last with their value regex) and intersects the per-filter id lists, smallest first.Query_Statement::executecalls it per element type when tags are checked late (check_keys_late == prefer_ranges), at the current date, with no id constraint already in place and non-global ranges. The result becomes the id constraint, so collection'sId_Predicateskips other elements on their raw id without decoding them.[k!=v],[!k],[k!~re]) and regex keys work as before. Without a positive filter, at a past date, or when the ranges span more than 65,536 coarse cells, nothing changes.Uint31_Indexorders by the low 31 bits first, so their cells are taken from those bits; ranges such as0x8c000040..0x0c000040are valid there.One file, 120 lines added. 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 alternate; median user+sys CPU and peak RSS of 3 runs. Base
upstream/mastera9d8f15. The queries: the maxheight query of #242 in three boxes at 1° and 0.99999°, the 20 heaviest query templates on the public servers in June 2026 moved to Boston and New England coordinates (p01–p20), and 15 diff, meta and past-date queries (d, h, m).The range strategy's queries with selective tags gain most, in CPU and even more in memory: dense_099 608 → 14 MB, p04 237 → 13 MB, m1 173 → 36 MB. Queries using the global tag index or a past date don't take the new path. The increases on such queries are noise: sparse_1 and p07 have identical instruction counts (valgrind callgrind, which repeats exactly) on both builds, 4.322 G and 53.583 G.
Non-selective tags. For
way["highway"](42,-72,43,-71); out geom;(h4), nearly every way matches, so the local tag entries are read here and again by the late check; CPU still fell 6% and peak memory 25%.Queries
dense_1:
dense_099:
sparse_1:
empty_1:
sparse_099 and empty_099 shrink their boxes' north and east edges by 0.00001° like dense_099. p01 is dense_1.
d1 (adiff amenity buildings):
d2 (diff highways):
d3 (adiff routes):
d4 (diff convert):
h1 (attic rel bbox):
h2 (attic way geom):
h3 (nwr bbox meta):
h4 (highways 1deg geom):
h5 (buildings center):
h6 (multipolygons geom):
h7 (nodes way bn):
h8 (attic amenity meta):
m1 (meta amenity):
m2 (meta buildings):
m3 (attic meta highways):
p01 (maxheight bbox1deg)
p02 (amenities around union)
p03 (admin in area)
p04 (brands bbox ci)
p05 (global data center)
p06 (food around regex)
p07 (global seamark recurse)
p08 (global cameras)
p09 (3d buildings bbox)
p10 (tourism around25k)
p11 (brownfield bigbbox)
p12 (clinic name ci around25k)
p13 (map call meta)
p14 (area by name worship)
p15 (tiny bbox many keys geom)
p16 (hgv restrictions bbox)
p17 (anchored regex around)
p18 (fuel bigbbox)
p19 (venues bbox name ci)
p20 (office around25k)
Testing
upstream/masteron all 41 queries above.Uint31_Indexranges, treated ranges like0x8c000040..0x0c000040as spanning everything, and fell back for all way statements; output was correct, only the gain was missing for ways.fuzz,historyandpropsrun on this PR.Limitations and open questions
Generated by Claude Code