[PR #20059] [MERGED] Fixes #20023: Add GiST index on Prefix.prefix for net contains ops #15814

Closed
opened 2025-12-30 00:24:12 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/20059
Author: @jnovinger
Created: 8/8/2025
Status: Merged
Merged: 8/8/2025
Merged by: @jnovinger

Base: mainHead: 20023-slow-prefix-deletion


📝 Commits (1)

  • eb4bd54 Fixes #20023: Add GiST index on Prefix.prefix for net contains ops

📊 Changes

2 files changed (+28 additions, -0 deletions)

View changed files

netbox/ipam/migrations/0082_add_prefix_network_containment_indexes.py (+20 -0)
📝 netbox/ipam/models/ip.py (+8 -0)

📄 Description

Fixes: #20023

Resolves performance issue where prefix deletion with 2000+ children took 5-10 minutes due to sequential scans in hierarchy depth/children calculations. Adding PostgreSQL GiST index with inet_ops enables efficient network containment operators (>>, <<, <<=) in annotate_hierarchy() queries.

Performance impact:

  • 30-60x speedup: 5-10 minutes → 10 seconds for large prefix deletions
  • Real-world validation: 4s migration time on 1.24M prefix dataset
  • Storage cost: 47MB index (11% of table storage, 38 bytes per prefix)

Works in conjunction with existing B-tree indexes on vrf_id for optimal query performance. Benefits all network containment operations including hierarchy navigation, aggregate views, and available IP/prefix calculations.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/20059 **Author:** [@jnovinger](https://github.com/jnovinger) **Created:** 8/8/2025 **Status:** ✅ Merged **Merged:** 8/8/2025 **Merged by:** [@jnovinger](https://github.com/jnovinger) **Base:** `main` ← **Head:** `20023-slow-prefix-deletion` --- ### 📝 Commits (1) - [`eb4bd54`](https://github.com/netbox-community/netbox/commit/eb4bd547e99e5e6a090708a511bcb2b08c6bb78c) Fixes #20023: Add GiST index on Prefix.prefix for net contains ops ### 📊 Changes **2 files changed** (+28 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `netbox/ipam/migrations/0082_add_prefix_network_containment_indexes.py` (+20 -0) 📝 `netbox/ipam/models/ip.py` (+8 -0) </details> ### 📄 Description ### Fixes: #20023 Resolves performance issue where prefix deletion with 2000+ children took 5-10 minutes due to sequential scans in hierarchy depth/children calculations. Adding PostgreSQL GiST index with inet_ops enables efficient network containment operators (>>, <<, <<=) in annotate_hierarchy() queries. Performance impact: - 30-60x speedup: 5-10 minutes → 10 seconds for large prefix deletions - Real-world validation: 4s migration time on 1.24M prefix dataset - Storage cost: 47MB index (11% of table storage, 38 bytes per prefix) Works in conjunction with existing B-tree indexes on vrf_id for optimal query performance. Benefits all network containment operations including hierarchy navigation, aggregate views, and available IP/prefix calculations. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-30 00:24:12 +01:00
adam closed this issue 2025-12-30 00:24:12 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#15814