Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4c87010

Browse files
committed
Fix crash in BRIN inclusion op functions, due to missing datum copy.
The BRIN add_value() and union() functions need to make a longer-livedcopy of the argument, if they want to store it in the BrinValues structalso passed as argument. The functions for the "inclusion operatorclasses" used with box, range and inet types didn't take into accountthat the union helper function might return its argument as is, withoutmaking a copy. Check for that case, and make a copy if necessary. Thatcase arises at least with the range_union() function, when one of thearguments is an 'empty' range:CREATE TABLE brintest (n numrange);CREATE INDEX brinidx ON brintest USING brin (n);INSERT INTO brintest VALUES ('empty');INSERT INTO brintest VALUES (numrange(0, 2^1000::numeric));INSERT INTO brintest VALUES ('(-1, 0)');SELECT brin_desummarize_range('brinidx', 0);SELECT brin_summarize_range('brinidx', 0);Backpatch down to 9.5, where BRIN was introduced.Discussion:https://www.postgresql.org/message-id/e6e1d6eb-0a67-36aa-e779-bcca59167c14%40iki.fiReviewed-by: Emre Hasegeli, Tom Lane, Alvaro Herrera
1 parent40d964e commit4c87010

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

‎src/backend/access/brin/brin_inclusion.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,14 @@ brin_inclusion_add_value(PG_FUNCTION_ARGS)
235235
Assert(finfo!=NULL);
236236
result=FunctionCall2Coll(finfo,colloid,
237237
column->bv_values[INCLUSION_UNION],newval);
238-
if (!attr->attbyval)
238+
if (!attr->attbyval&&
239+
DatumGetPointer(result)!=DatumGetPointer(column->bv_values[INCLUSION_UNION]))
240+
{
239241
pfree(DatumGetPointer(column->bv_values[INCLUSION_UNION]));
242+
243+
if (result==newval)
244+
result=datumCopy(result,attr->attbyval,attr->attlen);
245+
}
240246
column->bv_values[INCLUSION_UNION]=result;
241247

242248
PG_RETURN_BOOL(true);
@@ -574,8 +580,14 @@ brin_inclusion_union(PG_FUNCTION_ARGS)
574580
result=FunctionCall2Coll(finfo,colloid,
575581
col_a->bv_values[INCLUSION_UNION],
576582
col_b->bv_values[INCLUSION_UNION]);
577-
if (!attr->attbyval)
583+
if (!attr->attbyval&&
584+
DatumGetPointer(result)!=DatumGetPointer(col_a->bv_values[INCLUSION_UNION]))
585+
{
578586
pfree(DatumGetPointer(col_a->bv_values[INCLUSION_UNION]));
587+
588+
if (result==col_b->bv_values[INCLUSION_UNION])
589+
result=datumCopy(result,attr->attbyval,attr->attlen);
590+
}
579591
col_a->bv_values[INCLUSION_UNION]=result;
580592

581593
PG_RETURN_VOID();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp