mirror of
https://github.com/postgres/postgres.git
synced 2025-05-08 07:21:33 +03:00
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
This commit is contained in:
parent
8de4660a57
commit
0c7726c282
@ -2364,14 +2364,14 @@ brin_minmax_multi_distance_inet(PG_FUNCTION_ARGS)
|
|||||||
unsigned char mask;
|
unsigned char mask;
|
||||||
int nbits;
|
int nbits;
|
||||||
|
|
||||||
nbits = lena - (i * 8);
|
nbits = Max(0, lena - (i * 8));
|
||||||
if (nbits < 8)
|
if (nbits < 8)
|
||||||
{
|
{
|
||||||
mask = (0xFF << (8 - nbits));
|
mask = (0xFF << (8 - nbits));
|
||||||
addra[i] = (addra[i] & mask);
|
addra[i] = (addra[i] & mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
nbits = lenb - (i * 8);
|
nbits = Max(0, lenb - (i * 8));
|
||||||
if (nbits < 8)
|
if (nbits < 8)
|
||||||
{
|
{
|
||||||
mask = (0xFF << (8 - nbits));
|
mask = (0xFF << (8 - nbits));
|
||||||
|
@ -351,6 +351,12 @@ VACUUM brintest_multi; -- force a summarization cycle in brinidx
|
|||||||
insert into public.brintest_multi (float4col) values (real 'nan');
|
insert into public.brintest_multi (float4col) values (real 'nan');
|
||||||
insert into public.brintest_multi (float8col) values (real 'nan');
|
insert into public.brintest_multi (float8col) values (real 'nan');
|
||||||
UPDATE brintest_multi SET int8col = int8col * int4col;
|
UPDATE brintest_multi SET int8col = int8col * int4col;
|
||||||
|
-- Test handling of inet netmasks with inet_minmax_multi_ops
|
||||||
|
CREATE TABLE brin_test_inet (a inet);
|
||||||
|
CREATE INDEX ON brin_test_inet USING brin (a inet_minmax_multi_ops);
|
||||||
|
INSERT INTO brin_test_inet VALUES ('127.0.0.1/0');
|
||||||
|
INSERT INTO brin_test_inet VALUES ('0.0.0.0/12');
|
||||||
|
DROP TABLE brin_test_inet;
|
||||||
-- Tests for brin_summarize_new_values
|
-- Tests for brin_summarize_new_values
|
||||||
SELECT brin_summarize_new_values('brintest_multi'); -- error, not an index
|
SELECT brin_summarize_new_values('brintest_multi'); -- error, not an index
|
||||||
ERROR: "brintest_multi" is not an index
|
ERROR: "brintest_multi" is not an index
|
||||||
|
@ -357,6 +357,13 @@ insert into public.brintest_multi (float8col) values (real 'nan');
|
|||||||
|
|
||||||
UPDATE brintest_multi SET int8col = int8col * int4col;
|
UPDATE brintest_multi SET int8col = int8col * int4col;
|
||||||
|
|
||||||
|
-- Test handling of inet netmasks with inet_minmax_multi_ops
|
||||||
|
CREATE TABLE brin_test_inet (a inet);
|
||||||
|
CREATE INDEX ON brin_test_inet USING brin (a inet_minmax_multi_ops);
|
||||||
|
INSERT INTO brin_test_inet VALUES ('127.0.0.1/0');
|
||||||
|
INSERT INTO brin_test_inet VALUES ('0.0.0.0/12');
|
||||||
|
DROP TABLE brin_test_inet;
|
||||||
|
|
||||||
-- Tests for brin_summarize_new_values
|
-- Tests for brin_summarize_new_values
|
||||||
SELECT brin_summarize_new_values('brintest_multi'); -- error, not an index
|
SELECT brin_summarize_new_values('brintest_multi'); -- error, not an index
|
||||||
SELECT brin_summarize_new_values('tenk1_unique1'); -- error, not a BRIN index
|
SELECT brin_summarize_new_values('tenk1_unique1'); -- error, not a BRIN index
|
||||||
|
Loading…
x
Reference in New Issue
Block a user