@@ -1798,13 +1798,13 @@ check_index_only(RelOptInfo *rel, IndexOptInfo *index)
1798
1798
* Check that all needed attributes of the relation are available from the
1799
1799
* index.
1800
1800
*
1801
- *XXX this is overly conservative for partial indexes, since we will
1802
- *consider attributes involved in the index predicate asrequired even
1803
- * though the predicate won't need to be checked at runtime. (The same is
1804
- * true for attributes used only in index quals, if we are certain that
1805
- * the index is not lossy.) However, it would be quite expensive to
1806
- * determine that accurately at this point, so for now we take the easy
1807
- * way out.
1801
+ *For partial indexes we won't consider attributes involved in clauses
1802
+ *implied by the index predicate, asthose won't be needed at runtime.
1803
+ *
1804
+ *XXX The same is true for attributes used only in index quals, if we
1805
+ *are certain that the index is not lossy. However, it would be quite
1806
+ *expensive to determine that accurately at this point, so for now we
1807
+ *take the easy way out.
1808
1808
*/
1809
1809
1810
1810
/*
@@ -1819,6 +1819,27 @@ check_index_only(RelOptInfo *rel, IndexOptInfo *index)
1819
1819
{
1820
1820
RestrictInfo * rinfo = (RestrictInfo * )lfirst (lc );
1821
1821
1822
+ /*
1823
+ * If the index is partial, we won't consider the clauses that are
1824
+ * implied by the index predicate (those are not needed at runtime).
1825
+ */
1826
+ if (index -> indpred != NIL )
1827
+ {
1828
+ bool implied = false;
1829
+ List * clauses = NIL ;
1830
+
1831
+ /* need a list for the 'implied_by' call */
1832
+ clauses = lappend (clauses , (Node * )rinfo -> clause );
1833
+
1834
+ implied = predicate_implied_by (clauses ,index -> indpred );
1835
+
1836
+ /* we generally don't free memory, but well ... */
1837
+ list_free (clauses );
1838
+
1839
+ /* if the clause is implied by index predicate, skip it */
1840
+ if (implied )
1841
+ continue ;
1842
+ }
1822
1843
pull_varattnos ((Node * )rinfo -> clause ,rel -> relid ,& attrs_used );
1823
1844
}
1824
1845