From e271e28e7831d40fa3d4a90f196ec0987c91f792 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mudr=C3=A1k?= Date: Fri, 8 May 2020 14:14:07 +0200 Subject: [PATCH] MDL-68647 forum: Add index over posts privatereplyto field This is to further improve the performance of searching of posts related to the given user. Once both userid and privatereplyto are indexed, the query planner can use the merged index to search for posts records. --- mod/forum/db/install.xml | 3 ++- mod/forum/db/upgrade.php | 12 ++++++++++++ mod/forum/version.php | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/mod/forum/db/install.xml b/mod/forum/db/install.xml index ef7545dce73..bbda97aba99 100644 --- a/mod/forum/db/install.xml +++ b/mod/forum/db/install.xml @@ -1,5 +1,5 @@ - @@ -99,6 +99,7 @@ + diff --git a/mod/forum/db/upgrade.php b/mod/forum/db/upgrade.php index 1b140f49472..c367bf5ffac 100644 --- a/mod/forum/db/upgrade.php +++ b/mod/forum/db/upgrade.php @@ -294,5 +294,17 @@ function xmldb_forum_upgrade($oldversion) { upgrade_mod_savepoint(true, 2019111801, 'forum'); } + if ($oldversion < 2019111802) { + // Add index privatereplyto (not unique) to the forum_posts table. + $table = new xmldb_table('forum_posts'); + $index = new xmldb_index('privatereplyto', XMLDB_INDEX_NOTUNIQUE, ['privatereplyto']); + + if (!$dbman->index_exists($table, $index)) { + $dbman->add_index($table, $index); + } + + upgrade_mod_savepoint(true, 2019111802, 'forum'); + } + return true; } diff --git a/mod/forum/version.php b/mod/forum/version.php index 7d1f874ef9e..2b4d2eeaef5 100644 --- a/mod/forum/version.php +++ b/mod/forum/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2019111801; // The current module version (Date: YYYYMMDDXX) +$plugin->version = 2019111802; // The current module version (Date: YYYYMMDDXX) $plugin->requires = 2019111200; // Requires this Moodle version $plugin->component = 'mod_forum'; // Full name of the plugin (used for diagnostics)