From 6328005ace91c104e3b850b0464d23d541565aca Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Sun, 31 Dec 2023 00:23:29 +0900 Subject: [PATCH] Fix #2244 unnecessary composite index on tags table @Elkha --- modules/tag/schemas/tags.xml | 2 +- modules/tag/tag.class.php | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/modules/tag/schemas/tags.xml b/modules/tag/schemas/tags.xml index 452e567eb..2064202b6 100644 --- a/modules/tag/schemas/tags.xml +++ b/modules/tag/schemas/tags.xml @@ -2,6 +2,6 @@ - + diff --git a/modules/tag/tag.class.php b/modules/tag/tag.class.php index 4cb196df8..6e44ad449 100644 --- a/modules/tag/tag.class.php +++ b/modules/tag/tag.class.php @@ -12,8 +12,7 @@ class Tag extends ModuleObject */ public function moduleInstall() { - $oDB = DB::getInstance(); - $oDB->addIndex('tags', 'idx_tag', array('document_srl', 'tag')); + } /** @@ -21,9 +20,10 @@ class Tag extends ModuleObject */ public function checkUpdate() { - // tag in the index column of the table tag + // Convert unnecessary composite index into a single-column index. $oDB = DB::getInstance(); - if (!$oDB->isIndexExists('tags', 'idx_tag')) + $index = $oDB->getIndexInfo('tags', 'idx_tag'); + if (!$index || count($index->columns) > 1) { return true; } @@ -35,11 +35,16 @@ class Tag extends ModuleObject */ public function moduleUpdate() { - // tag in the index column of the table tag + // Convert unnecessary composite index into a single-column index. $oDB = DB::getInstance(); - if (!$oDB->isIndexExists('tags', 'idx_tag')) + $index = $oDB->getIndexInfo('tags', 'idx_tag'); + if (!$index || count($index->columns) > 1) { - $oDB->addIndex('tags', 'idx_tag', array('document_srl', 'tag')); + if ($index) + { + $oDB->dropIndex('tags', 'idx_tag'); + } + $oDB->addIndex('tags', 'idx_tag', ['tag']); } } }