Koha-clms/C4
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
..
AuthoritiesMarc Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Barcodes Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
ClassSortRoutine Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
ClassSplitRoutine Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Creators Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
External Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Form Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Heading Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
ILSDI Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Installer Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Labels Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Linker Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Members Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
OAI Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Output Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Patroncards Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Reports Bug 39164: Add max_statement_time to SQL report queries 2026-06-19 12:47:37 +12:00
SIP Bug 36752: Remove confusing TODOs 2026-05-23 15:58:50 -04:00
Search Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Serials Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Utils/DataTables Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Accounts.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Acquisition.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Auth.pm Bug 41076: [25.05.x] Adjust perl tidiness 2026-02-24 08:35:34 -07:00
Auth_cas_servers.yaml.sample
…
Auth_with_cas.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Auth_with_ldap.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Auth_with_shibboleth.pm Bug 41076: [25.05.x] Adjust perl tidiness 2026-02-24 08:35:34 -07:00
AuthoritiesMarc.pm Bug 41076: [25.05.x] Adjust perl tidiness 2026-02-24 08:35:34 -07:00
Barcodes.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Biblio.pm Bug 41076: [25.05.x] Adjust perl tidiness 2026-02-24 08:35:34 -07:00
Breeding.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Budgets.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Calendar.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Charset.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Circulation.pm Bug 41393: Set the correct reply to address for advance notices 2026-05-23 15:58:49 -04:00
ClassSortRoutine.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
ClassSource.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
ClassSplitRoutine.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Context.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Contract.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
CourseReserves.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Creators.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
HTML5Media.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Heading.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
HoldsQueue.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
ImportBatch.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
ImportExportFramework.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
InstallAuth.pm Bug 41076: [25.05.x] Adjust perl tidiness 2026-02-24 08:35:34 -07:00
Installer.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
ItemCirculationAlertPreference.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Items.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Koha.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Labels.pm Bug 21395: Make perlcritic happy 2020-06-29 12:37:02 +02:00
Languages.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Letters.pm Bug 42136: prevent cgi, directory, and file plugins from use in user-entered templates 2026-04-28 15:57:08 -06:00
Linker.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Log.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
MarcModificationTemplates.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Matcher.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Members.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Message.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Output.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Overdues.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Patroncards.pm Bug 38664: Tidy the whole codebase 2025-02-11 14:58:24 +01:00
Record.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Reports.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Reserves.pm Bug 19690: Change comments in IsAvailableForItemLevelRequest 2026-03-30 18:02:28 -04:00
Ris.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
RotatingCollections.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
SMS.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Scheduler.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Scrubber.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Search.pm Bug 41444: (QA follow-up) Rearrange comments 2026-05-23 15:58:48 -04:00
Serials.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Service.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
ShelfBrowser.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
SocialData.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Stats.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Suggestions.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
TTParser.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Tags.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
Templates.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
TmplToken.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
TmplTokenType.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
UsageStats.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
XISBN.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00
XSLT.pm Bug 40163: Fix several http addresses in the code docs 2026-01-07 14:32:30 +00:00