Commit 670bf71f authored by Heikki Linnakangas's avatar Heikki Linnakangas

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 a0a3883d,
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
parent 1a2b2034
......@@ -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));
}
......
......@@ -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 &&
return ((*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;
}
......
......@@ -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>
......
......@@ -1038,27 +1038,18 @@ gist_poly_compress(PG_FUNCTION_ARGS)
GISTENTRY *retval;
if (entry->leafkey)
{
retval = palloc(sizeof(GISTENTRY));
if (DatumGetPointer(entry->key) != NULL)
{
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);
}
else
{
gistentryinit(*retval, (Datum) 0,
retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
gistentryinit(*retval, PointerGetDatum(r),
entry->rel, entry->page,
entry->offset, FALSE);
}
}
else
retval = entry;
PG_RETURN_POINTER(retval);
......@@ -1112,9 +1103,6 @@ gist_circle_compress(PG_FUNCTION_ARGS)
GISTENTRY *retval;
if (entry->leafkey)
{
retval = palloc(sizeof(GISTENTRY));
if (DatumGetCircleP(entry->key) != NULL)
{
CIRCLE *in = DatumGetCircleP(entry->key);
BOX *r;
......@@ -1124,18 +1112,12 @@ gist_circle_compress(PG_FUNCTION_ARGS)
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,
retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
gistentryinit(*retval, PointerGetDatum(r),
entry->rel, entry->page,
entry->offset, FALSE);
}
}
else
retval = entry;
PG_RETURN_POINTER(retval);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment