Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 670bf71

Browse files
committed
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
1 parent 1a2b203 commit 670bf71

File tree

4 files changed

+25
-60
lines changed

4 files changed

+25
-60
lines changed

contrib/btree_gist/btree_utils_num.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,8 @@ gbt_num_same(const GBT_NUMKEY *a, const GBT_NUMKEY *b, const gbtree_ninfo *tinfo
147147
b2.lower = &(((GBT_NUMKEY *) b)[0]);
148148
b2.upper = &(((GBT_NUMKEY *) b)[tinfo->size]);
149149

150-
if (
151-
(*tinfo->f_eq) (b1.lower, b2.lower) &&
152-
(*tinfo->f_eq) (b1.upper, b2.upper)
153-
)
154-
return TRUE;
155-
return FALSE;
156-
150+
return ((*tinfo->f_eq) (b1.lower, b2.lower) &&
151+
(*tinfo->f_eq) (b1.upper, b2.upper));
157152
}
158153

159154

contrib/btree_gist/btree_utils_var.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,6 @@ bool
337337
gbt_var_same(Datum d1, Datum d2, Oid collation,
338338
const gbtree_vinfo *tinfo)
339339
{
340-
bool result;
341340
GBT_VARKEY *t1 = (GBT_VARKEY *) DatumGetPointer(d1);
342341
GBT_VARKEY *t2 = (GBT_VARKEY *) DatumGetPointer(d2);
343342
GBT_VARKEY_R r1,
@@ -346,13 +345,8 @@ gbt_var_same(Datum d1, Datum d2, Oid collation,
346345
r1 = gbt_var_key_readable(t1);
347346
r2 = gbt_var_key_readable(t2);
348347

349-
if (t1 && t2)
350-
result = ((*tinfo->f_cmp) (r1.lower, r2.lower, collation) == 0 &&
351-
(*tinfo->f_cmp) (r1.upper, r2.upper, collation) == 0);
352-
else
353-
result = (t1 == NULL && t2 == NULL);
354-
355-
return result;
348+
return ((*tinfo->f_cmp) (r1.lower, r2.lower, collation) == 0 &&
349+
(*tinfo->f_cmp) (r1.upper, r2.upper, collation) == 0);
356350
}
357351

358352

doc/src/sgml/gist.sgml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -497,12 +497,6 @@ my_compress(PG_FUNCTION_ARGS)
497497
type you're converting to in order to compress your leaf nodes, of
498498
course.
499499
</para>
500-
501-
<para>
502-
Depending on your needs, you could also need to care about
503-
compressing <literal>NULL</> values in there, storing for example
504-
<literal>(Datum) 0</> like <literal>gist_circle_compress</> does.
505-
</para>
506500
</listitem>
507501
</varlistentry>
508502

src/backend/access/gist/gistproc.c

Lines changed: 21 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,25 +1039,16 @@ gist_poly_compress(PG_FUNCTION_ARGS)
10391039

10401040
if (entry->leafkey)
10411041
{
1042-
retval = palloc(sizeof(GISTENTRY));
1043-
if (DatumGetPointer(entry->key) != NULL)
1044-
{
1045-
POLYGON *in = DatumGetPolygonP(entry->key);
1046-
BOX *r;
1042+
POLYGON *in = DatumGetPolygonP(entry->key);
1043+
BOX *r;
10471044

1048-
r = (BOX *) palloc(sizeof(BOX));
1049-
memcpy((void *) r, (void *) &(in->boundbox), sizeof(BOX));
1050-
gistentryinit(*retval, PointerGetDatum(r),
1051-
entry->rel, entry->page,
1052-
entry->offset, FALSE);
1045+
r = (BOX *) palloc(sizeof(BOX));
1046+
memcpy((void *) r, (void *) &(in->boundbox), sizeof(BOX));
10531047

1054-
}
1055-
else
1056-
{
1057-
gistentryinit(*retval, (Datum) 0,
1058-
entry->rel, entry->page,
1059-
entry->offset, FALSE);
1060-
}
1048+
retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
1049+
gistentryinit(*retval, PointerGetDatum(r),
1050+
entry->rel, entry->page,
1051+
entry->offset, FALSE);
10611052
}
10621053
else
10631054
retval = entry;
@@ -1113,28 +1104,19 @@ gist_circle_compress(PG_FUNCTION_ARGS)
11131104

11141105
if (entry->leafkey)
11151106
{
1116-
retval = palloc(sizeof(GISTENTRY));
1117-
if (DatumGetCircleP(entry->key) != NULL)
1118-
{
1119-
CIRCLE *in = DatumGetCircleP(entry->key);
1120-
BOX *r;
1121-
1122-
r = (BOX *) palloc(sizeof(BOX));
1123-
r->high.x = in->center.x + in->radius;
1124-
r->low.x = in->center.x - in->radius;
1125-
r->high.y = in->center.y + in->radius;
1126-
r->low.y = in->center.y - in->radius;
1127-
gistentryinit(*retval, PointerGetDatum(r),
1128-
entry->rel, entry->page,
1129-
entry->offset, FALSE);
1130-
1131-
}
1132-
else
1133-
{
1134-
gistentryinit(*retval, (Datum) 0,
1135-
entry->rel, entry->page,
1136-
entry->offset, FALSE);
1137-
}
1107+
CIRCLE *in = DatumGetCircleP(entry->key);
1108+
BOX *r;
1109+
1110+
r = (BOX *) palloc(sizeof(BOX));
1111+
r->high.x = in->center.x + in->radius;
1112+
r->low.x = in->center.x - in->radius;
1113+
r->high.y = in->center.y + in->radius;
1114+
r->low.y = in->center.y - in->radius;
1115+
1116+
retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
1117+
gistentryinit(*retval, PointerGetDatum(r),
1118+
entry->rel, entry->page,
1119+
entry->offset, FALSE);
11381120
}
11391121
else
11401122
retval = entry;

0 commit comments

Comments
 (0)