Skip to content

Add index on targets_login_data - #3071

Open
TheBeast85 wants to merge 1 commit into
greenbone:mainfrom
TheBeast85:perf/index-targets-login-data
Open

Add index on targets_login_data#3071
TheBeast85 wants to merge 1 commit into
greenbone:mainfrom
TheBeast85:perf/index-targets-login-data

Conversation

@TheBeast85

@TheBeast85 TheBeast85 commented Jul 30, 2026

Copy link
Copy Markdown

What

Add an index on targets_login_data (target, type)

Why

The target iterator looks up the credential of every login type with its own subquery, so listing targets scans this table once per target and login type. The table only had its primary key on id.

create_index is idempotent and runs from create_tables, so existing databases pick the index up on the next start without a migration.

The target iterator selects the credential and the login port for six
login types, each with its own correlated subquery on
targets_login_data.  Without an index the table is scanned once per
target and subquery, so listing targets gets slower with the square of
the number of targets that have credentials.

On an installation with 4500 targets, each with an ssh credential,
listing all targets took 5.1 s. With the index it takes 1.7 s.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@TheBeast85
TheBeast85 requested review from a team as code owners July 30, 2026 10:07
@greenbonebot
greenbonebot enabled auto-merge (rebase) July 30, 2026 10:08
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