Skip to content

Commit 25838f3

Browse files
committed
fix reused rtree nodes not being zeroed
1 parent 72cc0b6 commit 25838f3

File tree

3 files changed

+31
-24
lines changed

3 files changed

+31
-24
lines changed

src/spatial/index/rtree/rtree.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ RTreePointer RTree::MakePage(RTreeNodeType type) const {
3131
auto &alloc = type == RTreeNodeType::LEAF_PAGE ? *leaf_allocator : *node_allocator;
3232
pointer = alloc.New();
3333
pointer.SetMetadata(static_cast<uint8_t>(type));
34+
35+
// zero-initialize the node count
36+
auto &node = RefMutable(pointer);
37+
node.Clear();
38+
3439
return pointer;
3540
}
3641

@@ -655,4 +660,4 @@ void RTree::Print() const {
655660
Printer::Print(ToString());
656661
}
657662

658-
} // namespace duckdb
663+
} // namespace duckdb

src/spatial/modules/main/spatial_functions_scalar.cpp

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3003,7 +3003,6 @@ struct ST_Dump {
30033003
}
30043004
};
30053005

3006-
30073006
//======================================================================================================================
30083007
// ST_Expand
30093008
//======================================================================================================================
@@ -3016,28 +3015,29 @@ struct ST_Expand {
30163015
static void Execute(DataChunk &args, ExpressionState &state, Vector &result) {
30173016
auto &lstate = LocalState::ResetAndGet(state);
30183017

3019-
BinaryExecutor::Execute<string_t, double, string_t>(args.data[0], args.data[1], result, args.size(), [&](const string_t &blob, double distance) {
3020-
sgl::geometry geom;
3021-
lstate.Deserialize(blob, geom);
3022-
auto bbox = sgl::extent_xy::smallest();
3023-
3024-
if (sgl::ops::get_total_extent_xy(geom, bbox) == 0) {
3025-
const sgl::geometry empty(sgl::geometry_type::GEOMETRY_COLLECTION, false, false);
3026-
return lstate.Serialize(result, empty);
3027-
} else {
3028-
sgl::geometry expanded(sgl::geometry_type::POLYGON, false, false);
3029-
const auto min_x = bbox.min.x - distance;
3030-
const auto min_y = bbox.min.y - distance;
3031-
const auto max_x = bbox.max.x + distance;
3032-
const auto max_y = bbox.max.y + distance;
3033-
const double buffer[10] = {min_x, min_y, min_x, max_y, max_x, max_y, max_x, min_y, min_x, min_y};
3018+
BinaryExecutor::Execute<string_t, double, string_t>(
3019+
args.data[0], args.data[1], result, args.size(), [&](const string_t &blob, double distance) {
3020+
sgl::geometry geom;
3021+
lstate.Deserialize(blob, geom);
3022+
auto bbox = sgl::extent_xy::smallest();
30343023

3035-
sgl::geometry ring(sgl::geometry_type::LINESTRING, false, false);
3036-
ring.set_vertex_array(buffer, 5);
3037-
expanded.append_part(&ring);
3038-
return lstate.Serialize(result, expanded);
3039-
}
3040-
});
3024+
if (sgl::ops::get_total_extent_xy(geom, bbox) == 0) {
3025+
const sgl::geometry empty(sgl::geometry_type::GEOMETRY_COLLECTION, false, false);
3026+
return lstate.Serialize(result, empty);
3027+
} else {
3028+
sgl::geometry expanded(sgl::geometry_type::POLYGON, false, false);
3029+
const auto min_x = bbox.min.x - distance;
3030+
const auto min_y = bbox.min.y - distance;
3031+
const auto max_x = bbox.max.x + distance;
3032+
const auto max_y = bbox.max.y + distance;
3033+
const double buffer[10] = {min_x, min_y, min_x, max_y, max_x, max_y, max_x, min_y, min_x, min_y};
3034+
3035+
sgl::geometry ring(sgl::geometry_type::LINESTRING, false, false);
3036+
ring.set_vertex_array(buffer, 5);
3037+
expanded.append_part(&ring);
3038+
return lstate.Serialize(result, expanded);
3039+
}
3040+
});
30413041
}
30423042

30433043
//------------------------------------------------------------------------------------------------------------------
@@ -3079,7 +3079,6 @@ struct ST_Expand {
30793079
}
30803080
};
30813081

3082-
30833082
//======================================================================================================================
30843083
// ST_Extent
30853084
//======================================================================================================================

test/sql/geometry/st_expand.test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# name: test/sql/geometry/st_expand.test
2+
# group: [geometry]
3+
14
require spatial
25

36
query I

0 commit comments

Comments
 (0)