Skip to content

Commit eed57b1

Browse files
committed
Fix choose_bitmap_and() so that partial index predicates are considered when
deciding whether a potential additional indexscan is redundant or not. As now coded, any use of a partial index that was already used in a previous AND arm will be rejected as redundant. This might be overly restrictive, but not considering the point at all is definitely bad, as per example in bug #2441 from Arjen van der Meijden. In particular, a clauseless scan of a partial index was *never* considered redundant by the previous coding, and that's surely wrong. Being more flexible would also require some consideration of how not to double-count the index predicate's selectivity.
1 parent f323252 commit eed57b1

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/backend/optimizer/path/indxpath.c

Lines changed: 10 additions & 9 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.205 2006/05/18 17:12:10 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.206 2006/05/18 19:56:46 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -616,10 +616,10 @@ choose_bitmap_and(PlannerInfo *root, RelOptInfo *rel, List *paths)
616616
* non-selective. In any case, we'd surely be drastically misestimating
617617
* the selectivity if we count the same condition twice.
618618
*
619-
* XXX is there any risk of throwing away a useful partial index here
620-
* because we don't explicitly look at indpred? At least in simple cases,
621-
* the partial index will sort before competing non-partial indexes and so
622-
* it makes the right choice, but perhaps we need to work harder.
619+
* We include index predicate conditions in the redundancy test. Because
620+
* the test is just for pointer equality and not equal(), the effect is
621+
* that use of the same partial index in two different AND elements is
622+
* considered redundant. (XXX is this too strong?)
623623
*
624624
* Note: outputting the selected sub-paths in selectivity order is a good
625625
* thing even if we weren't using that as part of the selection method,
@@ -732,14 +732,14 @@ bitmap_and_cost_est(PlannerInfo *root, RelOptInfo *rel, List *paths)
732732
/*
733733
* pull_indexpath_quals
734734
*
735-
* Given the Path structure for a plain or bitmap indexscan, extract a
736-
* list of RestrictInfo nodes for all the indexquals used in the Path.
735+
* Given the Path structure for a plain or bitmap indexscan, extract a list
736+
* of all the indexquals and index predicate conditions used in the Path.
737737
*
738738
* This is sort of a simplified version of make_restrictinfo_from_bitmapqual;
739739
* here, we are not trying to produce an accurate representation of the AND/OR
740740
* semantics of the Path, but just find out all the base conditions used.
741741
*
742-
* The result list contains pointers to the RestrictInfos used in the Path,
742+
* The result list contains pointers to the expressions used in the Path,
743743
* but all the list cells are freshly built, so it's safe to destructively
744744
* modify the list (eg, by concat'ing it with other lists).
745745
*/
@@ -777,7 +777,8 @@ pull_indexpath_quals(Path *bitmapqual)
777777
{
778778
IndexPath *ipath = (IndexPath *) bitmapqual;
779779

780-
result = list_copy(ipath->indexclauses);
780+
result = get_actual_clauses(ipath->indexclauses);
781+
result = list_concat(result, list_copy(ipath->indexinfo->indpred));
781782
}
782783
else
783784
elog(ERROR, "unrecognized node type: %d", nodeTag(bitmapqual));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy