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

Commit2b1ab28

Browse files
committed
Fix handling of NULLs when merging BRIN summaries
When merging BRIN summaries, union_tuples() did not correctly update thetarget hasnulls/allnulls flags. When merging all-NULL summary into asummary without any NULL values, the result had both flags set to false(instead of having hasnulls=true).This happened because the code only considered the hasnulls flags,ignoring the possibility the source summary has allnulls=true.Discovered while investigating issues with handling empty BRIN rangesand handling of NULL values, but it's a separate problem (has nothing todo with empty ranges).Fixed by considering both flags on the source summary, and updating thehasnulls flag on the target summary.Backpatch to 11. The bug exists since 9.5 (where BRIN indexes wereintroduced), but those releases are EOL already.Discussion:https://postgr.es/m/9d993d0d-e431-2196-9ccc-0554d0e60154%40enterprisedb.com
1 parent0409c7f commit2b1ab28

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,10 +515,13 @@ brin_inclusion_union(PG_FUNCTION_ARGS)
515515
FmgrInfo*finfo;
516516
Datumresult;
517517

518+
/* Does the "b" summary represent any NULL values? */
519+
boolb_has_nulls= (col_b->bv_hasnulls||col_b->bv_allnulls);
520+
518521
Assert(col_a->bv_attno==col_b->bv_attno);
519522

520523
/* Adjust "hasnulls". */
521-
if (!col_a->bv_hasnulls&&col_b->bv_hasnulls)
524+
if (!col_a->bv_allnulls&&b_has_nulls)
522525
col_a->bv_hasnulls= true;
523526

524527
/* If there are no values in B, there's nothing left to do. */
@@ -533,10 +536,15 @@ brin_inclusion_union(PG_FUNCTION_ARGS)
533536
* B into A, and we're done. We cannot run the operators in this case,
534537
* because values in A might contain garbage. Note we already established
535538
* that B contains values.
539+
*
540+
* Also adjust "hasnulls" in order not to forget the summary represents NULL
541+
* values. This is not redundant with the earlier update, because that only
542+
* happens when allnulls=false.
536543
*/
537544
if (col_a->bv_allnulls)
538545
{
539546
col_a->bv_allnulls= false;
547+
col_a->bv_hasnulls= true;
540548
col_a->bv_values[INCLUSION_UNION]=
541549
datumCopy(col_b->bv_values[INCLUSION_UNION],
542550
attr->attbyval,attr->attlen);

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,13 @@ brin_minmax_union(PG_FUNCTION_ARGS)
248248
FmgrInfo*finfo;
249249
boolneedsadj;
250250

251+
/* Does the "b" summary represent any NULL values? */
252+
boolb_has_nulls= (col_b->bv_hasnulls||col_b->bv_allnulls);
253+
251254
Assert(col_a->bv_attno==col_b->bv_attno);
252255

253256
/* Adjust "hasnulls" */
254-
if (!col_a->bv_hasnulls&&col_b->bv_hasnulls)
257+
if (!col_a->bv_allnulls&&b_has_nulls)
255258
col_a->bv_hasnulls= true;
256259

257260
/* If there are no values in B, there's nothing left to do */
@@ -266,10 +269,15 @@ brin_minmax_union(PG_FUNCTION_ARGS)
266269
* B into A, and we're done. We cannot run the operators in this case,
267270
* because values in A might contain garbage. Note we already established
268271
* that B contains values.
272+
*
273+
* Also adjust "hasnulls" in order not to forget the summary represents NULL
274+
* values. This is not redundant with the earlier update, because that only
275+
* happens when allnulls=false.
269276
*/
270277
if (col_a->bv_allnulls)
271278
{
272279
col_a->bv_allnulls= false;
280+
col_a->bv_hasnulls= true;
273281
col_a->bv_values[0]=datumCopy(col_b->bv_values[0],
274282
attr->attbyval,attr->attlen);
275283
col_a->bv_values[1]=datumCopy(col_b->bv_values[1],

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp