Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7820ee2

Browse files
committed
Now that we are allowing index opclasses to contain operators that are
only stable and not immutable, pred_test_simple_clause has to guard against making invalid deductions. Add a test for immutability of the selected test_op.
1 parent 79b805f commit 7820ee2

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/backend/optimizer/path/indxpath.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* 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 $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -22,6 +22,7 @@
2222
#include "catalog/pg_namespace.h"
2323
#include "catalog/pg_opclass.h"
2424
#include "catalog/pg_operator.h"
25+
#include "catalog/pg_proc.h"
2526
#include "catalog/pg_type.h"
2627
#include "executor/executor.h"
2728
#include "nodes/makefuncs.h"
@@ -990,9 +991,10 @@ static const StrategyNumber
990991
* and constants can be different but the operators must be in the same btree
991992
* operator class. We use the above operator implication table to be able to
992993
* 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.)
996998
*
997999
* Eventually, rtree operators could also be handled by defining an
9981000
* appropriate "RT_implic_table" array.
@@ -1279,8 +1281,20 @@ pred_test_simple_clause(Expr *predicate, Node *clause)
12791281
}
12801282
if (OidIsValid(test_op))
12811283
{
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+
}
12841298
}
12851299
}
12861300

0 commit comments

Comments
 (0)