Repository navigation
Description
around with relations in its input set reads every candidate in each relation's whole extent, even though only the relation's members contribute geometry.
What happens
Around_Statement::calc_ranges (statements/around.cc) builds the candidate index ranges from the input set's indexes. For a relation, that's the relation's own index. A relation spanning several tiles gets a coarse compound index covering its whole bounding area, so for a long route or a boundary, every object in a large part of the province becomes a candidate. Each candidate has its geometry loaded and tested.
around's geometry for a relation, though, is only that of its direct node and way members (calc_lat_lons). So ranges built from the members' own indexes would cover everything the exact test can match, and nothing more.
Measurements
On the Nova Scotia history database (current data only), with the all-changes branch (#12) plus the grid fixes from #36:
Input of way(around.s0:20)["material"!~"^conc"] |
Time | Result |
|---|---|---|
.s0 as below: 188 ways and 14 relations |
11.5 s | 12,809 |
The same geometry given as ways: (way.s0; way(r.s0);) |
3.3 s | 12,799 |
where .s0 is
wr(newer:"2016-12-19T18:03:25Z")(45.574002,-62.284014,45.619842,-62.234392)->.s0;
The 10 extra results in the first row come from the relations' node members, which the second row leaves out. In a profile of the first row, most of the time goes to loading candidates (collect_items_range, make_geometry, sorting node ids), not to the distance tests.
Relation to #9
#9 is about the planner: around with a small radius forced the "read everything in the ranges" strategy even when a selective tag filter would choose fewer candidates. #13 fixes that. This issue is about the ranges themselves: they are too large for relation inputs, which matters most when no selective tag filter is available.
Possible fix
In calc_ranges, replace each current relation's own index with the indexes of its node members and the parent ranges of its way members, then expand by the radius as before. That's about 15 lines, with no change to the format or the query API.
Generated by Claude Code
Activity