From 3a765079db598c61fa892fca334609ff01ecc240 Mon Sep 17 00:00:00 2001 From: Tigran Manasyan Date: Tue, 20 Feb 2024 23:05:30 +0800 Subject: [PATCH] [KYUUBI #6066] Fix PostgreSQL metastore migration script failure if indexes already exist MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # :mag: Description ## Issue References ๐Ÿ”— This pull request is a small fix for #5674 ## Describe Your Solution ๐Ÿ”ง PostgreSQL support as backend for metadata store was added in #6027. If we choose it and run schema init scripts several times, then the following errors will be logged: `Error executing sql: CREATE UNIQUE INDEX unique_identifier_index ON metadata(identifier), with params: . ERROR: relation "unique_identifier_index" already exists`. This PR adds lacking `IF NOT EXISTS` to db indexes creation ddls in the PostgreSQL metastore init script. ## Types of changes :bookmark: - [x] Bugfix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) ## Test Plan ๐Ÿงช #### Behavior Without This Pull Request :coffin: #### Behavior With This Pull Request :tada: #### Related Unit Tests --- # Checklist ๐Ÿ“ - [x] This patch was not authored or co-authored using [Generative Tooling](https://www.apache.org/legal/generative-tooling.html) Closes #6066 from tigrulya-exe/feature/5674-postgresql-metadata-backend. Closes #6066 bb6487c16 [Tigran Manasyan] Fix PostgreSQL metastore migration script failure if indexes already exist Authored-by: Tigran Manasyan Signed-off-by: Cheng Pan --- .../metadata-store-schema-1.9.0.postgresql.sql | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/kyuubi-server/src/main/resources/sql/postgresql/metadata-store-schema-1.9.0.postgresql.sql b/kyuubi-server/src/main/resources/sql/postgresql/metadata-store-schema-1.9.0.postgresql.sql index 4c7ab0dc9..76d0e65b9 100644 --- a/kyuubi-server/src/main/resources/sql/postgresql/metadata-store-schema-1.9.0.postgresql.sql +++ b/kyuubi-server/src/main/resources/sql/postgresql/metadata-store-schema-1.9.0.postgresql.sql @@ -52,8 +52,8 @@ COMMENT ON COLUMN metadata.end_time IS 'the metadata end time'; COMMENT ON COLUMN metadata.priority IS 'the application priority, high value means high priority'; COMMENT ON COLUMN metadata.peer_instance_closed IS 'closed by peer kyuubi instance'; -CREATE UNIQUE INDEX unique_identifier_index ON metadata(identifier); -CREATE INDEX user_name_index ON metadata(user_name); -CREATE INDEX engine_type_index ON metadata(engine_type); -CREATE INDEX create_time_index ON metadata(create_time); -CREATE INDEX priority_create_time_index ON metadata(priority DESC, create_time ASC); \ No newline at end of file +CREATE UNIQUE INDEX IF NOT EXISTS unique_identifier_index ON metadata(identifier); +CREATE INDEX IF NOT EXISTS user_name_index ON metadata(user_name); +CREATE INDEX IF NOT EXISTS engine_type_index ON metadata(engine_type); +CREATE INDEX IF NOT EXISTS create_time_index ON metadata(create_time); +CREATE INDEX IF NOT EXISTS priority_create_time_index ON metadata(priority DESC, create_time ASC); \ No newline at end of file