From 3257456df730e157043abf6564e604a7da2b4aa2 Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Tue, 29 May 2007 17:06:35 +0000 Subject: [PATCH] added an index on the groupings table for the userId column --- docs/changelog/7.x.x.txt | 2 ++ docs/upgrades/upgrade_7.3.19-7.4.0.pl | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index dfce0d8e1..486d4e023 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -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) diff --git a/docs/upgrades/upgrade_7.3.19-7.4.0.pl b/docs/upgrades/upgrade_7.3.19-7.4.0.pl index 976b9fab8..26930af14 100644 --- a/docs/upgrades/upgrade_7.3.19-7.4.0.pl +++ b/docs/upgrades/upgrade_7.3.19-7.4.0.pl @@ -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;