Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit08ee64e

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 nowdoesn't support NULLs in arrays.
1 parentbad1a5c commit08ee64e

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
#defineNDIM 1
1919

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

5346

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

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

7668
/* beware of multiple evaluation of arguments to these macros! */
77-
#defineGETBYTE(x,i) ( *( (BITVECP)(x) + (int)( (i) /BITBYTE ) ) )
69+
#defineGETBYTE(x,i) ( *( (BITVECP)(x) + (int)( (i) /BITS_PER_BYTE ) ) )
7870
#defineGETBITBYTE(x,i) ( (*((char*)(x)) >> (i)) & 0x01 )
79-
#defineCLRBIT(x,i) GETBYTE(x,i) &= ~( 0x01 << ( (i) %BITBYTE ) )
80-
#defineSETBIT(x,i) GETBYTE(x,i) |= ( 0x01 << ( (i) %BITBYTE ) )
81-
#defineGETBIT(x,i) ( (GETBYTE(x,i) >> ( (i) %BITBYTE )) & 0x01 )
71+
#defineCLRBIT(x,i) GETBYTE(x,i) &= ~( 0x01 << ( (i) %BITS_PER_BYTE ) )
72+
#defineSETBIT(x,i) GETBYTE(x,i) |= ( 0x01 << ( (i) %BITS_PER_BYTE ) )
73+
#defineGETBIT(x,i) ( (GETBYTE(x,i) >> ( (i) %BITS_PER_BYTE )) & 0x01 )
8274
#defineHASHVAL(val) (((unsigned int)(val)) % SIGLENBIT)
8375
#defineHASH(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)

[8]ページ先頭

©2009-2025 Movatter.jp