Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RTREE: dont add columns again #387

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<DuckIndexEntry>();
duck_index.initial_index_size = gstate.rtree->Cast<BoundIndex>().GetInMemorySize();
duck_index.info = make_uniq<IndexDataTableInfo>(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));
Expand Down
3 changes: 0 additions & 3 deletions test/sql/index/rtree_insert.test
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
49 changes: 49 additions & 0 deletions test/sql/index/rtree_projection.test
Original file line number Diff line number Diff line change
@@ -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

Loading