Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9aefd56

Browse files
committed
Fix up btree's initial scankey processing to be able to detect redundant
or contradictory keys even in cross-data-type scenarios. This is another benefit of the opfamily rewrite: we can find the needed comparison operators now.
1 parent 3870341 commit 9aefd56

File tree

3 files changed

+208
-99
lines changed

3 files changed

+208
-99
lines changed

src/backend/access/nbtree/README

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
$PostgreSQL: pgsql/src/backend/access/nbtree/README,v 1.14 2006/11/01 19:43:17 tgl Exp $
1+
$PostgreSQL: pgsql/src/backend/access/nbtree/README,v 1.15 2006/12/28 23:16:39 tgl Exp $
22

33
This directory contains a correct implementation of Lehman and Yao's
44
high-concurrency B-tree management algorithm (P. Lehman and S. Yao,
@@ -480,7 +480,8 @@ than key.
480480
Notes to operator class implementors
481481
------------------------------------
482482

483-
With this implementation, we require each supported datatype to supply
484-
us with a comparison procedure via pg_amproc. This procedure must take
485-
two nonnull values A and B and return an int32 < 0, 0, or > 0 if A < B,
486-
A = B, or A > B, respectively. See nbtcompare.c for examples.
483+
With this implementation, we require each supported combination of
484+
datatypes to supply us with a comparison procedure via pg_amproc.
485+
This procedure must take two nonnull values A and B and return an int32 < 0,
486+
0, or > 0 if A < B, A = B, or A > B, respectively. See nbtcompare.c for
487+
examples.

src/backend/access/nbtree/nbtsearch.c

Lines changed: 14 additions & 10 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/nbtree/nbtsearch.c,v 1.108 2006/12/23 00:43:09 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.109 2006/12/28 23:16:39 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -476,16 +476,16 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
476476
* attributes to its right, because it would break our simplistic notion
477477
* of what initial positioning strategy to use.
478478
*
479-
* When the scan keys include non-default operators, _bt_preprocess_keys
479+
* When the scan keys include cross-type operators, _bt_preprocess_keys
480480
* may not be able to eliminate redundant keys; in such cases we will
481481
* arbitrarily pick a usable one for each attribute. This is correct
482482
* but possibly not optimal behavior. (For example, with keys like
483483
* "x >= 4 AND x >= 5" we would elect to scan starting at x=4 when
484-
* x=5 would be more efficient.) Since the situation only arises in
485-
* hokily-worded queries, live with it.
484+
* x=5 would be more efficient.) Since the situation only arises given
485+
* a poorly-worded query plus an incomplete opfamily, live with it.
486486
*
487487
* When both equality and inequality keys appear for a single attribute
488-
* (again, only possible when non-default operators appear), we *must*
488+
* (again, only possible when cross-type operators appear), we *must*
489489
* select one of the equality keys for the starting point, because
490490
* _bt_checkkeys() will stop the scan as soon as an equality qual fails.
491491
* For example, if we have keys like "x >= 4 AND x = 10" and we elect to
@@ -658,11 +658,15 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
658658
* to an insertion scan key by replacing the sk_func with the
659659
* appropriate btree comparison function.
660660
*
661-
* If scankey operator is of the default type for the index, we
662-
* can use the cached comparison function; otherwise gotta look it
663-
* up in the catalogs. Also, we support the convention that
664-
* sk_subtype == 0 means the default type; this is a hack to
665-
* simplify life for ScanKeyInit().
661+
* If scankey operator is not a cross-type comparison, we can use
662+
* the cached comparison function; otherwise gotta look it up in
663+
* the catalogs. (That can't lead to infinite recursion, since no
664+
* indexscan initiated by syscache lookup will use cross-data-type
665+
* operators.)
666+
*
667+
* We support the convention that sk_subtype == InvalidOid means
668+
* the opclass input type; this is a hack to simplify life for
669+
* ScanKeyInit().
666670
*/
667671
if (cur->sk_subtype == rel->rd_opcintype[i] ||
668672
cur->sk_subtype == InvalidOid)

0 commit comments

Comments
 (0)