Add missing index on netboxentity.deviceid#3794
Merged
lunkwill42 merged 1 commit into5.17.xfrom Feb 19, 2026
Merged
Conversation
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).
|
johannaengland
approved these changes
Feb 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Scope and purpose
Add a partial btree index on
netboxentity.deviceidto speed up lookups by device. Without this index, Django-generated queries filteringnetboxentitybydeviceidresult 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/amended tests for new/changed codeAdded/changed documentation<major>.<minor>.x). For a new feature or other additions, it should be based onmaster.If applicable: Created new issues if this PR does not fix the issue completely/there is further work to be doneIf this results in changes in the UI: Added screenshots of the before and afterIf this adds a new Python source code file: Added the boilerplate header to that file