Add missing SQL indexes #11912

Closed
opened 2025-12-29 21:51:27 +01:00 by adam · 1 comment
Owner

Originally created by @jeremystretch on GitHub (Dec 9, 2025).

Originally assigned to: @jeremystretch on GitHub.

Proposed Changes

Add indexes for generic foreign keys on the following models:

  • circuits.CircuitTermination (termination_type, termination_id)
  • dcim.MACAddress (assigned_object_type, assigned_object_id)
  • ipam.Prefix (scope_type, scope_id)
  • virtualization.Cluster (scope_type, scope_id)
  • wireless.WirelessLAN (scope_type, scope_id)

Additionally, ensure that all models have indexes for fields which are used for default ordering.

Justification

Adding these indexes will improve response times for common queries where a large number of records exist.

Originally created by @jeremystretch on GitHub (Dec 9, 2025). Originally assigned to: @jeremystretch on GitHub. ### Proposed Changes Add indexes for generic foreign keys on the following models: - circuits.CircuitTermination (`termination_type`, `termination_id`) - dcim.MACAddress (`assigned_object_type`, `assigned_object_id`) - ipam.Prefix (`scope_type`, `scope_id`) - virtualization.Cluster (`scope_type`, `scope_id`) - wireless.WirelessLAN (`scope_type`, `scope_id`) ~Additionally, ensure that all models have indexes for fields which are used for default ordering.~ ### Justification Adding these indexes will improve response times for common queries where a large number of records exist.
adam added the status: acceptedtype: housekeepingnetbox labels 2025-12-29 21:51:27 +01:00
adam closed this issue 2025-12-29 21:51:27 +01:00
Author
Owner

@jeremystretch commented on GitHub (Dec 15, 2025):

It also seems that there should be an index for ('tree_id', 'lft') on all models which employ MPTT, but it's not clear why these have not been created automatically. Upgrading to django-mptt v0.18 introduces a migration for the InventoryItem and InventoryItemTemplate models only; I suspect this is because these are the only models which inherit from MPTTModel directly.

@jeremystretch commented on GitHub (Dec 15, 2025): It also seems that there should be an index for `('tree_id', 'lft')` on all models which employ MPTT, but it's not clear why these have not been created automatically. Upgrading to django-mptt v0.18 introduces a migration for the InventoryItem and InventoryItemTemplate models only; I suspect this is because these are the only models which inherit from MPTTModel directly.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11912