Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 28d03fe

Browse files
committed
Minor cleanups in the BRIN code
BRIN bloom and minmax-multi opclasses were somewhat inconsistent when dealing with bool variables, assigning to them Datum values etc. While not a bug, it makes the code harder to understand, so fix that. While at it, update an incorrect comment copied to bloom opclass from minmax, talking about strategies not supported by bloom. Reviewed-by: Heikki Linnakangas Discussion: https://postgr.es/m/0e1f3350-c9cf-ab62-43a5-5dae314de89c%40enterprisedb.com
1 parent 4f49b3f commit 28d03fe

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

src/backend/access/brin/brin_bloom.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ brin_bloom_consistent(PG_FUNCTION_ARGS)
574574
Oid colloid = PG_GET_COLLATION();
575575
AttrNumber attno;
576576
Datum value;
577-
Datum matches;
577+
bool matches;
578578
FmgrInfo *finfo;
579579
uint32 hashValue;
580580
BloomFilter *filter;
@@ -584,6 +584,10 @@ brin_bloom_consistent(PG_FUNCTION_ARGS)
584584

585585
Assert(filter);
586586

587+
/*
588+
* Assume all scan keys match. We'll be searching for a scan key eliminating
589+
* the page range (we can stop on the first such key).
590+
*/
587591
matches = true;
588592

589593
for (keyno = 0; keyno < nkeys; keyno++)
@@ -601,9 +605,8 @@ brin_bloom_consistent(PG_FUNCTION_ARGS)
601605
case BloomEqualStrategyNumber:
602606

603607
/*
604-
* In the equality case (WHERE col = someval), we want to
605-
* return the current page range if the minimum value in the
606-
* range <= scan key, and the maximum value >= scan key.
608+
* We want to return the current page range if the bloom filter
609+
* seems to contain the value.
607610
*/
608611
finfo = bloom_get_procinfo(bdesc, attno, PROCNUM_HASH);
609612

@@ -614,15 +617,15 @@ brin_bloom_consistent(PG_FUNCTION_ARGS)
614617
default:
615618
/* shouldn't happen */
616619
elog(ERROR, "invalid strategy number %d", key->sk_strategy);
617-
matches = 0;
620+
matches = false;
618621
break;
619622
}
620623

621624
if (!matches)
622625
break;
623626
}
624627

625-
PG_RETURN_DATUM(matches);
628+
PG_RETURN_BOOL(matches);
626629
}
627630

628631
/*

src/backend/access/brin/brin_minmax_multi.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2602,7 +2602,7 @@ brin_minmax_multi_consistent(PG_FUNCTION_ARGS)
26022602

26032603
for (keyno = 0; keyno < nkeys; keyno++)
26042604
{
2605-
Datum matches;
2605+
bool matches;
26062606
ScanKey key = keys[keyno];
26072607

26082608
/* NULL keys are handled and filtered-out in bringetbitmap */
@@ -2618,7 +2618,7 @@ brin_minmax_multi_consistent(PG_FUNCTION_ARGS)
26182618
finfo = minmax_multi_get_strategy_procinfo(bdesc, attno, subtype,
26192619
key->sk_strategy);
26202620
/* first value from the array */
2621-
matches = FunctionCall2Coll(finfo, colloid, minval, value);
2621+
matches = DatumGetBool(FunctionCall2Coll(finfo, colloid, minval, value));
26222622
break;
26232623

26242624
case BTEqualStrategyNumber:
@@ -2664,18 +2664,18 @@ brin_minmax_multi_consistent(PG_FUNCTION_ARGS)
26642664
finfo = minmax_multi_get_strategy_procinfo(bdesc, attno, subtype,
26652665
key->sk_strategy);
26662666
/* last value from the array */
2667-
matches = FunctionCall2Coll(finfo, colloid, maxval, value);
2667+
matches = DatumGetBool(FunctionCall2Coll(finfo, colloid, maxval, value));
26682668
break;
26692669

26702670
default:
26712671
/* shouldn't happen */
26722672
elog(ERROR, "invalid strategy number %d", key->sk_strategy);
2673-
matches = 0;
2673+
matches = false;
26742674
break;
26752675
}
26762676

26772677
/* the range has to match all the scan keys */
2678-
matching &= DatumGetBool(matches);
2678+
matching &= matches;
26792679

26802680
/* once we find a non-matching key, we're done */
26812681
if (!matching)
@@ -2686,7 +2686,7 @@ brin_minmax_multi_consistent(PG_FUNCTION_ARGS)
26862686
* have we found a range matching all scan keys? if yes, we're done
26872687
*/
26882688
if (matching)
2689-
PG_RETURN_DATUM(BoolGetDatum(true));
2689+
PG_RETURN_BOOL(true);
26902690
}
26912691

26922692
/*
@@ -2703,7 +2703,7 @@ brin_minmax_multi_consistent(PG_FUNCTION_ARGS)
27032703

27042704
for (keyno = 0; keyno < nkeys; keyno++)
27052705
{
2706-
Datum matches;
2706+
bool matches;
27072707
ScanKey key = keys[keyno];
27082708

27092709
/* we've already dealt with NULL keys at the beginning */
@@ -2723,18 +2723,18 @@ brin_minmax_multi_consistent(PG_FUNCTION_ARGS)
27232723

27242724
finfo = minmax_multi_get_strategy_procinfo(bdesc, attno, subtype,
27252725
key->sk_strategy);
2726-
matches = FunctionCall2Coll(finfo, colloid, val, value);
2726+
matches = DatumGetBool(FunctionCall2Coll(finfo, colloid, val, value));
27272727
break;
27282728

27292729
default:
27302730
/* shouldn't happen */
27312731
elog(ERROR, "invalid strategy number %d", key->sk_strategy);
2732-
matches = 0;
2732+
matches = false;
27332733
break;
27342734
}
27352735

27362736
/* the range has to match all the scan keys */
2737-
matching &= DatumGetBool(matches);
2737+
matching &= matches;
27382738

27392739
/* once we find a non-matching key, we're done */
27402740
if (!matching)
@@ -2743,10 +2743,10 @@ brin_minmax_multi_consistent(PG_FUNCTION_ARGS)
27432743

27442744
/* have we found a range matching all scan keys? if yes, we're done */
27452745
if (matching)
2746-
PG_RETURN_DATUM(BoolGetDatum(true));
2746+
PG_RETURN_BOOL(true);
27472747
}
27482748

2749-
PG_RETURN_DATUM(BoolGetDatum(false));
2749+
PG_RETURN_BOOL(false);
27502750
}
27512751

27522752
/*

0 commit comments

Comments
 (0)