Skip to content

Fix: do not compute severity for tasks without a report - #3070

Open
TheBeast85 wants to merge 1 commit into
greenbone:mainfrom
TheBeast85:perf/task-severity-without-report
Open

Fix: do not compute severity for tasks without a report#3070
TheBeast85 wants to merge 1 commit into
greenbone:mainfrom
TheBeast85:perf/task-severity-without-report

Conversation

@TheBeast85

@TheBeast85 TheBeast85 commented Jul 30, 2026

Copy link
Copy Markdown

What

Look up the last report in a FROM subquery and pass its id to report_severity

Why

task_severity passed the report lookup straight to report_severity, so a task that never produced a report called report_severity(NULL, ...). That returns NULL, but only after the whole severity query has been evaluated, including the report_counts lookup and the dynamic severity check. The cost is per task, so it shows up wherever severity is aggregated over many tasks.

With the subquery there are no rows when the task has no report, so report_severity is never called and the result is unchanged.

On an installation with 4507 tasks the aggregate goes from 2782 ms to 376 ms. The saving is proportional to the number of tasks that never ran; where almost none of them have a report it was 2774 ms to 9 ms.

Checklist

  • Tests: severity distribution over all tasks identical before and after

task_severity() passes the result of the last report lookup straight to
report_severity(), so for a task that never produced a report it calls
report_severity(NULL, ...).  That returns NULL, but only after the whole
severity query has been evaluated, including the report_counts lookup and
the dynamic severity check.

The cost is per task, so it shows up wherever severity is aggregated over
many tasks - the task dashboard being the obvious one.

Look up the report in a FROM subquery instead and call report_severity with
its id.  Without a report the subquery has no rows, the scalar subquery
yields NULL and report_severity is never called.  The result is unchanged.

Measured on an installation with 4507 tasks, of which most have no report:

    select task_severity(id,0,70), count(*) from tasks group by 1
    before: 2782 ms      after: 376 ms

The saving is proportional to the number of tasks that never ran; on an
installation where almost none of them have a report the same aggregate went
from 2774 ms to 9 ms.  The severity distribution is identical either way.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant