88 * Portions Copyright (c) 1994, Regents of the University of California
99 *
1010 * IDENTIFICATION
11- *$PostgreSQL: pgsql/src/backend/access/gin/ginget.c,v 1.27 2009/06/11 14:48:53 momjian Exp $
11+ *$PostgreSQL: pgsql/src/backend/access/gin/ginget.c,v 1.28 2009/11/13 11:17:04 teodor Exp $
1212 *-------------------------------------------------------------------------
1313 */
1414
2525
2626typedef struct pendingPosition
2727{
28- Buffer pendingBuffer ;
29- OffsetNumber firstOffset ;
30- OffsetNumber lastOffset ;
31- ItemPointerData item ;
28+ Buffer pendingBuffer ;
29+ OffsetNumber firstOffset ;
30+ OffsetNumber lastOffset ;
31+ ItemPointerData item ;
32+ bool * hasMatchKey ;
3233}pendingPosition ;
3334
3435
@@ -873,6 +874,18 @@ matchPartialInPendingList(GinState *ginstate, Page page,
873874return false;
874875}
875876
877+ static bool
878+ hasAllMatchingKeys (GinScanOpaque so ,pendingPosition * pos )
879+ {
880+ int i ;
881+
882+ for (i = 0 ;i < so -> nkeys ;i ++ )
883+ if (pos -> hasMatchKey [i ]== false)
884+ return false;
885+
886+ return true;
887+ }
888+
876889/*
877890 * Sets entryRes array for each key by looking at
878891 * every entry per indexed value (heap's row) in pending list.
@@ -889,7 +902,6 @@ collectDatumForItem(IndexScanDesc scan, pendingPosition *pos)
889902IndexTuple itup ;
890903int i ,
891904j ;
892- bool hasMatch = false;
893905
894906/*
895907 * Resets entryRes
@@ -900,6 +912,7 @@ collectDatumForItem(IndexScanDesc scan, pendingPosition *pos)
900912
901913memset (key -> entryRes , FALSE,key -> nentries );
902914}
915+ memset (pos -> hasMatchKey , FALSE,so -> nkeys );
903916
904917for (;;)
905918{
@@ -1005,7 +1018,7 @@ collectDatumForItem(IndexScanDesc scan, pendingPosition *pos)
10051018entry -> extra_data );
10061019}
10071020
1008- hasMatch |=key -> entryRes [j ];
1021+ pos -> hasMatchKey [ i ] |=key -> entryRes [j ];
10091022}
10101023}
10111024
@@ -1017,7 +1030,7 @@ collectDatumForItem(IndexScanDesc scan, pendingPosition *pos)
10171030 * We scan all values from one tuple, go to next one
10181031 */
10191032
1020- return hasMatch ;
1033+ return hasAllMatchingKeys ( so , pos ) ;
10211034}
10221035else
10231036{
@@ -1034,7 +1047,7 @@ collectDatumForItem(IndexScanDesc scan, pendingPosition *pos)
10341047}
10351048}
10361049
1037- return hasMatch ;
1050+ return hasAllMatchingKeys ( so , pos ) ;
10381051}
10391052
10401053/*
@@ -1073,6 +1086,7 @@ scanPendingInsert(IndexScanDesc scan, TIDBitmap *tbm, int64 *ntids)
10731086LockBuffer (pos .pendingBuffer ,GIN_SHARE );
10741087pos .firstOffset = FirstOffsetNumber ;
10751088UnlockReleaseBuffer (metabuffer );
1089+ pos .hasMatchKey = palloc (sizeof (bool )* so -> nkeys );
10761090
10771091/*
10781092 * loop for each heap row. scanGetCandidate returns full row or row's
@@ -1126,6 +1140,8 @@ scanPendingInsert(IndexScanDesc scan, TIDBitmap *tbm, int64 *ntids)
11261140(* ntids )++ ;
11271141}
11281142}
1143+
1144+ pfree (pos .hasMatchKey );
11291145}
11301146
11311147/*