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
This commit is contained in:
parent
1a2b2034d4
commit
670bf71f65
@ -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 &&
|
||||
(*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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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>
|
||||
|
||||
|
@ -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;
|
||||
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);
|
||||
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;
|
||||
|
||||
}
|
||||
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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user