Skip to content

Commit c3d6c7d

Browse files
committed
Calculation of keys_are_unique flag was wrong for cases involving
redundant cross-datatype comparisons. Per example from Merlin Moncure.
1 parent 6ad835f commit c3d6c7d

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/backend/access/nbtree/nbtutils.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtutils.c,v 1.60 2004/08/29 05:06:40 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtutils.c,v 1.61 2004/12/15 19:16:39 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -224,11 +224,11 @@ _bt_preprocess_keys(IndexScanDesc scan)
224224
BTScanOpaque so = (BTScanOpaque) scan->opaque;
225225
int numberOfKeys = scan->numberOfKeys;
226226
int new_numberOfKeys;
227+
int numberOfEqualCols;
227228
ScanKey inkeys;
228229
ScanKey outkeys;
229230
ScanKey cur;
230231
ScanKey xform[BTMaxStrategyNumber];
231-
bool allEqualSoFar;
232232
bool hasOtherTypeEqual;
233233
Datum test;
234234
int i,
@@ -278,7 +278,7 @@ _bt_preprocess_keys(IndexScanDesc scan)
278278
* Otherwise, do the full set of pushups.
279279
*/
280280
new_numberOfKeys = 0;
281-
allEqualSoFar = true;
281+
numberOfEqualCols = 0;
282282

283283
/*
284284
* Initialize for processing of keys for attr 1.
@@ -321,7 +321,7 @@ _bt_preprocess_keys(IndexScanDesc scan)
321321
*/
322322
if (i == numberOfKeys || cur->sk_attno != attno)
323323
{
324-
bool priorAllEqualSoFar = allEqualSoFar;
324+
int priorNumberOfEqualCols = numberOfEqualCols;
325325

326326
/* check input keys are correctly ordered */
327327
if (i < numberOfKeys && cur->sk_attno != attno + 1)
@@ -355,14 +355,14 @@ _bt_preprocess_keys(IndexScanDesc scan)
355355
xform[BTLessEqualStrategyNumber - 1] = NULL;
356356
xform[BTGreaterEqualStrategyNumber - 1] = NULL;
357357
xform[BTGreaterStrategyNumber - 1] = NULL;
358+
/* track number of attrs for which we have "=" keys */
359+
numberOfEqualCols++;
358360
}
359361
else
360362
{
361-
/*
362-
* If no "=" for this key, we're done with required keys
363-
*/
364-
if (!hasOtherTypeEqual)
365-
allEqualSoFar = false;
363+
/* track number of attrs for which we have "=" keys */
364+
if (hasOtherTypeEqual)
365+
numberOfEqualCols++;
366366
}
367367

368368
/* keep only one of <, <= */
@@ -411,7 +411,7 @@ _bt_preprocess_keys(IndexScanDesc scan)
411411
* If all attrs before this one had "=", include these keys
412412
* into the required-keys count.
413413
*/
414-
if (priorAllEqualSoFar)
414+
if (priorNumberOfEqualCols == attno - 1)
415415
so->numberOfRequiredKeys = new_numberOfKeys;
416416

417417
/*
@@ -468,8 +468,8 @@ _bt_preprocess_keys(IndexScanDesc scan)
468468
* If unique index and we have equality keys for all columns, set
469469
* keys_are_unique flag for higher levels.
470470
*/
471-
if (allEqualSoFar && relation->rd_index->indisunique &&
472-
relation->rd_rel->relnatts == new_numberOfKeys)
471+
if (relation->rd_index->indisunique &&
472+
relation->rd_rel->relnatts == numberOfEqualCols)
473473
scan->keys_are_unique = true;
474474
}
475475

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