Repository navigation
Description
Importing a full-history file (.osh.pbf) directly with update_database --keep-attic produces wrong geometry for old way versions. That makes the database unreliable for testing anything that reads ways at past dates.
How it was found
A history test database was built by importing a Geofabrik full-history extract of Nova Scotia (every version from 2006 to 2026-11-15) like this:
osmium cat extract.osh.pbf -f osm -o - | update_database --db-dir=db/ --keep-atticThe extract is licensed and can't be shared, so only aggregate numbers are given here. Results were compared against osmium (osmium time-filter at a date, then the same bounding box).
Symptoms
-
Current data and nodes at past dates are exact. The node, way and relation ids match, and node counts in the box (44.60,-63.66,44.70,-63.52) at 2010, 2014, 2018 and 2022 equal osmium's.
-
Ways at past dates are wrong:
Date Ways in the box, osmium Ways in the box, Overpass 2010-01-01 1,751 1,263 2014-01-01 9,100 7,510 2018-01-01 54,565 48,679 2022-01-01 58,565 56,846 At 2018-01-01, osmium has 6,911 ways that Overpass misses, and 62% of them use a node that is deleted today, against 11% of the ways Overpass finds. Overpass also has 1,025 ways that osmium doesn't.
-
Old way versions can't resolve their nodes.
[date:"…"]; way(ID); out geom;prints such nodes at the placeholder position (lat 100, lon 200), andnode(w)returns nothing. The node versions themselves are stored correctly: looking them up by id or by bbox at that date works. -
aroundqueries over such ways become very slow. Any query whose input set at a past date contains such ways is affected:[out:csv(::count)][date:"2026-10-01T00:00:00Z"]; way["highway"="residential"](44.64,-63.60,44.66,-63.56)->.s0; node(around.s0:50)["amenity"]; out count;This takes 63 s on fossgis
master, against 0.1 s without the date. Time grows with the number of unresolvable node references in the input: 18 → 35 s, 26 → 63 s, 54 → 98 s. About 60% of the time goes to sorting the index ranges built bycalc_parents. In a differential-fuzzing hunt for degenerate queries, 38 of the 47 slow queries (2,500 run) combinedaroundwith[date:],[diff:]or[adiff:]. Queries whose input is only nodes are fast at any date.
Cause
When update_database computes a way version's geometry (osm-backend/way_updater.cc, Way_Updater::update → lookup_missing_nodes), it takes node positions from the nodes in the same update batch, including their old versions, or else from the current node table. It never reads the attic node tables.
- Diffs in time order: the nodes a way needs are in the same diff or still current, which is how production builds its history.
- A full-history file: it holds every node version before the first way. So old way versions are built from today's nodes:
- nodes deleted since aren't found
- nodes moved since give today's position
compute_idx_and_geometry skips any node it can't find, with the comment "something has gone wrong seriously". So a way that spans several tiles, and therefore stores its own geometry, ends up with stored geometry shorter than its node list. That probably explains the placeholders and the slow around queries. The exact path from short stored geometry to the huge range sets hasn't been traced.
What to do
-
For testing: build history databases by replaying the full-history file as time-ordered change files with
update_from_dir --keep-attic, as production does. That's being prepared separately. -
For upstream, possibly:
- make
update_databasereject or warn on full-history input - have the geometry lookup also consult attic nodes at the right timestamp; relations would need the same
- make readers validate stored geometry against the node list
None of this is planned. It affects only this unusual import path.
- make
Effect on other work
- The bbox inner-tile shortcut (bbox filter: keep ways in inner tiles without loading their geometry #21) differs from the baseline on
[date:]and[diff:]queries on this database, because of these ways. aroundwith a history setting can't be checked for degenerate queries until a replay-built database exists.
Generated by Claude Code
Activity
cldellow commentedon Nov 21, 2026
Findings from a separate investigation, with full-history extracts of Prince Edward Island and Nova Scotia (licensed; aggregate numbers only). The fixes are collected on
better-imports(#58), kept apart fromall-changes.Node_UpdaterandWay_Updatersetpartial_possiblefrom the meta mode in the initialiser, and the constructor body then overwrites it with!file_exists(...). On an empty database that turns on partial mode even with--keep-attic, and partial mode clearsnew_attic_skeletonsafter each update. So the way updater gets no node history at all, and the relation updater no way history. Fixing that (Keep new attic skeletons when importing into an empty database with attic #51) makes ways at 2018-01-01 match osmium exactly for PEI (7,469 missing → 0).-f osmhides a second bug. That format dropsvisible="false", and the parser ignores it anyway, so deleted versions are imported as live objects (History import: deleted versions (visible="false") are stored as live objects #45). That probably accounts for part of the 1,025 extra ways in the table above.better-imports, Nova Scotia matches osmium exactly for nodes and ways at 2014, 2018, 2022 and 2026-11-16 in the world box, and no deleted object is returned by id. The remaining differences (13 ways at 2010, and relations without node or way members) are gaps in the extract itself. So a direct import is usable without replaying the history as diffs.Generated by Claude Code
cldellow commentedon Nov 21, 2026
Re-imported with the
better-importsbranch: the broken way geometry is gone.The same full-history extract was imported directly, now as
osmium cat … -f osh | update_database --keep-attic. Theoshformat marks deletions withvisible="false", which that branch honours. The import took 8 min 15 s, against 14 min 39 s before, and wrote 214 thousand log lines instead of about 13 GB.Correction to the reference used above. The osmium way counts in the table above used
osmium extract -s simple, which misses some ways that do have a node inside the box. With-s complete_ways, the reference counts are higher. The old database was wrong either way: it was below even the lower reference.Checked against osmium (
time-filterat the date, thenextract -s complete_wayswith the box 44.60,-63.66,44.70,-63.52), at the level of individual ids:The old database had 48,679 ways at 2018-01-01.
aroundqueries are gone. The example in the description, a datedaroundover residential ways, went from over 150 s to 1.5 s. A 2,000-query history fuzz of the all-changes branch against fossgismasterhad 1 timeout, against 9 to 11 in runs of the same size on the old database, and 0 differences.So for testing, a direct import of a full-history file with
better-importsnow gives a usable history database. The import fixes themselves have no PR yet.Generated by Claude Code