added an index on the groupings table for the userId column

This commit is contained in:
Doug Bell 2007-05-29 17:06:35 +00:00
parent 1bdbb186aa
commit 3257456df7
2 changed files with 29 additions and 0 deletions

View file

@ -13,6 +13,8 @@
LIMIT clauses.
- add: SyndicatedContent wobject now has more ways of representing the long
description from the RSS feed.
- Added an index on the userId column of the groupings table to speed up
queries for groupIds by userId (instead of the usual userIds by groupId)

View file

@ -21,6 +21,7 @@ my $quiet; # this line required
my $session = start(); # this line required
# upgrade functions go here
addGroupingsIndexOnUserId($session);
fixProfileDataWithoutFields($session);
buildNewUserProfileTable($session);
addAttachmentsToEvents($session);
@ -37,6 +38,32 @@ finish($session); # this line required
#----------------------------------------------------------------------------
sub addGroupingsIndexOnUserId {
my $session = shift;
my $db = $session->db;
print qq{\tAdding index on `userId` column in `groupings` table for performance... } unless $quiet;
# See if we even NEED to add this index, if we don't it just takes up
# disk/memory space.
my %createTable
= $db->quickHash(
"SHOW CREATE TABLE `groupings`"
);
if ($createTable{'Create Table'} =~ /KEY\s+`[^`]+`\s+[(]`userId`[)]/) {
print " Skipped!\n",
"\t\tAn index already exists on the `userId` column in the `groupings` table\n"
unless $quiet;
}
else {
print "\n\t\tThis may take a while... " unless $quiet;
$db->write("ALTER TABLE `groupings` ADD INDEX `userId` (`userId`)");
print "DONE!\n" unless $quiet;
}
}
#----------------------------------------------------------------------------
sub fixProfileDataWithoutFields {
my $session = shift;
my $db = $session->db;