Skip to content

Add missing index on netboxentity.deviceid#3794

Merged
lunkwill42 merged 1 commit into5.17.xfrom
speedup/netboxentity-device-lookups
Feb 19, 2026
Merged

Add missing index on netboxentity.deviceid#3794
lunkwill42 merged 1 commit into5.17.xfrom
speedup/netboxentity-device-lookups

Conversation

@lunkwill42
Copy link
Copy Markdown
Member

Scope and purpose

Add a partial btree index on netboxentity.deviceid to speed up lookups by device. Without this index, Django-generated queries filtering netboxentity by deviceid result in sequential scans.

On a large production install, this reduced mean execution time of device-related entity lookups from 30265ms to 0.076ms (~400,000x improvement).

The schema change script drops any existing index by the same name before creating the standard one, to handle installations that may have already defined a local index.

Contributor Checklist

  • Added a changelog fragment for towncrier
  • Added/amended tests for new/changed code
  • Added/changed documentation
  • Linted/formatted the code with ruff, easiest by using pre-commit
  • Wrote the commit message so that the first line continues the sentence "If applied, this commit will ...", starts with a capital letter, does not end with punctuation and is 50 characters or less long. See https://cbea.ms/git-commit/
  • Based this pull request on the correct upstream branch: For a patch/bugfix affecting the latest stable version, it should be based on that version's branch (<major>.<minor>.x). For a new feature or other additions, it should be based on master.
  • If applicable: Created new issues if this PR does not fix the issue completely/there is further work to be done
  • If it's not obvious from a linked issue, described how to interact with NAV in order for a reviewer to observe the effects of this change first-hand (commands, URLs, UI interactions)
  • If this results in changes in the UI: Added screenshots of the before and after
  • If this adds a new Python source code file: Added the boilerplate header to that file

Lookups on netboxentity by deviceid cause sequential scans on
installations without a locally defined index. This adds a standard
partial btree index on deviceid to speed up these queries.

On a large production install, this reduced mean execution time of
device-related entity lookups from 30265ms to 0.076ms (~400,000x
improvement).
@lunkwill42 lunkwill42 self-assigned this Feb 17, 2026
@lunkwill42 lunkwill42 requested a review from a team February 17, 2026 14:48
@lunkwill42 lunkwill42 marked this pull request as ready for review February 17, 2026 14:48
@sonarqubecloud
Copy link
Copy Markdown

@lunkwill42 lunkwill42 merged commit b838e31 into 5.17.x Feb 19, 2026
16 checks passed
@lunkwill42 lunkwill42 deleted the speedup/netboxentity-device-lookups branch February 19, 2026 11:53
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.

2 participants