Skip to content

Commit 08ee64e

Browse files
committed
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.
1 parent bad1a5c commit 08ee64e

File tree

3 files changed

+16
-20
lines changed

3 files changed

+16
-20
lines changed

contrib/intarray/_int.h

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@
1717
/* dimension of array */
1818
#define NDIM 1
1919

20-
/*
21-
* flags for gist__int_ops, use ArrayType->flags
22-
* which is unused (see array.h)
23-
*/
24-
#define LEAFKEY (1<<31)
25-
#define ISLEAFKEY(x) ( ((ArrayType*)(x))->flags & LEAFKEY )
26-
2720
/* useful macros for accessing int4 arrays */
2821
#define ARRPTR(x) ( (int4 *) ARR_DATA_PTR(x) )
2922
#define ARRNELEMS(x) ArrayGetNItems( ARR_NDIM(x), ARR_DIMS(x))
@@ -52,10 +45,9 @@
5245

5346

5447
/* bigint defines */
55-
#define BITBYTE 8
5648
#define SIGLENINT 63 /* >122 => key will toast, so very slow!!! */
5749
#define SIGLEN ( sizeof(int)*SIGLENINT )
58-
#define SIGLENBIT (SIGLEN*BITBYTE)
50+
#define SIGLENBIT (SIGLEN*BITS_PER_BYTE)
5951

6052
typedef char BITVEC[SIGLEN];
6153
typedef char *BITVECP;
@@ -74,11 +66,11 @@ typedef char *BITVECP;
7466
}
7567

7668
/* beware of multiple evaluation of arguments to these macros! */
77-
#define GETBYTE(x,i) ( *( (BITVECP)(x) + (int)( (i) / BITBYTE ) ) )
69+
#define GETBYTE(x,i) ( *( (BITVECP)(x) + (int)( (i) / BITS_PER_BYTE ) ) )
7870
#define GETBITBYTE(x,i) ( (*((char*)(x)) >> (i)) & 0x01 )
79-
#define CLRBIT(x,i) GETBYTE(x,i) &= ~( 0x01 << ( (i) % BITBYTE ) )
80-
#define SETBIT(x,i) GETBYTE(x,i) |= ( 0x01 << ( (i) % BITBYTE ) )
81-
#define GETBIT(x,i) ( (GETBYTE(x,i) >> ( (i) % BITBYTE )) & 0x01 )
71+
#define CLRBIT(x,i) GETBYTE(x,i) &= ~( 0x01 << ( (i) % BITS_PER_BYTE ) )
72+
#define SETBIT(x,i) GETBYTE(x,i) |= ( 0x01 << ( (i) % BITS_PER_BYTE ) )
73+
#define GETBIT(x,i) ( (GETBYTE(x,i) >> ( (i) % BITS_PER_BYTE )) & 0x01 )
8274
#define HASHVAL(val) (((unsigned int)(val)) % SIGLENBIT)
8375
#define HASH(sign, val) SETBIT((sign), HASHVAL(val))
8476

contrib/intarray/_int_gist.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ g_int_consistent(PG_FUNCTION_ARGS)
3939
if (strategy == BooleanSearchStrategy)
4040
PG_RETURN_BOOL(execconsistent((QUERYTYPE *) query,
4141
(ArrayType *) DatumGetPointer(entry->key),
42-
ISLEAFKEY((ArrayType *) DatumGetPointer(entry->key))));
42+
GIST_LEAF(entry)));
4343

4444
/* XXX are we sure it's safe to scribble on the query object here? */
4545
/* XXX what about toasted input? */
@@ -131,16 +131,23 @@ g_int_compress(PG_FUNCTION_ARGS)
131131
{
132132
r = (ArrayType *) PG_DETOAST_DATUM_COPY(entry->key);
133133
PREPAREARR(r);
134-
r->flags |= LEAFKEY;
134+
135+
if (ARRNELEMS(r)>= 2 * MAXNUMRANGE)
136+
elog(NOTICE,"Input array is too big (%d maximum allowed, %d current), use gist__intbig_ops opclass instead",
137+
2 * MAXNUMRANGE - 1, ARRNELEMS(r));
138+
135139
retval = palloc(sizeof(GISTENTRY));
136140
gistentryinit(*retval, PointerGetDatum(r),
137141
entry->rel, entry->page, entry->offset, VARSIZE(r), FALSE);
138142

139143
PG_RETURN_POINTER(retval);
140144
}
141145

146+
/* leaf entries never compress one more time, only when entry->leafkey ==true,
147+
so now we work only with internal keys */
148+
142149
r = (ArrayType *) PG_DETOAST_DATUM(entry->key);
143-
if (ISLEAFKEY(r) || ARRISVOID(r))
150+
if (ARRISVOID(r))
144151
{
145152
if (r != (ArrayType *) DatumGetPointer(entry->key))
146153
pfree(r);
@@ -205,7 +212,7 @@ g_int_decompress(PG_FUNCTION_ARGS)
205212

206213
lenin = ARRNELEMS(in);
207214

208-
if (lenin < 2 * MAXNUMRANGE || ISLEAFKEY(in))
215+
if (lenin < 2 * MAXNUMRANGE)
209216
{ /* not compressed value */
210217
if (in != (ArrayType *) DatumGetPointer(entry->key))
211218
{
@@ -498,8 +505,6 @@ g_int_picksplit(PG_FUNCTION_ARGS)
498505
pfree(costvector);
499506
*right = *left = FirstOffsetNumber;
500507

501-
datum_l->flags &= ~LEAFKEY;
502-
datum_r->flags &= ~LEAFKEY;
503508
v->spl_ldatum = PointerGetDatum(datum_l);
504509
v->spl_rdatum = PointerGetDatum(datum_r);
505510

contrib/intarray/_int_tool.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ new_intArrayType(int num)
215215
ARR_SIZE(r) = nbytes;
216216
ARR_NDIM(r) = NDIM;
217217
ARR_ELEMTYPE(r) = INT4OID;
218-
r->flags &= ~LEAFKEY;
219218
*((int *) ARR_DIMS(r)) = num;
220219
*((int *) ARR_LBOUND(r)) = 1;
221220

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy