]> granicus.if.org Git - postgresql/commitdiff
Cleanup vectors of GISTENTRY and eliminate problem with 64-bit strict-aligned
authorTeodor Sigaev <teodor@sigaev.ru>
Tue, 30 Mar 2004 15:45:33 +0000 (15:45 +0000)
committerTeodor Sigaev <teodor@sigaev.ru>
Tue, 30 Mar 2004 15:45:33 +0000 (15:45 +0000)
boxes. Change interface to user-defined GiST support methods union and
picksplit. Now instead of bytea struct it used special GistEntryVector
structure.

24 files changed:
contrib/btree_gist/btree_common.c
contrib/btree_gist/btree_gist.h
contrib/btree_gist/btree_gist.sql.in
contrib/btree_gist/btree_num.c.in
contrib/btree_gist/btree_ts.c
contrib/cube/cube.c
contrib/cube/cube.sql.in
contrib/intarray/_int.sql.in
contrib/intarray/_int_gist.c
contrib/intarray/_intbig_gist.c
contrib/ltree/_ltree_gist.c
contrib/ltree/ltree.sql.in
contrib/ltree/ltree_gist.c
contrib/rtree_gist/rtree_gist.c
contrib/rtree_gist/rtree_gist.sql.in
contrib/seg/seg.c
contrib/seg/seg.sql.in
contrib/tsearch/gistidx.c
contrib/tsearch/tsearch.sql.in
contrib/tsearch2/gistidx.c
contrib/tsearch2/tsearch.sql.in
contrib/tsearch2/untsearch.sql.in
src/backend/access/gist/gist.c
src/include/access/gist.h

index 9306076e0aed94434980f1bfdb8377b7c68455c0..b2353bf57be05502b1e0597ed72c128f1ae2f1bd 100644 (file)
@@ -22,14 +22,14 @@ btree_decompress(PG_FUNCTION_ARGS)
 ** 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);
@@ -43,7 +43,7 @@ btree_picksplit(bytea *entryvec, GIST_SPLITVEC *v, BINARY_UNION bu, CMPFUNC cmp)
        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);
index ecbabc2dbb34e1017c31d5f7881cb5135433a348..08f6f1d29e241885a182370ec2562282eee3cc69 100644 (file)
@@ -21,5 +21,5 @@ typedef struct rix
 ** 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);
index 70db5a860dad74572e9b3633fa657d1f064e666a..b453d3029fe94a3d1b93b4830fea9650b6b5e5a8 100644 (file)
@@ -120,7 +120,7 @@ RETURNS internal
 AS 'MODULE_PATHNAME'
 LANGUAGE 'C';
 
-CREATE FUNCTION gint2_union(bytea, internal)
+CREATE FUNCTION gint2_union(internal, internal)
 RETURNS int4
 AS 'MODULE_PATHNAME'
 LANGUAGE 'C';
@@ -140,7 +140,7 @@ AS
        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),
@@ -176,7 +176,7 @@ RETURNS 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';
@@ -196,7 +196,7 @@ AS
        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),
@@ -232,7 +232,7 @@ RETURNS 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';
@@ -252,7 +252,7 @@ AS
        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),
@@ -289,7 +289,7 @@ RETURNS 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';
@@ -309,7 +309,7 @@ AS
        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),
@@ -348,7 +348,7 @@ RETURNS 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';
@@ -368,7 +368,7 @@ AS
        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),
@@ -422,7 +422,7 @@ RETURNS 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';
@@ -442,7 +442,7 @@ AS
        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),
index fd9052510fc611af8c9a874672d42c5f57e64974..1852834bb04769a2a108014373d6c6cf3cf9eef4 100644 (file)
@@ -138,22 +138,22 @@ g__BTREE_GIST_TYPE2___consistent(PG_FUNCTION_ARGS)
 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)
@@ -180,7 +180,7 @@ Datum
 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
index 59fdcdba5cde11ae57684c62201ace72c7d07c8b..658528dcb9931948445de465c0d50846c5163a30 100644 (file)
@@ -146,22 +146,22 @@ gts_consistent(PG_FUNCTION_ARGS)
 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))
@@ -204,7 +204,7 @@ Datum
 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
index 15fce4f1f7d6c56554dd0c674cda11f0a7a55e8b..b2cf5cf551fae2052d28ab3ad708bc2dbf4e3fe8 100644 (file)
@@ -46,10 +46,10 @@ bool                g_cube_consistent(GISTENTRY *entry, NDBOX * query, StrategyNumber strategy
 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);
 
@@ -211,28 +211,26 @@ g_cube_consistent(GISTENTRY *entry,
 ** 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);
@@ -289,7 +287,7 @@ g_cube_penalty(GISTENTRY *origentry, GISTENTRY *newentry, float *result)
 ** 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,
@@ -321,7 +319,7 @@ g_cube_picksplit(bytea *entryvec,
        /*
         * 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);
@@ -331,10 +329,10 @@ g_cube_picksplit(bytea *entryvec,
 
        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; */
@@ -369,10 +367,10 @@ g_cube_picksplit(bytea *entryvec,
        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);
 
@@ -411,7 +409,7 @@ g_cube_picksplit(bytea *entryvec,
                }
 
                /* 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);
index b9b812f5814460b62cbe976d13a12c5dbb6bdb1d..bd7137f8f78677ed6480e22524adc0f14eb79378 100644 (file)
@@ -324,7 +324,7 @@ RETURNS internal
 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';
@@ -357,7 +357,7 @@ CREATE OPERATOR CLASS gist_cube_ops
        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),
index 472cd1dc1c7986ae1d387cbc513c62c856bf448e..f0b35b218180bd987487aecfbb105e2640356928 100644 (file)
@@ -327,7 +327,7 @@ RETURNS 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';
@@ -348,7 +348,7 @@ DEFAULT FOR TYPE _int4 USING gist AS
        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),
@@ -402,7 +402,7 @@ RETURNS 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';
@@ -423,7 +423,7 @@ AS
        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),
index 39c9679adddfb490b27afad9da03d286b09c88be..ebf4ba3166c4381108d165bb37527fecd03870c2 100644 (file)
@@ -1,6 +1,6 @@
 #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
@@ -87,21 +87,20 @@ g_int_consistent(PG_FUNCTION_ARGS)
 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));
@@ -318,7 +317,7 @@ comparecost(const void *a, const void *b)
 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;
@@ -348,10 +347,10 @@ g_int_picksplit(PG_FUNCTION_ARGS)
        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);
@@ -360,10 +359,10 @@ g_int_picksplit(PG_FUNCTION_ARGS)
        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; */
@@ -403,10 +402,10 @@ g_int_picksplit(PG_FUNCTION_ARGS)
                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);
 
@@ -419,7 +418,7 @@ g_int_picksplit(PG_FUNCTION_ARGS)
        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);
@@ -467,7 +466,7 @@ g_int_picksplit(PG_FUNCTION_ARGS)
                }
 
                /* 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);
index e4588a0d4bbd12efe51cca97e1a878eac42fac42..04d26d90f9792e2c27ba4be519f20c4a4c8c7ad7 100644 (file)
@@ -1,6 +1,6 @@
 #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
 */
@@ -231,16 +231,15 @@ unionkey(BITVECP sbase, GISTTYPE * add)
 
 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;
@@ -283,7 +282,7 @@ comparecost(const void *a, const void *b) {
 
 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;
@@ -306,7 +305,7 @@ g_intbig_picksplit(PG_FUNCTION_ARGS) {
         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);
index 412fafa1ff8ec3834b29d40d6fb6b0e6f7fb7e0d..f1b2efb157ccd84c5ee4bd38fea1fc315d3ff7e2 100644 (file)
@@ -29,7 +29,7 @@ Datum         _ltree_picksplit(PG_FUNCTION_ARGS);
 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) + \
@@ -172,16 +172,15 @@ unionkey(BITVECP sbase, ltree_gist * add)
 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)))
                {
@@ -264,7 +263,7 @@ comparecost(const void *a, const void *b)
 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;
@@ -287,7 +286,7 @@ _ltree_picksplit(PG_FUNCTION_ARGS)
        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);
index 7d8bdc352405b75b023dd1e5f1e2a591c5757cfd..e80c391ab0e2e6e4d3a26b7ff68ce9b389cc2432 100644 (file)
@@ -499,7 +499,7 @@ CREATE FUNCTION ltree_penalty(internal,internal,internal)
 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';
@@ -520,7 +520,7 @@ CREATE OPERATOR CLASS gist_ltree_ops
        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),
@@ -825,7 +825,7 @@ 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';
@@ -845,7 +845,7 @@ CREATE OPERATOR CLASS gist__ltree_ops
        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),
index 65f408cd93c210d64d48c9cd281837cc6d62b9f4..eb091f99271055c78d3885b20cae25ba521eae88 100644 (file)
@@ -58,7 +58,7 @@ PG_FUNCTION_INFO_V1(ltree_consistent);
 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)
@@ -166,10 +166,9 @@ hashing(BITVECP sign, ltree * t)
 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,
@@ -181,7 +180,7 @@ ltree_union(PG_FUNCTION_ARGS)
        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))
@@ -285,7 +284,7 @@ treekey_cmp(const void *a, const void *b)
 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;
@@ -307,7 +306,7 @@ ltree_picksplit(PG_FUNCTION_ARGS)
 
        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);
index 4ba715e0e8db9e2054d7398647c5308a67a3e5e7..eee6c1e6b6670ae66defaef31c11efd71fc699c2 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * 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 $
  *
  *-------------------------------------------------------------------------
  */
@@ -98,21 +98,21 @@ gbox_consistent(PG_FUNCTION_ARGS)
 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)
@@ -186,7 +186,7 @@ compare_KB(const void *a, const void *b)
 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,
@@ -209,15 +209,15 @@ gbox_picksplit(PG_FUNCTION_ARGS)
        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 ||
@@ -243,7 +243,7 @@ gbox_picksplit(PG_FUNCTION_ARGS)
        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;
@@ -292,7 +292,7 @@ gbox_picksplit(PG_FUNCTION_ARGS)
 
        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
@@ -311,7 +311,7 @@ gbox_picksplit(PG_FUNCTION_ARGS)
                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);
index c721694f390507004357aa34c758c71fc3cff4ed..2fc38a7024e459e25671b15e541ed497453f6cc0 100644 (file)
@@ -34,7 +34,7 @@ RETURNS internal
 AS 'MODULE_PATHNAME'
 LANGUAGE 'C';
 
-CREATE FUNCTION gbox_union(bytea, internal)
+CREATE FUNCTION gbox_union(internal, internal)
 RETURNS box
 AS 'MODULE_PATHNAME'
 LANGUAGE 'C';
@@ -57,7 +57,7 @@ AS
        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),
@@ -96,7 +96,7 @@ AS
        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),
index b04441b1ed2e42418309125d10f0dcc369b51f5a..39f006291ed707ced21d1ce681ccde47338756eb 100644 (file)
@@ -48,10 +48,10 @@ bool                gseg_consistent(GISTENTRY *entry, SEG * query, StrategyNumber strategy);
 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);
 
@@ -222,7 +222,7 @@ gseg_consistent(GISTENTRY *entry,
 ** 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;
@@ -233,14 +233,14 @@ gseg_union(bytea *entryvec, int *sizep)
        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);
@@ -299,7 +299,7 @@ gseg_penalty(GISTENTRY *origentry, GISTENTRY *newentry, float *result)
 ** We use Guttman's poly time split algorithm
 */
 GIST_SPLITVEC *
-gseg_picksplit(bytea *entryvec,
+gseg_picksplit(GistEntryVector *entryvec,
                           GIST_SPLITVEC *v)
 {
        OffsetNumber i,
@@ -332,7 +332,7 @@ gseg_picksplit(bytea *entryvec,
        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);
@@ -342,10 +342,10 @@ gseg_picksplit(bytea *entryvec,
 
        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; */
@@ -380,10 +380,10 @@ gseg_picksplit(bytea *entryvec,
        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);
 
@@ -422,7 +422,7 @@ gseg_picksplit(bytea *entryvec,
                }
 
                /* 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);
index 2bfd96593dc8f447b68f70e229f61dc89517bbd7..52d2f61ad7a1fd6d5b39d9a16a616a8a861ef147 100644 (file)
@@ -328,7 +328,7 @@ RETURNS internal
 AS 'MODULE_PATHNAME'
 LANGUAGE 'C';
 
-CREATE FUNCTION gseg_union(bytea, internal)
+CREATE FUNCTION gseg_union(internal, internal)
 RETURNS seg 
 AS 'MODULE_PATHNAME'
 LANGUAGE 'C';
@@ -362,7 +362,7 @@ AS
        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),
index 9fe40fb0874001a7971672c6ed246215fb753946..5b00960e1cb2dbb78dd8c566365a54d0192938de 100644 (file)
@@ -42,7 +42,7 @@ Datum         gtxtidx_penalty(PG_FUNCTION_ARGS);
 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) + \
@@ -326,16 +326,15 @@ unionkey(BITVECP sbase, GISTTYPE * add)
 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)))
                {
@@ -513,7 +512,7 @@ comparecost(const void *a, const void *b)
 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;
@@ -544,7 +543,7 @@ gtxtidx_picksplit(PG_FUNCTION_ARGS)
        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);
index 899b720eb64417b316aa8e9c94dc01c540af69b8..b247e2327614c9fb034acdb8be2d35b31c384dfc 100644 (file)
@@ -192,7 +192,7 @@ RETURNS internal
 AS 'MODULE_PATHNAME'
 LANGUAGE 'C';
 
-CREATE FUNCTION gtxtidx_union(bytea, internal)
+CREATE FUNCTION gtxtidx_union(internal, internal)
 RETURNS _int4
 AS 'MODULE_PATHNAME'
 LANGUAGE 'C';
@@ -209,7 +209,7 @@ AS
        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),
index 7d5547896cb0300043a5d843354fd5580b5b518d..6f9475a0c79f1c2a3d51b90dd2515940a1774fe8 100644 (file)
@@ -42,7 +42,7 @@ Datum         gtsvector_penalty(PG_FUNCTION_ARGS);
 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) + \
@@ -326,16 +326,15 @@ unionkey(BITVECP sbase, GISTTYPE * add)
 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)))
                {
@@ -526,7 +525,7 @@ hemdistcache(CACHESIGN   *a, CACHESIGN   *b) {
 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;
@@ -549,7 +548,7 @@ gtsvector_picksplit(PG_FUNCTION_ARGS)
        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);
index 71925beed8194967519f62d5b4bec3aaf6f7f425..8e542919435eb31f5f5964dc62cd95d1cef54003 100644 (file)
@@ -581,7 +581,7 @@ RETURNS internal
 AS 'MODULE_PATHNAME'
 LANGUAGE 'C';
 
-CREATE FUNCTION gtsvector_union(bytea, internal)
+CREATE FUNCTION gtsvector_union(internal, internal)
 RETURNS _int4
 AS 'MODULE_PATHNAME'
 LANGUAGE 'C';
@@ -597,7 +597,7 @@ DEFAULT FOR TYPE tsvector USING gist
 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),
index e7cfcc6a879ac5066f119e2a18671b265e4f9834..f775ba4b9d518c3b7209530971172f185d8b11a6 100644 (file)
@@ -57,7 +57,7 @@ DROP FUNCTION gtsvector_compress(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();
index b117b33f72de197c327271e6dd0db435b9f5511c..3b3f8df6d7dce2d4b524798e36e04126667e0187 100644 (file)
@@ -8,7 +8,7 @@
  * 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 $
  *
  *-------------------------------------------------------------------------
  */
@@ -667,8 +667,7 @@ gistunion(Relation r, IndexTuple *itvec, int len, GISTSTATE *giststate)
        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,
@@ -680,9 +679,7 @@ gistunion(Relation r, IndexTuple *itvec, int len, GISTSTATE *giststate)
        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++)
        {
@@ -694,12 +691,12 @@ gistunion(Relation r, IndexTuple *itvec, int len, GISTSTATE *giststate)
                                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;
@@ -716,21 +713,21 @@ gistunion(Relation r, IndexTuple *itvec, int len, GISTSTATE *giststate)
                {
                        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, &centry[j], datum,
                                                   NULL, NULL, (OffsetNumber) 0,
@@ -748,7 +745,7 @@ gistunion(Relation r, IndexTuple *itvec, int len, GISTSTATE *giststate)
                }
        }
 
-       pfree(storage);                         /* pfree(evec); */
+       pfree(evec);
        pfree(needfree);
 
        newtup = (IndexTuple) index_formtuple(giststate->tupdesc, attr, isnull);
@@ -766,7 +763,7 @@ gistunion(Relation r, IndexTuple *itvec, int len, GISTSTATE *giststate)
 static IndexTuple
 gistgetadjusted(Relation r, IndexTuple oldtup, IndexTuple addtup, GISTSTATE *giststate)
 {
-       bytea      *evec;
+       GistEntryVector    *evec;
        Datum           datum;
        int                     datumsize;
        bool            result,
@@ -784,15 +781,12 @@ gistgetadjusted(Relation r, IndexTuple oldtup, IndexTuple addtup, GISTSTATE *gis
        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);
@@ -857,7 +851,7 @@ gistgetadjusted(Relation r, IndexTuple oldtup, IndexTuple addtup, GISTSTATE *gis
                                whatfree[j] = FALSE;
                }
        }
-       pfree(storage);                         /* pfree(evec); */
+       pfree(evec);
 
        if (neednew)
        {
@@ -885,8 +879,7 @@ gistunionsubkey(Relation r, GISTSTATE *giststate, IndexTuple *itvec, GIST_SPLITV
        int                     len,
                           *attrsize;
        OffsetNumber *entries;
-       bytea      *evec;
-       char       *storage;
+       GistEntryVector    *evec;
        Datum           datum;
        int                     datumsize;
        int                     reallen;
@@ -912,9 +905,7 @@ gistunionsubkey(Relation r, GISTSTATE *giststate, IndexTuple *itvec, GIST_SPLITV
                }
 
                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++)
                {
@@ -928,12 +919,12 @@ gistunionsubkey(Relation r, GISTSTATE *giststate, IndexTuple *itvec, GIST_SPLITV
                                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;
@@ -949,18 +940,18 @@ gistunionsubkey(Relation r, GISTSTATE *giststate, IndexTuple *itvec, GIST_SPLITV
                        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));
@@ -969,12 +960,12 @@ gistunionsubkey(Relation r, GISTSTATE *giststate, IndexTuple *itvec, GIST_SPLITV
 
                        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);
        }
 }
@@ -1065,8 +1056,7 @@ gistadjsubkey(Relation r,
                           *ev1p;
        float           lpenalty,
                                rpenalty;
-       bytea      *evec;
-       char       *storage;
+       GistEntryVector    *evec;
        int                     datumsize;
        bool            isnull[INDEX_MAX_KEYS];
        int                     i,
@@ -1098,12 +1088,10 @@ gistadjsubkey(Relation r,
                        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++)
@@ -1208,7 +1196,7 @@ gistadjsubkey(Relation r,
                }
                gistFreeAtt(r, identry, decfree);
        }
-       pfree(storage);                         /* pfree(evec); */
+       pfree(evec);
 }
 
 /*
@@ -1234,8 +1222,7 @@ gistSplit(Relation r,
                                rbknum;
        GISTPageOpaque opaque;
        GIST_SPLITVEC v;
-       bytea      *entryvec;
-       char       *storage;
+       GistEntryVector    *entryvec;
        bool       *decompvec;
        int                     i,
                                j,
@@ -1274,18 +1261,16 @@ gistSplit(Relation r,
        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;
@@ -1320,7 +1305,7 @@ gistSplit(Relation r,
                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);
@@ -1340,8 +1325,8 @@ gistSplit(Relation r,
        /* 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 */
index 72b77523cff9512431f4fa22fcb8b2ff208c82b1..1d4bc1989de82a4a343e8e81a9116a5cfb645086 100644 (file)
@@ -7,7 +7,7 @@
  * 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 $
  *
  *-------------------------------------------------------------------------
  */
@@ -157,6 +157,19 @@ typedef struct GISTENTRY
        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
  */