From 79f3b3be24902fe5428131b61e7f81f39f108eb2 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 20 Nov 2026 23:48:33 +0000 Subject: [PATCH] around: let the tag index drive queries whose around area is large Around_Constraint chose prefer_ranges whenever the radius was under 2 km. The query statement then reads every object in around's index ranges and checks tag filters afterwards. A small radius around a large input set, such as long relations, still covers a large area, so a selective tag filter went unused. Like Bbox_Constraint, also look at the area: with more than 65536 node index tiles (about one square degree), return ids_useful so that the tag index selects candidates within the ranges. The filters are the same, so results are unchanged. Nova Scotia extract: rel(45.566265,-62.428420,45.586924,-62.388716)->.s0; node(around.s0:0)["footway"]; takes 2.24 s -> 0.08 s. The 9 relations in .s0 include a long trail and boundaries, so their extent covers much of the province. With radius 2000 the same query already took 0.42 s on master, because radius alone decided the strategy. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01736kJUqyDw9zM3Bkh2W2QT --- src/overpass_api/statements/around.cc | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/overpass_api/statements/around.cc b/src/overpass_api/statements/around.cc index b1e7c532c..063c06353 100644 --- a/src/overpass_api/statements/around.cc +++ b/src/overpass_api/statements/around.cc @@ -127,8 +127,7 @@ class Around_Constraint : public Query_Constraint public: Around_Constraint(Around_Statement& around_) : around(&around_), ranges_used(false) {} - Query_Filter_Strategy delivers_data(Resource_Manager& rman) - { return (around->get_radius() < 2000) ? prefer_ranges : ids_useful; } + Query_Filter_Strategy delivers_data(Resource_Manager& rman); bool get_ranges(Resource_Manager& rman, Ranges< Uint32_Index >& ranges); bool get_ranges(Resource_Manager& rman, Ranges< Uint31_Index >& ranges); @@ -143,6 +142,29 @@ class Around_Constraint : public Query_Constraint }; +/* Reading every object in the ranges and checking tags afterwards (prefer_ranges) only pays + off while the ranges are small. A small radius around a large input set, such as long + relations, can still cover a large area, so look at the area as well as the radius. Like + Bbox_Constraint, let the tag index select candidates (ids_useful) once the area exceeds + about one square degree: 65536 node index tiles of about 0.00275 by 0.0055 degrees. */ +Query_Filter_Strategy Around_Constraint::delivers_data(Resource_Manager& rman) +{ + if (around->get_radius() >= 2000) + return ids_useful; + + const Set* input = rman.get_set(around->get_source_name()); + Ranges< Uint32_Index > ranges = around->calc_ranges(input ? *input : Set(), rman); + uint64 tiles = 0; + for (auto it = ranges.begin(); it != ranges.end(); ++it) + { + tiles += uint64(it.upper_bound().val()) - it.lower_bound().val(); + if (tiles > 65536) + return ids_useful; + } + return prefer_ranges; +} + + bool Around_Constraint::get_ranges (Resource_Manager& rman, Ranges< Uint32_Index >& ranges) {