8
8
* Portions Copyright (c) 1994, Regents of the University of California
9
9
*
10
10
* 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 $
12
12
*-------------------------------------------------------------------------
13
13
*/
14
14
25
25
26
26
typedef struct pendingPosition
27
27
{
28
- BufferpendingBuffer;
29
- OffsetNumber firstOffset;
30
- OffsetNumber lastOffset;
31
- ItemPointerData item;
28
+ BufferpendingBuffer;
29
+ OffsetNumber firstOffset;
30
+ OffsetNumber lastOffset;
31
+ ItemPointerData item;
32
+ bool *hasMatchKey;
32
33
} pendingPosition;
33
34
34
35
@@ -873,6 +874,18 @@ matchPartialInPendingList(GinState *ginstate, Page page,
873
874
return false;
874
875
}
875
876
877
+ static bool
878
+ hasAllMatchingKeys(GinScanOpaque so, pendingPosition *pos)
879
+ {
880
+ inti;
881
+
882
+ for (i = 0; i < so->nkeys; i++)
883
+ if (pos->hasMatchKey[i] == false)
884
+ return false;
885
+
886
+ return true;
887
+ }
888
+
876
889
/*
877
890
* Sets entryRes array for each key by looking at
878
891
* every entry per indexed value (heap's row) in pending list.
@@ -889,7 +902,6 @@ collectDatumForItem(IndexScanDesc scan, pendingPosition *pos)
889
902
IndexTupleitup;
890
903
inti,
891
904
j;
892
- boolhasMatch = false;
893
905
894
906
/*
895
907
* Resets entryRes
@@ -900,6 +912,7 @@ collectDatumForItem(IndexScanDesc scan, pendingPosition *pos)
900
912
901
913
memset(key->entryRes, FALSE, key->nentries);
902
914
}
915
+ memset(pos->hasMatchKey, FALSE, so->nkeys);
903
916
904
917
for (;;)
905
918
{
@@ -1005,7 +1018,7 @@ collectDatumForItem(IndexScanDesc scan, pendingPosition *pos)
1005
1018
entry->extra_data);
1006
1019
}
1007
1020
1008
- hasMatch |= key->entryRes[j];
1021
+ pos->hasMatchKey[i] |= key->entryRes[j];
1009
1022
}
1010
1023
}
1011
1024
@@ -1017,7 +1030,7 @@ collectDatumForItem(IndexScanDesc scan, pendingPosition *pos)
1017
1030
* We scan all values from one tuple, go to next one
1018
1031
*/
1019
1032
1020
- returnhasMatch ;
1033
+ returnhasAllMatchingKeys(so, pos) ;
1021
1034
}
1022
1035
else
1023
1036
{
@@ -1034,7 +1047,7 @@ collectDatumForItem(IndexScanDesc scan, pendingPosition *pos)
1034
1047
}
1035
1048
}
1036
1049
1037
- returnhasMatch ;
1050
+ returnhasAllMatchingKeys(so, pos) ;
1038
1051
}
1039
1052
1040
1053
/*
@@ -1073,6 +1086,7 @@ scanPendingInsert(IndexScanDesc scan, TIDBitmap *tbm, int64 *ntids)
1073
1086
LockBuffer(pos.pendingBuffer, GIN_SHARE);
1074
1087
pos.firstOffset = FirstOffsetNumber;
1075
1088
UnlockReleaseBuffer(metabuffer);
1089
+ pos.hasMatchKey = palloc(sizeof(bool) * so->nkeys);
1076
1090
1077
1091
/*
1078
1092
* loop for each heap row. scanGetCandidate returns full row or row's
@@ -1126,6 +1140,8 @@ scanPendingInsert(IndexScanDesc scan, TIDBitmap *tbm, int64 *ntids)
1126
1140
(*ntids)++;
1127
1141
}
1128
1142
}
1143
+
1144
+ pfree(pos.hasMatchKey);
1129
1145
}
1130
1146
1131
1147
/*