From c9dfb6d41e4fcca02195a590f1ed70c9a1b991a3 Mon Sep 17 00:00:00 2001 From: Eric Satterwhite Date: Thu, 19 Sep 2024 07:44:55 -0500 Subject: [PATCH] fix(metastore): add index to support index name wildcard expansion (#5438) The sql that is generated to expand an index name (index_id) into all of the matching index names uses the LIKE clause to do partial text matches. However, the only index on the index_id column utilizes the default btree configuration which can only do exact value comparisons. In environments with a large search volume over many thousands of indexes, this can be a bottle neck as the query will always do an full table scan. This drops and recreates the unique index on index_id to include the `varchar_pattern_ops` which allows for wildcard matching on a varchar column using the LIKE operator Fixes: #5437 --- .../postgresql/23_change-indexes-unique-index.down.sql | 2 ++ .../postgresql/23_change-indexes-unique-index.up.sql | 4 ++++ 2 files changed, 6 insertions(+) create mode 100644 quickwit/quickwit-metastore/migrations/postgresql/23_change-indexes-unique-index.down.sql create mode 100644 quickwit/quickwit-metastore/migrations/postgresql/23_change-indexes-unique-index.up.sql diff --git a/quickwit/quickwit-metastore/migrations/postgresql/23_change-indexes-unique-index.down.sql b/quickwit/quickwit-metastore/migrations/postgresql/23_change-indexes-unique-index.down.sql new file mode 100644 index 00000000000..dca2374f51c --- /dev/null +++ b/quickwit/quickwit-metastore/migrations/postgresql/23_change-indexes-unique-index.down.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS indexes_index_id_unique; +ALTER TABLE indexes ADD CONSTRAINT indexes_index_id_unique UNIQUE (index_id); diff --git a/quickwit/quickwit-metastore/migrations/postgresql/23_change-indexes-unique-index.up.sql b/quickwit/quickwit-metastore/migrations/postgresql/23_change-indexes-unique-index.up.sql new file mode 100644 index 00000000000..00abcd17db5 --- /dev/null +++ b/quickwit/quickwit-metastore/migrations/postgresql/23_change-indexes-unique-index.up.sql @@ -0,0 +1,4 @@ +ALTER TABLE indexes DROP CONSTRAINT IF EXISTS indexes_index_id_unique; + +CREATE UNIQUE INDEX IF NOT EXISTS indexes_index_id_unique + ON indexes USING btree ("index_id" varchar_pattern_ops);