From 84dbf894ea42da63bbc075faa80fa77893dff3c2 Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Fri, 27 May 2022 01:14:18 +0530 Subject: [PATCH] Added index on SidebarCategories table (#20045) ```release-note NONE ``` Co-authored-by: Mattermod --- .../mysql/000087_sidebar_categories_index.down.sql | 14 ++++++++++++++ .../mysql/000087_sidebar_categories_index.up.sql | 14 ++++++++++++++ .../000087_sidebar_categories_index.down.sql | 1 + .../000087_sidebar_categories_index.up.sql | 1 + 4 files changed, 30 insertions(+) create mode 100644 db/migrations/mysql/000087_sidebar_categories_index.down.sql create mode 100644 db/migrations/mysql/000087_sidebar_categories_index.up.sql create mode 100644 db/migrations/postgres/000087_sidebar_categories_index.down.sql create mode 100644 db/migrations/postgres/000087_sidebar_categories_index.up.sql diff --git a/db/migrations/mysql/000087_sidebar_categories_index.down.sql b/db/migrations/mysql/000087_sidebar_categories_index.down.sql new file mode 100644 index 0000000000..4590499137 --- /dev/null +++ b/db/migrations/mysql/000087_sidebar_categories_index.down.sql @@ -0,0 +1,14 @@ +SET @preparedStatement = (SELECT IF( + ( + SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS + WHERE table_name = 'SidebarCategories' + AND table_schema = DATABASE() + AND index_name = 'idx_sidebarcategories_userid_teamid' + ) > 0, + 'DROP INDEX idx_sidebarcategories_userid_teamid on SidebarCategories;', + 'SELECT 1;' +)); + +PREPARE removeIndexIfExists FROM @preparedStatement; +EXECUTE removeIndexIfExists; +DEALLOCATE PREPARE removeIndexIfExists; diff --git a/db/migrations/mysql/000087_sidebar_categories_index.up.sql b/db/migrations/mysql/000087_sidebar_categories_index.up.sql new file mode 100644 index 0000000000..9f77256683 --- /dev/null +++ b/db/migrations/mysql/000087_sidebar_categories_index.up.sql @@ -0,0 +1,14 @@ +SET @preparedStatement = (SELECT IF( + ( + SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS + WHERE table_name = 'SidebarCategories' + AND table_schema = DATABASE() + AND index_name = 'idx_sidebarcategories_userid_teamid' + ) > 0, + 'SELECT 1;', + 'CREATE INDEX idx_sidebarcategories_userid_teamid on SidebarCategories(UserId, TeamId) LOCK=NONE;' +)); + +PREPARE createIndexIfNotExists FROM @preparedStatement; +EXECUTE createIndexIfNotExists; +DEALLOCATE PREPARE createIndexIfNotExists; diff --git a/db/migrations/postgres/000087_sidebar_categories_index.down.sql b/db/migrations/postgres/000087_sidebar_categories_index.down.sql new file mode 100644 index 0000000000..c1e4114d7c --- /dev/null +++ b/db/migrations/postgres/000087_sidebar_categories_index.down.sql @@ -0,0 +1 @@ +DROP INDEX IF exists idx_sidebarcategories_userid_teamid; \ No newline at end of file diff --git a/db/migrations/postgres/000087_sidebar_categories_index.up.sql b/db/migrations/postgres/000087_sidebar_categories_index.up.sql new file mode 100644 index 0000000000..42e40d8093 --- /dev/null +++ b/db/migrations/postgres/000087_sidebar_categories_index.up.sql @@ -0,0 +1 @@ +CREATE INDEX IF NOT EXISTS idx_sidebarcategories_userid_teamid on sidebarcategories (userid, teamid); \ No newline at end of file