Repository navigation
perf(serverdb): render supernet filters as uncorrelated subqueries - #479
Merged
Merged
Conversation
A filter on a supernet attribute, such as route_network=regexp(...), was rendered as a correlated EXISTS over server_inet_attribute with a second sublink on the server table to match the networks by hostname. Postgres evaluated it per candidate server, probing the server's address by key and only then testing containment, so the GiST index on server_inet_attribute.value could not drive the join. Render the condition as "server.server_id IN (SELECT ...)" instead, driven from the matching networks' prefixes, the same shape #471 gave inherited supernet paths. Apply the hostname condition directly to the "supernet" alias, which is already a server row, instead of through a sublink. Both call sites share one helper so the join graph stays in a single place.
Contributor
Author
|
To give some context: The query in doubt being slow was We traced it down via PostgreSQL log to this one (our database with our servertypes): It was especially costly on the CPU side due to the many joins doing filtering. And this is where the LLM took over we simply asked it to do a root cause analyze in the query executor and suggest a faster way which it did by reordering the joins. Result looks sane and is being tested. |
TuxPowered42
requested changes
Oct 19, 2026
TuxPowered42
approved these changes
Oct 19, 2026
kofrezo
force-pushed
the
dk_improve_supernet_filter
branch
from
October 19, 2026 12:10
a4a3ac7 to
efe2f87
Compare
kofrezo
added a commit
that referenced
this pull request
Oct 19, 2026
) A filter on a supernet attribute, such as route_network=regexp(...), was rendered as a correlated EXISTS over server_inet_attribute with a second sublink on the server table to match the networks by hostname. Postgres evaluated it per candidate server, probing the server's address by key and only then testing containment, so the GiST index on server_inet_attribute.value could not drive the join. Render the condition as "server.server_id IN (SELECT ...)" instead, driven from the matching networks' prefixes, the same shape #471 gave inherited supernet paths. Apply the hostname condition directly to the "supernet" alias, which is already a server row, instead of through a sublink. Both call sites share one helper so the join graph stays in a single place.
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.
A filter on a supernet attribute, such as route_network=regexp(...), was rendered as a correlated EXISTS over server_inet_attribute with a second sublink on the server table to match the networks by hostname. Postgres evaluated it per candidate server, probing the server's address by key and only then testing containment, so the GiST index on server_inet_attribute.value could not drive the join.
Render the condition as "server.server_id IN (SELECT ...)" instead, driven from the matching networks' prefixes, the same shape #471 gave inherited supernet paths. Apply the hostname condition directly to the "supernet" alias, which is already a server row, instead of through a sublink. Both call sites share one helper so the join graph stays in a single place.