** The GiST PickSplit method
*/
extern GIST_SPLITVEC *
-btree_picksplit(bytea *entryvec, GIST_SPLITVEC *v, BINARY_UNION bu, CMPFUNC cmp)
+btree_picksplit(GistEntryVector *entryvec, GIST_SPLITVEC *v, BINARY_UNION bu, CMPFUNC cmp)
{
OffsetNumber i;
RIX *array;
OffsetNumber maxoff;
int nbytes;
- maxoff = ((VARSIZE(entryvec) - VARHDRSZ) / sizeof(GISTENTRY)) - 1;
+ maxoff = entryvec->n - 1;
nbytes = (maxoff + 2) * sizeof(OffsetNumber);
v->spl_left = (OffsetNumber *) palloc(nbytes);
v->spl_right = (OffsetNumber *) palloc(nbytes);
for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
{
array[i].index = i;
- array[i].r = (char *) DatumGetPointer((((GISTENTRY *) (VARDATA(entryvec)))[i].key));
+ array[i].r = (char *) DatumGetPointer((entryvec->vector[i].key));
}
qsort((void *) &array[FirstOffsetNumber], maxoff - FirstOffsetNumber + 1,
sizeof(RIX), cmp);
** Common btree-function (for all ops)
*/
-extern GIST_SPLITVEC *btree_picksplit(bytea *entryvec, GIST_SPLITVEC *v,
+extern GIST_SPLITVEC *btree_picksplit(GistEntryVector *entryvec, GIST_SPLITVEC *v,
BINARY_UNION bu, CMPFUNC cmp);
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
-CREATE FUNCTION gint2_union(bytea, internal)
+CREATE FUNCTION gint2_union(internal, internal)
RETURNS int4
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
OPERATOR 4 >= ,
OPERATOR 5 > ,
FUNCTION 1 gint2_consistent (internal, int2, int2),
- FUNCTION 2 gint2_union (bytea, internal),
+ FUNCTION 2 gint2_union (internal, internal),
FUNCTION 3 gint2_compress (internal),
FUNCTION 4 btree_decompress (internal),
FUNCTION 5 gint2_penalty (internal, internal, internal),
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
-CREATE FUNCTION gint4_union(bytea, internal)
+CREATE FUNCTION gint4_union(internal, internal)
RETURNS int4
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
OPERATOR 4 >= ,
OPERATOR 5 > ,
FUNCTION 1 gint4_consistent (internal, int4, int2),
- FUNCTION 2 gint4_union (bytea, internal),
+ FUNCTION 2 gint4_union (internal, internal),
FUNCTION 3 gint4_compress (internal),
FUNCTION 4 btree_decompress (internal),
FUNCTION 5 gint4_penalty (internal, internal, internal),
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
-CREATE FUNCTION gint8_union(bytea, internal)
+CREATE FUNCTION gint8_union(internal, internal)
RETURNS int8key
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
OPERATOR 4 >= ,
OPERATOR 5 > ,
FUNCTION 1 gint8_consistent (internal, int8, int2),
- FUNCTION 2 gint8_union (bytea, internal),
+ FUNCTION 2 gint8_union (internal, internal),
FUNCTION 3 gint8_compress (internal),
FUNCTION 4 btree_decompress (internal),
FUNCTION 5 gint8_penalty (internal, internal, internal),
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
-CREATE FUNCTION gfloat4_union(bytea, internal)
+CREATE FUNCTION gfloat4_union(internal, internal)
RETURNS int4
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
OPERATOR 4 >= ,
OPERATOR 5 > ,
FUNCTION 1 gfloat4_consistent (internal, float4, int2),
- FUNCTION 2 gfloat4_union (bytea, internal),
+ FUNCTION 2 gfloat4_union (internal, internal),
FUNCTION 3 gfloat4_compress (internal),
FUNCTION 4 btree_decompress (internal),
FUNCTION 5 gfloat4_penalty (internal, internal, internal),
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
-CREATE FUNCTION gfloat8_union(bytea, internal)
+CREATE FUNCTION gfloat8_union(internal, internal)
RETURNS int4
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
OPERATOR 4 >= ,
OPERATOR 5 > ,
FUNCTION 1 gfloat8_consistent (internal, float8, int2),
- FUNCTION 2 gfloat8_union (bytea, internal),
+ FUNCTION 2 gfloat8_union (internal, internal),
FUNCTION 3 gfloat8_compress (internal),
FUNCTION 4 btree_decompress (internal),
FUNCTION 5 gfloat8_penalty (internal, internal, internal),
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
-CREATE FUNCTION gts_union(bytea, internal)
+CREATE FUNCTION gts_union(internal, internal)
RETURNS int4
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
OPERATOR 4 >= ,
OPERATOR 5 > ,
FUNCTION 1 gts_consistent (internal, timestamp, int2),
- FUNCTION 2 gts_union (bytea, internal),
+ FUNCTION 2 gts_union (internal, internal),
FUNCTION 3 gts_compress (internal),
FUNCTION 4 btree_decompress (internal),
FUNCTION 5 gts_penalty (internal, internal, internal),
Datum
g__BTREE_GIST_TYPE2___union(PG_FUNCTION_ARGS)
{
- bytea *entryvec = (bytea *) PG_GETARG_POINTER(0);
+ GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
int i,
numranges;
__BTREE_GIST_TYPE__KEY *cur,
*out = palloc(sizeof(__BTREE_GIST_TYPE__KEY));
- numranges = (VARSIZE(entryvec) - VARHDRSZ) / sizeof(GISTENTRY);
+ numranges = entryvec->n;
*(int *) PG_GETARG_POINTER(1) = sizeof(__BTREE_GIST_TYPE__KEY);
- cur = (__BTREE_GIST_TYPE__KEY *) DatumGetPointer((((GISTENTRY *) (VARDATA(entryvec)))[0].key));
+ cur = (__BTREE_GIST_TYPE__KEY *) DatumGetPointer((entryvec->vector[0].key));
out->lower = cur->lower;
out->upper = cur->upper;
for (i = 1; i < numranges; i++)
{
- cur = (__BTREE_GIST_TYPE__KEY *) DatumGetPointer((((GISTENTRY *) (VARDATA(entryvec)))[i].key));
+ cur = (__BTREE_GIST_TYPE__KEY *) DatumGetPointer((entryvec->vector[i].key));
if (out->lower > cur->lower)
out->lower = cur->lower;
if (out->upper < cur->upper)
g__BTREE_GIST_TYPE2___picksplit(PG_FUNCTION_ARGS)
{
PG_RETURN_POINTER(btree_picksplit(
- (bytea *) PG_GETARG_POINTER(0),
+ (GistEntryVector *) PG_GETARG_POINTER(0),
(GIST_SPLITVEC *) PG_GETARG_POINTER(1),
g__BTREE_GIST_TYPE2___binary_union,
__BTREE_GIST_TYPE2__key_cmp
Datum
gts_union(PG_FUNCTION_ARGS)
{
- bytea *entryvec = (bytea *) PG_GETARG_POINTER(0);
+ GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
int i,
numranges;
TSKEY *cur,
*out = palloc(sizeof(TSKEY));
- numranges = (VARSIZE(entryvec) - VARHDRSZ) / sizeof(GISTENTRY);
+ numranges = entryvec->n;
*(int *) PG_GETARG_POINTER(1) = sizeof(TSKEY);
- cur = (TSKEY *) DatumGetPointer((((GISTENTRY *) (VARDATA(entryvec)))[0].key));
+ cur = (TSKEY *) DatumGetPointer((entryvec->vector[0].key));
out->lower = cur->lower;
out->upper = cur->upper;
for (i = 1; i < numranges; i++)
{
- cur = (TSKEY *) DatumGetPointer((((GISTENTRY *) (VARDATA(entryvec)))[i].key));
+ cur = (TSKEY *) DatumGetPointer((entryvec->vector[i].key));
if (TSGT(&out->lower, &cur->lower))
out->lower = cur->lower;
if (TSLT(&out->upper, &cur->upper))
gts_picksplit(PG_FUNCTION_ARGS)
{
PG_RETURN_POINTER(btree_picksplit(
- (bytea *) PG_GETARG_POINTER(0),
+ (GistEntryVector *) PG_GETARG_POINTER(0),
(GIST_SPLITVEC *) PG_GETARG_POINTER(1),
gts_binary_union,
tskey_cmp
GISTENTRY *g_cube_compress(GISTENTRY *entry);
GISTENTRY *g_cube_decompress(GISTENTRY *entry);
float *g_cube_penalty(GISTENTRY *origentry, GISTENTRY *newentry, float *result);
-GIST_SPLITVEC *g_cube_picksplit(bytea *entryvec, GIST_SPLITVEC *v);
+GIST_SPLITVEC *g_cube_picksplit(GistEntryVector *entryvec, GIST_SPLITVEC *v);
bool g_cube_leaf_consistent(NDBOX * key, NDBOX * query, StrategyNumber strategy);
bool g_cube_internal_consistent(NDBOX * key, NDBOX * query, StrategyNumber strategy);
-NDBOX *g_cube_union(bytea *entryvec, int *sizep);
+NDBOX *g_cube_union(GistEntryVector *entryvec, int *sizep);
NDBOX *g_cube_binary_union(NDBOX * r1, NDBOX * r2, int *sizep);
bool *g_cube_same(NDBOX * b1, NDBOX * b2, bool *result);
** returns the minimal bounding box that encloses all the entries in entryvec
*/
NDBOX *
-g_cube_union(bytea *entryvec, int *sizep)
+g_cube_union(GistEntryVector *entryvec, int *sizep)
{
- int numranges,
- i;
+ int i;
NDBOX *out = (NDBOX *) NULL;
NDBOX *tmp;
/*
* fprintf(stderr, "union\n");
*/
- numranges = (VARSIZE(entryvec) - VARHDRSZ) / sizeof(GISTENTRY);
- tmp = (NDBOX *) DatumGetPointer((((GISTENTRY *) (VARDATA(entryvec)))[0]).key);
+ tmp = (NDBOX *) DatumGetPointer(entryvec->vector[0].key);
/*
* sizep = sizeof(NDBOX); -- NDBOX has variable size
*/
*sizep = tmp->size;
- for (i = 1; i < numranges; i++)
+ for (i = 1; i < entryvec->n; i++)
{
out = g_cube_binary_union(tmp, (NDBOX *)
- DatumGetPointer((((GISTENTRY *) (VARDATA(entryvec)))[i]).key),
+ DatumGetPointer(entryvec->vector[i].key),
sizep);
if (i > 1)
pfree(tmp);
** We use Guttman's poly time split algorithm
*/
GIST_SPLITVEC *
-g_cube_picksplit(bytea *entryvec,
+g_cube_picksplit(GistEntryVector *entryvec,
GIST_SPLITVEC *v)
{
OffsetNumber i,
/*
* fprintf(stderr, "picksplit\n");
*/
- maxoff = ((VARSIZE(entryvec) - VARHDRSZ) / sizeof(GISTENTRY)) - 2;
+ maxoff = entryvec->n - 2;
nbytes = (maxoff + 2) * sizeof(OffsetNumber);
v->spl_left = (OffsetNumber *) palloc(nbytes);
v->spl_right = (OffsetNumber *) palloc(nbytes);
for (i = FirstOffsetNumber; i < maxoff; i = OffsetNumberNext(i))
{
- datum_alpha = (NDBOX *) DatumGetPointer(((GISTENTRY *) (VARDATA(entryvec)))[i].key);
+ datum_alpha = (NDBOX *) DatumGetPointer(entryvec->vector[i].key);
for (j = OffsetNumberNext(i); j <= maxoff; j = OffsetNumberNext(j))
{
- datum_beta = (NDBOX *) DatumGetPointer(((GISTENTRY *) (VARDATA(entryvec)))[j].key);
+ datum_beta = (NDBOX *) DatumGetPointer(entryvec->vector[j].key);
/* compute the wasted space by unioning these guys */
/* size_waste = size_union - size_inter; */
right = v->spl_right;
v->spl_nright = 0;
- datum_alpha = (NDBOX *) DatumGetPointer(((GISTENTRY *) (VARDATA(entryvec)))[seed_1].key);
+ datum_alpha = (NDBOX *) DatumGetPointer(entryvec->vector[seed_1].key);
datum_l = cube_union(datum_alpha, datum_alpha);
rt_cube_size(datum_l, &size_l);
- datum_beta = (NDBOX *) DatumGetPointer(((GISTENTRY *) (VARDATA(entryvec)))[seed_2].key);
+ datum_beta = (NDBOX *) DatumGetPointer(entryvec->vector[seed_2].key);
datum_r = cube_union(datum_beta, datum_beta);
rt_cube_size(datum_r, &size_r);
}
/* okay, which page needs least enlargement? */
- datum_alpha = (NDBOX *) DatumGetPointer(((GISTENTRY *) (VARDATA(entryvec)))[i].key);
+ datum_alpha = (NDBOX *) DatumGetPointer(entryvec->vector[i].key);
union_dl = cube_union(datum_l, datum_alpha);
union_dr = cube_union(datum_r, datum_alpha);
rt_cube_size(union_dl, &size_alpha);
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
-CREATE OR REPLACE FUNCTION g_cube_union(bytea, internal)
+CREATE OR REPLACE FUNCTION g_cube_union(internal, internal)
RETURNS cube
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
OPERATOR 7 @ ,
OPERATOR 8 ~ ,
FUNCTION 1 g_cube_consistent (internal, cube, int4),
- FUNCTION 2 g_cube_union (bytea, internal),
+ FUNCTION 2 g_cube_union (internal, internal),
FUNCTION 3 g_cube_compress (internal),
FUNCTION 4 g_cube_decompress (internal),
FUNCTION 5 g_cube_penalty (internal, internal, internal),
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
-CREATE FUNCTION g_int_union(bytea, internal)
+CREATE FUNCTION g_int_union(internal, internal)
RETURNS _int4
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
OPERATOR 8 ~,
OPERATOR 20 @@ (_int4, query_int),
FUNCTION 1 g_int_consistent (internal, _int4, int4),
- FUNCTION 2 g_int_union (bytea, internal),
+ FUNCTION 2 g_int_union (internal, internal),
FUNCTION 3 g_int_compress (internal),
FUNCTION 4 g_int_decompress (internal),
FUNCTION 5 g_int_penalty (internal, internal, internal),
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
-CREATE FUNCTION g_intbig_union(bytea, internal)
+CREATE FUNCTION g_intbig_union(internal, internal)
RETURNS _int4
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
OPERATOR 8 ~ RECHECK,
OPERATOR 20 @@ (_int4, query_int) RECHECK,
FUNCTION 1 g_intbig_consistent (internal, internal, int4),
- FUNCTION 2 g_intbig_union (bytea, internal),
+ FUNCTION 2 g_intbig_union (internal, internal),
FUNCTION 3 g_intbig_compress (internal),
FUNCTION 4 g_intbig_decompress (internal),
FUNCTION 5 g_intbig_penalty (internal, internal, internal),
#include "_int.h"
-#define GETENTRY(vec,pos) ((ArrayType *) DatumGetPointer(((GISTENTRY *) VARDATA(vec))[(pos)].key))
+#define GETENTRY(vec,pos) ((ArrayType *) DatumGetPointer((vec)->vector[(pos)].key))
/*
** GiST support methods
Datum
g_int_union(PG_FUNCTION_ARGS)
{
- bytea *entryvec = (bytea *) PG_GETARG_POINTER(0);
+ GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
int *size = (int *) PG_GETARG_POINTER(1);
- int4 i,
- len = (VARSIZE(entryvec) - VARHDRSZ) / sizeof(GISTENTRY);
+ int4 i;
ArrayType *res;
int totlen = 0,
*ptr;
- for (i = 0; i < len; i++)
+ for (i = 0; i < entryvec->n; i++)
totlen += ARRNELEMS(GETENTRY(entryvec, i));
res = new_intArrayType(totlen);
ptr = ARRPTR(res);
- for (i = 0; i < len; i++)
+ for (i = 0; i < entryvec->n; i++)
{
memcpy(ptr, ARRPTR(GETENTRY(entryvec, i)), ARRNELEMS(GETENTRY(entryvec, i)) * sizeof(int4));
ptr += ARRNELEMS(GETENTRY(entryvec, i));
Datum
g_int_picksplit(PG_FUNCTION_ARGS)
{
- bytea *entryvec = (bytea *) PG_GETARG_POINTER(0);
+ GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
OffsetNumber i,
j;
SPLITCOST *costvector;
#ifdef GIST_DEBUG
- elog(DEBUG3, "--------picksplit %d", (VARSIZE(entryvec) - VARHDRSZ) / sizeof(GISTENTRY));
+ elog(DEBUG3, "--------picksplit %d", entryvec->n);
#endif
- maxoff = ((VARSIZE(entryvec) - VARHDRSZ) / sizeof(GISTENTRY)) - 2;
+ maxoff = entryvec->n - 2;
nbytes = (maxoff + 2) * sizeof(OffsetNumber);
v->spl_left = (OffsetNumber *) palloc(nbytes);
v->spl_right = (OffsetNumber *) palloc(nbytes);
waste = 0.0;
for (i = FirstOffsetNumber; i < maxoff; i = OffsetNumberNext(i))
{
- datum_alpha = (ArrayType *) DatumGetPointer(((GISTENTRY *) VARDATA(entryvec))[i].key);
+ datum_alpha = GETENTRY(entryvec,i);
for (j = OffsetNumberNext(i); j <= maxoff; j = OffsetNumberNext(j))
{
- datum_beta = (ArrayType *) DatumGetPointer(((GISTENTRY *) VARDATA(entryvec))[j].key);
+ datum_beta = GETENTRY(entryvec,j);
/* compute the wasted space by unioning these guys */
/* size_waste = size_union - size_inter; */
seed_2 = 2;
}
- datum_alpha = (ArrayType *) DatumGetPointer(((GISTENTRY *) VARDATA(entryvec))[seed_1].key);
+ datum_alpha = GETENTRY(entryvec,seed_1);
datum_l = copy_intArrayType(datum_alpha);
rt__int_size(datum_l, &size_l);
- datum_beta = (ArrayType *) DatumGetPointer(((GISTENTRY *) VARDATA(entryvec))[seed_2].key);
+ datum_beta = GETENTRY(entryvec,seed_2);
datum_r = copy_intArrayType(datum_beta);
rt__int_size(datum_r, &size_r);
for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
{
costvector[i - 1].pos = i;
- datum_alpha = (ArrayType *) DatumGetPointer(((GISTENTRY *) VARDATA(entryvec))[i].key);
+ datum_alpha = GETENTRY(entryvec,i);
union_d = inner_int_union(datum_l, datum_alpha);
rt__int_size(union_d, &size_alpha);
pfree(union_d);
}
/* okay, which page needs least enlargement? */
- datum_alpha = (ArrayType *) DatumGetPointer(((GISTENTRY *) VARDATA(entryvec))[i].key);
+ datum_alpha = GETENTRY(entryvec,i);
union_dl = inner_int_union(datum_l, datum_alpha);
union_dr = inner_int_union(datum_r, datum_alpha);
rt__int_size(union_dl, &size_alpha);
#include "_int.h"
-#define GETENTRY(vec,pos) ((GISTTYPE *) DatumGetPointer(((GISTENTRY *) VARDATA(vec))[(pos)].key))
+#define GETENTRY(vec,pos) ((GISTTYPE *) DatumGetPointer((vec)->vector[(pos)].key))
/*
** _intbig methods
*/
Datum
g_intbig_union(PG_FUNCTION_ARGS) {
- bytea *entryvec = (bytea *) PG_GETARG_POINTER(0);
+ GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
int *size = (int *) PG_GETARG_POINTER(1);
BITVEC base;
- int4 len = (VARSIZE(entryvec) - VARHDRSZ) / sizeof(GISTENTRY);
- int4 i;
+ int4 i, len;
int4 flag = 0;
GISTTYPE *result;
MemSet((void *) base, 0, sizeof(BITVEC));
- for (i = 0; i < len; i++) {
+ for (i = 0; i < entryvec->n; i++) {
if (unionkey(base, GETENTRY(entryvec, i))) {
flag = ALLISTRUE;
break;
Datum
g_intbig_picksplit(PG_FUNCTION_ARGS) {
- bytea *entryvec = (bytea *) PG_GETARG_POINTER(0);
+ GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
OffsetNumber k,
j;
GISTTYPE *_k,
*_j;
- maxoff = ((VARSIZE(entryvec) - VARHDRSZ) / sizeof(GISTENTRY)) - 2;
+ maxoff = entryvec->n - 2;
nbytes = (maxoff + 2) * sizeof(OffsetNumber);
v->spl_left = (OffsetNumber *) palloc(nbytes);
v->spl_right = (OffsetNumber *) palloc(nbytes);
PG_FUNCTION_INFO_V1(_ltree_consistent);
Datum _ltree_consistent(PG_FUNCTION_ARGS);
-#define GETENTRY(vec,pos) ((ltree_gist *) DatumGetPointer(((GISTENTRY *) VARDATA(vec))[(pos)].key))
+#define GETENTRY(vec,pos) ((ltree_gist *) DatumGetPointer((vec)->vector[(pos)].key))
#define NEXTVAL(x) ( (ltree*)( (char*)(x) + INTALIGN( VARSIZE(x) ) ) )
#define SUMBIT(val) ( \
GETBITBYTE(val,0) + \
Datum
_ltree_union(PG_FUNCTION_ARGS)
{
- bytea *entryvec = (bytea *) PG_GETARG_POINTER(0);
+ GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
int *size = (int *) PG_GETARG_POINTER(1);
ABITVEC base;
- int4 len = (VARSIZE(entryvec) - VARHDRSZ) / sizeof(GISTENTRY);
- int4 i;
+ int4 i,len;
int4 flag = 0;
ltree_gist *result;
MemSet((void *) base, 0, sizeof(ABITVEC));
- for (i = 0; i < len; i++)
+ for (i = 0; i < entryvec->n; i++)
{
if (unionkey(base, GETENTRY(entryvec, i)))
{
Datum
_ltree_picksplit(PG_FUNCTION_ARGS)
{
- bytea *entryvec = (bytea *) PG_GETARG_POINTER(0);
+ GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
OffsetNumber k,
j;
ltree_gist *_k,
*_j;
- maxoff = ((VARSIZE(entryvec) - VARHDRSZ) / sizeof(GISTENTRY)) - 2;
+ maxoff = entryvec->n - 2;
nbytes = (maxoff + 2) * sizeof(OffsetNumber);
v->spl_left = (OffsetNumber *) palloc(nbytes);
v->spl_right = (OffsetNumber *) palloc(nbytes);
RETURNS internal as 'MODULE_PATHNAME' language 'C' with(isstrict);
CREATE FUNCTION ltree_picksplit(internal, internal)
RETURNS internal as 'MODULE_PATHNAME' language 'C';
-CREATE FUNCTION ltree_union(bytea, internal)
+CREATE FUNCTION ltree_union(internal, internal)
RETURNS int4 as 'MODULE_PATHNAME' language 'C';
CREATE FUNCTION ltree_same(internal, internal, internal)
RETURNS internal as 'MODULE_PATHNAME' language 'C';
OPERATOR 16 ? (ltree, _lquery) ,
OPERATOR 17 ? (_lquery, ltree) ,
FUNCTION 1 ltree_consistent (internal, internal, int2),
- FUNCTION 2 ltree_union (bytea, internal),
+ FUNCTION 2 ltree_union (internal, internal),
FUNCTION 3 ltree_compress (internal),
FUNCTION 4 ltree_decompress (internal),
FUNCTION 5 ltree_penalty (internal, internal, internal),
RETURNS internal
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
-CREATE FUNCTION _ltree_union(bytea, internal)
+CREATE FUNCTION _ltree_union(internal, internal)
RETURNS int4
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
OPERATOR 16 ? (_ltree, _lquery) RECHECK ,
OPERATOR 17 ? (_lquery, _ltree) RECHECK ,
FUNCTION 1 _ltree_consistent (internal, internal, int2),
- FUNCTION 2 _ltree_union (bytea, internal),
+ FUNCTION 2 _ltree_union (internal, internal),
FUNCTION 3 _ltree_compress (internal),
FUNCTION 4 ltree_decompress (internal),
FUNCTION 5 _ltree_penalty (internal, internal, internal),
Datum ltree_consistent(PG_FUNCTION_ARGS);
#define ISEQ(a,b) ( (a)->numlevel == (b)->numlevel && ltree_compare(a,b)==0 )
-#define GETENTRY(vec,pos) ((ltree_gist *) DatumGetPointer(((GISTENTRY *) VARDATA(vec))[(pos)].key))
+#define GETENTRY(vec,pos) ((ltree_gist *) DatumGetPointer((vec)->vector[(pos)].key))
Datum
ltree_compress(PG_FUNCTION_ARGS)
Datum
ltree_union(PG_FUNCTION_ARGS)
{
- bytea *entryvec = (bytea *) PG_GETARG_POINTER(0);
+ GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
int *size = (int *) PG_GETARG_POINTER(1);
BITVEC base;
- int4 len = (VARSIZE(entryvec) - VARHDRSZ) / sizeof(GISTENTRY);
int4 i,
j;
ltree_gist *result,
bool isleqr;
MemSet((void *) base, 0, sizeof(BITVEC));
- for (j = 0; j < len; j++)
+ for (j = 0; j < entryvec->n; j++)
{
cur = GETENTRY(entryvec, j);
if (LTG_ISONENODE(cur))
Datum
ltree_picksplit(PG_FUNCTION_ARGS)
{
- bytea *entryvec = (bytea *) PG_GETARG_POINTER(0);
+ GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
OffsetNumber j;
int4 i;
memset((void *) ls, 0, sizeof(BITVEC));
memset((void *) rs, 0, sizeof(BITVEC));
- maxoff = ((VARSIZE(entryvec) - VARHDRSZ) / sizeof(GISTENTRY)) - 1;
+ maxoff = entryvec->n - 1;
nbytes = (maxoff + 2) * sizeof(OffsetNumber);
v->spl_left = (OffsetNumber *) palloc(nbytes);
v->spl_right = (OffsetNumber *) palloc(nbytes);
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/contrib/rtree_gist/rtree_gist.c,v 1.8 2003/11/29 19:51:35 pgsql Exp $
+ * $PostgreSQL: pgsql/contrib/rtree_gist/rtree_gist.c,v 1.9 2004/03/30 15:45:33 teodor Exp $
*
*-------------------------------------------------------------------------
*/
Datum
gbox_union(PG_FUNCTION_ARGS)
{
- bytea *entryvec = (bytea *) PG_GETARG_POINTER(0);
+ GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
int *sizep = (int *) PG_GETARG_POINTER(1);
int numranges,
i;
BOX *cur,
*pageunion;
- numranges = (VARSIZE(entryvec) - VARHDRSZ) / sizeof(GISTENTRY);
+ numranges = entryvec->n;
pageunion = (BOX *) palloc(sizeof(BOX));
- cur = DatumGetBoxP(((GISTENTRY *) VARDATA(entryvec))[0].key);
+ cur = DatumGetBoxP(entryvec->vector[0].key);
memcpy((void *) pageunion, (void *) cur, sizeof(BOX));
for (i = 1; i < numranges; i++)
{
- cur = DatumGetBoxP(((GISTENTRY *) VARDATA(entryvec))[i].key);
+ cur = DatumGetBoxP(entryvec->vector[i].key);
if (pageunion->high.x < cur->high.x)
pageunion->high.x = cur->high.x;
if (pageunion->low.x > cur->low.x)
Datum
gbox_picksplit(PG_FUNCTION_ARGS)
{
- bytea *entryvec = (bytea *) PG_GETARG_POINTER(0);
+ GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
OffsetNumber i;
OffsetNumber *listL,
int nbytes;
posL = posR = posB = posT = 0;
- maxoff = ((VARSIZE(entryvec) - VARHDRSZ) / sizeof(GISTENTRY)) - 1;
+ maxoff = entryvec->n - 1;
- cur = DatumGetBoxP(((GISTENTRY *) VARDATA(entryvec))[FirstOffsetNumber].key);
+ cur = DatumGetBoxP(entryvec->vector[FirstOffsetNumber].key);
memcpy((void *) &pageunion, (void *) cur, sizeof(BOX));
/* find MBR */
for (i = OffsetNumberNext(FirstOffsetNumber); i <= maxoff; i = OffsetNumberNext(i))
{
- cur = DatumGetBoxP(((GISTENTRY *) VARDATA(entryvec))[i].key);
+ cur = DatumGetBoxP(entryvec->vector[i].key);
if (allisequal == true && (
pageunion.high.x != cur->high.x ||
pageunion.high.y != cur->high.y ||
unionR = (BOX *) palloc(sizeof(BOX));
if (allisequal)
{
- cur = DatumGetBoxP(((GISTENTRY *) VARDATA(entryvec))[OffsetNumberNext(FirstOffsetNumber)].key);
+ cur = DatumGetBoxP(entryvec->vector[OffsetNumberNext(FirstOffsetNumber)].key);
if (memcmp((void *) cur, (void *) &pageunion, sizeof(BOX)) == 0)
{
v->spl_left = listL;
for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
{
- cur = DatumGetBoxP(((GISTENTRY *) VARDATA(entryvec))[i].key);
+ cur = DatumGetBoxP(entryvec->vector[i].key);
if (cur->low.x - pageunion.low.x < pageunion.high.x - cur->high.x)
ADDLIST(listL, unionL, posL, i);
else
posL = posR = posB = posT = 0;
for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
{
- arr[i - 1].key = DatumGetBoxP(((GISTENTRY *) VARDATA(entryvec))[i].key);
+ arr[i - 1].key = DatumGetBoxP(entryvec->vector[i].key);
arr[i - 1].pos = i;
}
qsort(arr, maxoff, sizeof(KBsort), compare_KB);
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
-CREATE FUNCTION gbox_union(bytea, internal)
+CREATE FUNCTION gbox_union(internal, internal)
RETURNS box
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
OPERATOR 7 ~ ,
OPERATOR 8 @ ,
FUNCTION 1 gbox_consistent (internal, box, int4),
- FUNCTION 2 gbox_union (bytea, internal),
+ FUNCTION 2 gbox_union (internal, internal),
FUNCTION 3 gbox_compress (internal),
FUNCTION 4 rtree_decompress (internal),
FUNCTION 5 gbox_penalty (internal, internal, internal),
OPERATOR 7 ~ RECHECK,
OPERATOR 8 @ RECHECK,
FUNCTION 1 gpoly_consistent (internal, polygon, int4),
- FUNCTION 2 gbox_union (bytea, internal),
+ FUNCTION 2 gbox_union (internal, internal),
FUNCTION 3 gpoly_compress (internal),
FUNCTION 4 rtree_decompress (internal),
FUNCTION 5 gbox_penalty (internal, internal, internal),
GISTENTRY *gseg_compress(GISTENTRY *entry);
GISTENTRY *gseg_decompress(GISTENTRY *entry);
float *gseg_penalty(GISTENTRY *origentry, GISTENTRY *newentry, float *result);
-GIST_SPLITVEC *gseg_picksplit(bytea *entryvec, GIST_SPLITVEC *v);
+GIST_SPLITVEC *gseg_picksplit(GistEntryVector *entryvec, GIST_SPLITVEC *v);
bool gseg_leaf_consistent(SEG * key, SEG * query, StrategyNumber strategy);
bool gseg_internal_consistent(SEG * key, SEG * query, StrategyNumber strategy);
-SEG *gseg_union(bytea *entryvec, int *sizep);
+SEG *gseg_union(GistEntryVector *entryvec, int *sizep);
SEG *gseg_binary_union(SEG * r1, SEG * r2, int *sizep);
bool *gseg_same(SEG * b1, SEG * b2, bool *result);
** returns the minimal bounding seg that encloses all the entries in entryvec
*/
SEG *
-gseg_union(bytea *entryvec, int *sizep)
+gseg_union(GistEntryVector *entryvec, int *sizep)
{
int numranges,
i;
fprintf(stderr, "union\n");
#endif
- numranges = (VARSIZE(entryvec) - VARHDRSZ) / sizeof(GISTENTRY);
- tmp = (SEG *) DatumGetPointer(((GISTENTRY *) VARDATA(entryvec))[0].key);
+ numranges = entryvec->n;
+ tmp = (SEG *) DatumGetPointer(entryvec->vector[0].key);
*sizep = sizeof(SEG);
for (i = 1; i < numranges; i++)
{
out = gseg_binary_union(tmp, (SEG *)
- DatumGetPointer(((GISTENTRY *) VARDATA(entryvec))[i].key),
+ DatumGetPointer(entryvec->vector[i].key),
sizep);
if (i > 1)
pfree(tmp);
** We use Guttman's poly time split algorithm
*/
GIST_SPLITVEC *
-gseg_picksplit(bytea *entryvec,
+gseg_picksplit(GistEntryVector *entryvec,
GIST_SPLITVEC *v)
{
OffsetNumber i,
fprintf(stderr, "picksplit\n");
#endif
- maxoff = ((VARSIZE(entryvec) - VARHDRSZ) / sizeof(GISTENTRY)) - 2;
+ maxoff = entryvec->n - 2;
nbytes = (maxoff + 2) * sizeof(OffsetNumber);
v->spl_left = (OffsetNumber *) palloc(nbytes);
v->spl_right = (OffsetNumber *) palloc(nbytes);
for (i = FirstOffsetNumber; i < maxoff; i = OffsetNumberNext(i))
{
- datum_alpha = (SEG *) DatumGetPointer(((GISTENTRY *) VARDATA(entryvec))[i].key);
+ datum_alpha = (SEG *) DatumGetPointer(entryvec->vector[i].key);
for (j = OffsetNumberNext(i); j <= maxoff; j = OffsetNumberNext(j))
{
- datum_beta = (SEG *) DatumGetPointer(((GISTENTRY *) VARDATA(entryvec))[j].key);
+ datum_beta = (SEG *) DatumGetPointer(entryvec->vector[j].key);
/* compute the wasted space by unioning these guys */
/* size_waste = size_union - size_inter; */
right = v->spl_right;
v->spl_nright = 0;
- datum_alpha = (SEG *) DatumGetPointer(((GISTENTRY *) VARDATA(entryvec))[seed_1].key);
+ datum_alpha = (SEG *) DatumGetPointer(entryvec->vector[seed_1].key);
datum_l = seg_union(datum_alpha, datum_alpha);
rt_seg_size(datum_l, &size_l);
- datum_beta = (SEG *) DatumGetPointer(((GISTENTRY *) VARDATA(entryvec))[seed_2].key);
+ datum_beta = (SEG *) DatumGetPointer(entryvec->vector[seed_2].key);
datum_r = seg_union(datum_beta, datum_beta);
rt_seg_size(datum_r, &size_r);
}
/* okay, which page needs least enlargement? */
- datum_alpha = (SEG *) DatumGetPointer(((GISTENTRY *) VARDATA(entryvec))[i].key);
+ datum_alpha = (SEG *) DatumGetPointer(entryvec->vector[i].key);
union_dl = seg_union(datum_l, datum_alpha);
union_dr = seg_union(datum_r, datum_alpha);
rt_seg_size(union_dl, &size_alpha);
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
-CREATE FUNCTION gseg_union(bytea, internal)
+CREATE FUNCTION gseg_union(internal, internal)
RETURNS seg
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
OPERATOR 7 @ ,
OPERATOR 8 ~ ,
FUNCTION 1 gseg_consistent (internal, seg, int4),
- FUNCTION 2 gseg_union (bytea, internal),
+ FUNCTION 2 gseg_union (internal, internal),
FUNCTION 3 gseg_compress (internal),
FUNCTION 4 gseg_decompress (internal),
FUNCTION 5 gseg_penalty (internal, internal, internal),
PG_FUNCTION_INFO_V1(gtxtidx_picksplit);
Datum gtxtidx_picksplit(PG_FUNCTION_ARGS);
-#define GETENTRY(vec,pos) ((GISTTYPE *) DatumGetPointer(((GISTENTRY *) VARDATA(vec))[(pos)].key))
+#define GETENTRY(vec,pos) ((GISTTYPE *) DatumGetPointer((vec)->vector[(pos)].key))
#define SUMBIT(val) ( \
GETBITBYTE(val,0) + \
GETBITBYTE(val,1) + \
Datum
gtxtidx_union(PG_FUNCTION_ARGS)
{
- bytea *entryvec = (bytea *) PG_GETARG_POINTER(0);
+ GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
int *size = (int *) PG_GETARG_POINTER(1);
BITVEC base;
- int4 len = (VARSIZE(entryvec) - VARHDRSZ) / sizeof(GISTENTRY);
- int4 i;
+ int4 i,len;
int4 flag = 0;
GISTTYPE *result;
MemSet((void *) base, 0, sizeof(BITVEC));
- for (i = 0; i < len; i++)
+ for (i = 0; i < entryvec->n; i++)
{
if (unionkey(base, GETENTRY(entryvec, i)))
{
Datum
gtxtidx_picksplit(PG_FUNCTION_ARGS)
{
- bytea *entryvec = (bytea *) PG_GETARG_POINTER(0);
+ GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
OffsetNumber k,
j;
char valtmp;
SPLITCOST *costvector;
- maxoff = ((VARSIZE(entryvec) - VARHDRSZ) / sizeof(GISTENTRY)) - 2;
+ maxoff = entryvec->n - 2;
nbytes = (maxoff + 2) * sizeof(OffsetNumber);
v->spl_left = (OffsetNumber *) palloc(nbytes);
v->spl_right = (OffsetNumber *) palloc(nbytes);
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
-CREATE FUNCTION gtxtidx_union(bytea, internal)
+CREATE FUNCTION gtxtidx_union(internal, internal)
RETURNS _int4
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
OPERATOR 1 @@ (txtidx, query_txt) RECHECK ,
OPERATOR 2 ## (txtidx, mquery_txt) RECHECK ,
FUNCTION 1 gtxtidx_consistent (gtxtidx, internal, int4),
- FUNCTION 2 gtxtidx_union (bytea, internal),
+ FUNCTION 2 gtxtidx_union (internal, internal),
FUNCTION 3 gtxtidx_compress (internal),
FUNCTION 4 gtxtidx_decompress (internal),
FUNCTION 5 gtxtidx_penalty (internal, internal, internal),
PG_FUNCTION_INFO_V1(gtsvector_picksplit);
Datum gtsvector_picksplit(PG_FUNCTION_ARGS);
-#define GETENTRY(vec,pos) ((GISTTYPE *) DatumGetPointer(((GISTENTRY *) VARDATA(vec))[(pos)].key))
+#define GETENTRY(vec,pos) ((GISTTYPE *) DatumGetPointer((vec)->vector[(pos)].key))
#define SUMBIT(val) ( \
GETBITBYTE(val,0) + \
GETBITBYTE(val,1) + \
Datum
gtsvector_union(PG_FUNCTION_ARGS)
{
- bytea *entryvec = (bytea *) PG_GETARG_POINTER(0);
+ GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
int *size = (int *) PG_GETARG_POINTER(1);
BITVEC base;
- int4 len = (VARSIZE(entryvec) - VARHDRSZ) / sizeof(GISTENTRY);
- int4 i;
+ int4 i,len;
int4 flag = 0;
GISTTYPE *result;
MemSet((void *) base, 0, sizeof(BITVEC));
- for (i = 0; i < len; i++)
+ for (i = 0; i < entryvec->n; i++)
{
if (unionkey(base, GETENTRY(entryvec, i)))
{
Datum
gtsvector_picksplit(PG_FUNCTION_ARGS)
{
- bytea *entryvec = (bytea *) PG_GETARG_POINTER(0);
+ GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
OffsetNumber k,
j;
CACHESIGN *cache;
SPLITCOST *costvector;
- maxoff = ((VARSIZE(entryvec) - VARHDRSZ) / sizeof(GISTENTRY)) - 2;
+ maxoff = entryvec->n - 2;
nbytes = (maxoff + 2) * sizeof(OffsetNumber);
v->spl_left = (OffsetNumber *) palloc(nbytes);
v->spl_right = (OffsetNumber *) palloc(nbytes);
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
-CREATE FUNCTION gtsvector_union(bytea, internal)
+CREATE FUNCTION gtsvector_union(internal, internal)
RETURNS _int4
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
AS
OPERATOR 1 @@ (tsvector, tsquery) RECHECK ,
FUNCTION 1 gtsvector_consistent (gtsvector, internal, int4),
- FUNCTION 2 gtsvector_union (bytea, internal),
+ FUNCTION 2 gtsvector_union (internal, internal),
FUNCTION 3 gtsvector_compress (internal),
FUNCTION 4 gtsvector_decompress (internal),
FUNCTION 5 gtsvector_penalty (internal, internal, internal),
DROP FUNCTION gtsvector_decompress(internal);
DROP FUNCTION gtsvector_penalty(internal,internal,internal);
DROP FUNCTION gtsvector_picksplit(internal, internal);
-DROP FUNCTION gtsvector_union(bytea, internal);
+DROP FUNCTION gtsvector_union(internal, internal);
DROP FUNCTION reset_tsearch();
DROP FUNCTION tsearch2() CASCADE;
DROP FUNCTION _get_parser_from_curcfg();
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/gist/gist.c,v 1.108 2004/02/10 03:42:42 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/gist/gist.c,v 1.109 2004/03/30 15:45:33 teodor Exp $
*
*-------------------------------------------------------------------------
*/
Datum attr[INDEX_MAX_KEYS];
bool whatfree[INDEX_MAX_KEYS];
char isnull[INDEX_MAX_KEYS];
- char *storage;
- bytea *evec;
+ GistEntryVector *evec;
Datum datum;
int datumsize,
i,
int reallen;
needfree = (bool *) palloc(((len == 1) ? 2 : len) * sizeof(bool));
- /* workaround for 64-bit: ensure GISTENTRY array is maxaligned */
- storage = (char *) palloc(((len == 1) ? 2 : len) * sizeof(GISTENTRY) + MAXALIGN(VARHDRSZ));
- evec = (bytea *) (storage + MAXALIGN(VARHDRSZ) - VARHDRSZ);
+ evec = (GistEntryVector *) palloc(((len == 1) ? 2 : len) * sizeof(GISTENTRY) + GEVHDRSZ);
for (j = 0; j < r->rd_att->natts; j++)
{
continue;
gistdentryinit(giststate, j,
- &((GISTENTRY *) VARDATA(evec))[reallen],
+ &(evec->vector[reallen]),
datum,
NULL, NULL, (OffsetNumber) 0,
ATTSIZE(datum, giststate->tupdesc, j + 1, IsNull), FALSE, IsNull);
if ((!isAttByVal(giststate, j)) &&
- ((GISTENTRY *) VARDATA(evec))[reallen].key != datum)
+ evec->vector[reallen].key != datum)
needfree[reallen] = TRUE;
else
needfree[reallen] = FALSE;
{
if (reallen == 1)
{
- VARATT_SIZEP(evec) = 2 * sizeof(GISTENTRY) + VARHDRSZ;
- gistentryinit(((GISTENTRY *) VARDATA(evec))[1],
- ((GISTENTRY *) VARDATA(evec))[0].key, r, NULL,
- (OffsetNumber) 0, ((GISTENTRY *) VARDATA(evec))[0].bytes, FALSE);
+ evec->n = 2;
+ gistentryinit(evec->vector[1],
+ evec->vector[0].key, r, NULL,
+ (OffsetNumber) 0, evec->vector[0].bytes, FALSE);
}
else
- VARATT_SIZEP(evec) = reallen * sizeof(GISTENTRY) + VARHDRSZ;
+ evec->n = reallen;
datum = FunctionCall2(&giststate->unionFn[j],
PointerGetDatum(evec),
PointerGetDatum(&datumsize));
for (i = 0; i < reallen; i++)
if (needfree[i])
- pfree(DatumGetPointer(((GISTENTRY *) VARDATA(evec))[i].key));
+ pfree(DatumGetPointer(evec->vector[i].key));
gistcentryinit(giststate, j, ¢ry[j], datum,
NULL, NULL, (OffsetNumber) 0,
}
}
- pfree(storage); /* pfree(evec); */
+ pfree(evec);
pfree(needfree);
newtup = (IndexTuple) index_formtuple(giststate->tupdesc, attr, isnull);
static IndexTuple
gistgetadjusted(Relation r, IndexTuple oldtup, IndexTuple addtup, GISTSTATE *giststate)
{
- bytea *evec;
+ GistEntryVector *evec;
Datum datum;
int datumsize;
bool result,
bool oldisnull[INDEX_MAX_KEYS],
addisnull[INDEX_MAX_KEYS];
IndexTuple newtup = NULL;
- char *storage;
int j;
- /* workaround for 64-bit: ensure GISTENTRY array is maxaligned */
- storage = (char *) palloc(2 * sizeof(GISTENTRY) + MAXALIGN(VARHDRSZ));
- evec = (bytea *) (storage + MAXALIGN(VARHDRSZ) - VARHDRSZ);
- VARATT_SIZEP(evec) = 2 * sizeof(GISTENTRY) + VARHDRSZ;
- ev0p = &((GISTENTRY *) VARDATA(evec))[0];
- ev1p = &((GISTENTRY *) VARDATA(evec))[1];
+ evec = palloc(2 * sizeof(GISTENTRY) + GEVHDRSZ);
+ evec->n = 2;
+ ev0p = &(evec->vector[0]);
+ ev1p = &(evec->vector[1]);
gistDeCompressAtt(giststate, r, oldtup, NULL,
(OffsetNumber) 0, oldatt, olddec, oldisnull);
whatfree[j] = FALSE;
}
}
- pfree(storage); /* pfree(evec); */
+ pfree(evec);
if (neednew)
{
int len,
*attrsize;
OffsetNumber *entries;
- bytea *evec;
- char *storage;
+ GistEntryVector *evec;
Datum datum;
int datumsize;
int reallen;
}
needfree = (bool *) palloc(((len == 1) ? 2 : len) * sizeof(bool));
- /* workaround for 64-bit: ensure GISTENTRY array is maxaligned */
- storage = (char *) palloc(((len == 1) ? 2 : len) * sizeof(GISTENTRY) + MAXALIGN(VARHDRSZ));
- evec = (bytea *) (storage + MAXALIGN(VARHDRSZ) - VARHDRSZ);
+ evec = palloc(((len == 1) ? 2 : len) * sizeof(GISTENTRY) + GEVHDRSZ);
for (j = 1; j < r->rd_att->natts; j++)
{
if (IsNull)
continue;
gistdentryinit(giststate, j,
- &((GISTENTRY *) VARDATA(evec))[reallen],
+ &(evec->vector[reallen]),
datum,
NULL, NULL, (OffsetNumber) 0,
ATTSIZE(datum, giststate->tupdesc, j + 1, IsNull), FALSE, IsNull);
if ((!isAttByVal(giststate, j)) &&
- ((GISTENTRY *) VARDATA(evec))[reallen].key != datum)
+ evec->vector[reallen].key != datum)
needfree[reallen] = TRUE;
else
needfree[reallen] = FALSE;
else
{
/*
- * ((GISTENTRY *) VARDATA(evec))[0].bytes may be not
+ * evec->vector[0].bytes may be not
* defined, so form union with itself
*/
if (reallen == 1)
{
- VARATT_SIZEP(evec) = 2 * sizeof(GISTENTRY) + VARHDRSZ;
- memcpy((void *) &((GISTENTRY *) VARDATA(evec))[1],
- (void *) &((GISTENTRY *) VARDATA(evec))[0],
+ evec->n = 2;
+ memcpy((void *) &(evec->vector[1]),
+ (void *) &(evec->vector[0]),
sizeof(GISTENTRY));
}
else
- VARATT_SIZEP(evec) = reallen * sizeof(GISTENTRY) + VARHDRSZ;
+ evec->n = reallen;
datum = FunctionCall2(&giststate->unionFn[j],
PointerGetDatum(evec),
PointerGetDatum(&datumsize));
for (i = 0; i < reallen; i++)
if (needfree[i])
- pfree(DatumGetPointer(((GISTENTRY *) VARDATA(evec))[i].key));
+ pfree(DatumGetPointer(evec->vector[i].key));
attr[j] = datum;
attrsize[j] = datumsize;
}
- pfree(storage); /* pfree(evec); */
+ pfree(evec);
pfree(needfree);
}
}
*ev1p;
float lpenalty,
rpenalty;
- bytea *evec;
- char *storage;
+ GistEntryVector *evec;
int datumsize;
bool isnull[INDEX_MAX_KEYS];
int i,
curlen--;
v->spl_nright = curlen;
- /* workaround for 64-bit: ensure GISTENTRY array is maxaligned */
- storage = (char *) palloc(2 * sizeof(GISTENTRY) + MAXALIGN(VARHDRSZ));
- evec = (bytea *) (storage + MAXALIGN(VARHDRSZ) - VARHDRSZ);
- VARATT_SIZEP(evec) = 2 * sizeof(GISTENTRY) + VARHDRSZ;
- ev0p = &((GISTENTRY *) VARDATA(evec))[0];
- ev1p = &((GISTENTRY *) VARDATA(evec))[1];
+ evec = palloc(2 * sizeof(GISTENTRY) + GEVHDRSZ);
+ evec->n = 2;
+ ev0p = &(evec->vector[0]);
+ ev1p = &(evec->vector[1]);
/* add equivalent tuple */
for (i = 0; i < *len; i++)
}
gistFreeAtt(r, identry, decfree);
}
- pfree(storage); /* pfree(evec); */
+ pfree(evec);
}
/*
rbknum;
GISTPageOpaque opaque;
GIST_SPLITVEC v;
- bytea *entryvec;
- char *storage;
+ GistEntryVector *entryvec;
bool *decompvec;
int i,
j,
right = (Page) BufferGetPage(rightbuf);
/* generate the item array */
- /* workaround for 64-bit: ensure GISTENTRY array is maxaligned */
- storage = palloc(MAXALIGN(VARHDRSZ) + (*len + 1) * sizeof(GISTENTRY));
- entryvec = (bytea *) (storage + MAXALIGN(VARHDRSZ) - VARHDRSZ);
+ entryvec = palloc(GEVHDRSZ + (*len + 1) * sizeof(GISTENTRY));
+ entryvec->n = *len + 1;
decompvec = (bool *) palloc((*len + 1) * sizeof(bool));
- VARATT_SIZEP(entryvec) = (*len + 1) * sizeof(GISTENTRY) + VARHDRSZ;
for (i = 1; i <= *len; i++)
{
datum = index_getattr(itup[i - 1], 1, giststate->tupdesc, &IsNull);
- gistdentryinit(giststate, 0, &((GISTENTRY *) VARDATA(entryvec))[i],
+ gistdentryinit(giststate, 0, &(entryvec->vector[i]),
datum, r, p, i,
ATTSIZE(datum, giststate->tupdesc, 1, IsNull), FALSE, IsNull);
- if ((!isAttByVal(giststate, 0)) && ((GISTENTRY *) VARDATA(entryvec))[i].key != datum)
+ if ((!isAttByVal(giststate, 0)) && entryvec->vector[i].key != datum)
decompvec[i] = TRUE;
else
decompvec[i] = FALSE;
v.spl_grpflag = (char *) palloc0(sizeof(char) * (*len + 1));
v.spl_ngrp = (int *) palloc(sizeof(int) * (*len + 1));
- MaxGrpId = gistfindgroup(giststate, (GISTENTRY *) VARDATA(entryvec), &v);
+ MaxGrpId = gistfindgroup(giststate, entryvec->vector, &v);
/* form union of sub keys for each page (l,p) */
gistunionsubkey(r, giststate, itup, &v);
/* clean up the entry vector: its keys need to be deleted, too */
for (i = 1; i <= *len; i++)
if (decompvec[i])
- pfree(DatumGetPointer(((GISTENTRY *) VARDATA(entryvec))[i].key));
- pfree(storage); /* pfree(entryvec); */
+ pfree(DatumGetPointer(entryvec->vector[i].key));
+ pfree(entryvec);
pfree(decompvec);
/* form left and right vector */
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/access/gist.h,v 1.39 2003/11/29 22:40:55 pgsql Exp $
+ * $PostgreSQL: pgsql/src/include/access/gist.h,v 1.40 2004/03/30 15:45:33 teodor Exp $
*
*-------------------------------------------------------------------------
*/
bool leafkey;
} GISTENTRY;
+
+/*
+ * Vector of GISTENTRY struct's, user-defined
+ * methods union andpick split takes it as one of args
+ */
+
+typedef struct {
+ int32 n; /* number of elements */
+ GISTENTRY vector[1];
+} GistEntryVector;
+
+#define GEVHDRSZ ( offsetof(GistEntryVector, vector[0]) )
+
/*
* macro to initialize a GISTENTRY
*/