Repository navigation
Conversation
…e lookup
With a bbox of 1 square degree or more, a query statement with tag filters
looks up ids in the global tag index (collect_ids) and filters by the bbox
afterwards. It looked keys up in the order written, and each further key
read its whole index range, binary-searching every entry against the
candidates so far. For way["maxheight"]["highway"] over open ocean that
meant collecting every maxheight way in the database and then reading the
whole highway index, though none of them could be in the box.
Query_Statement::execute now computes the constraints' node, way and
relation ranges before the tag lookup (they don't depend on it) and passes
them to progress_1 and collect_ids. At the current date:
- keep_ids_inside drops candidates whose cell lies outside those ranges
after each lookup; when none are left, the lookup stops.
- The key and key-value lookups run smallest first, counted in blocks of
the global tag index (Block_Backend::count_blocks, from the block index
alone).
- When checking the remaining tags late would read fewer local tag blocks
than the remaining lookups would read global ones, the lookup stops and
the query checks all tags late (check_keys_late = prefer_ranges).
The global tag index stores coarse indices, so a candidate is kept if its
cell overlaps the ranges, as intersect_ranges does.
On a US northeast full-history extract (Geofabrik), warm cache, 4-core VM,
median CPU of 5 runs:
[out:json][timeout:90]; (way["maxheight"]["highway"](39.0,-70.0,40.0,-69.0); way["bridge"]["maxheight"](39.0,-70.0,40.0,-69.0); way["tunnel"]["maxheight"](39.0,-70.0,40.0,-69.0); node["maxheight"]["highway"](39.0,-70.0,40.0,-69.0); ); out center;
0.24 s -> 0.00 s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01736kJWpJaGbt8ML6jz9N35
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 #242.
Change
Query_Statement::execute(statements/query.cc) computes the constraints' node, way and relation ranges before the tag lookup instead of after it (they don't depend on it), and passes them toprogress_1andcollect_ids(data/tags_global_reader.h). At the current date,collect_idsnow:keep_ids_inside), and stops when none are left. The global tag index stores coarse indices (multiples of 0x100), so a candidate is kept if its cell overlaps the ranges, asintersect_rangesdoes. A constraint never collects elements outside its ranges, so this drops nothing it would have returned.Block_Backend::count_blocks(template_db/block_backend.h) counts them from the block index alone, without reading or decompressing anything.check_keys_late = prefer_ranges) when that reads fewer blocks than the remaining global lookups: the candidates' cells' skeleton and local tag blocks (count_late_check_blocks), against the remaining lookups' global blocks.Past-date lookups are unchanged. 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 alternating; median user+sys CPU and peak RSS. Base
upstream/mastera9d8f15.The prompting query in three 1° × 1° boxes and their 0.99999° versions (just under 1 square degree, which collects the whole box instead), 5 runs:
The 0.99999° versions don't use the global tag index and are unchanged. In the dense box (Worcester to Springfield, 1,025 results) the gain is smaller, since about a thousand candidates do lie in the box; the time there is now mostly reading their skeletons and printing them.
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, identical output on all 20:
Queries
dense_1:
sparse_1:
empty_1:
The 0.99999° versions shrink each box's north and east edges by 0.00001°. p01 is dense_1.
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 the 6 and 20 queries above.node["maxheight"]["highway"]to it in the dense box, which then read the node skeletons of every candidate cell (+7% instructions overall); counting skeleton blocks as well fixes that (dense box now 13.21 → 11.17 G instructions).fuzz,historyandpropsrun on this PR. This change reorders work for every tag-filtered query statement, so their results matter most.Limitations and open questions
[date:]) lookups keep the old order and don't drop candidates by range.Generated by Claude Code