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

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

@clawosiris

clawosiris commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Review result: I found no blocking correctness issue in the SQL rewrite.

I verified the exact current head (19a95738) against PostgreSQL 17. The new FROM subquery skips report_severity for tasks with no completed report (including missing tasks and tasks with only non-completed reports), while targetless-task behavior, latest completed report selection, legacy date ordering, and the overrides/min_qod arguments remain unchanged. The exact head also passes Debug and Release builds plus all 11 existing CTests.

There is a meaningful coverage gap: none of the existing tests executes the installed task_severity SQL, and this change is duplicated across four schema-version branches. I opened draft #3209 with a PostgreSQL-backed regression for all four definitions and tagged @TheBeast85 there. Its local validation passes all 12 CTests.

One integration caveat: #3070 is currently 219 commits behind main, and only the July automation checks ran on the PR. The commit applies cleanly to current main; a combined current-main simulation with #3209 also passes a Release build and all 14 CTests. I still recommend rebasing so the current hosted build/test matrix runs before merge.

Agent: GEA
Model: openai/gpt-5.6-sol
Thinking: xhigh
Bot-Owner: @llunved

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>
auto-merge was automatically disabled October 23, 2026 11:06

Head branch was pushed to by a user without write access

@TheBeast85
TheBeast85 force-pushed the perf/task-severity-without-report branch from 19a9573 to bc8a6f6 Compare October 23, 2026 11:06
@greenbonebot
greenbonebot enabled auto-merge (rebase) October 23, 2026 11:06
@TheBeast85

Copy link
Copy Markdown
Author

Thanks for the review and for the regression test in #3209! Rebased onto current main, no conflicts and no content change. Release build and all CTests pass, including the task severity test from #3209 applied on top.

@daniel-grnbn

Copy link
Copy Markdown

@TheBeast85 if that is OK with you, I'll remove the draft label from #3209 and merge it into this branch?

@TheBeast85

Copy link
Copy Markdown
Author

@daniel-grnbn Yes, please go ahead and merge #3209 into this branch. Thanks for the tests!

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.

3 participants