Skip to content

newer queries on a large box re-read node blocks about 3.6 times #33

Open

Description

@cldellow

newer queries on a large box decompress the same node blocks several times.

Query

[out:csv(::count)]; nwr(newer:"2026-11-08T00:00:00Z")(43.3,-66.5,47.1,-59.6); out count;

Measurement

fossgis master (8edf11b), with throwaway instrumentation that counts decompressions per (file, block) (not on any branch). The database is a Nova Scotia history database imported from a full-history extract with --keep-attic.

File Decompressions Distinct blocks Ratio
nodes.bin 5,798 1,622 3.57
nodes_meta.bin 3,368 3,368 1.00
ways.bin 3,092 1,594 1.94
ways_meta.bin 197 197 1.00
relations.bin 12 12 1.00
All files 12,474 6,800 1.83

The metadata is read once, but node blocks are read about 3.6 times and way blocks about twice. The pattern differs from the uid_touched case, so the cause is probably different too: perhaps the query statement re-reading the box for each constraint, or the way geometry check loading nodes again. A simulated LRU cache of decompressed blocks catches none of these re-reads, even at 128 MB, so they come from separate passes over the whole box.

Cost

The query takes about 5.2 s of CPU on the baseline, about 15% of it in LZ4_decompress_safe. The extra node and way decompressions (about 5,700) cost roughly 350 ms, or about 7% of the query, plus parsing those blocks again.

Possible fix

Not investigated yet. The first step is tracing which statements read nodes.bin here and in what order (for example with a backtrace on each read of an already-read block), then checking whether those passes can share their results.


Generated by Claude Code

Activity

  1. cldellow commented on Nov 21, 2026

    @cldellow
    OwnerAuthor

    Where the re-reads come from, traced. I attributed every block read to its call path with strace -e mmap -k on fossgis master: each block read memory-maps its block, so the trace shows every read and its caller. The query is the one above:

    [out:csv(::count)]; nwr(newer:"2026-11-08T00:00:00Z")(43.3,-66.5,47.1,-59.6); out count;
    
    Pass nodes.bin reads ways.bin reads
    Collecting the box's nodes (collect_items_range in Query_Statement::execute) 1,622
    Collecting the box's ways 1,594
    Bbox geometry of the ways that passed newer (Bbox_Filter::filter → Way_Geometry_Store → small_way_members) 1,622
    Bbox geometry of the relation member ways (same path) 935
    Finding the member nodes of the 211 relations that passed newer (Bbox_Filter::filter → relation_node_members) 1,619
    Finding their member ways (relation_way_members) 1,498

    Within each pass, every block is read once. The re-reads are separate passes over the same province-sized area.

    What this means:

    • The node pass is inherent. newer has no index on timestamps, so every node in the box is collected and its metadata checked. That's 3.7 s of the 5.6 s, split by object type on master.
    • Geometry for the 4,920 newer ways is needed to check whether each way really crosses the box. They are spread over the province, so their nodes touch nearly every node block.
    • The relation member lookup scans almost the whole box for 211 relations. relation_node_members narrows its ranges with the members' indexes, but a relation stores per-member indexes only when its own index is very large. Otherwise the relation's own extent is used, and 211 relations spread across the province cover nearly all of it. Narrowing this further would need per-member indexes for all relations, which is an on-disk format change.

    A related finding: filter order follows the query text. In this query, newer is written before the bbox, and newer already runs before the geometry is built. Written the other way round, way(43.3,-66.5,47.1,-59.6)(newer:"2026-11-08T00:00:00Z") takes 6.3 s instead of 1.4 s, because geometry is built for all 882,729 ways first. That's #40, with a fix that runs metadata-only filters first.

    Conclusion: without a format change, there's no simple fix for this query's re-reads. The node pass and the way geometry are needed, and the relation lookup is bounded by what relations store. Keeping this open for the record. The practical improvements are #40 (order), the metadata change #31 (−14% on this query) and a faster allocator (#35, −18%).


    Generated by Claude Code

  2. added
    query-perf
    on Nov 21, 2026
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

    query-perf

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions