Skip to content

Commit 5e75f67

Browse files
committed
Fix multicolumn GIN's wrong results with fastupdate enabled.
User-defined consistent functions believes the check array contains at least one true element which was not a true for scanning pending list. Per report from Yury Don <yura@vpcit.ru>
1 parent 0894c6b commit 5e75f67

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

src/backend/access/gin/ginget.c

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
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

@@ -25,10 +25,11 @@
2525

2626
typedef 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,
873874
return 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)
889902
IndexTuple itup;
890903
int i,
891904
j;
892-
bool hasMatch = false;
893905

894906
/*
895907
* Resets entryRes
@@ -900,6 +912,7 @@ collectDatumForItem(IndexScanDesc scan, pendingPosition *pos)
900912

901913
memset(key->entryRes, FALSE, key->nentries);
902914
}
915+
memset(pos->hasMatchKey, FALSE, so->nkeys);
903916

904917
for (;;)
905918
{
@@ -1005,7 +1018,7 @@ collectDatumForItem(IndexScanDesc scan, pendingPosition *pos)
10051018
entry->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
}
10221035
else
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)
10731086
LockBuffer(pos.pendingBuffer, GIN_SHARE);
10741087
pos.firstOffset = FirstOffsetNumber;
10751088
UnlockReleaseBuffer(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
/*

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