|
8 | 8 | * |
9 | 9 | * |
10 | 10 | * 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 $ |
12 | 12 | * |
13 | 13 | *------------------------------------------------------------------------- |
14 | 14 | */ |
@@ -224,11 +224,11 @@ _bt_preprocess_keys(IndexScanDesc scan) |
224 | 224 | BTScanOpaqueso= (BTScanOpaque)scan->opaque; |
225 | 225 | intnumberOfKeys=scan->numberOfKeys; |
226 | 226 | intnew_numberOfKeys; |
| 227 | +intnumberOfEqualCols; |
227 | 228 | ScanKeyinkeys; |
228 | 229 | ScanKeyoutkeys; |
229 | 230 | ScanKeycur; |
230 | 231 | ScanKeyxform[BTMaxStrategyNumber]; |
231 | | -boolallEqualSoFar; |
232 | 232 | boolhasOtherTypeEqual; |
233 | 233 | Datumtest; |
234 | 234 | inti, |
@@ -278,7 +278,7 @@ _bt_preprocess_keys(IndexScanDesc scan) |
278 | 278 | * Otherwise, do the full set of pushups. |
279 | 279 | */ |
280 | 280 | new_numberOfKeys=0; |
281 | | -allEqualSoFar=true; |
| 281 | +numberOfEqualCols=0; |
282 | 282 |
|
283 | 283 | /* |
284 | 284 | * Initialize for processing of keys for attr 1. |
@@ -321,7 +321,7 @@ _bt_preprocess_keys(IndexScanDesc scan) |
321 | 321 | */ |
322 | 322 | if (i==numberOfKeys||cur->sk_attno!=attno) |
323 | 323 | { |
324 | | -boolpriorAllEqualSoFar=allEqualSoFar; |
| 324 | +intpriorNumberOfEqualCols=numberOfEqualCols; |
325 | 325 |
|
326 | 326 | /* check input keys are correctly ordered */ |
327 | 327 | if (i<numberOfKeys&&cur->sk_attno!=attno+1) |
@@ -355,14 +355,14 @@ _bt_preprocess_keys(IndexScanDesc scan) |
355 | 355 | xform[BTLessEqualStrategyNumber-1]=NULL; |
356 | 356 | xform[BTGreaterEqualStrategyNumber-1]=NULL; |
357 | 357 | xform[BTGreaterStrategyNumber-1]=NULL; |
| 358 | +/* track number of attrs for which we have "=" keys */ |
| 359 | +numberOfEqualCols++; |
358 | 360 | } |
359 | 361 | else |
360 | 362 | { |
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++; |
366 | 366 | } |
367 | 367 |
|
368 | 368 | /* keep only one of <, <= */ |
@@ -411,7 +411,7 @@ _bt_preprocess_keys(IndexScanDesc scan) |
411 | 411 | * If all attrs before this one had "=", include these keys |
412 | 412 | * into the required-keys count. |
413 | 413 | */ |
414 | | -if (priorAllEqualSoFar) |
| 414 | +if (priorNumberOfEqualCols==attno-1) |
415 | 415 | so->numberOfRequiredKeys=new_numberOfKeys; |
416 | 416 |
|
417 | 417 | /* |
@@ -468,8 +468,8 @@ _bt_preprocess_keys(IndexScanDesc scan) |
468 | 468 | * If unique index and we have equality keys for all columns, set |
469 | 469 | * keys_are_unique flag for higher levels. |
470 | 470 | */ |
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) |
473 | 473 | scan->keys_are_unique= true; |
474 | 474 | } |
475 | 475 |
|
|