Koha-clms/Koha/Database
Kyle M Hall 430281a59a
Bug 43101: search_for_data_inconsistencies.pl inlines every biblionumber in the catalog as an OR chain
Queries that use OR instead of IN are less efficient and can lead to
situations where the query takes a very long time to complete due to
row level scanning. We found one instance where they query had been
running for over 10 days!

This patch makes ids() return a subquery instead of a list of results,
and switches the callers to using IN. The database now resolves the set
itself and the queries stay a constant size no matter how large the
catalog is. This is super efficient because the subquery doesn't even
execute as a separate query since biblionumber is the primary key!

Test Plan:
1) Apply the unit tests patch
2) prove t/db_dependent/Koha/Database/DataInconsistency.t
3) Note the ids() subtest fails
4) Apply this patch
5) prove t/db_dependent/Koha/Database/DataInconsistency.t
6) Note all tests pass!
7) Run misc/maintenance/search_for_data_inconsistencies.pl
8) Note the output is the same as before the patch
9) Bonus: Re-run it with DBIC_TRACE=1 and note the queries now use
   IN (SELECT ...) instead of one OR clause per bib!

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-07-27 12:13:05 +00:00
..
Auditor.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
Columns.pm Bug 41752: label concactfirstname and contactname as Guarantor first name and Guarantor surname 2026-02-06 15:17:27 -07:00
Commenter.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
DataInconsistency.pm Bug 43101: search_for_data_inconsistencies.pl inlines every biblionumber in the catalog as an OR chain 2026-07-27 12:13:05 +00:00