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 d129c406..9b729a61 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 @@ -285,20 +285,17 @@ static void AddIndexToCatalog(ClientContext &context, CreateRTreeIndexGlobalStat // Create the index entry in the catalog auto &schema = table.schema; - const auto index_entry = schema.CreateIndex(context, info, table).get(); - if (!index_entry) { - D_ASSERT(info.on_conflict == OnCreateConflict::IGNORE_ON_CONFLICT); - // index already exists, but error ignored because of IF NOT EXISTS - return; + + if (schema.GetEntry(schema.GetCatalogTransaction(context), CatalogType::INDEX_ENTRY, info.index_name)) { + if (info.on_conflict != OnCreateConflict::IGNORE_ON_CONFLICT) { + throw CatalogException("Index with name \"%s\" already exists", info.index_name); + } } - // Get the entry as a DuckIndexEntry + const auto index_entry = schema.CreateIndex(schema.GetCatalogTransaction(context), info, table).get(); + D_ASSERT(index_entry); auto &duck_index = index_entry->Cast(); duck_index.initial_index_size = gstate.rtree->Cast().GetInMemorySize(); - duck_index.info = make_uniq(storage.GetDataTableInfo(), duck_index.name); - for (auto &parsed_expr : info.parsed_expressions) { - duck_index.parsed_expressions.push_back(parsed_expr->Copy()); - } // Finally add it to storage storage.AddIndex(std::move(gstate.rtree)); diff --git a/test/sql/index/rtree_insert.test b/test/sql/index/rtree_insert.test index e13962a3..d99f9613 100644 --- a/test/sql/index/rtree_insert.test +++ b/test/sql/index/rtree_insert.test @@ -6,9 +6,6 @@ CREATE TABLE t1 (geom GEOMETRY); statement ok INSERT INTO t1 (geom) VALUES ('POINT(1 1)'); -statement ok -pragma threads=1; - statement ok CREATE TABLE points AS SELECT geom::GEOMETRY FROM st_generatepoints({min_x: 0, min_y: 0, max_x: 10000, max_y: 10000}::BOX_2D, 100_000, 1337) as pts(geom); diff --git a/test/sql/index/rtree_projection.test b/test/sql/index/rtree_projection.test new file mode 100644 index 00000000..b60c922a --- /dev/null +++ b/test/sql/index/rtree_projection.test @@ -0,0 +1,49 @@ +require spatial + +statement ok +CREATE TABLE t1 (id int, geom GEOMETRY); + +statement ok +CREATE OR REPLACE TABLE points AS SELECT row_number() over () as id, geom::GEOMETRY as geom +FROM st_generatepoints({min_x: 0, min_y: 0, max_x: 10000, max_y: 10000}::BOX_2D, 1000, 1337) as pts(geom); + +statement ok +CREATE INDEX my_idx ON points USING RTREE(geom); + + +# Test different projections +query II rowsort +SELECT * FROM points WHERE ST_Intersects(geom, ST_MakeEnvelope(0, 0, 500, 500)); +---- +351 POINT (359.812940005213 406.6655575297773) +472 POINT (169.11179292947054 129.24372218549252) +775 POINT (173.61568519845605 455.52933821454644) + +query II rowsort +SELECT geom, id FROM points WHERE ST_Intersects(geom, ST_MakeEnvelope(0, 0, 500, 500)); +---- +POINT (169.11179292947054 129.24372218549252) 472 +POINT (173.61568519845605 455.52933821454644) 775 +POINT (359.812940005213 406.6655575297773) 351 + +query I rowsort +SELECT id FROM points WHERE ST_Intersects(geom, ST_MakeEnvelope(0, 0, 500, 500)); +---- +351 +472 +775 + +query III rowsort +SELECT id, geom, ST_Intersects(geom, ST_MakeEnvelope(0, 0, 500, 500)) as contained FROM points WHERE ST_Intersects(geom, ST_MakeEnvelope(0, 0, 500, 500)); +---- +351 POINT (359.812940005213 406.6655575297773) true +472 POINT (169.11179292947054 129.24372218549252) true +775 POINT (173.61568519845605 455.52933821454644) true + +query I rowsort +SELECT ST_Intersects(geom, ST_MakeEnvelope(0, 0, 500, 500)) as contained FROM points WHERE ST_Intersects(geom, ST_MakeEnvelope(0, 0, 500, 500)); +---- +true +true +true +