From: Heikki Linnakangas Date: Wed, 28 Jan 2015 07:47:39 +0000 (+0200) Subject: Remove dead NULL-pointer checks in GiST code. X-Git-Tag: REL9_5_ALPHA1~862 X-Git-Url: http://git.postgresql.org/gitweb/?a=commitdiff_plain;h=670bf71f65c2315fc2ea7265d540402093db8cef;p=postgresql.git Remove dead NULL-pointer checks in GiST code. 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 --- diff --git a/contrib/btree_gist/btree_utils_num.c b/contrib/btree_gist/btree_utils_num.c index 505633c98b8..7adf3aac48e 100644 --- a/contrib/btree_gist/btree_utils_num.c +++ b/contrib/btree_gist/btree_utils_num.c @@ -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)); } diff --git a/contrib/btree_gist/btree_utils_var.c b/contrib/btree_gist/btree_utils_var.c index b7dd060a944..6ad33478d09 100644 --- a/contrib/btree_gist/btree_utils_var.c +++ b/contrib/btree_gist/btree_utils_var.c @@ -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); } diff --git a/doc/src/sgml/gist.sgml b/doc/src/sgml/gist.sgml index 5de282b2948..31ce2790047 100644 --- a/doc/src/sgml/gist.sgml +++ b/doc/src/sgml/gist.sgml @@ -497,12 +497,6 @@ my_compress(PG_FUNCTION_ARGS) type you're converting to in order to compress your leaf nodes, of course. - - - Depending on your needs, you could also need to care about - compressing NULL values in there, storing for example - (Datum) 0 like gist_circle_compress does. - diff --git a/src/backend/access/gist/gistproc.c b/src/backend/access/gist/gistproc.c index 4decaa6f14d..9fab6c87c05 100644 --- a/src/backend/access/gist/gistproc.c +++ b/src/backend/access/gist/gistproc.c @@ -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;