Skip to content

Commit

Permalink
Add temporary indexes to speed up migration queries - refs CT#7909
Browse files Browse the repository at this point in the history
  • Loading branch information
ywarnier committed Oct 21, 2015
1 parent d03ed1b commit 2776c37
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions main/install/install.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2067,6 +2067,19 @@ function fixIds(EntityManager $em)
error_log('Update tools');
}

// Create temporary indexes to increase speed of the following operations
// Adding and removing indexes will usually take much less time than
// the execution without indexes of the queries in this function, particularly
// for large tables
$sql = "ALTER TABLE c_document ADD INDEX tmpidx_doc(c_id, id)";
$connection->executeQuery($sql);
$sql = "ALTER TABLE c_student_publication ADD INDEX tmpidx_stud (c_id, id)";
$connection->executeQuery($sql);
$sql = "ALTER TABLE c_quiz ADD INDEX tmpidx_quiz (c_id, id)";
$connection->executeQuery($sql);
$sql = "ALTER TABLE c_item_property ADD INDEX tmpidx_ip (to_group_id)";
$connection->executeQuery($sql);

$sql = "SELECT * FROM c_lp_item";
$result = $connection->fetchAll($sql);
foreach ($result as $item) {
Expand Down Expand Up @@ -2534,6 +2547,15 @@ function fixIds(EntityManager $em)
}
}
}
// Drop temporary indexes added to increase speed of this function's queries
$sql = "ALTER TABLE c_document DROP INDEX tmpidx_doc";
$connection->executeQuery($sql);
$sql = "ALTER TABLE c_student_publication DROP INDEX tmpidx_stud";
$connection->executeQuery($sql);
$sql = "ALTER TABLE c_quiz DROP INDEX tmpidx_quiz";
$connection->executeQuery($sql);
$sql = "ALTER TABLE c_item_property DROP INDEX tmpidx_ip";
$connection->executeQuery($sql);
}

/**
Expand Down

0 comments on commit 2776c37

Please sign in to comment.