Tweak BRIN minmax operator class
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Thu, 22 Jan 2015 20:01:09 +0000 (17:01 -0300)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Thu, 22 Jan 2015 20:01:09 +0000 (17:01 -0300)
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
src/include/catalog/pg_opclass.h
src/test/regress/expected/brin.out
src/test/regress/sql/brin.sql

index 68ea7d533576d39ec6b902132d1666ad533fc302..299d6f7bf6e802cfe6b52ffabc71649e213b628d 100644 (file)
@@ -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],
index f5d0f6eea18de8f94bb47b623faebe5cb58d14c7..b3acef66de2deb971e2f2955157b58d720f8f565 100644 (file)
@@ -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 ));
index 61a544efedd6caf49b59ec90cffcbc439a14aea9..f47f3663759082326b31e69aa38725750fa7f135 100644 (file)
@@ -65,7 +65,7 @@ CREATE INDEX brinidx ON brintest USING brin (
    float4col,
    float8col,
    macaddrcol,
-   inetcol,
+   inetcol inet_minmax_ops,
    bpcharcol,
    datecol,
    timecol,
index b1d2c5c8eaa34e3eccde5b12913cedd6fc6fe4ca..3aff92529a14efbec09f914e7e84b98c22e4fbac 100644 (file)
@@ -68,7 +68,7 @@ CREATE INDEX brinidx ON brintest USING brin (
    float4col,
    float8col,
    macaddrcol,
-   inetcol,
+   inetcol inet_minmax_ops,
    bpcharcol,
    datecol,
    timecol,