Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 972bf7d

Browse files
committed
Tweak BRIN minmax operator class
In the union support proc, we were not checking the hasnulls flag of value A early enough, so it could be skipped if the "allnulls" flag in value B is set. Also, a check on the allnulls flag of value "B" was redundant, so remove it. Also change inet_minmax_ops to not be the default opclass for type inet, as a future inclusion operator class would be more useful and it's pretty difficult to change default opclass for a datatype later on. (There is no catversion bump for this catalog change; this shouldn't be a problem.) Extracted from a larger patch to add an "inclusion" operator class. Author: Emre Hasegeli
1 parent b04d691 commit 972bf7d

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

src/backend/access/brin/brin_minmax.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -256,23 +256,24 @@ brin_minmax_union(PG_FUNCTION_ARGS)
256256

257257
Assert(col_a->bv_attno == col_b->bv_attno);
258258

259-
/* If there are no values in B, there's nothing to do */
259+
/* Adjust "hasnulls" */
260+
if (!col_a->bv_hasnulls && col_b->bv_hasnulls)
261+
col_a->bv_hasnulls = true;
262+
263+
/* If there are no values in B, there's nothing left to do */
260264
if (col_b->bv_allnulls)
261265
PG_RETURN_VOID();
262266

263267
attno = col_a->bv_attno;
264268
attr = bdesc->bd_tupdesc->attrs[attno - 1];
265269

266-
/* Adjust "hasnulls" */
267-
if (col_b->bv_hasnulls && !col_a->bv_hasnulls)
268-
col_a->bv_hasnulls = true;
269-
270270
/*
271-
* Adjust "allnulls". If B has values but A doesn't, just copy the values
272-
* from B into A, and we're done. (We cannot run the operators in this
273-
* case, because values in A might contain garbage.)
271+
* Adjust "allnulls". If A doesn't have values, just copy the values
272+
* from B into A, and we're done. We cannot run the operators in this
273+
* case, because values in A might contain garbage. Note we already
274+
* established that B contains values.
274275
*/
275-
if (!col_b->bv_allnulls && col_a->bv_allnulls)
276+
if (col_a->bv_allnulls)
276277
{
277278
col_a->bv_allnulls = false;
278279
col_a->bv_values[0] = datumCopy(col_b->bv_values[0],

src/include/catalog/pg_opclass.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ DATA(insert ( 3580 float8_minmax_ops PGNSP PGUID 4070 701 t 0 ));
252252
DATA(insert ( 3580 abstime_minmax_ops PGNSP PGUID 4072 702 t 0 ));
253253
DATA(insert ( 3580 reltime_minmax_ops PGNSP PGUID 4073 703 t 0 ));
254254
DATA(insert ( 3580 macaddr_minmax_ops PGNSP PGUID 4074 829 t 0 ));
255-
DATA(insert ( 3580 inet_minmax_ops PGNSP PGUID 4075 869 t 0 ));
255+
DATA(insert ( 3580 inet_minmax_ops PGNSP PGUID 4075 869 f 0 ));
256256
DATA(insert ( 3580 bpchar_minmax_ops PGNSP PGUID 4076 1042 t 0 ));
257257
DATA(insert ( 3580 time_minmax_ops PGNSP PGUID 4077 1083 t 0 ));
258258
DATA(insert ( 3580 date_minmax_ops PGNSP PGUID 4059 1082 t 0 ));

src/test/regress/expected/brin.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ CREATE INDEX brinidx ON brintest USING brin (
6565
float4col,
6666
float8col,
6767
macaddrcol,
68-
inetcol,
68+
inetcol inet_minmax_ops,
6969
bpcharcol,
7070
datecol,
7171
timecol,

src/test/regress/sql/brin.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ CREATE INDEX brinidx ON brintest USING brin (
6868
float4col,
6969
float8col,
7070
macaddrcol,
71-
inetcol,
71+
inetcol inet_minmax_ops,
7272
bpcharcol,
7373
datecol,
7474
timecol,

0 commit comments

Comments
 (0)