Skip to content

query: collect only the elements the local tag index says match - #255

Open
cldellow wants to merge 1 commit into
masterfrom
query-local-tags-first
Open

cldellow wants to merge 1 commit into
masterfrom
query-local-tags-first

Conversation

@cldellow

Copy link
Copy Markdown
Owner

Fixes #254.

Change

  • New 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::execute calls 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's Id_Predicate skips other elements on their raw id without decoding them.
  • Everything else is unchanged. The late tag check still runs on what is collected, so negated filters ([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.
  • Ways and relations. Uint31_Index orders by the low 31 bits first, so their cells are taken from those bits; ranges such as 0x8c000040..0x0c000040 are 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/master a9d8f15. 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).

Query CPU, master CPU, this PR change peak, master peak, this PR
d1 16.12 s 16.12 s +0% 509 MB 509 MB
d2 6.42 s 6.67 s +4% 230 MB 231 MB
d3 9.28 s 8.78 s -5% 66 MB 66 MB
d4 6.74 s 6.58 s -2% 220 MB 220 MB
dense 6.49 s 1.59 s -76% 608 MB 14 MB
dense 1.42 s 1.48 s +4% 13 MB 14 MB
empty_099 0.00 s 0.00 s — 10 MB 9 MB
empty_1 0.33 s 0.35 s +6% 12 MB 12 MB
h1 15.45 s 14.75 s -5% 144 MB 144 MB
h2 4.78 s 4.70 s -2% 166 MB 166 MB
h3 1.84 s 1.83 s -1% 97 MB 98 MB
h4 15.96 s 15.00 s -6% 785 MB 586 MB
h5 6.60 s 6.41 s -3% 394 MB 395 MB
h6 11.98 s 12.42 s +4% 336 MB 336 MB
h7 3.01 s 3.01 s +0% 176 MB 177 MB
h8 8.65 s 8.57 s -1% 544 MB 544 MB
m1 1.40 s 0.84 s -40% 173 MB 36 MB
m2 1.16 s 1.23 s +6% 95 MB 87 MB
m3 2.69 s 2.64 s -2% 105 MB 105 MB
p01 1.52 s 1.43 s -6% 13 MB 14 MB
p02 1.29 s 1.29 s +0% 21 MB 21 MB
p03 2.39 s 2.36 s -1% 20 MB 20 MB
p04 7.00 s 1.84 s -74% 237 MB 13 MB
p05 0.63 s 0.63 s +0% 11 MB 12 MB
p06 0.44 s 0.39 s -11% 20 MB 16 MB
p07 5.24 s 5.59 s +7% 34 MB 34 MB
p08 0.01 s 0.01 s — 9 MB 10 MB
p09 3.38 s 2.25 s -33% 53 MB 44 MB
p10 4.35 s 4.49 s +3% 36 MB 37 MB
p11 3.94 s 3.77 s -4% 15 MB 16 MB
p12 1.12 s 1.08 s -4% 13 MB 14 MB
p13 0.24 s 0.20 s -17% 23 MB 24 MB
p14 1.56 s 1.55 s -1% 12 MB 12 MB
p15 0.54 s 0.39 s -28% 23 MB 15 MB
p16 9.19 s 8.86 s -4% 77 MB 78 MB
p17 0.58 s 0.59 s +2% 16 MB 16 MB
p18 10.19 s 10.11 s -1% 19 MB 20 MB
p19 7.15 s 7.09 s -1% 17 MB 17 MB
p20 0.75 s 0.67 s -11% 13 MB 13 MB
sparse_099 0.67 s 0.11 s -84% 89 MB 11 MB
sparse_1 0.42 s 0.52 s +24% 12 MB 13 MB
total 182.9 s 168.2 s -8.1%

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:

[out:json][timeout:90]; (way["maxheight"]["highway"](42.0,-72.0,43.0,-71.0); way["bridge"]["maxheight"](42.0,-72.0,43.0,-71.0); way["tunnel"]["maxheight"](42.0,-72.0,43.0,-71.0); node["maxheight"]["highway"](42.0,-72.0,43.0,-71.0); ); out center;

dense_099:

[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;

sparse_1:

[out:json][timeout:90]; (way["maxheight"]["highway"](41.0,-70.5,42.0,-69.5); way["bridge"]["maxheight"](41.0,-70.5,42.0,-69.5); way["tunnel"]["maxheight"](41.0,-70.5,42.0,-69.5); node["maxheight"]["highway"](41.0,-70.5,42.0,-69.5); ); out center;

empty_1:

[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;

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):

[adiff:"2025-01-01T00:00:00Z","2026-11-01T00:00:00Z"]; (node["amenity"](42.2,-71.3,42.5,-70.9); way["building"](42.3,-71.15,42.4,-71.0); ); out geom;

d2 (diff highways):

[diff:"2024-01-01T00:00:00Z","2026-11-01T00:00:00Z"]; way["highway"](42.3,-71.2,42.4,-71.0); out geom;

d3 (adiff routes):

[adiff:"2025-06-01T00:00:00Z","2026-11-01T00:00:00Z"]; relation["route"="bus"](42.2,-71.3,42.5,-70.9); out geom;

d4 (diff convert):

[diff:"2024-01-01T00:00:00Z","2026-11-01T00:00:00Z"]; nwr["amenity"](42.3,-71.2,42.4,-71.0); convert item ::id=id(), name=t["name"], amenity=t["amenity"]; out;

h1 (attic rel bbox):

[date:"2020-01-01T00:00:00Z"]; rel(42.0,-72.0,43.0,-70.5); out body;

h2 (attic way geom):

[date:"2020-01-01T00:00:00Z"]; way(42.30,-71.15,42.40,-71.00); out geom;

h3 (nwr bbox meta):

nwr(42.33,-71.10,42.38,-71.03); out meta;

h4 (highways 1deg geom):

way["highway"](42.0,-72.0,43.0,-71.0); out geom;

h5 (buildings center):

way["building"](42.2,-71.3,42.5,-70.9); out center;

h6 (multipolygons geom):

[out:json]; relation["type"="multipolygon"]["natural"](41.5,-73.5,43.0,-70.0); out geom;

h7 (nodes way bn):

node(42.30,-71.15,42.40,-71.00); way(bn); out geom;

h8 (attic amenity meta):

[date:"2018-06-01T00:00:00Z"]; (node["amenity"](42.2,-71.3,42.5,-70.9); way["amenity"](42.2,-71.3,42.5,-70.9);); out meta;

m1 (meta amenity):

node["amenity"](42.2,-71.3,42.5,-70.9); out meta;

m2 (meta buildings):

way["building"](42.3,-71.15,42.4,-71.0); out meta;

m3 (attic meta highways):

[date:"2022-01-01T00:00:00Z"]; way["highway"](42.3,-71.2,42.4,-71.0); out meta;

p01 (maxheight bbox1deg)

[out:json][timeout:90]; (way["maxheight"]["highway"](42.0,-72.0,43.0,-71.0); way["bridge"]["maxheight"](42.0,-72.0,43.0,-71.0); way["tunnel"]["maxheight"](42.0,-72.0,43.0,-71.0); node["maxheight"]["highway"](42.0,-72.0,43.0,-71.0); ); out center;

p02 (amenities around union)

[out:json][timeout:30]; (node["amenity"="school"](around:3000,42.3601,-71.0589); way["amenity"="school"](around:3000,42.3601,-71.0589); node["amenity"="kindergarten"](around:3000,42.3601,-71.0589); way["amenity"="kindergarten"](around:3000,42.3601,-71.0589); node["amenity"="hospital"](around:5000,42.3601,-71.0589); node["amenity"="clinic"](around:5000,42.3601,-71.0589); way["amenity"="hospital"](around:5000,42.3601,-71.0589); node["amenity"="pharmacy"](around:3000,42.3601,-71.0589); node["shop"~"supermarket|convenience|mall"](around:2000,42.3601,-71.0589); way["shop"~"supermarket|convenience|mall"](around:2000,42.3601,-71.0589); node["highway"="bus_stop"](around:1500,42.3601,-71.0589); node["public_transport"="stop_position"](around:1500,42.3601,-71.0589); node["railway"="station"](around:5000,42.3601,-71.0589); node["railway"="halt"](around:5000,42.3601,-71.0589); way["natural"="water"](around:3000,42.3601,-71.0589); relation["natural"="water"](around:3000,42.3601,-71.0589); way["landuse"="forest"](around:3000,42.3601,-71.0589); relation["landuse"="forest"](around:3000,42.3601,-71.0589); way["leisure"="park"](around:2000,42.3601,-71.0589); way["highway"~"primary|secondary|tertiary"](around:2000,42.3601,-71.0589); way["highway"~"residential|unclassified|service"](around:500,42.3601,-71.0589); way["railway"~"rail|narrow_gauge"](around:1000,42.3601,-71.0589); way["landuse"="industrial"](around:3000,42.3601,-71.0589); node["landuse"="landfill"](around:5000,42.3601,-71.0589); way["landuse"="landfill"](around:5000,42.3601,-71.0589); node["amenity"="post_office"](around:3000,42.3601,-71.0589); node["amenity"="fuel"](around:3000,42.3601,-71.0589); ); out center body;

p03 (admin in area)

[out:json][timeout:30]; area(3600061315)->.country; (way["boundary"="administrative"]["admin_level"="8"](area.country); relation["boundary"="administrative"]["admin_level"="8"](area.country); ); out geom;

p04 (brands bbox ci)

[out:json][timeout:25]; (node["amenity"~"fuel|truck_stop"]["brand"~"travelcenters of america|petro stopping center|love's travel stop|ta travelcenters|pilot flying j|sapp brothers|pilot travel|seven eleven|road ranger|sapp bros|race trac|flying j|ta petro|buc-ee's|racetrac|speedway|circle k|7-eleven|7 eleven|flyingj|buc ees|am best|circlek|7eleven|love's|bucees|ambest|ambest|loves|pilot|petro|7-11|7 11|wawa|ta",i](42.16,-71.26,42.56,-70.86); node["amenity"~"fuel|truck_stop"]["name"~"travelcenters of america|petro stopping center|love's travel stop|ta travelcenters|pilot flying j|sapp brothers|pilot travel|seven eleven|road ranger|sapp bros|race trac|flying j|ta petro|buc-ee's|racetrac|speedway|circle k|7-eleven|7 eleven|flyingj|buc ees|am best|circlek|7eleven|love's|bucees|ambest|ambest|loves|pilot|petro|7-11|7 11|wawa|ta",i](42.16,-71.26,42.56,-70.86); way["amenity"~"fuel|truck_stop"]["brand"~"travelcenters of america|petro stopping center|love's travel stop|ta travelcenters|pilot flying j|sapp brothers|pilot travel|seven eleven|road ranger|sapp bros|race trac|flying j|ta petro|buc-ee's|racetrac|speedway|circle k|7-eleven|7 eleven|flyingj|buc ees|am best|circlek|7eleven|love's|bucees|ambest|ambest|loves|pilot|petro|7-11|7 11|wawa|ta",i](42.16,-71.26,42.56,-70.86); way["amenity"~"fuel|truck_stop"]["name"~"travelcenters of america|petro stopping center|love's travel stop|ta travelcenters|pilot flying j|sapp brothers|pilot travel|seven eleven|road ranger|sapp bros|race trac|flying j|ta petro|buc-ee's|racetrac|speedway|circle k|7-eleven|7 eleven|flyingj|buc ees|am best|circlek|7eleven|love's|bucees|ambest|ambest|loves|pilot|petro|7-11|7 11|wawa|ta",i](42.16,-71.26,42.56,-70.86); node["shop"~"convenience|supermarket"]["brand"~"travelcenters of america|petro stopping center|love's travel stop|ta travelcenters|pilot flying j|sapp brothers|pilot travel|seven eleven|road ranger|sapp bros|race trac|flying j|ta petro|buc-ee's|racetrac|speedway|circle k|7-eleven|7 eleven|flyingj|buc ees|am best|circlek|7eleven|love's|bucees|ambest|ambest|loves|pilot|petro|7-11|7 11|wawa|ta",i](42.16,-71.26,42.56,-70.86); node["shop"~"convenience|supermarket"]["name"~"travelcenters of america|petro stopping center|love's travel stop|ta travelcenters|pilot flying j|sapp brothers|pilot travel|seven eleven|road ranger|sapp bros|race trac|flying j|ta petro|buc-ee's|racetrac|speedway|circle k|7-eleven|7 eleven|flyingj|buc ees|am best|circlek|7eleven|love's|bucees|ambest|ambest|loves|pilot|petro|7-11|7 11|wawa|ta",i](42.16,-71.26,42.56,-70.86); node["leisure"~"fitness_centre|sports_centre"]["brand"~"planet fitness|planet-fitness|crunch fitness|crunch-fitness|planetfitness|crunch gym",i](42.16,-71.26,42.56,-70.86); node["leisure"~"fitness_centre|sports_centre"]["name"~"planet fitness|planet-fitness|crunch fitness|crunch-fitness|planetfitness|crunch gym",i](42.16,-71.26,42.56,-70.86); way["leisure"~"fitness_centre|sports_centre"]["brand"~"planet fitness|planet-fitness|crunch fitness|crunch-fitness|planetfitness|crunch gym",i](42.16,-71.26,42.56,-70.86); way["leisure"~"fitness_centre|sports_centre"]["name"~"planet fitness|planet-fitness|crunch fitness|crunch-fitness|planetfitness|crunch gym",i](42.16,-71.26,42.56,-70.86); node["amenity"="gym"]["brand"~"planet fitness|planet-fitness|crunch fitness|crunch-fitness|planetfitness|crunch gym",i](42.16,-71.26,42.56,-70.86); node["amenity"="gym"]["name"~"planet fitness|planet-fitness|crunch fitness|crunch-fitness|planetfitness|crunch gym",i](42.16,-71.26,42.56,-70.86); way["amenity"="gym"]["name"~"planet fitness|planet-fitness|crunch fitness|crunch-fitness|planetfitness|crunch gym",i](42.16,-71.26,42.56,-70.86); ); out center tags;

p05 (global data center)

[out:json][timeout:300]; (node["telecom"="data_center"]; way["telecom"="data_center"]; ); out center tags;

p06 (food around regex)

[out:json][timeout:40]; (node["amenity"~"restaurant|cafe|ramen|sushi|izakaya|fast_food|bar|pub|food_court"](around:500,42.3601,-71.0589); way["amenity"~"restaurant|cafe|ramen|sushi|izakaya|fast_food|bar|pub|food_court"](around:500,42.3601,-71.0589); node["amenity"~"school|university|college|kindergarten"](around:1000,42.3601,-71.0589); way["amenity"~"school|university|college|kindergarten"](around:1000,42.3601,-71.0589); node["amenity"~"hospital|clinic|doctors|pharmacy"](around:5000,42.3601,-71.0589); way["amenity"~"hospital|clinic|doctors|pharmacy"](around:5000,42.3601,-71.0589); node["railway"~"station|halt"](around:1000,42.3601,-71.0589); way["railway"~"station|halt"](around:1000,42.3601,-71.0589); node["highway"="bus_stop"](around:1000,42.3601,-71.0589); node["amenity"="parking"](around:500,42.3601,-71.0589); way["amenity"="parking"](around:500,42.3601,-71.0589); node["shop"="convenience"](around:500,42.3601,-71.0589); way["shop"="convenience"](around:500,42.3601,-71.0589); node["tourism"~"hotel|motel|hostel|guest_house|ryokan"](around:2000,42.3601,-71.0589); way["tourism"~"hotel|motel|hostel|guest_house|ryokan"](around:2000,42.3601,-71.0589); ); out center;

p07 (global seamark recurse)

(rel['seamark:type']; >; way['seamark:type']; >; node['seamark:type']; ); out meta;

p08 (global cameras)

[out:json][timeout:30]; (node["camera:type"="traffic_monitoring"]["camera:url"]; node["camera:type"="traffic_monitoring"]["camera:image"]; node["camera:type"="traffic_monitoring"]["image"]; node["camera:type"="traffic_monitoring"]["url"]; node["surveillance:type"="traffic_monitoring"]["camera:url"]; node["surveillance:type"="traffic_monitoring"]["camera:image"]; node["surveillance:type"="traffic_monitoring"]["image"]; node["surveillance:type"="traffic_monitoring"]["url"]; node["man_made"="surveillance"]["camera:type"="traffic_monitoring"]["camera:url"]; node["man_made"="surveillance"]["camera:type"="traffic_monitoring"]["camera:image"]; node["man_made"="surveillance"]["camera:type"="traffic_monitoring"]["image"]; node["man_made"="surveillance"]["camera:type"="traffic_monitoring"]["url"]; ); out body;

p09 (3d buildings bbox)

[out:json][timeout:360][bbox:42.34,-71.08,42.38,-71.04]; (nwr["building"]; nwr["building:part"]; relation["type"="building"]; nwr["highway"]; nwr["landuse"]["landuse"!="salt_pond"]; nwr["natural"]["natural"!="coastline"]["natural"!="bay"]["natural"!="strait"]; nwr["leisure"]; nwr["water"]["water"!="bay"]["water"!="ocean"]["water"!="sea"]["tidal"!="yes"]; nwr["waterway"]["waterway"!="tidal_channel"]; nwr["amenity"]; nwr["tourism"]; nwr["bridge"]; nwr["railway"]; nwr["roller_coaster"]; nwr["barrier"]; nwr["entrance"]; nwr["door"]; nwr["power"]; nwr["historic"]; nwr["emergency"]; nwr["advertising"]; nwr["man_made"]; nwr["aeroway"]; nwr["3dmr"]; way["place"]["place"!~"^(ocean|sea|bay|strait|sound|fjord)$"]; way; )->.relsinbbox; (way(r.relsinbbox); )->.waysinbbox; (node(w.waysinbbox); node(w.relsinbbox); )->.nodesinbbox; .relsinbbox out body; .waysinbbox out body; .nodesinbbox out skel qt;

p10 (tourism around25k)

[out:json][timeout:45]; (node["tourism"](around:25000,42.3601,-71.0589); way["tourism"](around:25000,42.3601,-71.0589); node["amenity"~"restaurant|cafe|bar|pub|nightclub|fast_food|food_court|biergarten|ice_cream|bakery"](around:25000,42.3601,-71.0589); way["amenity"~"restaurant|cafe|bar|pub"](around:25000,42.3601,-71.0589); node["amenity"~"theatre|cinema|museum|arts_centre|library|community_centre|concert_hall|studio"](around:25000,42.3601,-71.0589); way["amenity"~"theatre|cinema|museum|arts_centre"](around:25000,42.3601,-71.0589); node["leisure"~"park|garden|stadium|sports_centre|swimming_pool|beach_resort|water_park|marina|golf_course"](around:25000,42.3601,-71.0589); way["leisure"~"park|garden|stadium|nature_reserve"](around:25000,42.3601,-71.0589); node["shop"~"mall|department_store|supermarket|marketplace|clothes|books|gift|art|antiques|wine|craft|boutique"](around:25000,42.3601,-71.0589); way["shop"~"mall|department_store|marketplace"](around:25000,42.3601,-71.0589); node["historic"](around:25000,42.3601,-71.0589); way["historic"](around:25000,42.3601,-71.0589); node["natural"~"peak|beach|spring|cave_entrance|volcano|waterfall"](around:25000,42.3601,-71.0589); node["man_made"~"tower|lighthouse|windmill"](around:25000,42.3601,-71.0589); ); out body center 500;

p11 (brownfield bigbbox)

[out:json][timeout:180]; (way["landuse"="brownfield"](40.5,-80.0,47.5,-67.0); way["landuse"="landfill"](40.5,-80.0,47.5,-67.0); node["man_made"="dump"](40.5,-80.0,47.5,-67.0); way["abandoned:landuse"="industrial"](40.5,-80.0,47.5,-67.0); ); out geom;

p12 (clinic name ci around25k)

[out:json][timeout:30]; (node["amenity"="clinic"]["name"~"cosmetic|aesthetic|beauty|skin|plastic",i](around:25000,42.3601,-71.0589); way["amenity"="clinic"]["name"~"cosmetic|aesthetic|beauty|skin|plastic",i](around:25000,42.3601,-71.0589); node["healthcare"~"aesthetics|cosmetics",i](around:25000,42.3601,-71.0589); way["healthcare"~"aesthetics|cosmetics",i](around:25000,42.3601,-71.0589); ); out body center qt;

p13 (map call meta)

[bbox:42.355,-71.065,42.365,-71.055]; (node(42.355,-71.065,42.365,-71.055); way(bn); node(w); ); (._; (rel(bn)->.a; rel(bw)->.a; ); rel(br); ); out meta;

p14 (area by name worship)

[out:json][timeout:90]; area["name"="Massachusetts"]->.searchArea; (node["amenity"="place_of_worship"]["religion"="jewish"](area.searchArea); way["amenity"="place_of_worship"]["religion"="jewish"](area.searchArea); rel["amenity"="place_of_worship"]["religion"="jewish"](area.searchArea); ); out body 200;

p15 (tiny bbox many keys geom)

[out:json][timeout:25][bbox:42.3580,-71.0620,42.3624,-71.0565]; (node[amenity]; way[amenity]; relation[amenity]; node[building~"^(commercial|retail|office|public|civic|school|college|university|kindergarten|hospital|clinic|transportation|train_station|church|chapel|mosque|temple|synagogue|hotel|supermarket)$"]; way[building~"^(commercial|retail|office|public|civic|school|college|university|kindergarten|hospital|clinic|transportation|train_station|church|chapel|mosque|temple|synagogue|hotel|supermarket)$"]; relation[building~"^(commercial|retail|office|public|civic|school|college|university|kindergarten|hospital|clinic|transportation|train_station|church|chapel|mosque|temple|synagogue|hotel|supermarket)$"]; node[entrance]; node[highway~"^(bus_stop|crossing|elevator)$"]; way[highway~"^(bridleway|bus_guideway|cycleway|footway|living_street|motorway|motorway_link|path|pedestrian|primary|primary_link|residential|residential_link|road|secondary|secondary_link|service|steps|tertiary|tertiary_link|trunk|trunk_link|unclassified)$"]; relation[highway~"^(bridleway|bus_guideway|cycleway|footway|living_street|motorway|motorway_link|path|pedestrian|primary|primary_link|residential|residential_link|road|secondary|secondary_link|service|steps|tertiary|tertiary_link|trunk|trunk_link|unclassified)$"]; node[historic]; way[historic]; relation[historic]; node[indoormark="beacon"]; way[indoormark="beacon"]; relation[indoormark="beacon"]; way[landuse="construction"]; relation[landuse="construction"]; node[leisure]; way[leisure~"^(pitch|park|garden|playground|sports_centre|stadium|golf_course|marina|water_park)$"]; relation[leisure~"^(pitch|park|garden|playground|sports_centre|stadium|golf_course|marina|water_park)$"]; node[office]; way[office]; relation[office]; node[railway~"^(platform|station|subway_entrance|tram_stop)$"]; way[railway~"^(platform|station)$"]; relation[railway~"^(platform|station)$"]; node[shop]; way[shop]; relation[shop]; node[tourism]; way[tourism]; relation[tourism]; way[zoo="enclosure"]; relation[zoo="enclosure"]; ); out geom;

p16 (hgv restrictions bbox)

[out:json][timeout:120]; (way["maxheight"](41.2400,-73.5100,42.8900,-69.9300); way["maxweight"](41.2400,-73.5100,42.8900,-69.9300); way["maxlength"](41.2400,-73.5100,42.8900,-69.9300); way["maxwidth"](41.2400,-73.5100,42.8900,-69.9300); way["hazmat"](41.2400,-73.5100,42.8900,-69.9300); way["hgv"](41.2400,-73.5100,42.8900,-69.9300); node["maxheight"](41.2400,-73.5100,42.8900,-69.9300); node["maxweight"](41.2400,-73.5100,42.8900,-69.9300); ); out geom;

p17 (anchored regex around)

[out:json][timeout:15]; (node["amenity"~"^(restaurant|fast_food|cafe|pharmacy|school|food_court)$"](around:4828,42.3601,-71.0589); way["amenity"~"^(restaurant|fast_food|cafe|pharmacy|school|food_court)$"](around:4828,42.3601,-71.0589); node["shop"~"^(supermarket|grocery|convenience|bakery)$"](around:4828,42.3601,-71.0589); way["shop"~"^(supermarket|grocery|convenience|bakery)$"](around:4828,42.3601,-71.0589); node["leisure"~"^(park|recreation_ground|fitness_centre|fitness_center|dog_park|playground)$"](around:4828,42.3601,-71.0589); way["leisure"~"^(park|recreation_ground|fitness_centre|fitness_center|dog_park|playground)$"](around:4828,42.3601,-71.0589); relation["leisure"~"^(park|recreation_ground)$"](around:4828,42.3601,-71.0589); ); out center tags;

p18 (fuel bigbbox)

[out:json][timeout:420]; (node["amenity"="fuel"](40.5,-80.0,46.6,-69.7); way["amenity"="fuel"](40.5,-80.0,46.6,-69.7); ); out center;

p19 (venues bbox name ci)

[out:json][timeout:90]; (node["amenity"~"community_centre|arts_centre|theatre|cinema|concert_hall|events_venue|convention_centre|conference_centre|social_facility|public_building"](41.80,-72.00,43.05,-70.10); node["leisure"~"sports_hall|sports_centre|ice_rink|arena"](41.80,-72.00,43.05,-70.10); node["building"~"gymnasium|sports_hall|civic|hall|public|community_centre|grandstand|sports_centre"](41.80,-72.00,43.05,-70.10); node["amenity"="gym"](41.80,-72.00,43.05,-70.10); node["name"~"town hall|community center|community centre|recreation center|civic center|function hall|grange hall|vfw post|american legion|masonic|banquet|convention center|fairgrounds|exhibition center",i](41.80,-72.00,43.05,-70.10); way["amenity"~"community_centre|arts_centre|theatre|cinema|concert_hall|events_venue|convention_centre|conference_centre|social_facility|public_building"](41.80,-72.00,43.05,-70.10); way["leisure"~"sports_hall|sports_centre|ice_rink|arena"](41.80,-72.00,43.05,-70.10); way["building"~"gymnasium|sports_hall|civic|hall|public|community_centre|grandstand|sports_centre"](41.80,-72.00,43.05,-70.10); way["name"~"town hall|community center|community centre|recreation center|civic center|function hall|grange hall|vfw post|american legion|masonic|banquet|convention center|fairgrounds|exhibition center",i](41.80,-72.00,43.05,-70.10); relation["amenity"~"community_centre|arts_centre|theatre|cinema|concert_hall|events_venue|convention_centre|conference_centre|social_facility|public_building"](41.80,-72.00,43.05,-70.10); relation["leisure"~"sports_hall|sports_centre|ice_rink|arena"](41.80,-72.00,43.05,-70.10); relation["building"~"gymnasium|sports_hall|civic|hall|public|community_centre|grandstand|sports_centre"](41.80,-72.00,43.05,-70.10); ); out center tags;

p20 (office around25k)

[out:json][timeout:30]; (node["office"="hr"](around:25000,42.3601,-71.0589); way["office"="hr"](around:25000,42.3601,-71.0589); node["office"="consulting"]["name"~"hr|human resource|talent|workforce|people",i](around:25000,42.3601,-71.0589); way["office"="consulting"]["name"~"hr|human resource|talent|workforce|people",i](around:25000,42.3601,-71.0589); ); out body center qt;

Testing

  • Byte-identical output to upstream/master on all 41 queries above.
  • A first version took cells from the raw 32-bit values of Uint31_Index ranges, treated ranges like 0x8c000040..0x0c000040 as spanning everything, and fell back for all way statements; output was correct, only the gain was missing for ways.
  • CI: fuzz, history and props run on this PR.

Limitations and open questions



Generated by Claude Code

@cldellow cldellow added query-memory query-perf Query performance change; collected on all-changes labels Nov 27, 2026 — with Claude
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
cldellow force-pushed the query-local-tags-first branch from d053c62 to edbe5e3 Compare November 27, 2026 02:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

query-memory query-perf Query performance change; collected on all-changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Late tag checks decode every element in the ranges before checking tags

2 participants