diff --git a/kyuubi-server/src/main/resources/sql/derby/005-KYUUBI-5327.derby.sql b/kyuubi-server/src/main/resources/sql/derby/005-KYUUBI-5327.derby.sql new file mode 100644 index 00000000000..32c44d0fb64 --- /dev/null +++ b/kyuubi-server/src/main/resources/sql/derby/005-KYUUBI-5327.derby.sql @@ -0,0 +1,3 @@ +ALTER TABLE metadata ADD COLUMN priority int NOT NULL DEFAULT 10; + +CREATE INDEX metadata_priority_create_time_index ON metadata(priority, create_time); diff --git a/kyuubi-server/src/main/resources/sql/derby/metadata-store-schema-1.8.0.derby.sql b/kyuubi-server/src/main/resources/sql/derby/metadata-store-schema-1.8.0.derby.sql index 8d333bda2bd..139f70d3b8b 100644 --- a/kyuubi-server/src/main/resources/sql/derby/metadata-store-schema-1.8.0.derby.sql +++ b/kyuubi-server/src/main/resources/sql/derby/metadata-store-schema-1.8.0.derby.sql @@ -26,6 +26,7 @@ CREATE TABLE metadata( engine_state varchar(32), -- the engine application state engine_error clob, -- the engine application diagnose end_time bigint, -- the metadata end time + priority int NOT NULL DEFAULT 10, -- the application priority, high value means high priority peer_instance_closed boolean default FALSE -- closed by peer kyuubi instance ); @@ -36,3 +37,5 @@ CREATE INDEX metadata_user_name_index ON metadata(user_name); CREATE INDEX metadata_engine_type_index ON metadata(engine_type); CREATE INDEX metadata_create_time_index ON metadata(create_time); + +CREATE INDEX metadata_priority_create_time_index ON metadata(priority, create_time); diff --git a/kyuubi-server/src/main/resources/sql/mysql/005-KYUUBI-5327.mysql.sql b/kyuubi-server/src/main/resources/sql/mysql/005-KYUUBI-5327.mysql.sql new file mode 100644 index 00000000000..0637e053d8d --- /dev/null +++ b/kyuubi-server/src/main/resources/sql/mysql/005-KYUUBI-5327.mysql.sql @@ -0,0 +1,13 @@ +SELECT '< KYUUBI-5327: Introduce priority in metadata' AS ' '; + +ALTER TABLE metadata ADD COLUMN priority int NOT NULL DEFAULT 10 COMMENT 'the application priority, high value means high priority'; + +-- In MySQL 5.7, A key_part specification can end with ASC or DESC. +-- These keywords are permitted for future extensions for specifying ascending or descending index value storage. +-- Currently, they are parsed but ignored; index values are always stored in ascending order. +-- In MySQL 8 this can take effect and this index will be hit if query order by priority DESC, create_time ASC. +-- See more detail in: +-- https://dev.mysql.com/doc/refman/8.0/en/index-hints.html +-- https://dev.mysql.com/doc/refman/8.0/en/create-index.html +-- https://dev.mysql.com/doc/refman/5.7/en/create-index.html +ALTER TABLE metadata ADD INDEX priority_create_time_index(priority DESC, create_time ASC); diff --git a/kyuubi-server/src/main/resources/sql/mysql/metadata-store-schema-1.8.0.mysql.sql b/kyuubi-server/src/main/resources/sql/mysql/metadata-store-schema-1.8.0.mysql.sql index 77df8fa0562..fb2019848d7 100644 --- a/kyuubi-server/src/main/resources/sql/mysql/metadata-store-schema-1.8.0.mysql.sql +++ b/kyuubi-server/src/main/resources/sql/mysql/metadata-store-schema-1.8.0.mysql.sql @@ -24,9 +24,12 @@ CREATE TABLE IF NOT EXISTS metadata( engine_state varchar(32) COMMENT 'the engine application state', engine_error mediumtext COMMENT 'the engine application diagnose', end_time bigint COMMENT 'the metadata end time', + priority int NOT NULL DEFAULT 10 COMMENT 'the application priority, high value means high priority', peer_instance_closed boolean default '0' COMMENT 'closed by peer kyuubi instance', UNIQUE INDEX unique_identifier_index(identifier), INDEX user_name_index(user_name), INDEX engine_type_index(engine_type), - INDEX create_time_index(create_time) + INDEX create_time_index(create_time), + -- See more detail about this index in ./005-KYUUBI-5327.mysql.sql + INDEX priority_create_time_index(priority DESC, create_time ASC) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; diff --git a/kyuubi-server/src/main/resources/sql/mysql/upgrade-1.7.0-to-1.8.0.mysql.sql b/kyuubi-server/src/main/resources/sql/mysql/upgrade-1.7.0-to-1.8.0.mysql.sql index 473997448ba..0dd3abfda55 100644 --- a/kyuubi-server/src/main/resources/sql/mysql/upgrade-1.7.0-to-1.8.0.mysql.sql +++ b/kyuubi-server/src/main/resources/sql/mysql/upgrade-1.7.0-to-1.8.0.mysql.sql @@ -1,4 +1,5 @@ SELECT '< Upgrading MetaStore schema from 1.7.0 to 1.8.0 >' AS ' '; SOURCE 003-KYUUBI-5078.mysql.sql; SOURCE 004-KYUUBI-5131.mysql.sql; +SOURCE 005-KYUUBI-5327.mysql.sql; SELECT '< Finished upgrading MetaStore schema from 1.7.0 to 1.8.0 >' AS ' '; diff --git a/kyuubi-server/src/main/resources/sql/sqlite/metadata-store-schema-1.8.0.sqlite.sql b/kyuubi-server/src/main/resources/sql/sqlite/metadata-store-schema-1.8.0.sqlite.sql index 656de6e5d62..aa50267eba0 100644 --- a/kyuubi-server/src/main/resources/sql/sqlite/metadata-store-schema-1.8.0.sqlite.sql +++ b/kyuubi-server/src/main/resources/sql/sqlite/metadata-store-schema-1.8.0.sqlite.sql @@ -24,6 +24,7 @@ CREATE TABLE IF NOT EXISTS metadata( engine_state varchar(32), -- the engine application state engine_error mediumtext, -- the engine application diagnose end_time bigint, -- the metadata end time + priority INTEGER NOT NULL DEFAULT 10, -- the application priority, high value means high priority peer_instance_closed boolean default '0' -- closed by peer kyuubi instance ); @@ -34,3 +35,5 @@ CREATE INDEX IF NOT EXISTS metadata_user_name_index ON metadata(user_name); CREATE INDEX IF NOT EXISTS metadata_engine_type_index ON metadata(engine_type); CREATE INDEX IF NOT EXISTS metadata_create_time_index ON metadata(create_time); + +CREATE INDEX IF NOT EXISTS metadata_priority_create_time_index ON metadata(priority, create_time);