Replies: 1 comment 8 replies
-
Hello, I wanted to bring up a concern about the proposed workaround. It appears that the proposed workaround would lead to a lot of duplicated data, which is not ideal for managing a efficient database. While currently there may be a small impact on performance, I don't believe that duplicating data is the right approach. I am hopeful that the community can find a more elegant solution that accomplishes more efficient queries while maintaining the functionality that currently addresses issue #946. Whenever I have some time to think this over, I will try to recall some of my past DBA experience to can come up with a possible solution. |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Overview
I started digging into query performance for
IPAddress
after a DBA reached out with some concerns. I was going to open an issue but 1) there's not a great solution right now, 2) the only idea I have for resolving it isn't worth the effort without more use cases or a larger impact. So these are just my notes in case the topic is ever re-visited in the future.[Edit] Better solution proposed #11503 (reply in thread)
Add an index to the
address
field on theIPAddress
model to reduce lookup/search cost to the database.Remove
CAST(HOST())
usage as it increases lookup cost quite a bit, even when indexingaddress
.netbox/netbox/ipam/lookups.py
Line 154 in d7c37d9
However,
CAST(HOST())
can't be removed without affecting this scenario #946 (comment) which definitely has value.Test results
I tested both
gist (address inet_ops)
andbtree
and saw a similar reduction in lookup cost and time - but removingCAST(HOST())
had the biggest impact, indexing makes it even better. With approximately 260K IP addresses, the index only increased the disk size of the table by 4-7 MB (from ~47MB to ~51MB) depending on index type.Removing
CAST(HOST())
doesn't impact this scenario #6632, and all the "nested" prefix/IP layouts all seemed to work fine since Postgres understands IP/mask nested relationships (except as mentioned in #946 (comment))/32 prefix with /32 IP

/25 prefix with /26 child prefix, which contains a /26 IP



Possible workarounds
As for my workaround idea - one or two "private" fields could be added to the
IPAddress
model to store the IP address without the mask (and another with just the mask optionally). Those fields would be modified automatically during.save()
or similar method that's called anytime a model is modified.Better workaround
#11503 (reply in thread)
Beta Was this translation helpful? Give feedback.
All reactions