@@ -232,7 +232,7 @@ typedef struct
232232 * is there value 'val' in array or not ?
233233 */
234234static bool
235- checkcondition_arr (void * checkval ,int4 val )
235+ checkcondition_arr (void * checkval ,ITEM * item )
236236{
237237int4 * StopLow = ((CHKVAL * )checkval )-> arrb ;
238238int4 * StopHigh = ((CHKVAL * )checkval )-> arre ;
@@ -243,9 +243,9 @@ checkcondition_arr(void *checkval, int4 val)
243243while (StopLow < StopHigh )
244244{
245245StopMiddle = StopLow + (StopHigh - StopLow ) /2 ;
246- if (* StopMiddle == val )
246+ if (* StopMiddle == item -> val )
247247return (true);
248- else if (* StopMiddle < val )
248+ else if (* StopMiddle < item -> val )
249249StopLow = StopMiddle + 1 ;
250250else
251251StopHigh = StopMiddle ;
@@ -254,20 +254,20 @@ checkcondition_arr(void *checkval, int4 val)
254254}
255255
256256static bool
257- checkcondition_bit (void * checkval ,int4 val )
257+ checkcondition_bit (void * checkval ,ITEM * item )
258258{
259- return GETBIT (checkval ,HASHVAL (val ));
259+ return GETBIT (checkval ,HASHVAL (item -> val ));
260260}
261261
262262/*
263263 * check for boolean condition
264264 */
265265static bool
266- execute (ITEM * curitem ,void * checkval ,bool calcnot ,bool (* chkcond ) (void * checkval ,int4 val ))
266+ execute (ITEM * curitem ,void * checkval ,bool calcnot ,bool (* chkcond ) (void * checkval ,ITEM * item ))
267267{
268268
269269if (curitem -> type == VAL )
270- return (* chkcond ) (checkval ,curitem -> val );
270+ return (* chkcond ) (checkval ,curitem );
271271else if (curitem -> val == (int4 )'!' )
272272{
273273return (calcnot ) ?
@@ -319,6 +319,40 @@ execconsistent(QUERYTYPE * query, ArrayType *array, bool calcnot)
319319);
320320}
321321
322+ typedef struct {
323+ ITEM * first ;
324+ bool * mapped_check ;
325+ }GinChkVal ;
326+
327+ static bool
328+ checkcondition_gin (void * checkval ,ITEM * item ) {
329+ GinChkVal * gcv = (GinChkVal * )checkval ;
330+
331+ return gcv -> mapped_check [item - gcv -> first ];
332+ }
333+
334+ bool
335+ ginconsistent (QUERYTYPE * query ,bool * check ) {
336+ GinChkVal gcv ;
337+ ITEM * items = GETQUERY (query );
338+ int i ,j = 0 ;
339+
340+ if (query -> size < 0 )
341+ return FALSE;
342+
343+ gcv .first = items ;
344+ gcv .mapped_check = (bool * )palloc (sizeof (bool )* query -> size );
345+ for (i = 0 ;i < query -> size ;i ++ )
346+ if (items [i ].type == VAL )
347+ gcv .mapped_check [i ]= check [j ++ ];
348+
349+ return execute (
350+ GETQUERY (query )+ query -> size - 1 ,
351+ (void * )& gcv , true,
352+ checkcondition_gin
353+ );
354+ }
355+
322356/*
323357 * boolean operations
324358 */
@@ -588,7 +622,7 @@ countdroptree(ITEM * q, int4 pos)
588622 * result of all '!' will be = 'true', so
589623 * we can modify query tree for clearing
590624 */
591- static int4
625+ int4
592626shorterquery (ITEM * q ,int4 len )
593627{
594628int4 index ,