Minor refactoring of btree_gist code.
The gbt_var_key_copy function was doing two different things depending on the boolean argument. Seems cleaner to have two separate functions. Remove unused argument from gbt_num_compress.
This commit is contained in:
parent
55b59eda13
commit
8816af65e4
17 changed files with 51 additions and 54 deletions
|
@ -99,7 +99,7 @@ gbt_bit_l2n(GBT_VARKEY *leaf)
|
|||
|
||||
o = gbt_bit_xfrm(r.lower);
|
||||
r.upper = r.lower = o;
|
||||
out = gbt_var_key_copy(&r, TRUE);
|
||||
out = gbt_var_key_copy(&r);
|
||||
pfree(o);
|
||||
|
||||
return out;
|
||||
|
|
|
@ -119,9 +119,8 @@ Datum
|
|||
gbt_cash_compress(PG_FUNCTION_ARGS)
|
||||
{
|
||||
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
|
||||
GISTENTRY *retval = NULL;
|
||||
|
||||
PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
|
||||
PG_RETURN_POINTER(gbt_num_compress(entry, &tinfo));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -130,9 +130,8 @@ Datum
|
|||
gbt_date_compress(PG_FUNCTION_ARGS)
|
||||
{
|
||||
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
|
||||
GISTENTRY *retval = NULL;
|
||||
|
||||
PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
|
||||
PG_RETURN_POINTER(gbt_num_compress(entry, &tinfo));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -112,9 +112,8 @@ Datum
|
|||
gbt_float4_compress(PG_FUNCTION_ARGS)
|
||||
{
|
||||
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
|
||||
GISTENTRY *retval = NULL;
|
||||
|
||||
PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
|
||||
PG_RETURN_POINTER(gbt_num_compress(entry, &tinfo));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -119,9 +119,8 @@ Datum
|
|||
gbt_float8_compress(PG_FUNCTION_ARGS)
|
||||
{
|
||||
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
|
||||
GISTENTRY *retval = NULL;
|
||||
|
||||
PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
|
||||
PG_RETURN_POINTER(gbt_num_compress(entry, &tinfo));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -119,9 +119,8 @@ Datum
|
|||
gbt_int2_compress(PG_FUNCTION_ARGS)
|
||||
{
|
||||
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
|
||||
GISTENTRY *retval = NULL;
|
||||
|
||||
PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
|
||||
PG_RETURN_POINTER(gbt_num_compress(entry, &tinfo));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -120,9 +120,8 @@ Datum
|
|||
gbt_int4_compress(PG_FUNCTION_ARGS)
|
||||
{
|
||||
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
|
||||
GISTENTRY *retval = NULL;
|
||||
|
||||
PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
|
||||
PG_RETURN_POINTER(gbt_num_compress(entry, &tinfo));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -120,9 +120,8 @@ Datum
|
|||
gbt_int8_compress(PG_FUNCTION_ARGS)
|
||||
{
|
||||
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
|
||||
GISTENTRY *retval = NULL;
|
||||
|
||||
PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
|
||||
PG_RETURN_POINTER(gbt_num_compress(entry, &tinfo));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -110,9 +110,8 @@ Datum
|
|||
gbt_macad_compress(PG_FUNCTION_ARGS)
|
||||
{
|
||||
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
|
||||
GISTENTRY *retval = NULL;
|
||||
|
||||
PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
|
||||
PG_RETURN_POINTER(gbt_num_compress(entry, &tinfo));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -170,7 +170,7 @@ gbt_numeric_penalty(PG_FUNCTION_ARGS)
|
|||
uk;
|
||||
|
||||
rk = gbt_var_key_readable(org);
|
||||
uni = PointerGetDatum(gbt_var_key_copy(&rk, TRUE));
|
||||
uni = PointerGetDatum(gbt_var_key_copy(&rk));
|
||||
gbt_var_bin_union(&uni, newe, PG_GET_COLLATION(), &tinfo);
|
||||
ok = gbt_var_key_readable(org);
|
||||
uk = gbt_var_key_readable((GBT_VARKEY *) DatumGetPointer(uni));
|
||||
|
|
|
@ -120,9 +120,8 @@ Datum
|
|||
gbt_oid_compress(PG_FUNCTION_ARGS)
|
||||
{
|
||||
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
|
||||
GISTENTRY *retval = NULL;
|
||||
|
||||
PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
|
||||
PG_RETURN_POINTER(gbt_num_compress(entry, &tinfo));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -157,9 +157,8 @@ Datum
|
|||
gbt_time_compress(PG_FUNCTION_ARGS)
|
||||
{
|
||||
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
|
||||
GISTENTRY *retval = NULL;
|
||||
|
||||
PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
|
||||
PG_RETURN_POINTER(gbt_num_compress(entry, &tinfo));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -212,9 +212,8 @@ Datum
|
|||
gbt_ts_compress(PG_FUNCTION_ARGS)
|
||||
{
|
||||
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
|
||||
GISTENTRY *retval = NULL;
|
||||
|
||||
PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
|
||||
PG_RETURN_POINTER(gbt_num_compress(entry, &tinfo));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -11,8 +11,10 @@
|
|||
|
||||
|
||||
GISTENTRY *
|
||||
gbt_num_compress(GISTENTRY *retval, GISTENTRY *entry, const gbtree_ninfo *tinfo)
|
||||
gbt_num_compress(GISTENTRY *entry, const gbtree_ninfo *tinfo)
|
||||
{
|
||||
GISTENTRY *retval;
|
||||
|
||||
if (entry->leafkey)
|
||||
{
|
||||
union
|
||||
|
|
|
@ -128,8 +128,7 @@ extern float8 gbt_num_distance(const GBT_NUMKEY_R *key, const void *query,
|
|||
extern GIST_SPLITVEC *gbt_num_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v,
|
||||
const gbtree_ninfo *tinfo);
|
||||
|
||||
extern GISTENTRY *gbt_num_compress(GISTENTRY *retval, GISTENTRY *entry,
|
||||
const gbtree_ninfo *tinfo);
|
||||
extern GISTENTRY *gbt_num_compress(GISTENTRY *entry, const gbtree_ninfo *tinfo);
|
||||
|
||||
|
||||
extern void *gbt_num_union(GBT_NUMKEY *out, const GistEntryVector *entryvec,
|
||||
|
|
|
@ -66,26 +66,37 @@ gbt_var_key_readable(const GBT_VARKEY *k)
|
|||
}
|
||||
|
||||
|
||||
GBT_VARKEY *
|
||||
gbt_var_key_copy(const GBT_VARKEY_R *u, bool force_node)
|
||||
/*
|
||||
* Create a leaf-entry to store in the index, from a single Datum.
|
||||
*/
|
||||
static GBT_VARKEY *
|
||||
gbt_var_key_from_datum(const struct varlena *u)
|
||||
{
|
||||
int32 lowersize = VARSIZE(u);
|
||||
GBT_VARKEY *r;
|
||||
|
||||
r = (GBT_VARKEY *) palloc(lowersize + VARHDRSZ);
|
||||
memcpy(VARDATA(r), u, lowersize);
|
||||
SET_VARSIZE(r, lowersize + VARHDRSZ);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/*
|
||||
* Create an entry to store in the index, from lower and upper bound.
|
||||
*/
|
||||
GBT_VARKEY *
|
||||
gbt_var_key_copy(const GBT_VARKEY_R *u)
|
||||
{
|
||||
GBT_VARKEY *r = NULL;
|
||||
int32 lowersize = VARSIZE(u->lower);
|
||||
int32 uppersize = VARSIZE(u->upper);
|
||||
GBT_VARKEY *r;
|
||||
|
||||
r = (GBT_VARKEY *) palloc0(INTALIGN(lowersize) + uppersize + VARHDRSZ);
|
||||
memcpy(VARDATA(r), u->lower, lowersize);
|
||||
memcpy(VARDATA(r) + INTALIGN(lowersize), u->upper, uppersize);
|
||||
SET_VARSIZE(r, INTALIGN(lowersize) + uppersize + VARHDRSZ);
|
||||
|
||||
if (u->lower == u->upper && !force_node)
|
||||
{ /* leaf key mode */
|
||||
r = (GBT_VARKEY *) palloc(lowersize + VARHDRSZ);
|
||||
memcpy(VARDATA(r), u->lower, lowersize);
|
||||
SET_VARSIZE(r, lowersize + VARHDRSZ);
|
||||
}
|
||||
else
|
||||
{ /* node key mode */
|
||||
r = (GBT_VARKEY *) palloc0(INTALIGN(lowersize) + uppersize + VARHDRSZ);
|
||||
memcpy(VARDATA(r), u->lower, lowersize);
|
||||
memcpy(VARDATA(r) + INTALIGN(lowersize), u->upper, uppersize);
|
||||
SET_VARSIZE(r, INTALIGN(lowersize) + uppersize + VARHDRSZ);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
|
@ -255,18 +266,17 @@ gbt_var_bin_union(Datum *u, GBT_VARKEY *e, Oid collation,
|
|||
}
|
||||
|
||||
if (update)
|
||||
*u = PointerGetDatum(gbt_var_key_copy(&nr, TRUE));
|
||||
*u = PointerGetDatum(gbt_var_key_copy(&nr));
|
||||
}
|
||||
else
|
||||
{
|
||||
nr.lower = eo.lower;
|
||||
nr.upper = eo.upper;
|
||||
*u = PointerGetDatum(gbt_var_key_copy(&nr, TRUE));
|
||||
*u = PointerGetDatum(gbt_var_key_copy(&nr));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
GISTENTRY *
|
||||
gbt_var_compress(GISTENTRY *entry, const gbtree_vinfo *tinfo)
|
||||
{
|
||||
|
@ -274,12 +284,10 @@ gbt_var_compress(GISTENTRY *entry, const gbtree_vinfo *tinfo)
|
|||
|
||||
if (entry->leafkey)
|
||||
{
|
||||
GBT_VARKEY *r = NULL;
|
||||
bytea *leaf = (bytea *) DatumGetPointer(PG_DETOAST_DATUM(entry->key));
|
||||
GBT_VARKEY_R u;
|
||||
struct varlena *leaf = PG_DETOAST_DATUM(entry->key);
|
||||
GBT_VARKEY *r;
|
||||
|
||||
u.lower = u.upper = leaf;
|
||||
r = gbt_var_key_copy(&u, FALSE);
|
||||
r = gbt_var_key_from_datum(leaf);
|
||||
|
||||
retval = palloc(sizeof(GISTENTRY));
|
||||
gistentryinit(*retval, PointerGetDatum(r),
|
||||
|
@ -293,7 +301,6 @@ gbt_var_compress(GISTENTRY *entry, const gbtree_vinfo *tinfo)
|
|||
}
|
||||
|
||||
|
||||
|
||||
GBT_VARKEY *
|
||||
gbt_var_union(const GistEntryVector *entryvec, int32 *size, Oid collation,
|
||||
const gbtree_vinfo *tinfo)
|
||||
|
@ -308,7 +315,7 @@ gbt_var_union(const GistEntryVector *entryvec, int32 *size, Oid collation,
|
|||
|
||||
cur = (GBT_VARKEY *) DatumGetPointer(entryvec->vector[0].key);
|
||||
rk = gbt_var_key_readable(cur);
|
||||
out = PointerGetDatum(gbt_var_key_copy(&rk, TRUE));
|
||||
out = PointerGetDatum(gbt_var_key_copy(&rk));
|
||||
|
||||
for (i = 1; i < numranges; i++)
|
||||
{
|
||||
|
|
|
@ -47,7 +47,7 @@ typedef struct
|
|||
|
||||
extern GBT_VARKEY_R gbt_var_key_readable(const GBT_VARKEY *k);
|
||||
|
||||
extern GBT_VARKEY *gbt_var_key_copy(const GBT_VARKEY_R *u, bool force_node);
|
||||
extern GBT_VARKEY *gbt_var_key_copy(const GBT_VARKEY_R *u);
|
||||
|
||||
extern GISTENTRY *gbt_var_compress(GISTENTRY *entry, const gbtree_vinfo *tinfo);
|
||||
|
||||
|
|
Loading…
Reference in a new issue