Commit 537ee5a1 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Add usr table indexes for faster searches



Search is much faster in Postgres with these indexes on the lowercase
profile fields.

In MySQL we can't create the indexes without changing the types of the
column from text to varchar.  An upgrade to do this would have to be
destructive, and would require admin notification.  It's not worth doing
that, because MySQL cannot create indexes on functions of columns,
and we could not create the lowercase indexes that would be useful for
user searches.

Change-Id: I9ffb6ce02a5f3e8fc2cf158424b37b754edd8d34
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent a8f76e09
......@@ -2320,5 +2320,21 @@ function xmldb_core_upgrade($oldversion=0) {
add_field($table, $field);
}
if ($oldversion < 2011052600) {
// Add more indexes to the usr table for user searches
if (is_postgres()) {
$table = new XMLDBTable('usr');
$index = new XMLDBIndex('usr_fir_ix');
if (!index_exists($table, $index)) {
execute_sql('CREATE INDEX {usr_fir_ix} ON {usr}(LOWER(firstname))');
execute_sql('CREATE INDEX {usr_las_ix} ON {usr}(LOWER(lastname))');
execute_sql('CREATE INDEX {usr_pre_ix} ON {usr}(LOWER(preferredname))');
execute_sql('CREATE INDEX {usr_stu_ix} ON {usr}(LOWER(studentid))');
execute_sql('CREATE INDEX {usr_ema_ix} ON {usr}(LOWER(email))');
}
}
}
return $status;
}
......@@ -587,6 +587,15 @@ function core_postinst() {
execute_sql('DROP INDEX {usr_use_uix}');
execute_sql('CREATE UNIQUE INDEX {usr_use_uix} ON {usr}(LOWER(username))');
// Add user search indexes
// Postgres only. We could create non-lowercased indexes in MySQL, but
// they would not be useful, and would require a change to varchar columns.
execute_sql('CREATE INDEX {usr_fir_ix} ON {usr}(LOWER(firstname))');
execute_sql('CREATE INDEX {usr_las_ix} ON {usr}(LOWER(lastname))');
execute_sql('CREATE INDEX {usr_pre_ix} ON {usr}(LOWER(preferredname))');
execute_sql('CREATE INDEX {usr_ema_ix} ON {usr}(LOWER(email))');
execute_sql('CREATE INDEX {usr_stu_ix} ON {usr}(LOWER(studentid))');
// Only one profile view per user
execute_sql("CREATE UNIQUE INDEX {view_own_type_uix} ON {view}(owner) WHERE type = 'profile'");
}
......
......@@ -28,7 +28,7 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2011052500;
$config->version = 2011052600;
$config->release = '1.5.0dev';
$config->minupgradefrom = 2008040200;
$config->minupgraderelease = '1.0.0 (release tag 1.0.0_RELEASE)';
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment