*result = 0.0;
- res = Max(newentry->upper - origentry->upper, 0) +
- Max(origentry->lower - newentry->lower, 0);
+ penalty_range_enlarge ( origentry->lower, origentry->upper, newentry->lower, newentry->upper );
if ( res > 0 ){
*result += FLT_MIN ;
dateKEY *kkk = (dateKEY *) DatumGetPointer(entry->key);
GBT_NUMKEY_R key ;
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
key.lower = (GBT_NUMKEY*) &kkk->lower ;
key.upper = (GBT_NUMKEY*) &kkk->upper ;
-
+
PG_RETURN_BOOL(
gbt_num_consistent( &key, (void*)&query,&strategy,GIST_LEAF(entry),&tinfo)
);
gbt_float4_consistent(PG_FUNCTION_ARGS)
{
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- float4 query = PG_GETARG_FLOAT4(1);
- float4KEY *kkk = (float4KEY *) DatumGetPointer(entry->key);
+ float4 query = PG_GETARG_FLOAT4(1);
+ float4KEY *kkk = (float4KEY *) DatumGetPointer(entry->key);
GBT_NUMKEY_R key ;
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
key.lower = (GBT_NUMKEY*) &kkk->lower ;
*result = 0.0;
- res = Max(newentry->upper - origentry->upper, 0) +
- Max(origentry->lower - newentry->lower, 0);
+ penalty_range_enlarge ( origentry->lower, origentry->upper, newentry->lower, newentry->upper );
if ( res > 0 ){
*result += FLT_MIN ;
Datum
gbt_float8_consistent(PG_FUNCTION_ARGS)
{
+
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
float8 query = PG_GETARG_FLOAT8(1);
float8KEY *kkk = (float8KEY *) DatumGetPointer(entry->key);
*result = 0.0;
- res = Max(newentry->upper - origentry->upper, 0) +
- Max(origentry->lower - newentry->lower, 0);
+ penalty_range_enlarge ( origentry->lower, origentry->upper, newentry->lower, newentry->upper );
if ( res > 0 ){
*result += FLT_MIN ;
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
+CREATE FUNCTION gbt_intv_decompress(internal)
+RETURNS internal
+AS 'MODULE_PATHNAME'
+LANGUAGE 'C';
+
CREATE FUNCTION gbt_intv_penalty(internal,internal,internal)
RETURNS internal
AS 'MODULE_PATHNAME'
FUNCTION 1 gbt_intv_consistent (internal, interval, int2),
FUNCTION 2 gbt_intv_union (bytea, internal),
FUNCTION 3 gbt_intv_compress (internal),
- FUNCTION 4 gbt_decompress (internal),
+ FUNCTION 4 gbt_intv_decompress (internal),
FUNCTION 5 gbt_intv_penalty (internal, internal, internal),
FUNCTION 6 gbt_intv_picksplit (internal, internal),
FUNCTION 7 gbt_intv_same (internal, internal, internal),
){
inetKEY *kkk = (inetKEY *) DatumGetPointer(entry->key);
GBT_NUMKEY_R key ;
+
key.lower = (GBT_NUMKEY*) &kkk->lower ;
key.upper = (GBT_NUMKEY*) &kkk->upper ;
-
+
return (
gbt_num_consistent( &key, (void*)query,strategy,GIST_LEAF(entry),&tinfo)
);
*result = 0.0;
- res = Max(newentry->upper - origentry->upper, 0) +
- Max(origentry->lower - newentry->lower, 0);
+ penalty_range_enlarge ( origentry->lower, origentry->upper, newentry->lower, newentry->upper );
if ( res > 0 ){
*result += FLT_MIN ;
*result = 0.0;
- res = Max(newentry->upper - origentry->upper, 0) +
- Max(origentry->lower - newentry->lower, 0);
+ penalty_range_enlarge ( origentry->lower, origentry->upper, newentry->lower, newentry->upper );
if ( res > 0 ){
*result += FLT_MIN ;
Datum
gbt_int4_consistent(PG_FUNCTION_ARGS)
{
+
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
int32 query = PG_GETARG_INT32(1);
int32KEY *kkk = (int32KEY *) DatumGetPointer(entry->key);
*result = 0.0;
- res = Max(newentry->upper - origentry->upper, 0) +
- Max(origentry->lower - newentry->lower, 0);
+ penalty_range_enlarge ( origentry->lower, origentry->upper, newentry->lower, newentry->upper );
if ( res > 0 ){
*result += FLT_MIN ;
*result = 0.0;
- res = Max(newentry->upper - origentry->upper, 0) +
- Max(origentry->lower - newentry->lower, 0);
+ penalty_range_enlarge ( origentry->lower, origentry->upper, newentry->lower, newentry->upper );
if ( res > 0 ){
*result += FLT_MIN ;
typedef struct
{
- Interval lower,
- upper;
+ Interval lower, upper;
} intvKEY;
** Interval ops
*/
PG_FUNCTION_INFO_V1(gbt_intv_compress);
+PG_FUNCTION_INFO_V1(gbt_intv_decompress);
PG_FUNCTION_INFO_V1(gbt_intv_union);
PG_FUNCTION_INFO_V1(gbt_intv_picksplit);
PG_FUNCTION_INFO_V1(gbt_intv_consistent);
PG_FUNCTION_INFO_V1(gbt_intv_same);
Datum gbt_intv_compress(PG_FUNCTION_ARGS);
+Datum gbt_intv_decompress(PG_FUNCTION_ARGS);
Datum gbt_intv_union(PG_FUNCTION_ARGS);
Datum gbt_intv_picksplit(PG_FUNCTION_ARGS);
Datum gbt_intv_consistent(PG_FUNCTION_ARGS);
static bool gbt_intvgt (const void *a, const void *b)
{
- return DirectFunctionCall2 ( interval_gt , IntervalPGetDatum ( a ) , IntervalPGetDatum ( b ) );
+ return DatumGetBool(DirectFunctionCall2 ( interval_gt , IntervalPGetDatum ( a ) , IntervalPGetDatum ( b ) ));
}
static bool gbt_intvge (const void *a, const void *b)
{
- return DirectFunctionCall2 ( interval_ge , IntervalPGetDatum ( a ) , IntervalPGetDatum ( b ) );
+ return DatumGetBool(DirectFunctionCall2 ( interval_ge , IntervalPGetDatum ( a ) , IntervalPGetDatum ( b ) ));
}
static bool gbt_intveq (const void *a, const void *b)
{
- return DirectFunctionCall2 ( interval_eq , IntervalPGetDatum ( a ) , IntervalPGetDatum ( b ) );
+ return DatumGetBool(DirectFunctionCall2 ( interval_eq , IntervalPGetDatum ( a ) , IntervalPGetDatum ( b ) ));
}
static bool gbt_intvle (const void *a, const void *b)
{
- return DirectFunctionCall2 ( interval_le , IntervalPGetDatum ( a ) , IntervalPGetDatum ( b ) );
+ return DatumGetBool(DirectFunctionCall2 ( interval_le , IntervalPGetDatum ( a ) , IntervalPGetDatum ( b ) ));
}
static bool gbt_intvlt (const void *a, const void *b)
{
- return DirectFunctionCall2 ( interval_lt , IntervalPGetDatum ( a ) , IntervalPGetDatum ( b ) );
+ return DatumGetBool(DirectFunctionCall2 ( interval_lt , IntervalPGetDatum ( a ) , IntervalPGetDatum ( b ) ));
}
static int
{
return DatumGetInt32 (
DirectFunctionCall2 ( interval_cmp ,
- IntervalPGetDatum(&((Nsrt *) a)->t[0]) ,
- IntervalPGetDatum(&((Nsrt *) b)->t[0])
+ IntervalPGetDatum(((Nsrt *) a)->t) ,
+ IntervalPGetDatum(((Nsrt *) b)->t)
)
);
}
+
+static double intr2num ( const Interval * i )
+{
+ double ret = 0.0;
+ struct pg_tm tm;
+ fsec_t fsec;
+ interval2tm( *i, &tm, &fsec);
+ ret += ( tm.tm_year * 360.0 * 86400.0 ) ;
+ ret += ( tm.tm_mon * 12.0 * 86400.0 ) ;
+ ret += ( tm.tm_mday * 86400.0 ) ;
+ ret += ( tm.tm_hour * 3600.0 ) ;
+ ret += ( tm.tm_min * 60.0 ) ;
+ ret += ( tm.tm_sec ) ;
+ ret += ( fsec / 1000000.0 );
+
+ return ( ret );
+}
+
+#define INTERVALSIZE 12
+
static const gbtree_ninfo tinfo =
{
gbt_t_intv,
gbt_intv_compress(PG_FUNCTION_ARGS)
{
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- GISTENTRY *retval = NULL;
- PG_RETURN_POINTER( gbt_num_compress( retval , entry , &tinfo ));
+ GISTENTRY *retval = entry;
+ if ( entry->leafkey || INTERVALSIZE != sizeof(Interval) ) {
+ char *r = ( char * ) palloc(2 * INTERVALSIZE);
+
+ retval = palloc(sizeof(GISTENTRY));
+
+ if ( entry->leafkey ) {
+ Interval *key = DatumGetIntervalP(entry->key);
+ memcpy( (void*) r , (void*)key, INTERVALSIZE);
+ memcpy( (void*)(r + INTERVALSIZE), (void*)key, INTERVALSIZE);
+ } else {
+ intvKEY *key = ( intvKEY * ) DatumGetPointer(entry->key);
+ memcpy(r, &key->lower, INTERVALSIZE);
+ memcpy(r + INTERVALSIZE, &key->upper, INTERVALSIZE);
+ }
+ gistentryinit(*retval, PointerGetDatum(r),
+ entry->rel, entry->page,
+ entry->offset, 2 * INTERVALSIZE, FALSE);
+ }
+
+ PG_RETURN_POINTER(retval);
+
}
-
+
+Datum
+gbt_intv_decompress(PG_FUNCTION_ARGS)
+{
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ GISTENTRY *retval = entry;
+
+ if ( INTERVALSIZE != sizeof(Interval) ) {
+ intvKEY *r = palloc(sizeof(intvKEY));
+ char *key = DatumGetPointer(entry->key);
+
+ retval = palloc(sizeof(GISTENTRY));
+ memcpy( &r->lower, key, INTERVALSIZE);
+ memcpy( &r->upper, key+ INTERVALSIZE, INTERVALSIZE);
+
+ gistentryinit(*retval, PointerGetDatum(r),
+ entry->rel, entry->page,
+ entry->offset, sizeof(intvKEY), FALSE);
+ }
+ PG_RETURN_POINTER(retval);
+}
+
Datum
gbt_intv_consistent(PG_FUNCTION_ARGS)
intvKEY *kkk = (intvKEY *) DatumGetPointer(entry->key);
GBT_NUMKEY_R key ;
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
key.lower = (GBT_NUMKEY*) &kkk->lower ;
key.upper = (GBT_NUMKEY*) &kkk->upper ;
{
intvKEY *origentry = (intvKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
intvKEY *newentry = (intvKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
- float *result = (float *) PG_GETARG_POINTER(2);
- Interval *intr;
-#ifdef HAVE_INT64_TIMESTAMP
- int64 res;
-#else
- double res;
-#endif
-
- intr = DatumGetIntervalP(DirectFunctionCall2(
- interval_mi,
- IntervalPGetDatum(&newentry->upper),
- IntervalPGetDatum(&origentry->upper)
- ));
-
- /* see interval_larger */
+ float *result = (float *) PG_GETARG_POINTER(2);
+ double iorg[2], inew[2], res;
- res = Max(intr->time + intr->month * (30 * 86400), 0);
- pfree(intr);
+ iorg[0] = intr2num ( &origentry->lower );
+ iorg[1] = intr2num ( &origentry->upper );
+ inew[0] = intr2num ( &newentry->lower );
+ inew[1] = intr2num ( &newentry->upper );
- intr = DatumGetIntervalP(DirectFunctionCall2(
- interval_mi,
- IntervalPGetDatum(&origentry->lower),
- IntervalPGetDatum(&newentry->lower)
- ));
-
- /* see interval_larger */
- res += Max(intr->time + intr->month * (30 * 86400), 0);
- pfree(intr);
+ penalty_range_enlarge ( iorg[0], iorg[1], inew[0], inew[1] );
*result = 0.0;
if ( res > 0 ){
-
- intr = DatumGetIntervalP(DirectFunctionCall2(
- interval_mi,
- IntervalPGetDatum(&origentry->upper),
- IntervalPGetDatum(&origentry->lower)
- ));
-
*result += FLT_MIN ;
- *result += (float) ( res / ( (double) ( res + intr->time + intr->month * (30 * 86400) ) ) );
+ *result += (float) ( res / ( res + iorg[1] - iorg[0] ) );
*result *= ( FLT_MAX / ( ( (GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1 ) );
-
- pfree ( intr );
-
}
PG_RETURN_POINTER(result);
-
}
Datum
-static int64 mac_2_int64 ( macaddr * m ){
+static uint64 mac_2_uint64 ( macaddr * m ){
unsigned char * mi = ( unsigned char * ) m;
- int64 res = 0;
+ uint64 res = 0;
int i;
for (i=0; i<6; i++ ){
- res += mi[i] << ( (5-i)*8 );
+ res += ( ( (uint64) mi[i] ) << ( (uint64) ( (5-i)*8 ) ) );
}
return res;
}
Datum
gbt_macad_consistent(PG_FUNCTION_ARGS)
{
+
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
macaddr *query = (macaddr *) PG_GETARG_POINTER(1);
macKEY *kkk = (macKEY *) DatumGetPointer(entry->key);
macKEY *origentry = (macKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
macKEY *newentry = (macKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
float *result = (float *) PG_GETARG_POINTER(2);
- int64 iorg[2], inew[2], res ;
+ uint64 iorg[2], inew[2];
+ uint64 res;
- iorg[0] = mac_2_int64 ( &origentry->lower );
- iorg[1] = mac_2_int64 ( &origentry->upper );
- inew[0] = mac_2_int64 ( &newentry->lower );
- inew[1] = mac_2_int64 ( &newentry->upper );
+ iorg[0] = mac_2_uint64 ( &origentry->lower );
+ iorg[1] = mac_2_uint64 ( &origentry->upper );
+ inew[0] = mac_2_uint64 ( &newentry->lower );
+ inew[1] = mac_2_uint64 ( &newentry->upper );
- res = Max(inew[1] - iorg[1], 0) +
- Max(iorg[0] - inew[0] , 0);
+ penalty_range_enlarge ( iorg[0], iorg[1], inew[0], inew[1] );
*result = 0.0;
if ( res > 0 ){
*result += FLT_MIN ;
- *result += (float) ( res / ( (double) ( res + iorg[1] - iorg[0] ) ) );
+ *result += (float) ( ( (double)res ) / ( (double)res + (double)iorg[1] - (double)iorg[0] ) );
*result *= ( FLT_MAX / ( ( (GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1 ) );
}
Datum
gbt_oid_consistent(PG_FUNCTION_ARGS)
{
+
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
Oid query = PG_GETARG_OID(1);
oidKEY *kkk = (oidKEY *) DatumGetPointer(entry->key);
oidKEY *newentry = (oidKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
float *result = (float *) PG_GETARG_POINTER(2);
- Oid res ;
+ Oid res = 0 ;
*result = 0.0;
- res = Max(newentry->upper - origentry->upper, 0) +
- Max(origentry->lower - newentry->lower, 0);
+ penalty_range_enlarge ( origentry->lower, origentry->upper, newentry->lower , newentry->upper );
if ( res > 0 ){
*result += FLT_MIN ;
{
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
TimeADT query = PG_GETARG_TIMEADT( 1 );
- timeKEY *kkk = (timeKEY *) DatumGetPointer(entry->key);
+ timeKEY *kkk = (timeKEY*) DatumGetPointer(entry->key);
GBT_NUMKEY_R key ;
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
key.lower = (GBT_NUMKEY*) &kkk->lower ;
key.upper = (GBT_NUMKEY*) &kkk->upper ;
+
PG_RETURN_BOOL(
gbt_num_consistent( &key, (void*)&query,&strategy,GIST_LEAF(entry),&tinfo)
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
TimeTzADT *query = PG_GETARG_TIMETZADT_P( 1 );
TimeADT qqq = query->time + query->zone ;
- timeKEY *kkk = (timeKEY *) DatumGetPointer(entry->key);
+ timeKEY *kkk = (timeKEY*) DatumGetPointer(entry->key);
GBT_NUMKEY_R key ;
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
key.lower = (GBT_NUMKEY*) &kkk->lower ;
key.upper = (GBT_NUMKEY*) &kkk->upper ;
if (entry->leafkey)
{
tsKEY *r = (tsKEY *) palloc(sizeof(tsKEY));
-
+
TimestampTz ts = *(TimestampTz *) DatumGetPointer(entry->key);
Timestamp gmt ;
tsKEY *kkk = (tsKEY *) DatumGetPointer(entry->key);
GBT_NUMKEY_R key ;
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
key.lower = (GBT_NUMKEY*) &kkk->lower ;
key.upper = (GBT_NUMKEY*) &kkk->upper ;
{
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
TimestampTz *query = (Timestamp *) PG_GETARG_POINTER(1);
- tsKEY *kkk = (tsKEY *) DatumGetPointer(entry->key);
+ char *kkk = (char *) DatumGetPointer(entry->key);
GBT_NUMKEY_R key ;
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
Timestamp qqq ;
- key.lower = (GBT_NUMKEY*) &kkk->lower ;
- key.upper = (GBT_NUMKEY*) &kkk->upper ;
+
+ key.lower = (GBT_NUMKEY*) &kkk[0];
+ key.upper = (GBT_NUMKEY*) &kkk[MAXALIGN(tinfo.size)];
tstz_to_ts_gmt ( &qqq, query );
PG_RETURN_BOOL(
TimeADT ts;
DateADT dt;
} v ;
-
- GBT_NUMKEY *r = ( GBT_NUMKEY * ) palloc(2 * tinfo->size);
+
+ GBT_NUMKEY *r = ( GBT_NUMKEY * ) palloc(2 * tinfo->size );
void *leaf = NULL;
switch ( tinfo->t )
leaf = DatumGetPointer(entry->key);
}
- memcpy ( (void*) &r[0] , leaf, tinfo->size );
- memcpy ( (void*) &r[tinfo->size] , leaf, tinfo->size );
-
+ memset ( (void*) &r[0] , 0 , 2*tinfo->size );
+ memcpy ( (void*) &r[0] , leaf, tinfo->size );
+ memcpy ( (void*) &r[tinfo->size] , leaf, tinfo->size );
retval = palloc(sizeof(GISTENTRY));
gistentryinit(*retval, PointerGetDatum(r), entry->rel, entry->page,
- entry->offset,( 2 * tinfo->size), FALSE);
+ entry->offset,( 2 * tinfo->size ), FALSE);
} else
retval = entry;
GBT_NUMKEY * cur ;
GBT_NUMKEY_R o, c;
- numranges = entryvec->n;
- cur = (GBT_NUMKEY *) DatumGetPointer((entryvec->vector[0].key));
+ numranges = entryvec->n;
+ cur = (GBT_NUMKEY *) DatumGetPointer((entryvec->vector[0].key));
o.lower = &((GBT_NUMKEY *)out)[0];
cur = (GBT_NUMKEY *) DatumGetPointer((entryvec->vector[i].key));
c.lower = &cur[0];
c.upper = &cur[tinfo->size];
-
if ( (*tinfo->f_gt)(o.lower, c.lower) ) /* out->lower > cur->lower */
memcpy( (void* ) o.lower, (void*) c.lower, tinfo->size );
if ( (*tinfo->f_lt)(o.upper, c.upper) ) /* out->upper < cur->upper */
{
GBT_NUMKEY_R rd;
+
rd.lower = &e[0];
rd.upper = &e[tinfo->size];
if (!DatumGetPointer(*u))
{
*u = PointerGetDatum(palloc(2 * tinfo->size));
- memcpy( (void* ) &( ( (GBT_NUMKEY *) DatumGetPointer(*u) )[0] ) , (void*)rd.lower , tinfo->size );
+ memcpy( (void* ) &( ( (GBT_NUMKEY *) DatumGetPointer(*u) )[0] ) , (void*)rd.lower , tinfo->size );
memcpy( (void* ) &( ( (GBT_NUMKEY *) DatumGetPointer(*u) )[tinfo->size]) , (void*)rd.upper , tinfo->size );
}
else
{
GBT_NUMKEY_R ur ;
- ur.lower = &( ( (GBT_NUMKEY *) DatumGetPointer(*u) )[0] ) ;
+ ur.lower = &( ( (GBT_NUMKEY *) DatumGetPointer(*u) )[0] ) ;
ur.upper = &( ( (GBT_NUMKEY *) DatumGetPointer(*u) )[tinfo->size]) ;
if ( (*tinfo->f_gt)((void*)ur.lower, (void*)rd.lower) )
memcpy( (void*) ur.lower, (void*) rd.lower, tinfo->size );
if ( (*tinfo->f_lt)((void*)ur.upper, (void*)rd.upper) )
memcpy( (void*) ur.upper, (void*) rd.upper, tinfo->size );
}
-
}
* Numeric btree functions
*/
+
+#define penalty_range_enlarge(olower,oupper,nlower,nupper) do { \
+ res = 0; \
+ if ( (nupper) > (oupper) ) \
+ res += ( (nupper) - (oupper) ); \
+ if ( (olower) > (nlower) ) \
+ res += ( (olower) - (nlower) ); \
+} while (0);
+
+
+
extern bool gbt_num_consistent( const GBT_NUMKEY_R * key , const void * query,
const StrategyNumber * strategy , bool is_leaf,
const gbtree_ninfo * tinfo );
GBT_VARKEY_R r ;
r.lower = ( bytea * ) &(((char*)k)[VARHDRSZ] ) ;
if ( VARSIZE(k) > ( VARHDRSZ+(VARSIZE(r.lower)) ) )
- r.upper = ( bytea * ) &(((char*)k)[VARHDRSZ+(VARSIZE(r.lower))] ) ;
+ r.upper = ( bytea * ) &(((char*)k)[VARHDRSZ+INTALIGN(VARSIZE(r.lower))] ) ;
else
r.upper = r.lower;
return r;
} else { /* node key mode */
- r = (GBT_VARKEY *) palloc(VARSIZE(u->lower) + VARSIZE(u->upper) + VARHDRSZ );
+ r = (GBT_VARKEY *) palloc(INTALIGN(VARSIZE(u->lower)) + VARSIZE(u->upper) + VARHDRSZ );
memcpy ( (void*) VARDATA(r) , (void*) u->lower , VARSIZE(u->lower) );
- memcpy ( (void*)&(((char *)r)[VARHDRSZ+VARSIZE(u->lower)]), (void*) u->upper , VARSIZE(u->upper) );
- r->vl_len = VARSIZE(u->lower) + VARSIZE(u->upper) + VARHDRSZ ;
+ memcpy ( (void*)&(((char *)r)[VARHDRSZ+INTALIGN(VARSIZE(u->lower))]), (void*) u->upper , VARSIZE(u->upper) );
+ r->vl_len = INTALIGN(VARSIZE(u->lower)) + VARSIZE(u->upper) + VARHDRSZ ;
}
return r;
len1 = Min( len1, length ) ;
len2 = Min( len2, length ) ;
- si = 3*VARHDRSZ + len1 + len2;
+ si = 2*VARHDRSZ + INTALIGN(VARHDRSZ+len1) + len2;
out = (GBT_VARKEY *) palloc ( si );
out->vl_len = si;
memcpy ( (void*) &(((char*)out)[VARHDRSZ]) , (void*)r.lower, len1+VARHDRSZ-s );
- memcpy ( (void*) &(((char*)out)[2*VARHDRSZ+len1]) , (void*)r.upper, len2+VARHDRSZ-s );
+ memcpy ( (void*) &(((char*)out)[VARHDRSZ+INTALIGN(VARHDRSZ+len1)]) , (void*)r.upper, len2+VARHDRSZ-s );
if (tinfo->str)
{
- ((char*)out)[2*VARHDRSZ+len1-1] = '\0';
- ((char*)out)[3*VARHDRSZ+len1+len2-1] = '\0';
+ ((char*)out)[VARHDRSZ+INTALIGN(VARHDRSZ+len1)-1] = '\0';
+ ((char*)out)[2*VARHDRSZ+INTALIGN(VARHDRSZ+len1)+len2-1] = '\0';
}
*((int32*)&(((char*)out)[VARHDRSZ])) = len1 + VARHDRSZ;
- *((int32*)&(((char*)out)[2*VARHDRSZ+len1])) = len2 + VARHDRSZ;
+ *((int32*)&(((char*)out)[VARHDRSZ+INTALIGN(VARHDRSZ+len1)])) = len2 + VARHDRSZ;
return out;
}