From 25d5a9cea25d8177b32aa362bee7a7e67991f5d9 Mon Sep 17 00:00:00 2001 From: Rohit Panchal Date: Fri, 13 Dec 2024 00:59:24 +0530 Subject: [PATCH] MDL-83991 tag: Optimized tag sql query --- public/tag/classes/tag.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/public/tag/classes/tag.php b/public/tag/classes/tag.php index c1d56bfc41e..bda28e13767 100644 --- a/public/tag/classes/tag.php +++ b/public/tag/classes/tag.php @@ -1763,16 +1763,15 @@ class core_tag_tag { list($contextsql, $contextsqlparams) = $DB->get_in_or_equal($contextids); $params = array_merge($params, $contextsqlparams); - $subsql = "SELECT DISTINCT t.id - FROM {tag} t - JOIN {tag_instance} ti ON t.id = ti.tagid - WHERE component = ? - AND itemtype = ? - AND contextid {$contextsql}"; + $subsql = "SELECT DISTINCT ti.tagid + FROM {tag_instance} ti + WHERE ti.component = ? + AND ti.itemtype = ? + AND ti.contextid {$contextsql}"; $sql = "SELECT tt.* - FROM ($subsql) tv - JOIN {tag} tt ON tt.id = tv.id"; + FROM ($subsql) tv + JOIN {tag} tt ON tt.id = tv.tagid"; return array_map(function($record) { return new core_tag_tag($record);