Koha-clms/t
Mark Hofstetter a70ac8f320
Bug 39164: Add max_statement_time to SQL report queries
Reports may consume too much resources of the db. To avoid that a new config param
'report_sql_max_statement_time_seconds' was created, which sets the maximum time a report statement may
take to execute in seconds. If it takes longer it will be aborted.

reflowed the code, so that is is executed after is_sql_valid, and put
the code in a subroutine

Test plan:
0. if you run this test in ktd you should check if you are running
   mysql or mariadb, and then be able to switch database
1. create a new report by going to
More > Reports > New SQL Report
(/cgi-bin/koha/reports/guided_reports.pl?op=add_form_sql)

enter the following SQL (which only purpose is to run long)

select ExtractValue(bm1.metadata,'//controlfield[@tag="001"]')
  from biblio_metadata bm1
  join biblio_metadata bm2 on
    ExtractValue(bm1.metadata,'//controlfield[@tag="001"]') =
    ExtractValue(bm2.metadata,'//datafield[@tag="773"]/subfield[@code="w"]')

give the Report a name eg "extract_long"
2. run the report
3. report should be executed and return several 1000 lines on ktd
4. apply patch
5. add a the parameter to koha-conf.xml to the <config> </config> part
<report_sql_max_statement_time_seconds>0.001</report_sql_max_statement_time_seconds>

OR use the following statemtn
sed -i '/<biblioserver>/a <report_sql_max_statement_time_seconds>0.001<\/report_sql_max_statement_time_seconds>' /etc/koha/sites/kohadev/koha-conf.xml
6. restart koha
    koha-plack --restart kohadev
7. go back to the report page and rerun report which now should lead to an error
The following error was encountered:
The database returned the following error:
Query execution was interrupted, maximum statement execution time exceeded
Please check the log for further details.
8. in koha-conf.xml set
<report_sql_max_statement_time_seconds>20</report_sql_max_statement_time_seconds>
9. restart koha
10. rerun query, which now should execute as before
11. stop ktd, and restart with the "other" database

DB_IMAGE=mysql:8.0 ktd up
DB_IMAGE=mariadb:10.5 ktd up

12. repeat from step 1 (omit applying the patch)
13. Sign off
14. Thx

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Wainui Witika-Park <wainuiwitikapark@catalyst.net.nz>
2026-06-19 12:47:37 +12:00
..
Acquisition Bug 38944: Add Test::NoWarnings to tests no producing warnings 2025-03-13 17:25:03 +01:00
Biblio Bug 40163: (follow-up) Fix wrong GNU links and update test 2026-01-07 14:32:37 +00:00
Budgets Bug 38944: Add Test::NoWarnings to tests no producing warnings 2025-03-13 17:25:03 +01:00
Circulation Bug 40163: (follow-up) Fix wrong GNU links and update test 2026-01-07 14:32:37 +00:00
External Bug 38944: Add Test::NoWarnings to tests no producing warnings 2025-03-13 17:25:03 +01:00
Koha Bug 41076: [25.05.x] Adjust perl tidiness 2026-02-24 08:35:34 -07:00
Number Bug 39325: Automatic fix 2025-04-28 18:51:22 +02:00
SIP Bug 40163: (follow-up) Fix wrong GNU links and update test 2026-01-07 14:32:37 +00:00
Search Bug 40163: (follow-up) Fix wrong GNU links and update test 2026-01-07 14:32:37 +00:00
Serials Bug 40163: (follow-up) Fix wrong GNU links and update test 2026-01-07 14:32:37 +00:00
Template Bug 42136: Add tests 2026-04-28 15:57:08 -06:00
Test Bug 41076: [25.05.x] Adjust perl tidiness 2026-02-24 08:35:34 -07:00
cypress (follow-up) Fix failing Dialog_spec.ts test 2026-06-05 14:02:40 -06:00
data Bug 41032: Fix Open Fifth missing in plugin repos config 2025-12-01 15:53:27 +01:00
db_dependent Bug 39164: Add max_statement_time to SQL report queries 2026-06-19 12:47:37 +12:00
edi_testfiles Bug 38689: Improve test coverage 2025-02-21 16:41:23 +01:00
etc Bug 38664: Tidy the whole codebase 2025-02-11 14:58:24 +01:00
lib Bug 41076: [25.05.x] Adjust perl tidiness 2026-02-24 08:35:34 -07:00
mock_templates/intranet-tmpl/prog Bug 41177: Add aria-disabled to breadcrumbs 2025-12-01 15:53:08 +01:00
00-check-atomic-updates.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2026-01-07 14:32:37 +00:00
00-load.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2026-01-07 14:32:37 +00:00
00-merge-conflict-markers.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2026-01-07 14:32:37 +00:00
00-testcritic.t Bug 38944: Revert changes to t/00-testcritic.t 2025-03-13 17:25:06 +01:00
00-valid-xml.t Bug 41076: [25.05.x] Adjust perl tidiness 2026-02-24 08:35:34 -07:00
Auth.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2026-01-07 14:32:37 +00:00
AuthoritiesMarc_MARC21.t Bug 38944: Add Test::NoWarnings to tests no producing warnings 2025-03-13 17:25:03 +01:00
AuthoritiesMarc_UNIMARC.t Bug 38944: Add Test::NoWarnings to tests no producing warnings 2025-03-13 17:25:03 +01:00
Barcodes_EAN13.t Bug 38944: Add Test::NoWarnings to tests no producing warnings 2025-03-13 17:25:03 +01:00
Barcodes_annual.t Bug 38944: Add Test::NoWarnings to tests no producing warnings 2025-03-13 17:25:03 +01:00
Barcodes_hbyymmincr.t Bug 38944: Add Test::NoWarnings to tests no producing warnings 2025-03-13 17:25:03 +01:00
Barcodes_incremental.t Bug 38944: Add Test::NoWarnings to tests no producing warnings 2025-03-13 17:25:03 +01:00
Biblio.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2026-01-07 14:32:37 +00:00
Biblio2.t Bug 38944: Manual changes 2025-03-13 17:25:04 +01:00
Budgets.t Bug 38944: Add Test::NoWarnings to tests no producing warnings 2025-03-13 17:25:03 +01:00
Charset.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2026-01-07 14:32:37 +00:00
Circulation_barcodedecode.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2026-01-07 14:32:37 +00:00
ClassSortRoutine.t Bug 38944: Add Test::NoWarnings to tests no producing warnings 2025-03-13 17:25:03 +01:00
ClassSortRoutine_Dewey.t Bug 38944: Add Test::NoWarnings to tests no producing warnings 2025-03-13 17:25:03 +01:00
ClassSortRoutine_Generic.t Bug 38944: Add Test::NoWarnings to tests no producing warnings 2025-03-13 17:25:03 +01:00
ClassSortRoutine_LCC.t Bug 39325: Automatic fix 2025-04-28 18:51:22 +02:00
ClassSource.t Bug 38944: Add Test::NoWarnings to tests no producing warnings 2025-03-13 17:25:03 +01:00
Context.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2026-01-07 14:32:37 +00:00
Contract.t Bug 38944: Add Test::NoWarnings to tests no producing warnings 2025-03-13 17:25:03 +01:00
CookieManager.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2026-01-07 14:32:37 +00:00
Creators.t Bug 39325: Automatic fix 2025-04-28 18:51:22 +02:00
DateUtils.t Bug 38944: Add Test::NoWarnings to tests no producing warnings 2025-03-13 17:25:03 +01:00
EdiInvoice.t Bug 38944: Add Test::NoWarnings to tests no producing warnings 2025-03-13 17:25:03 +01:00
Edifact.t Bug 40386: Remove warnings from EDI when running tests 2025-08-22 09:47:50 +02:00
Ediorder.t Bug 38944: Add Test::NoWarnings to tests no producing warnings 2025-03-13 17:25:03 +01:00
Ediordrsp.t Bug 38944: Add Test::NoWarnings to tests no producing warnings 2025-03-13 17:25:03 +01:00
Form_MessagingPreferences.t Bug 34776: Add unit tests for sub restore_form_values 2025-07-10 22:47:22 +02:00
HtmlTags.t Bug 38944: Add Test::NoWarnings to tests no producing warnings 2025-03-13 17:25:03 +01:00
ImportBatch.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2026-01-07 14:32:37 +00:00
Installer_PerlModules.t Bug 38944: Add Test::NoWarnings to tests no producing warnings 2025-03-13 17:25:03 +01:00
ItemCirculationAlertPreference.t Bug 38944: Add Test::NoWarnings to tests no producing warnings 2025-03-13 17:25:03 +01:00
Koha_MetadataRecord.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2026-01-07 14:32:37 +00:00
Koha_SearchEngine_Elasticsearch_Browse.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2026-01-07 14:32:37 +00:00
Koha_Template_Plugin_HtmlId.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2026-01-07 14:32:37 +00:00
Koha_Template_Plugin_Koha.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2026-01-07 14:32:37 +00:00
Koha_Util_FrameworkPlugin.t Bug 38944: Add Test::NoWarnings to tests no producing warnings 2025-03-13 17:25:03 +01:00
Koha_Util_MARC.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2026-01-07 14:32:37 +00:00
Koha_XSLT_HTTPS.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2026-01-07 14:32:37 +00:00
Labels.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2026-01-07 14:32:37 +00:00
Labels_split_Regex.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2026-01-07 14:32:37 +00:00
Labels_split_ccn.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2026-01-07 14:32:37 +00:00
Labels_split_ddcn.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2026-01-07 14:32:37 +00:00
Labels_split_lccn.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2026-01-07 14:32:37 +00:00
Languages.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2026-01-07 14:32:37 +00:00
Logger.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2026-01-07 14:32:37 +00:00
Makefile.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2026-01-07 14:32:37 +00:00
Members_Messaging.t Bug 38944: Add Test::NoWarnings to tests no producing warnings 2025-03-13 17:25:03 +01:00
OpenLibrarySearch.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2026-01-07 14:32:37 +00:00
Output.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2026-01-07 14:32:37 +00:00
Output_JSONStream.t Bug 39325: Automatic fix 2025-04-28 18:51:22 +02:00
Patroncards.t Bug 38944: Add Test::NoWarnings to tests no producing warnings 2025-03-13 17:25:03 +01:00
Patroncards_Batch.t Bug 38944: Add Test::NoWarnings to tests no producing warnings 2025-03-13 17:25:03 +01:00
Patroncards_Lib.t Bug 38944: Add Test::NoWarnings to tests no producing warnings 2025-03-13 17:25:03 +01:00
Patroncards_Patroncard.t Bug 38944: Add Test::NoWarnings to tests no producing warnings 2025-03-13 17:25:03 +01:00
Patroncards_Profile.t Bug 38944: Add Test::NoWarnings to tests no producing warnings 2025-03-13 17:25:03 +01:00
Patroncards_Template.t Bug 38944: Add Test::NoWarnings to tests no producing warnings 2025-03-13 17:25:03 +01:00
RecordProcessor.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2026-01-07 14:32:37 +00:00
Ris.t Bug 38944: Add Test::NoWarnings to tests no producing warnings 2025-03-13 17:25:03 +01:00
SMS.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2026-01-07 14:32:37 +00:00
Scheduler.t Bug 38944: Add Test::NoWarnings to tests no producing warnings 2025-03-13 17:25:03 +01:00
Scrubber.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2026-01-07 14:32:37 +00:00
Search.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2026-01-07 14:32:37 +00:00
Search_PazPar2.t Bug 38944: Add Test::NoWarnings to tests no producing warnings 2025-03-13 17:25:03 +01:00
SimpleMARC.t Bug 38944: Add Test::NoWarnings to tests no producing warnings 2025-03-13 17:25:03 +01:00
SuggestionEngine.t Bug 38944: Manual changes 2025-03-13 17:25:04 +01:00
SuggestionEngine_AuthorityFile.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2026-01-07 14:32:37 +00:00
TmplToken.t Bug 38944: Add Test::NoWarnings to tests no producing warnings 2025-03-13 17:25:03 +01:00
Token.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2026-01-07 14:32:37 +00:00
template_filters.t Bug 40163: (follow-up) Fix wrong GNU links and update test 2026-01-07 14:32:37 +00:00
timezones.t Bug 38944: Add Test::NoWarnings to tests no producing warnings 2025-03-13 17:25:03 +01:00