diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2015-03-26 23:10:10 +0200 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2015-03-26 23:10:10 +0200 |
commit | 8816af65e4f8285d3ef73158b09490099921f870 (patch) | |
tree | 87402c00b071e4373d9a1f4989e50e23eb04f618 /contrib/btree_gist/btree_utils_var.c | |
parent | 55b59eda13a742f8af913734e22ecc8a21754414 (diff) | |
download | postgresql-8816af65e4f8285d3ef73158b09490099921f870.tar.gz postgresql-8816af65e4f8285d3ef73158b09490099921f870.zip |
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.
Diffstat (limited to 'contrib/btree_gist/btree_utils_var.c')
-rw-r--r-- | contrib/btree_gist/btree_utils_var.c | 57 |
1 files changed, 32 insertions, 25 deletions
diff --git a/contrib/btree_gist/btree_utils_var.c b/contrib/btree_gist/btree_utils_var.c index 6ad33478d09..e664211198e 100644 --- a/contrib/btree_gist/btree_utils_var.c +++ b/contrib/btree_gist/btree_utils_var.c @@ -66,26 +66,37 @@ gbt_var_key_readable(const GBT_VARKEY *k) } +/* + * 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, bool force_node) +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++) { |