Bug 21288: Slowness in acquisition caused by GetInvoices

The SQL query done by GetInvoices is quite slow on our production server,
taking about a minute.

In the query, there's this join:

  LEFT JOIN subscription ON biblio.biblionumber = subscription.biblionumber

but there's no index on subscription.biblionumber. Adding the index speeds
up the query so it only takes up about 3 seconds.

Signed-off-by: Pasi Kallinen <pasi.kallinen@joensuu.fi>

Signed-off-by: Mark Tompsett <mtompset@hotmail.com>
Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
This commit is contained in:
Pasi Kallinen 2018-08-30 11:29:54 +03:00 committed by Nick Clemens
parent a6f8eac4ed
commit cb406f72b0
2 changed files with 10 additions and 0 deletions

View file

@ -0,0 +1,9 @@
$DBversion = 'XXX'; # will be replaced by the RM
if( CheckVersion( $DBversion ) ) {
$dbh->do(q{
CREATE INDEX `by_biblionumber` ON `subscription` (`biblionumber`)
});
SetVersion( $DBversion );
print "Upgrade to $DBversion done (Bug 21288: Slowness in acquisition caused by GetInvoices\n";
}

View file

@ -2098,6 +2098,7 @@ CREATE TABLE `subscription` ( -- information related to the subscription
`itemtype` VARCHAR( 10 ) NULL,
`previousitemtype` VARCHAR( 10 ) NULL,
PRIMARY KEY (`subscriptionid`),
KEY `by_biblionumber` (`biblionumber`),
CONSTRAINT subscription_ibfk_1 FOREIGN KEY (periodicity) REFERENCES subscription_frequencies (id) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT subscription_ibfk_2 FOREIGN KEY (numberpattern) REFERENCES subscription_numberpatterns (id) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;