Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbc19d66

Browse files
committed
When testing usability of a partial index, recognize that an index
predicate of the form 'foo IS NOT NULL' is implied by a WHERE clausethat uses 'foo' in any strict operator or function. Per suggestionand preliminary implementation by John Siracusa; some further hackingby moi.
1 parent5ae3816 commitbc19d66

File tree

1 file changed

+44
-13
lines changed

1 file changed

+44
-13
lines changed

‎src/backend/optimizer/path/indxpath.c

Lines changed: 44 additions & 13 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.156 2004/01/0722:02:48 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.157 2004/03/0705:43:53 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -965,24 +965,38 @@ static const StrategyNumber
965965
};
966966

967967

968-
/*
968+
/*----------
969969
* pred_test_simple_clause
970970
* Does the "predicate inclusion test" for a "simple clause" predicate
971971
* and a "simple clause" restriction.
972972
*
973-
* We have two strategies for determining whether one simple clause
974-
* implies another.A simple and general way is to see if they are
975-
* equal(); this works for any kind of expression. (Actually, there
976-
* is an implied assumption that the functions in the expression are
977-
* immutable, ie dependent only on their input arguments --- but this
978-
* was checked for the predicate by CheckPredicate().)
973+
* We have three strategies for determining whether one simple clause
974+
* implies another:
975+
*
976+
* A simple and general way is to see if they are equal(); this works for any
977+
* kind of expression. (Actually, there is an implied assumption that the
978+
* functions in the expression are immutable, ie dependent only on their input
979+
* arguments --- but this was checked for the predicate by CheckPredicate().)
979980
*
980-
* Our other way works only for (binary boolean) operators that are
981-
* in some btree operator class. We use the above operator implication
982-
* table to be able to derive implications between nonidentical clauses.
981+
* When the predicate is of the form "foo IS NOT NULL", we can conclude that
982+
* the predicate is implied if the clause is a strict operator or function
983+
* that has "foo" as an input. In this case the clause must yield NULL when
984+
* "foo" is NULL, which we can take as equivalent to FALSE because we know
985+
* we are within an AND/OR subtree of a WHERE clause. (Again, "foo" is
986+
* already known immutable, so the clause will certainly always fail.)
983987
*
984-
* Eventually, rtree operators could also be handled by defining an
985-
* appropriate "RT_implic_table" array.
988+
* Our other way works only for binary boolean opclauses of the form
989+
* "foo op constant", where "foo" is the same in both clauses. The operators
990+
* and constants can be different but the operators must be in the same btree
991+
* operator class. We use the above operator implication table to be able to
992+
* 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.)
996+
*
997+
* Eventually, rtree operators could also be handled by defining an
998+
* appropriate "RT_implic_table" array.
999+
*----------
9861000
*/
9871001
staticbool
9881002
pred_test_simple_clause(Expr*predicate,Node*clause)
@@ -1020,6 +1034,23 @@ pred_test_simple_clause(Expr *predicate, Node *clause)
10201034
if (equal((Node*)predicate,clause))
10211035
return true;
10221036

1037+
/* Next try the IS NOT NULL case */
1038+
if (predicate&&IsA(predicate,NullTest)&&
1039+
((NullTest*)predicate)->nulltesttype==IS_NOT_NULL)
1040+
{
1041+
Expr*nonnullarg= ((NullTest*)predicate)->arg;
1042+
1043+
if (is_opclause(clause)&&
1044+
member(nonnullarg, ((OpExpr*)clause)->args)&&
1045+
op_strict(((OpExpr*)clause)->opno))
1046+
return true;
1047+
if (is_funcclause(clause)&&
1048+
member(nonnullarg, ((FuncExpr*)clause)->args)&&
1049+
func_strict(((FuncExpr*)clause)->funcid))
1050+
return true;
1051+
return false;/* we can't succeed below... */
1052+
}
1053+
10231054
/*
10241055
* Can't do anything more unless they are both binary opclauses with a
10251056
* Const on one side, and identical subexpressions on the other sides.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp