1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

Cleanup of GiST extensions in contrib/: now that we always invoke GiST

methods in a short-lived memory context, there is no need for GiST methods
to do their own manual (and error-prone) memory management.
This commit is contained in:
Neil Conway
2005-05-21 12:08:06 +00:00
parent 875813439d
commit 36ab600511
16 changed files with 18 additions and 174 deletions

View File

@ -127,7 +127,6 @@ gbt_bit_consistent(PG_FUNCTION_ARGS)
{
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(entry->key);
void *qtst = (void *) PG_GETARG_POINTER(1);
void *query = (void *) DatumGetByteaP(PG_GETARG_DATUM(1));
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
bool retval = FALSE;
@ -140,11 +139,7 @@ gbt_bit_consistent(PG_FUNCTION_ARGS)
bytea *q = gbt_bit_xfrm((bytea *) query);
retval = gbt_var_consistent(&r, (void *) q, &strategy, FALSE, &tinfo);
pfree(q);
}
if (qtst != query)
pfree(query);
PG_RETURN_BOOL(retval);
}

View File

@ -97,16 +97,12 @@ gbt_bytea_consistent(PG_FUNCTION_ARGS)
{
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(entry->key);
void *qtst = (void *) PG_GETARG_POINTER(1);
void *query = (void *) DatumGetByteaP(PG_GETARG_DATUM(1));
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
bool retval = FALSE;
bool retval;
GBT_VARKEY_R r = gbt_var_key_readable(key);
retval = gbt_var_consistent(&r, query, &strategy, GIST_LEAF(entry), &tinfo);
if (qtst != query)
pfree(query);
PG_RETURN_BOOL(retval);
}

View File

@ -98,16 +98,12 @@ gbt_numeric_consistent(PG_FUNCTION_ARGS)
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(entry->key);
void *qtst = (void *) PG_GETARG_POINTER(1);
void *query = (void *) DatumGetNumeric(PG_GETARG_DATUM(1));
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
bool retval = FALSE;
bool retval;
GBT_VARKEY_R r = gbt_var_key_readable(key);
retval = gbt_var_consistent(&r, query, &strategy, GIST_LEAF(entry), &tinfo);
if (qtst != query)
pfree(query);
PG_RETURN_BOOL(retval);
}
@ -164,8 +160,6 @@ gbt_numeric_penalty(PG_FUNCTION_ARGS)
PointerGetDatum(uk.lower)
));
pfree(DatumGetPointer(uni));
os = DatumGetNumeric(DirectFunctionCall2(
numeric_sub,
PointerGetDatum(ok.upper),
@ -178,27 +172,21 @@ gbt_numeric_penalty(PG_FUNCTION_ARGS)
NumericGetDatum(os)
));
pfree(os);
if (NUMERIC_IS_NAN(us))
{
if (NUMERIC_IS_NAN(os))
*result = 0.0;
else
*result = 1.0;
}
else
{
Numeric nul = DatumGetNumeric(DirectFunctionCall1(int4_numeric, Int32GetDatum(0)));
*result = 0.0;
if (DirectFunctionCall2(numeric_gt, NumericGetDatum(ds), NumericGetDatum(nul)))
{
*result += FLT_MIN;
os = DatumGetNumeric(DirectFunctionCall2(
numeric_div,
@ -206,19 +194,12 @@ gbt_numeric_penalty(PG_FUNCTION_ARGS)
NumericGetDatum(us)
));
*result += (float4) DatumGetFloat8(DirectFunctionCall1(numeric_float8_no_overflow, NumericGetDatum(os)));
pfree(os);
}
pfree(nul);
}
if (*result > 0)
*result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
pfree(us);
pfree(ds);
PG_RETURN_POINTER(result);
}

View File

@ -108,8 +108,6 @@ gbt_bpchar_compress(PG_FUNCTION_ARGS)
entry->rel, entry->page,
entry->offset, VARSIZE(DatumGetPointer(d)), TRUE);
retval = gbt_var_compress(&trim, &tinfo);
pfree(DatumGetPointer(d));
}
else
retval = entry;
@ -124,7 +122,6 @@ gbt_text_consistent(PG_FUNCTION_ARGS)
{
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(entry->key);
void *qtst = (void *) PG_GETARG_POINTER(1);
void *query = (void *) DatumGetTextP(PG_GETARG_DATUM(1));
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
bool retval = FALSE;
@ -132,9 +129,6 @@ gbt_text_consistent(PG_FUNCTION_ARGS)
retval = gbt_var_consistent(&r, query, &strategy, GIST_LEAF(entry), &tinfo);
if (qtst != query)
pfree(query);
PG_RETURN_BOOL(retval);
}
@ -144,25 +138,17 @@ gbt_bpchar_consistent(PG_FUNCTION_ARGS)
{
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(entry->key);
void *qtst = (void *) PG_GETARG_POINTER(1);
void *query = (void *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(1)));
void *trim = (void *) DatumGetPointer(DirectFunctionCall1(rtrim1, PointerGetDatum(query)));
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
bool retval = FALSE;
bool retval;
GBT_VARKEY_R r = gbt_var_key_readable(key);
retval = gbt_var_consistent(&r, trim, &strategy, GIST_LEAF(entry), &tinfo);
pfree(trim);
if (qtst != query)
pfree(query);
PG_RETURN_BOOL(retval);
}
Datum
gbt_text_union(PG_FUNCTION_ARGS)
{

View File

@ -222,7 +222,6 @@ gbt_time_penalty(PG_FUNCTION_ARGS)
/* see interval_larger */
res = Max(intr->time + intr->month * (30 * 86400), 0);
pfree(intr);
intr = DatumGetIntervalP(DirectFunctionCall2(
time_mi_time,
@ -231,7 +230,6 @@ gbt_time_penalty(PG_FUNCTION_ARGS)
/* see interval_larger */
res += Max(intr->time + intr->month * (30 * 86400), 0);
pfree(intr);
*result = 0.0;
@ -244,7 +242,6 @@ gbt_time_penalty(PG_FUNCTION_ARGS)
*result += FLT_MIN;
*result += (float) (res / ((double) (res + intr->time + intr->month * (30 * 86400))));
*result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
pfree(intr);
}
PG_RETURN_POINTER(result);

View File

@ -226,7 +226,6 @@ gbt_ts_penalty(PG_FUNCTION_ARGS)
#ifdef HAVE_INT64_TIMESTAMP
int64 res;
#else
double res;
#endif
@ -240,7 +239,6 @@ gbt_ts_penalty(PG_FUNCTION_ARGS)
/* see interval_larger */
res = Max(intr->time + intr->month * (30 * 86400), 0);
pfree(intr);
intr = DatumGetIntervalP(DirectFunctionCall2(
timestamp_mi,
@ -250,7 +248,6 @@ gbt_ts_penalty(PG_FUNCTION_ARGS)
/* see interval_larger */
res += Max(intr->time + intr->month * (30 * 86400), 0);
pfree(intr);
*result = 0.0;
@ -264,11 +261,9 @@ gbt_ts_penalty(PG_FUNCTION_ARGS)
*result += FLT_MIN;
*result += (float) (res / ((double) (res + intr->time + intr->month * (30 * 86400))));
*result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
pfree(intr);
}
PG_RETURN_POINTER(result);
}

View File

@ -246,7 +246,5 @@ gbt_num_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v,
}
}
pfree(arr);
return v;
}

View File

@ -9,21 +9,21 @@ Datum gbt_var_decompress(PG_FUNCTION_ARGS);
Datum
gbt_var_decompress(PG_FUNCTION_ARGS)
{
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(PG_DETOAST_DATUM(entry->key));
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(PG_DETOAST_DATUM(entry->key));
if (key != (GBT_VARKEY *) DatumGetPointer(entry->key))
{
GISTENTRY *retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
if (key != (GBT_VARKEY *) DatumGetPointer(entry->key))
{
GISTENTRY *retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
gistentryinit(*retval, PointerGetDatum(key),
entry->rel, entry->page,
entry->offset, VARSIZE(key), FALSE);
gistentryinit(*retval, PointerGetDatum(key),
entry->rel, entry->page,
entry->offset, VARSIZE(key), FALSE);
PG_RETURN_POINTER(retval);
}
PG_RETURN_POINTER(retval);
}
PG_RETURN_POINTER(entry);
PG_RETURN_POINTER(entry);
}
/* Returns a better readable representaion of variable key ( sets pointer ) */
@ -216,7 +216,6 @@ gbt_var_bin_union(Datum *u, GBT_VARKEY * e, const gbtree_vinfo * tinfo)
GBT_VARKEY_R nr;
GBT_VARKEY_R eo = gbt_var_key_readable(e);
if (eo.lower == eo.upper) /* leaf */
{
tmp = gbt_var_leaf2node(e, tinfo);
@ -235,20 +234,16 @@ gbt_var_bin_union(Datum *u, GBT_VARKEY * e, const gbtree_vinfo * tinfo)
nr.upper = ro.upper;
nk = gbt_var_key_copy(&nr, TRUE);
}
if ((*tinfo->f_cmp) ((bytea *) ro.upper, (bytea *) eo.upper) < 0)
{
nr.upper = eo.upper;
nr.lower = ro.lower;
nk = gbt_var_key_copy(&nr, TRUE);
}
if (nk)
{
pfree(DatumGetPointer(*u));
*u = PointerGetDatum(nk);
}
}
else
{
@ -256,10 +251,6 @@ gbt_var_bin_union(Datum *u, GBT_VARKEY * e, const gbtree_vinfo * tinfo)
nr.upper = eo.upper;
*u = PointerGetDatum(gbt_var_key_copy(&nr, TRUE));
}
if (tmp && tmp != e)
pfree(tmp);
}
@ -273,15 +264,12 @@ gbt_var_compress(GISTENTRY *entry, const gbtree_vinfo * tinfo)
if (entry->leafkey)
{
GBT_VARKEY *r = NULL;
bytea *tstd = (bytea *) DatumGetPointer(entry->key); /* toasted */
bytea *leaf = (bytea *) DatumGetPointer(PG_DETOAST_DATUM(entry->key)); /* untoasted */
bytea *leaf = (bytea *) DatumGetPointer(PG_DETOAST_DATUM(entry->key));
GBT_VARKEY_R u;
u.lower = u.upper = leaf;
r = gbt_var_key_copy(&u, FALSE);
if (tstd != leaf)
pfree(leaf);
retval = palloc(sizeof(GISTENTRY));
gistentryinit(*retval, PointerGetDatum(r),
entry->rel, entry->page,
@ -319,7 +307,6 @@ gbt_var_union(const GistEntryVector *entryvec, int32 *size, const gbtree_vinfo *
/* Truncate (=compress) key */
if (tinfo->trnc)
{
int32 plen;
@ -328,7 +315,6 @@ gbt_var_union(const GistEntryVector *entryvec, int32 *size, const gbtree_vinfo *
plen = gbt_var_node_cp_len((GBT_VARKEY *) DatumGetPointer(out), tinfo);
trc = gbt_var_node_truncate((GBT_VARKEY *) DatumGetPointer(out), plen + 1, tinfo);
pfree(DatumGetPointer(out));
out = PointerGetDatum(trc);
}
@ -428,17 +414,12 @@ gbt_var_penalty(float *res, const GISTENTRY *o, const GISTENTRY *n, const gbtree
}
dres /= 256.0;
}
pfree(DatumGetPointer(d));
*res += FLT_MIN;
*res += (float) (dres / ((double) (ol + 1)));
*res *= (FLT_MAX / (o->rel->rd_att->natts + 1));
}
if (tmp && tmp != newe)
pfree(tmp);
return res;
}
@ -524,18 +505,9 @@ gbt_var_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v, const gbtre
}
}
/* Free strxfrm'ed leafs */
for (i = 0; i < svcntr; i++)
pfree(sv[i]);
if (sv)
pfree(sv);
/* Truncate (=compress) key */
if (tinfo->trnc)
{
int32 ll = gbt_var_node_cp_len((GBT_VARKEY *) DatumGetPointer(v->spl_ldatum), tinfo);
int32 lr = gbt_var_node_cp_len((GBT_VARKEY *) DatumGetPointer(v->spl_rdatum), tinfo);
GBT_VARKEY *dl;
@ -546,15 +518,10 @@ gbt_var_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v, const gbtre
dl = gbt_var_node_truncate((GBT_VARKEY *) DatumGetPointer(v->spl_ldatum), ll, tinfo);
dr = gbt_var_node_truncate((GBT_VARKEY *) DatumGetPointer(v->spl_rdatum), ll, tinfo);
pfree(DatumGetPointer(v->spl_ldatum));
pfree(DatumGetPointer(v->spl_rdatum));
v->spl_ldatum = PointerGetDatum(dl);
v->spl_rdatum = PointerGetDatum(dr);
}
pfree(arr);
return v;
}