Add index on extras_cachedvalue.object_id for better update performance with many interfaces #14966
Labels
status: accepted
This issue has been accepted for implementation
type: feature
Introduction of new functionality to the application
NetBox version
v3.7.0
Feature type
Data model extension
Proposed functionality
Add an index to the object_id column on the extras_cachedvalue table.
This was suggested before in #11775 but for inserting new interfaces, and that was solved in #11785 by skipping the clearing of the cache on inserts, but that logic does of course not apply to updating interfaces.
Then there was an implementation of indexes for all generic foreign keys in #11790, but that did not include this object_id as it is something that can refer to multiple tables and is therefore not a formal foreign key.
Use case
When there are many interfaces (we are currently working with 300k+, times 7 attributes gives 2.2 million rows in the extras_cachedvalue table), updating (many of) them takes a lot of time. Looking at the PostgreSQL stats, this is the query that takes a lot of time:
where in this instance 38 is the ID of dcim.interface, and that object_id is just an example.
Adding the suggested index made a big improvement in the time it takes to process the updates.
Database changes
CREATE INDEX extras_cachedvalue_object_id_TBD ON extras_cachedvalue USING btree(object_id);
External dependencies
No response
The text was updated successfully, but these errors were encountered: