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

Commitd42ffda

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 parent0966291 commitd42ffda

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
@@ -249,10 +249,13 @@ brin_minmax_union(PG_FUNCTION_ARGS)
249249
FmgrInfo*finfo;
250250
boolneedsadj;
251251

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

254257
/* Adjust "hasnulls" */
255-
if (!col_a->bv_hasnulls&&col_b->bv_hasnulls)
258+
if (!col_a->bv_allnulls&&b_has_nulls)
256259
col_a->bv_hasnulls= true;
257260

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp