From f9a2119a49c2df57fbbf8c1f3d02817a130dd099 Mon Sep 17 00:00:00 2001 From: Max Gabrielsson Date: Mon, 30 Sep 2024 13:42:49 +0200 Subject: [PATCH 1/2] handle ignore on conflict for rtree index --- .../rtree/rtree_index_create_physical.cpp | 3 +++ test/sql/index/rtree_conflict.test | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 test/sql/index/rtree_conflict.test diff --git a/spatial/src/spatial/core/index/rtree/rtree_index_create_physical.cpp b/spatial/src/spatial/core/index/rtree/rtree_index_create_physical.cpp index 9b729a61..ed2455fa 100644 --- a/spatial/src/spatial/core/index/rtree/rtree_index_create_physical.cpp +++ b/spatial/src/spatial/core/index/rtree/rtree_index_create_physical.cpp @@ -290,6 +290,9 @@ static void AddIndexToCatalog(ClientContext &context, CreateRTreeIndexGlobalStat if (info.on_conflict != OnCreateConflict::IGNORE_ON_CONFLICT) { throw CatalogException("Index with name \"%s\" already exists", info.index_name); } + // IF NOT EXISTS on existing index. We are done. + // TODO: Early out before this. + return; } const auto index_entry = schema.CreateIndex(schema.GetCatalogTransaction(context), info, table).get(); diff --git a/test/sql/index/rtree_conflict.test b/test/sql/index/rtree_conflict.test new file mode 100644 index 00000000..232c2d2d --- /dev/null +++ b/test/sql/index/rtree_conflict.test @@ -0,0 +1,18 @@ +require spatial + +statement ok +create table nodes (name varchar, pt geometry); + +statement ok +create index if not exists nodes_pt_idx on nodes using rtree(pt); + +statement ok +create index if not exists nodes_pt_idx on nodes using rtree(pt); + +statement error +create index nodes_pt_idx on nodes using rtree(pt); +---- +Catalog Error: Index with name "nodes_pt_idx" already exists + +statement ok +create index if not exists nodes_pt_idx on nodes using rtree(pt); From f931ea18f0d78044f3eed2de1969c5718879817f Mon Sep 17 00:00:00 2001 From: Max Gabrielsson Date: Mon, 30 Sep 2024 15:20:27 +0200 Subject: [PATCH 2/2] dont destroy evicted blocks --- spatial/include/spatial/core/util/managed_collection.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spatial/include/spatial/core/util/managed_collection.hpp b/spatial/include/spatial/core/util/managed_collection.hpp index dbf21f12..472e6e24 100644 --- a/spatial/include/spatial/core/util/managed_collection.hpp +++ b/spatial/include/spatial/core/util/managed_collection.hpp @@ -95,7 +95,7 @@ void ManagedCollection::InitializeAppend(ManagedCollectionAppendState &state, state.block = &blocks.back(); state.block->item_count = 0; state.block->item_capacity = block_capacity; - state.handle = manager.Allocate(MemoryTag::EXTENSION, block_size, true); + state.handle = manager.Allocate(MemoryTag::EXTENSION, block_size, false); state.block->handle = state.handle.GetBlockHandle(); } } @@ -109,7 +109,7 @@ void ManagedCollection::Append(ManagedCollectionAppendState &state, const T * state.block = &blocks.back(); state.block->item_count = 0; state.block->item_capacity = block_capacity; - state.handle = manager.Allocate(MemoryTag::EXTENSION, block_size, true); + state.handle = manager.Allocate(MemoryTag::EXTENSION, block_size, false); state.block->handle = state.handle.GetBlockHandle(); }