mirror of
https://github.com/moodle/moodle.git
synced 2025-08-10 19:36:41 +02:00
MDL-42882 upgrade: improved SQL query
Kudos to Tim Hunt who came up with this, on mysql with 4 milion records (and a fast SSD) the performance difference is: Original: 36.83 sec New query: 8.63 sec
This commit is contained in:
parent
5f38edeefd
commit
b7f4097043
1 changed files with 7 additions and 10 deletions
|
@ -2096,16 +2096,13 @@ function upgrade_fix_missing_root_folders() {
|
||||||
global $DB, $USER;
|
global $DB, $USER;
|
||||||
|
|
||||||
$transaction = $DB->start_delegated_transaction();
|
$transaction = $DB->start_delegated_transaction();
|
||||||
$sql = "SELECT distinct f1.contextid, f1.component, f1.filearea, f1.itemid
|
|
||||||
FROM {files} f1 left JOIN {files} f2
|
$sql = "SELECT contextid, component, filearea, itemid
|
||||||
ON f1.contextid = f2.contextid
|
FROM {files}
|
||||||
AND f1.component = f2.component
|
WHERE (component <> 'user' OR filearea <> 'draft')
|
||||||
AND f1.filearea = f2.filearea
|
GROUP BY contextid, component, filearea, itemid
|
||||||
AND f1.itemid = f2.itemid
|
HAVING MAX(CASE WHEN filename = '.' AND filepath = '/' THEN 1 ELSE 0 END) = 0";
|
||||||
AND f2.filename = '.'
|
|
||||||
AND f2.filepath = '/'
|
|
||||||
WHERE (f1.component <> 'user' or f1.filearea <> 'draft')
|
|
||||||
and f2.id is null";
|
|
||||||
$rs = $DB->get_recordset_sql($sql);
|
$rs = $DB->get_recordset_sql($sql);
|
||||||
$defaults = array('filepath' => '/',
|
$defaults = array('filepath' => '/',
|
||||||
'filename' => '.',
|
'filename' => '.',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue