This code is very difficult to review since its complexity has gone through the roof.
I think I said this the last this was changed, but I really think we should break this down into multiple queries (via views, perhaps) so that individual pieces can be tested easier.
For now, I attempted to review by comparing the added/changed tests to the added/changed code. I think I would like to see more specific tests to capture each edge case, such as:
This code is very difficult to review since its complexity has gone through the roof.
I think I said this the last this was changed, but I really think we should break this down into multiple queries (via views, perhaps) so that individual pieces can be tested easier.
For now, I attempted to review by comparing the added/changed tests to the added/changed code. I think I would like to see more specific tests to capture each edge case, such as:
test_ _default_ domain_ is_extra_ special_ ipv4 _default_ domain_ is_extra_ special_ ipv6 _domains_ are_special _attached_ addresses_ only_map_ back_to_ node
test_
test_
test_
That way it's clearer to future maintainers how each edge case and branch called out in the SQL maps to a requirement for a specific behavior.