mirror of
https://github.com/postgres/postgres.git
synced 2025-06-05 23:56:58 +03:00
Remove usage of ArrayType->flags field, use pgsql's macros BITS_PER_BYTE instead
of self-defined macros, add limit of Array to gist__int_ops. BTW, intarray now doesn't support NULLs in arrays.
This commit is contained in:
parent
bad1a5c217
commit
08ee64ebf5
@ -17,13 +17,6 @@
|
|||||||
/* dimension of array */
|
/* dimension of array */
|
||||||
#define NDIM 1
|
#define NDIM 1
|
||||||
|
|
||||||
/*
|
|
||||||
* flags for gist__int_ops, use ArrayType->flags
|
|
||||||
* which is unused (see array.h)
|
|
||||||
*/
|
|
||||||
#define LEAFKEY (1<<31)
|
|
||||||
#define ISLEAFKEY(x) ( ((ArrayType*)(x))->flags & LEAFKEY )
|
|
||||||
|
|
||||||
/* useful macros for accessing int4 arrays */
|
/* useful macros for accessing int4 arrays */
|
||||||
#define ARRPTR(x) ( (int4 *) ARR_DATA_PTR(x) )
|
#define ARRPTR(x) ( (int4 *) ARR_DATA_PTR(x) )
|
||||||
#define ARRNELEMS(x) ArrayGetNItems( ARR_NDIM(x), ARR_DIMS(x))
|
#define ARRNELEMS(x) ArrayGetNItems( ARR_NDIM(x), ARR_DIMS(x))
|
||||||
@ -52,10 +45,9 @@
|
|||||||
|
|
||||||
|
|
||||||
/* bigint defines */
|
/* bigint defines */
|
||||||
#define BITBYTE 8
|
|
||||||
#define SIGLENINT 63 /* >122 => key will toast, so very slow!!! */
|
#define SIGLENINT 63 /* >122 => key will toast, so very slow!!! */
|
||||||
#define SIGLEN ( sizeof(int)*SIGLENINT )
|
#define SIGLEN ( sizeof(int)*SIGLENINT )
|
||||||
#define SIGLENBIT (SIGLEN*BITBYTE)
|
#define SIGLENBIT (SIGLEN*BITS_PER_BYTE)
|
||||||
|
|
||||||
typedef char BITVEC[SIGLEN];
|
typedef char BITVEC[SIGLEN];
|
||||||
typedef char *BITVECP;
|
typedef char *BITVECP;
|
||||||
@ -74,11 +66,11 @@ typedef char *BITVECP;
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* beware of multiple evaluation of arguments to these macros! */
|
/* beware of multiple evaluation of arguments to these macros! */
|
||||||
#define GETBYTE(x,i) ( *( (BITVECP)(x) + (int)( (i) / BITBYTE ) ) )
|
#define GETBYTE(x,i) ( *( (BITVECP)(x) + (int)( (i) / BITS_PER_BYTE ) ) )
|
||||||
#define GETBITBYTE(x,i) ( (*((char*)(x)) >> (i)) & 0x01 )
|
#define GETBITBYTE(x,i) ( (*((char*)(x)) >> (i)) & 0x01 )
|
||||||
#define CLRBIT(x,i) GETBYTE(x,i) &= ~( 0x01 << ( (i) % BITBYTE ) )
|
#define CLRBIT(x,i) GETBYTE(x,i) &= ~( 0x01 << ( (i) % BITS_PER_BYTE ) )
|
||||||
#define SETBIT(x,i) GETBYTE(x,i) |= ( 0x01 << ( (i) % BITBYTE ) )
|
#define SETBIT(x,i) GETBYTE(x,i) |= ( 0x01 << ( (i) % BITS_PER_BYTE ) )
|
||||||
#define GETBIT(x,i) ( (GETBYTE(x,i) >> ( (i) % BITBYTE )) & 0x01 )
|
#define GETBIT(x,i) ( (GETBYTE(x,i) >> ( (i) % BITS_PER_BYTE )) & 0x01 )
|
||||||
#define HASHVAL(val) (((unsigned int)(val)) % SIGLENBIT)
|
#define HASHVAL(val) (((unsigned int)(val)) % SIGLENBIT)
|
||||||
#define HASH(sign, val) SETBIT((sign), HASHVAL(val))
|
#define HASH(sign, val) SETBIT((sign), HASHVAL(val))
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ g_int_consistent(PG_FUNCTION_ARGS)
|
|||||||
if (strategy == BooleanSearchStrategy)
|
if (strategy == BooleanSearchStrategy)
|
||||||
PG_RETURN_BOOL(execconsistent((QUERYTYPE *) query,
|
PG_RETURN_BOOL(execconsistent((QUERYTYPE *) query,
|
||||||
(ArrayType *) DatumGetPointer(entry->key),
|
(ArrayType *) DatumGetPointer(entry->key),
|
||||||
ISLEAFKEY((ArrayType *) DatumGetPointer(entry->key))));
|
GIST_LEAF(entry)));
|
||||||
|
|
||||||
/* XXX are we sure it's safe to scribble on the query object here? */
|
/* XXX are we sure it's safe to scribble on the query object here? */
|
||||||
/* XXX what about toasted input? */
|
/* XXX what about toasted input? */
|
||||||
@ -131,7 +131,11 @@ g_int_compress(PG_FUNCTION_ARGS)
|
|||||||
{
|
{
|
||||||
r = (ArrayType *) PG_DETOAST_DATUM_COPY(entry->key);
|
r = (ArrayType *) PG_DETOAST_DATUM_COPY(entry->key);
|
||||||
PREPAREARR(r);
|
PREPAREARR(r);
|
||||||
r->flags |= LEAFKEY;
|
|
||||||
|
if (ARRNELEMS(r)>= 2 * MAXNUMRANGE)
|
||||||
|
elog(NOTICE,"Input array is too big (%d maximum allowed, %d current), use gist__intbig_ops opclass instead",
|
||||||
|
2 * MAXNUMRANGE - 1, ARRNELEMS(r));
|
||||||
|
|
||||||
retval = palloc(sizeof(GISTENTRY));
|
retval = palloc(sizeof(GISTENTRY));
|
||||||
gistentryinit(*retval, PointerGetDatum(r),
|
gistentryinit(*retval, PointerGetDatum(r),
|
||||||
entry->rel, entry->page, entry->offset, VARSIZE(r), FALSE);
|
entry->rel, entry->page, entry->offset, VARSIZE(r), FALSE);
|
||||||
@ -139,8 +143,11 @@ g_int_compress(PG_FUNCTION_ARGS)
|
|||||||
PG_RETURN_POINTER(retval);
|
PG_RETURN_POINTER(retval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* leaf entries never compress one more time, only when entry->leafkey ==true,
|
||||||
|
so now we work only with internal keys */
|
||||||
|
|
||||||
r = (ArrayType *) PG_DETOAST_DATUM(entry->key);
|
r = (ArrayType *) PG_DETOAST_DATUM(entry->key);
|
||||||
if (ISLEAFKEY(r) || ARRISVOID(r))
|
if (ARRISVOID(r))
|
||||||
{
|
{
|
||||||
if (r != (ArrayType *) DatumGetPointer(entry->key))
|
if (r != (ArrayType *) DatumGetPointer(entry->key))
|
||||||
pfree(r);
|
pfree(r);
|
||||||
@ -205,7 +212,7 @@ g_int_decompress(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
lenin = ARRNELEMS(in);
|
lenin = ARRNELEMS(in);
|
||||||
|
|
||||||
if (lenin < 2 * MAXNUMRANGE || ISLEAFKEY(in))
|
if (lenin < 2 * MAXNUMRANGE)
|
||||||
{ /* not compressed value */
|
{ /* not compressed value */
|
||||||
if (in != (ArrayType *) DatumGetPointer(entry->key))
|
if (in != (ArrayType *) DatumGetPointer(entry->key))
|
||||||
{
|
{
|
||||||
@ -498,8 +505,6 @@ g_int_picksplit(PG_FUNCTION_ARGS)
|
|||||||
pfree(costvector);
|
pfree(costvector);
|
||||||
*right = *left = FirstOffsetNumber;
|
*right = *left = FirstOffsetNumber;
|
||||||
|
|
||||||
datum_l->flags &= ~LEAFKEY;
|
|
||||||
datum_r->flags &= ~LEAFKEY;
|
|
||||||
v->spl_ldatum = PointerGetDatum(datum_l);
|
v->spl_ldatum = PointerGetDatum(datum_l);
|
||||||
v->spl_rdatum = PointerGetDatum(datum_r);
|
v->spl_rdatum = PointerGetDatum(datum_r);
|
||||||
|
|
||||||
|
@ -215,7 +215,6 @@ new_intArrayType(int num)
|
|||||||
ARR_SIZE(r) = nbytes;
|
ARR_SIZE(r) = nbytes;
|
||||||
ARR_NDIM(r) = NDIM;
|
ARR_NDIM(r) = NDIM;
|
||||||
ARR_ELEMTYPE(r) = INT4OID;
|
ARR_ELEMTYPE(r) = INT4OID;
|
||||||
r->flags &= ~LEAFKEY;
|
|
||||||
*((int *) ARR_DIMS(r)) = num;
|
*((int *) ARR_DIMS(r)) = num;
|
||||||
*((int *) ARR_LBOUND(r)) = 1;
|
*((int *) ARR_LBOUND(r)) = 1;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user