Skip to content

recurse: handle wr(bn) in the query constraint - #193

Merged
cldellow merged 1 commit into
masterfrom
recurse-node-wr-ranges
Dec 5, 2026
Merged

cldellow merged 1 commit into
masterfrom
recurse-node-wr-ranges

Conversation

@cldellow

Copy link
Copy Markdown
Owner

Fixes #192.

Change

Recurse_Constraint (statements/recurse.cc) now handles RECURSE_NODE_WR, the type of wr(bn.…) in a query statement, like the standalone statement does: as RECURSE_NODE_WAY for ways and RECURSE_NODE_RELATION for relations.

  • get_way_ranges / get_relation_ranges: the parent indices of the input nodes, instead of global ranges.
  • get_data: collects the ways (with the position, as for bn) and the relations of the input nodes, including the role case for relations.
  • filter: keeps the ways and relations that have an input node, instead of dropping all ways and only the current relations.

With a role (wr(bn.s:"role")), filter still empties both ways and relations, as before and as the standalone statement does; that case is unchanged.

One file, 11 lines added, 8 removed. No change to the database format or the query API.

Impact

US northeast full-history extract (Geofabrik), current-date queries unless stated, warm cache, 4-core VM. Input node(42.3601,-71.0590,42.3620,-71.0570)->.s; unless stated:

Statement upstream/master This PR
wr(bn.s)["highway"]; out count; "Filters too weak", 9.07 s, 420 MB 99 ways, 0.02 s, 10 MB
wr(bn.s)["type"="route"]; out count; 0, 0.16 s 11 relations, 0.01 s
wr(bn.s)[~"^tig"~"A"]; out count; "Filters too weak", 9.37 s 0, 0.01 s
with .s = 5 ways (way["tiger:zip_left_2"="04344"]): wr(bn.s)["building"="yes"]; out count; "Filters too weak", 9.39 s, 420 MB 0, 0.02 s
[date:"2020-01-01T00:00:00Z"]: wr(bn.s)["type"="route"]; out ids; 15,010 elements 1 relation

Benchmark queries: none uses wr(bn); the timing workflow runs them on this PR.

Testing

  • Against union semantics: for 5 input sets (all nodes of a small block, traffic signals, a node box, 5 ways, an empty set) × 6 filters (none, ["highway"], ["building"="yes"], ["type"="route"], ["name"~"^Main",i], ["highway"]["highway"!="footway"]) × 3 dates (current, 2020-01-01, 2014-06-01), wr(bn.s)[filter] with this PR gives the same output as (way(bn.s)[filter]; rel(bn.s)[filter];) on upstream/master: 90 of 90.
  • Unchanged cases: wr(bn.s:"stop") and wr(bn.s:"") with the same inputs, filters and dates: identical to upstream/master, 180 of 180.
  • CI: fuzz, history and props run on this PR.

Expected CI differences

Queries with wr(bn.…) plus a tag filter will differ from upstream/master, because upstream/master returns nothing, "Filters too weak", or extra relations for them. In the fuzz workflows' queries this shows up as "Filters too weak" turning into results. Each such difference should match the union form above.


Generated by Claude Code

@cldellow cldellow added bug Fixes wrong results (in addition to the kind label) query-perf Query performance change; collected on all-changes labels Nov 24, 2026 — with Claude

Copy link
Copy Markdown
Owner Author

CI on this PR, against upstream/master c3a20c0. The differences are the ones this PR is meant to cause.

Workflow Run Result
fuzz 45423324989 5,950 same, 36 different, 14 skipped (timeouts on both builds)
history 45423325221 1,989 same, 10 different, 1 skipped (timeout on both builds)

fuzz: all 36 differing queries contain wr(bn.…) with a tag filter (checked in all 21 fuzz-failures artifacts):

  • 35: upstream/master fails the statement with "Filters too weak" (its filters are only negated or key-regex filters, so without the constraint's ranges there's nothing to narrow by); with this PR it runs. The printed output is identical in all 35, mostly because the statement's result is empty or not printed; the difference is the error.
  • 1: wr(bn.s0)["type"="boundary"] over the nodes and ways of a box returns nothing on upstream/master and 3 boundary relations with this PR, the bug in wr(bn.s) with a tag filter returns nothing at the current date and unrelated relations at past dates #192.

history: the 10 differing queries are in encrypted artifacts and weren't inspected. They are expected to be the same pattern, including the past-date case in #192 where upstream/master returns relation versions unrelated to the input.


Generated by Claude Code

@cldellow

Copy link
Copy Markdown
Owner Author

Colin thoughts: checks fail, because they correctly identify that this is a change in behaviour. When I dig into the artifacts, the a.out and b.out file contents seem to be the same, which is suspicious. Maybe a bug in the fuzz artifact outputter, will dig into it.

Separately, this class of bug could have been caught by our property-based tester (it was caught by Claude when investigating a slow query), will look at extending it.

@cldellow

Copy link
Copy Markdown
Owner Author

Colin thoughts: #201 fixes the fuzz artifact issue, it wasn't including the stderr output.

@cldellow

Copy link
Copy Markdown
Owner Author

Colin thoughts: #202 fixes the proeprty based tester to now detect this class of error.

cldellow pushed a commit that referenced this pull request Nov 26, 2026
…ne's way + relation answer

The baseline (upstream master) gets wr(bn.s) with filters wrong (issue #192): it returns
nothing at the current date, unrelated relations at past dates, or fails with "Filters too
weak". #193 fixes it on all-changes, so every such query showed up as a difference.

wr_union.py rewrites each top-level wr...(bn...) statement as its way and relation halves,
both reading the same _, which the baseline answers correctly. A difference is accepted only
if the candidate's output equals the baseline's for the rewritten query, so a regression in
the candidate's wr(bn) still fails. fuzz.py reports such queries as verdict expected-wr-bn;
props.py counts them as fixed. Statements inside unions, differences or blocks are not
rewritten, and neither is any query that has one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01736kJTiuJPoCWZs7RtFYjm
@cldellow
cldellow force-pushed the recurse-node-wr-ranges branch 2 times, most recently from e4fb860 to 3ee5733 Compare November 30, 2026 13:58
@cldellow

Copy link
Copy Markdown
Owner Author

Offered upstream in fossgis#21

…ters

In a query statement, wr(bn.s) is a Recurse_Constraint of type
RECURSE_NODE_WR, which none of the constraint's methods handled:
get_way_ranges and get_relation_ranges returned global ranges, get_data
collected nothing, and filter dropped all ways and kept attic relations
unfiltered. So wr(bn.s) with a tag filter fell back to the tag filter
over the whole database: it returned nothing or failed with "Filters too
weak" at the current date, and returned unrelated relations at a past
date.

Handle RECURSE_NODE_WR in these methods as RECURSE_NODE_WAY for ways and
RECURSE_NODE_RELATION for relations, as the standalone wr(bn.s)
statement does.

The regression tests regression_wr_bn_tag_filter and
regression_wr_bn_tag_filter_date cover the current and past-date cases.

On a Nova Scotia extract:

  [out:csv(::count)]; node(44.6470,-63.5760,44.6490,-63.5730)->.s;
  wr(bn.s)["highway"]; out count;

returned 0 ways in 0.53 s, and now returns 141 in 0.01 s, the same as
(way(bn.s)["highway"]; rel(bn.s)["highway"];).

Co-Authored-By: Colin Dellow <cldellow@gmail.com>
@cldellow
cldellow force-pushed the recurse-node-wr-ranges branch from 3ee5733 to 3bfdade Compare December 1, 2026 01:22
@cldellow
cldellow merged commit 02ae8f7 into master Dec 5, 2026
75 of 89 checks passed

cldellow commented Dec 5, 2026

Copy link
Copy Markdown
Owner Author

Merged upstream as fossgis@02ae8f7. The fork's master now includes it (8969948), and all-changes is being rebased onto it. Closing.


Generated by Claude Code

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

Labels

bug Fixes wrong results (in addition to the kind label) query-perf Query performance change; collected on all-changes upstreamed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wr(bn.s) with a tag filter returns nothing at the current date and unrelated relations at past dates

2 participants