Repository navigation
Conversation
Bbox_Filter::filter built a Way_Geometry_Store for every candidate way,
reading the nodes of each one to test whether it really meets the box.
A way whose index is a single tile (bit 31 clear) has all its nodes in
that tile. If the tile lies inside the box, so do all of its nodes, and
Bbox_Filter::matches accepts any way with a node inside. Keep such ways
without loading their geometry; test only the rest. A tile's bounds are
the positions decoded with the lowest and highest ll_lower. Boxes that
cross the antimeridian, and the history path, are unchanged.
Nova Scotia extract, CPU time, alternating runs:
[out:csv(::count)]; way(44.60,-63.66,44.70,-63.52); out count;
263 ms -> 133 ms
[out:csv(::count)]; way[highway](44.60,-63.66,44.70,-63.52); out count;
132 ms -> 109 ms
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01736kJUqyDw9zM3Bkh2W2QT
|
Colin's thoughts: Accept ways that are trivially in the bbox; only do expensive geometry operations on ways we can't so prove. The regression suite found a case where the new behaviour differs from the old behaviour: when querying a history with referentially broken objects: I believe the history was broken due to how I constructed my test database. I'm retrying with a Geofabrik .osh.pbf, will see if that resolves it. Note that the .osh.pbf only has data up to Nov 15, so we'll need to test a variant of that query to confirm correctness. The query as is would trivially return 0 for both upstream and this patch. |
|
Re-check on a history database built from a full-history extract: the difference remains, and the new database is itself inconsistent at past dates. I rebuilt the history test database by importing a full-history extract of Nova Scotia (an The database is right for current data and wrong for some ways at past datesChecked against the extract with osmium:
The cause is the import, not the extract. When Results on this databaseEach query compared against fossgis
All 9 extra objects in the Correction to the descriptionThe description says the history path is unchanged. That is only partly true. In a What this means
Generated by Claude Code |
|
Re-check on a correctly imported history database: no differences. The history database was rebuilt from the same full-history extract with the importer fixes on the The all-changes branch was also identical on 1,999 of 2,000 history-feature fuzz queries (1 timeout). So every difference seen so far came from broken test databases. The open question remains: can a production database contain a way whose index disagrees with its nodes' positions at a past date, for example after the 2012 redaction? The 6 ways above are that shape of data. Here they lack geometry on both builds, so they don't show up as a difference. Generated by Claude Code |
Fixes #19.
Change
Bbox_Filter::filter(data/bbox_filter.cc) built aWay_Geometry_Storefor every candidate way, reading the nodes of each one to test whether the way really meets the box.This keeps, without loading geometry, every way whose index tile lies entirely inside the box:
Uint31_Indexis a single tile (bit 31 clear) has all its nodes in that tile. If the tile lies inside the box, so do all of the way's nodes.Bbox_Filter::matchesaccepts any way with a node inside the box: single nodes viacontains(), segments viaintersects().ll_lower. Every node position in a tile lies between them.[date:]and[diff:]queries, use the exact test as before. Objects unchanged since the queried date come from the current tables, so they take this path in date queries too.One file, about 35 lines. Based on fossgis
master. No change to the database format or the query API.Impact
CPU time (user + system), median of 5 alternating runs per build, Nova Scotia test database (Geofabrik extract of 2026-11-08, imported with
--meta), warm cache, 4-core VM. Output is byte-identical for every query. The box (44.60,-63.66,44.70,-63.52) is central Halifax.master[out:csv(::count)]; way(44.60,-63.66,44.70,-63.52); out count;[out:csv(::count)]; way[highway](44.60,-63.66,44.70,-63.52); out count;(benchmark q04)[out:json]; way[building](44.60,-63.66,44.70,-63.52); out tags;[out:json]; way[highway](44.60,-63.66,44.70,-63.52); out geom;(benchmark q10)[out:csv(::count)]; nwr[amenity](44.60,-63.66,44.70,-63.52); out count;[out:xml]; nwr[amenity](44.60,-63.66,44.70,-63.52); out meta;(benchmark q08)[out:json]; way[building](44.640,-63.585,44.655,-63.565); out geom;(benchmark q09)¹
out geomloads the nodes for output anyway.² In a small box, few tiles lie entirely inside.
Testing
This change skips work, so it got targeted checks beyond the standard fuzzer:
ll_lower.[out:csv(::id;false)]; way["k"](S,W,N,E); out ids;(one in three without a tag filter). The boxes were 0.001° to 0.5° high, at random positions around sampled nodes. 0 differences againstmaster.master(bench/fuzz.py, see Benchmark queries and differential fuzzer #2). 0 differences; 15 skipped, all timeouts. That's three more thanmaster's usual 12, because the run shared the CPU with a build.complete). That covered 10,000 queries across the plain, area and history databases (6,000 / 2,000 / 2,000), with 0 differences. The per-PR fuzz run above predates a fuzzer fix: about 8% of its queries were invalid on both builds, so it rests on roughly 5,500 queries that ran (see Benchmark queries and differential fuzzer #2).Memory
No new allocation beyond a map holding the moved vectors (moved, not copied). Peak memory (RSS) drops, because the skipped geometry is never loaded:
masterout countLimitations
Differs on referentially broken data. On the history test database (see Benchmark queries and differential fuzzer #2), which has gaps from its regional filtering, this query returns 162 more objects than the baseline (15,078 against 14,916):
All 162 are ways none of whose nodes exist in that database. On databases where every way's nodes exist, which OSM's API guarantees for planet-derived data, output is identical.
Update: re-checked on a database imported directly from a full-history extract. That
newerquery now matches. A[date:"2018-01-01T00:00:00Z"]query returns 9 more ways than the baseline (1,788 against 1,779), and a[diff:]query differs too. All 9 are current versions whose nodes can't be resolved at that date. The direct import itself leaves ways whose index disagrees with their nodes' past positions, so this database isn't representative of production either. Whether production has such ways is unknown. Details in the comments.Simple tile indexes only. Ways with compound indexes, which span several tiles, still take the exact test, even if their whole region is inside the box.
Relations and antimeridian boxes untested: relations are unchanged, and antimeridian-crossing boxes aren't covered by the test database.
[date:]queries reach this change for objects unchanged since the date; see the update above.Narrow test setup: one regional extract, warm cache, one VM.
Generated by Claude Code