Fix network subset support with custom operator classes

Started by Kirill Reshke5 days ago2 messageshackers

Thread notes

1 note#bug
hackorum-bot#bug
hackorum-bot
2 days ago

@global #bug

#bug
Jump to latest
#1Kirill Reshke
reshkekirill@gmail.com

Hi,

The planner support function for the inet << and <<= operators
rewrites the predicate into range clauses of the form

key >= network_scan_first(C) AND key <= network_scan_last(C)

which only works when opfamily is same as network_cmp_internal().
Since be1cc9aaf5b [0]https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=be1cc9aaf5b79f07bc0483a0c95366c77a844d0a this is actually not checked. [0]https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=be1cc9aaf5b79f07bc0483a0c95366c77a844d0a commit message
says that

To fix restore the opfamily == NETWORK_BTREE_FAM_OID check inside
match_network_subset.

A regression test with a masklen-ordered btree opclass over inet is
included as a separate patch. This case looks too narrow to spend CI
cycles on, OTOH this is real historical regression.

[0]: https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=be1cc9aaf5b79f07bc0483a0c95366c77a844d0a

--
Best regards,
Kirill Reshke

Attachments:

t259717_1
0001-fix-network-subset-support.patchapplication/octet-stream; name=0001-fix-network-subset-support.patchDownload+5-0
0002-test-network-subset-support.patchapplication/octet-stream; name=0002-test-network-subset-support.patchDownload+44-0
#2Andrey Borodin
amborodin@acm.org
In reply to: Kirill Reshke (#1)
Re: Fix network subset support with custom operator classes

Hi Kirill,

The family OID check also removes index bounds from a copy of the
standard inet opclass in a separate family. Could we instead follow
like_support.c: select the standard inet operators, then check
op_in_opfamily() for the target family?

With the reverse opclass from your test, explicitly writing the standard

= and <= bounds produces an Index Cond and returns the expected two

rows. That suggests we can fix the operator selection without losing
the generalization from be1cc9aaf5b.

I'd keep the test.

Thank you!

Best regards, Andrey Borodin.