summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeikki Linnakangas2015-01-28 07:47:39 +0000
committerHeikki Linnakangas2015-01-28 08:03:58 +0000
commit670bf71f65c2315fc2ea7265d540402093db8cef (patch)
treee77a2a457ceac76e75b787950e8d58fe9aa72a48
parent1a2b2034d48d46ec3d128b167cb7df317b4cd49a (diff)
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
-rw-r--r--contrib/btree_gist/btree_utils_num.c9
-rw-r--r--contrib/btree_gist/btree_utils_var.c10
-rw-r--r--doc/src/sgml/gist.sgml6
-rw-r--r--src/backend/access/gist/gistproc.c60
4 files changed, 25 insertions, 60 deletions
diff --git a/contrib/btree_gist/btree_utils_num.c b/contrib/btree_gist/btree_utils_num.c
index 505633c98b..7adf3aac48 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 b7dd060a94..6ad33478d0 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 5de282b294..31ce279004 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.
</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>
diff --git a/src/backend/access/gist/gistproc.c b/src/backend/access/gist/gistproc.c
index 4decaa6f14..9fab6c87c0 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;