Skip to content

Direct full-history import builds wrong geometry for old way versions #34

Open

Description

@cldellow

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-attic

The 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

  1. 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.

  2. 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.

  3. Old way versions can't resolve their nodes. [date:"…"]; way(ID); out geom; prints such nodes at the placeholder position (lat 100, lon 200), and node(w) returns nothing. The node versions themselves are stored correctly: looking them up by id or by bbox at that date works.

  4. around queries 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 by calc_parents. In a differential-fuzzing hunt for degenerate queries, 38 of the 47 slow queries (2,500 run) combined around with [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_database reject 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.

Effect on other work


Generated by Claude Code

Activity

  1. cldellow commented on Nov 21, 2026

    @cldellow
    OwnerAuthor

    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 from all-changes.

    • The node versions aren't missing; they're thrown away. Node_Updater and Way_Updater set partial_possible from 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 clears new_attic_skeletons after 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).
    • Reading the attic node tables is needed too, but only when an import spans several flushes, as Nova Scotia's does: the history from earlier batches is then on disk only (History import in several batches ignores node history written by earlier batches #47, fixed by Read stored attic nodes and ways when importing in several batches #54).
    • -f osm hides a second bug. That format drops visible="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.
    • With all of 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

  2. added
    import-fix
    bug
    on Nov 21, 2026
  3. cldellow commented on Nov 21, 2026

    @cldellow
    OwnerAuthor

    Re-imported with the better-imports branch: the broken way geometry is gone.

    The same full-history extract was imported directly, now as osmium cat … -f osh | update_database --keep-attic. The osh format marks deletions with visible="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-filter at the date, then extract -s complete_ways with the box 44.60,-63.66,44.70,-63.52), at the level of individual ids:

    Date Ways, osmium Ways, new database Only osmium Only Overpass
    2010-01-01 1,793 1,787 6 0
    2014-01-01 9,250 9,250 0 0
    2018-01-01 54,822 54,822 0 0
    2022-01-01 58,835 58,835 0 0

    The old database had 48,679 ways at 2018-01-01.

    • Current data: node, way and relation ids still match exactly. The same 542 relations are reachable only by id, as before.
    • Nodes at past dates still match exactly.
    • The 6 ways missing at 2010 are a data problem. Each references nodes that don't exist at that date anywhere in the extract (11 references in total), plausibly removed in the 2012 licence-change redaction. Overpass treats a way with any unresolvable node as having no geometry, while osmium uses the nodes it has. That's long-standing query behaviour, not the import.
    • The slow around queries are gone. The example in the description, a dated around over residential ways, went from over 150 s to 1.5 s. A 2,000-query history fuzz of the all-changes branch against fossgis master had 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-imports now gives a usable history database. The import fixes themselves have no PR yet.


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugimport-fix

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions