mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
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:
@ -99,7 +99,7 @@ gbt_bit_l2n(GBT_VARKEY *leaf)
|
|||||||
|
|
||||||
o = gbt_bit_xfrm(r.lower);
|
o = gbt_bit_xfrm(r.lower);
|
||||||
r.upper = r.lower = o;
|
r.upper = r.lower = o;
|
||||||
out = gbt_var_key_copy(&r, TRUE);
|
out = gbt_var_key_copy(&r);
|
||||||
pfree(o);
|
pfree(o);
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
|
@ -119,9 +119,8 @@ Datum
|
|||||||
gbt_cash_compress(PG_FUNCTION_ARGS)
|
gbt_cash_compress(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
|
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)
|
gbt_date_compress(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
|
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)
|
gbt_float4_compress(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
|
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)
|
gbt_float8_compress(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
|
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)
|
gbt_int2_compress(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
|
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)
|
gbt_int4_compress(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
|
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)
|
gbt_int8_compress(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
|
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)
|
gbt_macad_compress(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
|
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;
|
uk;
|
||||||
|
|
||||||
rk = gbt_var_key_readable(org);
|
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);
|
gbt_var_bin_union(&uni, newe, PG_GET_COLLATION(), &tinfo);
|
||||||
ok = gbt_var_key_readable(org);
|
ok = gbt_var_key_readable(org);
|
||||||
uk = gbt_var_key_readable((GBT_VARKEY *) DatumGetPointer(uni));
|
uk = gbt_var_key_readable((GBT_VARKEY *) DatumGetPointer(uni));
|
||||||
|
@ -120,9 +120,8 @@ Datum
|
|||||||
gbt_oid_compress(PG_FUNCTION_ARGS)
|
gbt_oid_compress(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
|
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)
|
gbt_time_compress(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
|
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)
|
gbt_ts_compress(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
|
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 *
|
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)
|
if (entry->leafkey)
|
||||||
{
|
{
|
||||||
union
|
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,
|
extern GIST_SPLITVEC *gbt_num_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v,
|
||||||
const gbtree_ninfo *tinfo);
|
const gbtree_ninfo *tinfo);
|
||||||
|
|
||||||
extern GISTENTRY *gbt_num_compress(GISTENTRY *retval, GISTENTRY *entry,
|
extern GISTENTRY *gbt_num_compress(GISTENTRY *entry, const gbtree_ninfo *tinfo);
|
||||||
const gbtree_ninfo *tinfo);
|
|
||||||
|
|
||||||
|
|
||||||
extern void *gbt_num_union(GBT_NUMKEY *out, const GistEntryVector *entryvec,
|
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 lowersize = VARSIZE(u->lower);
|
||||||
int32 uppersize = VARSIZE(u->upper);
|
int32 uppersize = VARSIZE(u->upper);
|
||||||
|
GBT_VARKEY *r;
|
||||||
|
|
||||||
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);
|
r = (GBT_VARKEY *) palloc0(INTALIGN(lowersize) + uppersize + VARHDRSZ);
|
||||||
memcpy(VARDATA(r), u->lower, lowersize);
|
memcpy(VARDATA(r), u->lower, lowersize);
|
||||||
memcpy(VARDATA(r) + INTALIGN(lowersize), u->upper, uppersize);
|
memcpy(VARDATA(r) + INTALIGN(lowersize), u->upper, uppersize);
|
||||||
SET_VARSIZE(r, INTALIGN(lowersize) + uppersize + VARHDRSZ);
|
SET_VARSIZE(r, INTALIGN(lowersize) + uppersize + VARHDRSZ);
|
||||||
}
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,18 +266,17 @@ gbt_var_bin_union(Datum *u, GBT_VARKEY *e, Oid collation,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (update)
|
if (update)
|
||||||
*u = PointerGetDatum(gbt_var_key_copy(&nr, TRUE));
|
*u = PointerGetDatum(gbt_var_key_copy(&nr));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
nr.lower = eo.lower;
|
nr.lower = eo.lower;
|
||||||
nr.upper = eo.upper;
|
nr.upper = eo.upper;
|
||||||
*u = PointerGetDatum(gbt_var_key_copy(&nr, TRUE));
|
*u = PointerGetDatum(gbt_var_key_copy(&nr));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GISTENTRY *
|
GISTENTRY *
|
||||||
gbt_var_compress(GISTENTRY *entry, const gbtree_vinfo *tinfo)
|
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)
|
if (entry->leafkey)
|
||||||
{
|
{
|
||||||
GBT_VARKEY *r = NULL;
|
struct varlena *leaf = PG_DETOAST_DATUM(entry->key);
|
||||||
bytea *leaf = (bytea *) DatumGetPointer(PG_DETOAST_DATUM(entry->key));
|
GBT_VARKEY *r;
|
||||||
GBT_VARKEY_R u;
|
|
||||||
|
|
||||||
u.lower = u.upper = leaf;
|
r = gbt_var_key_from_datum(leaf);
|
||||||
r = gbt_var_key_copy(&u, FALSE);
|
|
||||||
|
|
||||||
retval = palloc(sizeof(GISTENTRY));
|
retval = palloc(sizeof(GISTENTRY));
|
||||||
gistentryinit(*retval, PointerGetDatum(r),
|
gistentryinit(*retval, PointerGetDatum(r),
|
||||||
@ -293,7 +301,6 @@ gbt_var_compress(GISTENTRY *entry, const gbtree_vinfo *tinfo)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GBT_VARKEY *
|
GBT_VARKEY *
|
||||||
gbt_var_union(const GistEntryVector *entryvec, int32 *size, Oid collation,
|
gbt_var_union(const GistEntryVector *entryvec, int32 *size, Oid collation,
|
||||||
const gbtree_vinfo *tinfo)
|
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);
|
cur = (GBT_VARKEY *) DatumGetPointer(entryvec->vector[0].key);
|
||||||
rk = gbt_var_key_readable(cur);
|
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++)
|
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_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);
|
extern GISTENTRY *gbt_var_compress(GISTENTRY *entry, const gbtree_vinfo *tinfo);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user