Commit 24679346 authored by Tom Lane's avatar Tom Lane

Modify partial-index-predicate applicability tester to test whether

clauses are equal(), before trying to match them up using btree opclass
inference rules.  This allows it to recognize many simple cases involving
non-btree operations, for example 'x IS NULL'.  Clean up code a little.
parent 7d6fbe15
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_index.sgml,v 1.20 2001/07/16 05:06:57 tgl Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/create_index.sgml,v 1.21 2001/08/06 18:09:45 tgl Exp $
Postgres documentation Postgres documentation
--> -->
...@@ -256,21 +256,26 @@ ERROR: Cannot create index: 'index_name' already exists. ...@@ -256,21 +256,26 @@ ERROR: Cannot create index: 'index_name' already exists.
billed and unbilled orders where the unbilled orders take up a small billed and unbilled orders where the unbilled orders take up a small
fraction of the total table and yet that is an often used section, you fraction of the total table and yet that is an often used section, you
can improve performance by creating an index on just that portion. can improve performance by creating an index on just that portion.
Another possible application is to use <command>WHERE</command> with
<command>UNIQUE</command> to enforce uniqueness over a subset of a
table.
</para> </para>
<para> <para>
The expression used in the <command>WHERE</command> clause may refer The expression used in the <command>WHERE</command> clause may refer
only to columns of the underlying table (but it can use all columns, only to columns of the underlying table (but it can use all columns,
not only the one(s) being indexed). Currently, the not only the one(s) being indexed). Presently, sub-SELECTs and
<productname>PostgreSQL</productname> planner can only devise query aggregate expressions are also forbidden in <command>WHERE</command>.
plans that make use of a partial index when the predicate is built from </para>
<command>AND</command> and <command>OR</command> combinations of
elements of the form <para>
<firstterm>column</firstterm> All functions and operators used in an index definition must be
<firstterm>operator</firstterm> <firstterm>cachable</>, that is, their results must depend only on
<firstterm>constant</firstterm>. their input arguments and never on any outside influence (such as
However, more general predicates may still be useful in conjunction the contents of another table or the current time). This restriction
with UNIQUE indexes, to enforce uniqueness over a subset of a table. ensures that the behavior of the index is well-defined. To use a
user-defined function in an index, remember to mark the function cachable
when you create it.
</para> </para>
<para> <para>
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.53 2001/07/17 21:53:01 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.54 2001/08/06 18:09:45 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -146,10 +146,12 @@ DefineIndex(char *heapRelationName, ...@@ -146,10 +146,12 @@ DefineIndex(char *heapRelationName,
/* /*
* Convert the partial-index predicate from parsetree form to * Convert the partial-index predicate from parsetree form to
* an implicit-AND qual expression, for easier evaluation at runtime. * an implicit-AND qual expression, for easier evaluation at runtime.
* While we are at it, we reduce it to a canonical (CNF or DNF) form
* to simplify the task of proving implications.
*/ */
if (predicate != NULL && rangetable != NIL) if (predicate != NULL && rangetable != NIL)
{ {
cnfPred = cnfify((Expr *) copyObject(predicate), true); cnfPred = canonicalize_qual((Expr *) copyObject(predicate), true);
fix_opids((Node *) cnfPred); fix_opids((Node *) cnfPred);
CheckPredicate(cnfPred, rangetable, relationId); CheckPredicate(cnfPred, rangetable, relationId);
} }
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment