Remove dead NULL-pointer checks in GiST code.
authorHeikki Linnakangas <[email protected]>
Wed, 28 Jan 2015 07:47:39 +0000 (09:47 +0200)
committerHeikki Linnakangas <[email protected]>
Wed, 28 Jan 2015 08:03:58 +0000 (10:03 +0200)
gist_poly_compress() and gist_circle_compress() checked for a NULL-pointer
key argument, but that was dead code; the gist code never passes a
NULL-pointer to the "compress" method.

This commit also removes a documentation note added in commit a0a3883,
about doing NULL-pointer checks in the "compress" method. It was added
based on the fact that some implementations were doing NULL-pointer
checks, but those checks were unnecessary in the first place.

The NULL-pointer check in gbt_var_same() function was also unnecessary.
The arguments to the "same" method come from the "compress", "union", or
"picksplit" methods, but none of them return a NULL pointer.

None of this is to be confused with SQL NULL values. Those are dealt with
by the gist machinery, and are never passed to the GiST opclass methods.

Michael Paquier

contrib/btree_gist/btree_utils_num.c
contrib/btree_gist/btree_utils_var.c
doc/src/sgml/gist.sgml
src/backend/access/gist/gistproc.c

index 505633c98b815bf15c52e5254a64697fa6e959db..7adf3aac48e61e23e9e436163f579a3bfb6e542e 100644 (file)
@@ -147,13 +147,8 @@ gbt_num_same(const GBT_NUMKEY *a, const GBT_NUMKEY *b, const gbtree_ninfo *tinfo
    b2.lower = &(((GBT_NUMKEY *) b)[0]);
    b2.upper = &(((GBT_NUMKEY *) b)[tinfo->size]);
 
-   if (
-       (*tinfo->f_eq) (b1.lower, b2.lower) &&
-       (*tinfo->f_eq) (b1.upper, b2.upper)
-       )
-       return TRUE;
-   return FALSE;
-
+   return ((*tinfo->f_eq) (b1.lower, b2.lower) &&
+           (*tinfo->f_eq) (b1.upper, b2.upper));
 }
 
 
index b7dd060a944ba237a8ab48e55f3a6ba5f2cb9c72..6ad33478d09f0b05fe54a145b702047481410d4a 100644 (file)
@@ -337,7 +337,6 @@ bool
 gbt_var_same(Datum d1, Datum d2, Oid collation,
             const gbtree_vinfo *tinfo)
 {
-   bool        result;
    GBT_VARKEY *t1 = (GBT_VARKEY *) DatumGetPointer(d1);
    GBT_VARKEY *t2 = (GBT_VARKEY *) DatumGetPointer(d2);
    GBT_VARKEY_R r1,
@@ -346,13 +345,8 @@ gbt_var_same(Datum d1, Datum d2, Oid collation,
    r1 = gbt_var_key_readable(t1);
    r2 = gbt_var_key_readable(t2);
 
-   if (t1 && t2)
-       result = ((*tinfo->f_cmp) (r1.lower, r2.lower, collation) == 0 &&
-                 (*tinfo->f_cmp) (r1.upper, r2.upper, collation) == 0);
-   else
-       result = (t1 == NULL && t2 == NULL);
-
-   return result;
+   return ((*tinfo->f_cmp) (r1.lower, r2.lower, collation) == 0 &&
+           (*tinfo->f_cmp) (r1.upper, r2.upper, collation) == 0);
 }
 
 
index 5de282b29485aa50a4b57ff2e9cf154994bb4c1c..31ce2790047e5487d5e24e08200eefaaa2a5c85c 100644 (file)
@@ -497,12 +497,6 @@ my_compress(PG_FUNCTION_ARGS)
        type you're converting to in order to compress your leaf nodes, of
        course.
       </para>
-
-      <para>
-        Depending on your needs, you could also need to care about
-        compressing <literal>NULL</> values in there, storing for example
-        <literal>(Datum) 0</> like <literal>gist_circle_compress</> does.
-      </para>
      </listitem>
     </varlistentry>
 
index 4decaa6f14dd1cd7c9877d9b59c1a6f77abe24ab..9fab6c87c0573f7207471c97ea0847cc81e32ccf 100644 (file)
@@ -1039,25 +1039,16 @@ gist_poly_compress(PG_FUNCTION_ARGS)
 
    if (entry->leafkey)
    {
-       retval = palloc(sizeof(GISTENTRY));
-       if (DatumGetPointer(entry->key) != NULL)
-       {
-           POLYGON    *in = DatumGetPolygonP(entry->key);
-           BOX        *r;
+       POLYGON    *in = DatumGetPolygonP(entry->key);
+       BOX        *r;
 
-           r = (BOX *) palloc(sizeof(BOX));
-           memcpy((void *) r, (void *) &(in->boundbox), sizeof(BOX));
-           gistentryinit(*retval, PointerGetDatum(r),
-                         entry->rel, entry->page,
-                         entry->offset, FALSE);
+       r = (BOX *) palloc(sizeof(BOX));
+       memcpy((void *) r, (void *) &(in->boundbox), sizeof(BOX));
 
-       }
-       else
-       {
-           gistentryinit(*retval, (Datum) 0,
-                         entry->rel, entry->page,
-                         entry->offset, FALSE);
-       }
+       retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
+       gistentryinit(*retval, PointerGetDatum(r),
+                     entry->rel, entry->page,
+                     entry->offset, FALSE);
    }
    else
        retval = entry;
@@ -1113,28 +1104,19 @@ gist_circle_compress(PG_FUNCTION_ARGS)
 
    if (entry->leafkey)
    {
-       retval = palloc(sizeof(GISTENTRY));
-       if (DatumGetCircleP(entry->key) != NULL)
-       {
-           CIRCLE     *in = DatumGetCircleP(entry->key);
-           BOX        *r;
-
-           r = (BOX *) palloc(sizeof(BOX));
-           r->high.x = in->center.x + in->radius;
-           r->low.x = in->center.x - in->radius;
-           r->high.y = in->center.y + in->radius;
-           r->low.y = in->center.y - in->radius;
-           gistentryinit(*retval, PointerGetDatum(r),
-                         entry->rel, entry->page,
-                         entry->offset, FALSE);
-
-       }
-       else
-       {
-           gistentryinit(*retval, (Datum) 0,
-                         entry->rel, entry->page,
-                         entry->offset, FALSE);
-       }
+       CIRCLE     *in = DatumGetCircleP(entry->key);
+       BOX        *r;
+
+       r = (BOX *) palloc(sizeof(BOX));
+       r->high.x = in->center.x + in->radius;
+       r->low.x = in->center.x - in->radius;
+       r->high.y = in->center.y + in->radius;
+       r->low.y = in->center.y - in->radius;
+
+       retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
+       gistentryinit(*retval, PointerGetDatum(r),
+                     entry->rel, entry->page,
+                     entry->offset, FALSE);
    }
    else
        retval = entry;