Skip to content

FIX: Keep SQLite analytics filter values within the facet budget - #4811

Open
Behnam (behnam-o) wants to merge 1 commit into
microsoft:mainfrom
behnam-o:fix/sqlite-analytics-facet-timeout
Open

Behnam (behnam-o) wants to merge 1 commit into
microsoft:mainfrom
behnam-o:fix/sqlite-analytics-facet-timeout

Conversation

@behnam-o

Copy link
Copy Markdown
Collaborator

Description

On SQLite, the analytics filter values for Operation, scenario, attack type, and objective target can time out on moderately large databases. Their facet queries group expressions whose fallbacks reference each result's embedded identifier JSON, and SQLite copies every referenced column into its GROUP BY sorter for every row, even though those fallbacks are never taken. This PR keeps these facets well within the 1-second facet budget.

  • Group projected keys on SQLite: these facets now group a materialized per-result projection of kind, key, and label, as the SQL Server facet path already does with its lateral projection. Facet options are unchanged.
  • Label, operator, and model facets already projected their values on SQLite, and array facets (harm categories, converters) use a separate path; neither changes.

Measured through the backend against a local SQLite database with 10,777 attack results (about 10 KB of identifier JSON each), with the default 1-second facet budget:

Facet Before After
Objective target 504 timeout (about 1.8 s) 0.45 s
Attack type 504 timeout (about 1.7 s) 0.44 s
Operation 0.13–0.53 s 0.06–0.23 s

Facets still read every result in the filtered cohort, so much larger SQLite databases can still exceed the budget (about 1.1–1.2 s at 32K results); that is not addressed here. Related: #4790 fixes report heatmap timeouts on Azure SQL, a separate path.

SQLite copies every column a GROUP BY key references into its sorter,
including embedded identifier JSON that only never-taken fallbacks read.
Scalar facets with derived keys (Operation, scenario, attack type,
objective target) grouped those expressions directly, so on a database
with about 11K results the objective-target and attack-type facets took
about 1.7 seconds and always exceeded the 1-second facet budget.

Group a materialized projection of each result's kind, key, and label
instead, as the SQL Server path already does with its lateral projection.
Facet options are unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings December 2, 2026 20:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified that would block approval.

No open issues 🎉

What changed in this PR

Improves SQLite analytics facet performance by grouping projected keys and labels rather than carrying embedded identifier JSON through sorting, without changing facet options.

Changes:

  • Materializes projections for Operation, scenario, attack type, and objective target facets.
  • Adds SQL compilation checks for all four dimensions.
  • Documents the optimization and SQLite version behavior.
File Description
tests/​unit/​memory/​test_attack_analytics.py Verifies materialized projections and grouping on SQLite.
pyrit/​memory/​attack_analytics_query.py Projects scalar facet keys and labels before grouping.
doc/​code/​analytics/​0_attack_results.md Explains how projections reduce SQLite sorting overhead.

Review effort: Balanced

@jbolor21 jbolor21 self-assigned this Dec 3, 2026

This branch has not been deployed

No deployments
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