Bug 13740: Remove the NOT NULL clause in GetBorrowersToExpunge
C4::Borrowers::GetBorrowersToExpunge should not use a "NOT IN", it is not efficient at all. With only 1 guarantor and more than 136k patrons, the not in clause in this subroutine takes ages: mysql> select count(*) FROM borrowers where borrowernumber NOT IN (SELECT guarantorid FROM borrowers WHERE guarantorid IS NOT NULL AND guarantorid <> 0) ; [...] not ended after 5min With the query modified by this patch, the results come after 1 sec :) Test plan: Verify the delete_patrons.pl cronjob or the cleanborrowers tools work as before. Especially with guarantors. Signed-off-by: Brendan Gallagher <brendan@bywatersolutions.com> Signed-off-by: Koha Team AMU <koha.aixmarseille@gmail.com> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
This commit is contained in:
parent
eb2d7db655
commit
b721b6f9f3
1 changed files with 10 additions and 3 deletions
|
@ -2109,17 +2109,24 @@ sub GetBorrowersToExpunge {
|
||||||
: "");
|
: "");
|
||||||
|
|
||||||
my $dbh = C4::Context->dbh;
|
my $dbh = C4::Context->dbh;
|
||||||
my $query = "
|
my $query = q|
|
||||||
SELECT borrowers.borrowernumber,
|
SELECT borrowers.borrowernumber,
|
||||||
MAX(old_issues.timestamp) AS latestissue,
|
MAX(old_issues.timestamp) AS latestissue,
|
||||||
MAX(issues.timestamp) AS currentissue
|
MAX(issues.timestamp) AS currentissue
|
||||||
FROM borrowers
|
FROM borrowers
|
||||||
JOIN categories USING (categorycode)
|
JOIN categories USING (categorycode)
|
||||||
|
LEFT JOIN (
|
||||||
|
SELECT guarantorid
|
||||||
|
FROM borrowers
|
||||||
|
WHERE guarantorid IS NOT NULL
|
||||||
|
AND guarantorid <> 0
|
||||||
|
) as tmp ON borrowers.borrowernumber=tmp.guarantorid
|
||||||
LEFT JOIN old_issues USING (borrowernumber)
|
LEFT JOIN old_issues USING (borrowernumber)
|
||||||
LEFT JOIN issues USING (borrowernumber)
|
LEFT JOIN issues USING (borrowernumber)
|
||||||
WHERE category_type <> 'S'
|
WHERE category_type <> 'S'
|
||||||
AND borrowernumber NOT IN (SELECT guarantorid FROM borrowers WHERE guarantorid IS NOT NULL AND guarantorid <> 0)
|
AND tmp.guarantorid IS NOT NULL
|
||||||
";
|
|;
|
||||||
|
|
||||||
my @query_params;
|
my @query_params;
|
||||||
if ( $filterbranch && $filterbranch ne "" ) {
|
if ( $filterbranch && $filterbranch ne "" ) {
|
||||||
$query.= " AND borrowers.branchcode = ? ";
|
$query.= " AND borrowers.branchcode = ? ";
|
||||||
|
|
Loading…
Reference in a new issue