From 972bf7d6f13005dfe89ae3f8a3b937a4a0580c85 Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Thu, 22 Jan 2015 17:01:09 -0300 Subject: [PATCH] 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 --- src/backend/access/brin/brin_minmax.c | 19 ++++++++++--------- src/include/catalog/pg_opclass.h | 2 +- src/test/regress/expected/brin.out | 2 +- src/test/regress/sql/brin.sql | 2 +- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/backend/access/brin/brin_minmax.c b/src/backend/access/brin/brin_minmax.c index 68ea7d53357..299d6f7bf6e 100644 --- a/src/backend/access/brin/brin_minmax.c +++ b/src/backend/access/brin/brin_minmax.c @@ -256,23 +256,24 @@ brin_minmax_union(PG_FUNCTION_ARGS) Assert(col_a->bv_attno == col_b->bv_attno); - /* If there are no values in B, there's nothing to do */ + /* Adjust "hasnulls" */ + if (!col_a->bv_hasnulls && col_b->bv_hasnulls) + col_a->bv_hasnulls = true; + + /* If there are no values in B, there's nothing left to do */ if (col_b->bv_allnulls) PG_RETURN_VOID(); attno = col_a->bv_attno; attr = bdesc->bd_tupdesc->attrs[attno - 1]; - /* Adjust "hasnulls" */ - if (col_b->bv_hasnulls && !col_a->bv_hasnulls) - col_a->bv_hasnulls = true; - /* - * Adjust "allnulls". If B has values but A doesn't, just copy the values - * from B into A, and we're done. (We cannot run the operators in this - * case, because values in A might contain garbage.) + * Adjust "allnulls". If A doesn't have values, just copy the values + * from B into A, and we're done. We cannot run the operators in this + * case, because values in A might contain garbage. Note we already + * established that B contains values. */ - if (!col_b->bv_allnulls && col_a->bv_allnulls) + if (col_a->bv_allnulls) { col_a->bv_allnulls = false; col_a->bv_values[0] = datumCopy(col_b->bv_values[0], diff --git a/src/include/catalog/pg_opclass.h b/src/include/catalog/pg_opclass.h index f5d0f6eea18..b3acef66de2 100644 --- a/src/include/catalog/pg_opclass.h +++ b/src/include/catalog/pg_opclass.h @@ -252,7 +252,7 @@ DATA(insert ( 3580 float8_minmax_ops PGNSP PGUID 4070 701 t 0 )); DATA(insert ( 3580 abstime_minmax_ops PGNSP PGUID 4072 702 t 0 )); DATA(insert ( 3580 reltime_minmax_ops PGNSP PGUID 4073 703 t 0 )); DATA(insert ( 3580 macaddr_minmax_ops PGNSP PGUID 4074 829 t 0 )); -DATA(insert ( 3580 inet_minmax_ops PGNSP PGUID 4075 869 t 0 )); +DATA(insert ( 3580 inet_minmax_ops PGNSP PGUID 4075 869 f 0 )); DATA(insert ( 3580 bpchar_minmax_ops PGNSP PGUID 4076 1042 t 0 )); DATA(insert ( 3580 time_minmax_ops PGNSP PGUID 4077 1083 t 0 )); DATA(insert ( 3580 date_minmax_ops PGNSP PGUID 4059 1082 t 0 )); diff --git a/src/test/regress/expected/brin.out b/src/test/regress/expected/brin.out index 61a544efedd..f47f3663759 100644 --- a/src/test/regress/expected/brin.out +++ b/src/test/regress/expected/brin.out @@ -65,7 +65,7 @@ CREATE INDEX brinidx ON brintest USING brin ( float4col, float8col, macaddrcol, - inetcol, + inetcol inet_minmax_ops, bpcharcol, datecol, timecol, diff --git a/src/test/regress/sql/brin.sql b/src/test/regress/sql/brin.sql index b1d2c5c8eaa..3aff92529a1 100644 --- a/src/test/regress/sql/brin.sql +++ b/src/test/regress/sql/brin.sql @@ -68,7 +68,7 @@ CREATE INDEX brinidx ON brintest USING brin ( float4col, float8col, macaddrcol, - inetcol, + inetcol inet_minmax_ops, bpcharcol, datecol, timecol, -- 2.39.5