|
9 | 9 | *
|
10 | 10 | *
|
11 | 11 | * IDENTIFICATION
|
12 |
| - * $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.157 2004/03/07 05:43:53 tgl Exp $ |
| 12 | + * $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.158 2004/03/27 00:24:28 tgl Exp $ |
13 | 13 | *
|
14 | 14 | *-------------------------------------------------------------------------
|
15 | 15 | */
|
|
22 | 22 | #include "catalog/pg_namespace.h"
|
23 | 23 | #include "catalog/pg_opclass.h"
|
24 | 24 | #include "catalog/pg_operator.h"
|
| 25 | +#include "catalog/pg_proc.h" |
25 | 26 | #include "catalog/pg_type.h"
|
26 | 27 | #include "executor/executor.h"
|
27 | 28 | #include "nodes/makefuncs.h"
|
@@ -990,9 +991,10 @@ static const StrategyNumber
|
990 | 991 | * and constants can be different but the operators must be in the same btree
|
991 | 992 | * operator class. We use the above operator implication table to be able to
|
992 | 993 | * derive implications between nonidentical clauses. (Note: "foo" is known
|
993 |
| - * immutable, and constants are surely immutable, and we assume that operators |
994 |
| - * that are in btree opclasses are immutable, so there's no need to do extra |
995 |
| - * mutability checks in this case either.) |
| 994 | + * immutable, and constants are surely immutable, but we have to check that |
| 995 | + * the operators are too. As of 7.5 it's possible for opclasses to contain |
| 996 | + * operators that are merely stable, and we dare not make deductions with |
| 997 | + * these.) |
996 | 998 | *
|
997 | 999 | * Eventually, rtree operators could also be handled by defining an
|
998 | 1000 | * appropriate "RT_implic_table" array.
|
@@ -1279,8 +1281,20 @@ pred_test_simple_clause(Expr *predicate, Node *clause)
|
1279 | 1281 | }
|
1280 | 1282 | if (OidIsValid(test_op))
|
1281 | 1283 | {
|
1282 |
| - found = true; |
1283 |
| - break; |
| 1284 | + /* |
| 1285 | + * Last check: test_op must be immutable. |
| 1286 | + * |
| 1287 | + * Note that we require only the test_op to be immutable, not |
| 1288 | + * the original clause_op. (pred_op must be immutable, else it |
| 1289 | + * would not be allowed in an index predicate.) Essentially |
| 1290 | + * we are assuming that the opclass is consistent even if it |
| 1291 | + * contains operators that are merely stable. |
| 1292 | + */ |
| 1293 | + if (op_volatile(test_op) == PROVOLATILE_IMMUTABLE) |
| 1294 | + { |
| 1295 | + found = true; |
| 1296 | + break; |
| 1297 | + } |
1284 | 1298 | }
|
1285 | 1299 | }
|
1286 | 1300 |
|
|
0 commit comments