From 27c4ebdaceb9c5c9b84cb85294912edb47bd04c7 Mon Sep 17 00:00:00 2001 From: Philipp Memmel Date: Wed, 12 Mar 2025 14:59:06 +0100 Subject: [PATCH] MDL-85034 core_course: Add index to course_sections for mod_subsection This is a backport of MDL-84844. --- lib/db/install.xml | 3 ++- lib/db/upgrade.php | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/db/install.xml b/lib/db/install.xml index b7bd829f0ac..7781ac5f446 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -1,5 +1,5 @@ - @@ -395,6 +395,7 @@ + diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index c96e5731eed..6a888d4b53d 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -1489,5 +1489,17 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2024100702.03); } + if ($oldversion < 2024100704.05) { + // Add index for querying delegated sections. + $table = new xmldb_table('course_sections'); + $index = new xmldb_index('component_itemid', XMLDB_INDEX_NOTUNIQUE, ['component', 'itemid']); + + if (!$dbman->index_exists($table, $index)) { + $dbman->add_index($table, $index); + } + // Main savepoint reached. + upgrade_main_savepoint(true, 2024100704.05); + } + return true; }