From 4bc1d8cec187f1605abe28fa59aac9da3325ea74 Mon Sep 17 00:00:00 2001 From: John Doe Date: Fri, 14 Nov 2025 11:32:02 +0000 Subject: [PATCH] Bug 41248: Add index on background_jobs.data Index decreases search result time from 1.6 seconds to 0.001 seconds on 153,205 rows Signed-off-by: Kyle M Hall --- .../data/mysql/atomicupdate/bug_41248.pl | 24 +++++++++++++++++++ installer/data/mysql/kohastructure.sql | 3 ++- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100755 installer/data/mysql/atomicupdate/bug_41248.pl diff --git a/installer/data/mysql/atomicupdate/bug_41248.pl b/installer/data/mysql/atomicupdate/bug_41248.pl new file mode 100755 index 00000000000..5004bb1c06e --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_41248.pl @@ -0,0 +1,24 @@ +use Modern::Perl; +use Koha::Installer::Output qw(say_warning say_success say_info); + +return { + bug_number => "41248", + description => "Add index on background_jobs.data", + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @$args{qw(dbh out)}; + + unless ( index_exists( 'background_jobs', 'borrowernumber' ) ) { + $dbh->do( + q{ + ALTER TABLE background_jobs + ADD INDEX idx_data_255 (data(255)); + } + ); + + say_success( $out, "Added index idx_data_255 for background_jobs.data" ); + } else { + say_info( $out, "Index idx_data_255 for background_jobs.data already exists" ); + } + } +}; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index d3b36dca871..c261f75b609 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -1084,7 +1084,8 @@ CREATE TABLE `background_jobs` ( PRIMARY KEY (`id`), KEY `borrowernumber` (`borrowernumber`), KEY `queue` (`queue`), - KEY `status` (`status`) + KEY `status` (`status`), + KEY `idx_data_255` (`data`(255)) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- 2.50.1 (Apple Git-155)