Skip to content

GPKG sources are merged in rowid order instead of lowest zoom first #276

Done

Description

@shimoncohen

Describe the bug
Since #255 (keyset paging), GPKG sources are read in rowid order instead of lowest zoom first. Merge order matters: when a new tile only partly covers its area, the rest is filled by upscaling the closest lower-zoom tile already in the target. A GPKG keeps all zoom levels in one tile table, and rowid order is insertion order. When a table is not stored lowest zoom first (the test files below are stored z18 first), z18 tiles are now merged before the z17 tiles they used to be filled from. The same merge then gives different output than v2.2.3.

To Reproduce

  1. Merge a z16 GPKG and a z18 GPKG into a new GPKG with v2.2.3 and with master: MergerCli 1000 gpkg out.gpkg <bbox> gpkg z16.gpkg gpkg z18.gpkg. In this source, rows are stored z18 first, then z17 and lower.
  2. Compare the two outputs tile by tile: 897 of 34,764 tiles differ (45 at z16, 284 at z17, 568 at z18). All are edge tiles where part of the tile is filled from a lower zoom.
  3. Running v2.2.3 twice gives byte-identical output, so the difference comes from master, not run-to-run noise.

Tables stored lowest zoom first merge as before, which is why the existing tests, which insert tiles in ascending zoom order, did not catch it.

Expected behavior
The same inputs produce the same output as v2.2.3: tiles are merged lowest zoom first.

Additional context

  • Where: GpkgClient.GetBatch pages with WHERE rowid > $lastId ORDER BY rowid. v2.2.3 used ORDER BY zoom_level with LIMIT/OFFSET. SQLite served that through the GPKG's UNIQUE(zoom_level, tile_column, tile_row) index, so the effective order was zoom, then column, then row.
  • Possible fix: page on that same index with WHERE (zoom_level, tile_column, tile_row) > (?, ?, ?). It keeps the constant page cost of keyset paging and restores the v2.2.3 order; I checked that output is byte-identical to v2.2.3 again.

Activity

  1. self-assigned this
    on Nov 24, 2026
  2. added
    bug
    on Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions