diff options
| author | Tomas Vondra <tomas.vondra@postgresql.org> | 2023-03-20 09:51:50 +0100 |
|---|---|---|
| committer | Tomas Vondra <tomas.vondra@postgresql.org> | 2023-03-20 10:16:54 +0100 |
| commit | 6a78a42fea0c457dfee2a5ac5431df02342eafd2 (patch) | |
| tree | bdff966a3d87750151ed4669722289f84d65aa99 /src/backend/access/brin/brin_minmax_multi.c | |
| parent | f654f343c6a89f76aa0385bb92a1c6802126974c (diff) | |
Fix netmask handling in inet_minmax_multi_ops
When calculating distance in brin_minmax_multi_distance_inet(), the
netmask was applied incorrectly. This results in (seemingly) incorrect
ordering of values, triggering an assert.
For builds without asserts this is mostly harmless - we may merge other
ranges, possibly resulting in slightly less efficient index. But it's
still correct and the greedy algorithm doesn't guarantee optimality
anyway.
Backpatch to 14, where minmax-multi indexes were introduced.
Reported by Dmitry Dolgov, investigation and fix by me.
Reported-by: Dmitry Dolgov
Backpatch-through: 14
Discussion: https://postgr.es/m/17774-c6f3e36dd4471e67@postgresql.org
Diffstat (limited to 'src/backend/access/brin/brin_minmax_multi.c')
| -rw-r--r-- | src/backend/access/brin/brin_minmax_multi.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/backend/access/brin/brin_minmax_multi.c b/src/backend/access/brin/brin_minmax_multi.c index 73cc94de7bf..89df60b24dd 100644 --- a/src/backend/access/brin/brin_minmax_multi.c +++ b/src/backend/access/brin/brin_minmax_multi.c @@ -2364,14 +2364,14 @@ brin_minmax_multi_distance_inet(PG_FUNCTION_ARGS) unsigned char mask; int nbits; - nbits = lena - (i * 8); + nbits = Max(0, lena - (i * 8)); if (nbits < 8) { mask = (0xFF << (8 - nbits)); addra[i] = (addra[i] & mask); } - nbits = lenb - (i * 8); + nbits = Max(0, lenb - (i * 8)); if (nbits < 8) { mask = (0xFF << (8 - nbits)); |
