mirror of
https://github.com/postgres/postgres.git
synced 2025-11-10 17:42:29 +03:00
Fix matching of boolean index columns to sort ordering.
Normally, if we have a WHERE clause like "indexcol = constant", the planner will figure out that that index column can be ignored when determining whether the index has a desired sort ordering. But this failed to work for boolean index columns, because a condition like "boolcol = true" is canonicalized to just "boolcol" which does not give rise to an EquivalenceClass. Add a check to allow the same type of deduction to be made in this case too. Per a complaint from Dima Pavlov. Arguably this is a bug, but given the limited impact and the small number of complaints so far, I won't risk destabilizing plans in stable branches by back-patching. Patch by me, reviewed by Michael Paquier Discussion: https://postgr.es/m/1788.1481605684@sss.pgh.pa.us
This commit is contained in:
@@ -480,17 +480,30 @@ build_index_pathkeys(PlannerInfo *root,
|
||||
index->rel->relids,
|
||||
false);
|
||||
|
||||
/*
|
||||
* If the sort key isn't already present in any EquivalenceClass, then
|
||||
* it's not an interesting sort order for this query. So we can stop
|
||||
* now --- lower-order sort keys aren't useful either.
|
||||
*/
|
||||
if (!cpathkey)
|
||||
break;
|
||||
|
||||
/* Add to list unless redundant */
|
||||
if (!pathkey_is_redundant(cpathkey, retval))
|
||||
retval = lappend(retval, cpathkey);
|
||||
if (cpathkey)
|
||||
{
|
||||
/*
|
||||
* We found the sort key in an EquivalenceClass, so it's relevant
|
||||
* for this query. Add it to list, unless it's redundant.
|
||||
*/
|
||||
if (!pathkey_is_redundant(cpathkey, retval))
|
||||
retval = lappend(retval, cpathkey);
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Boolean index keys might be redundant even if they do not
|
||||
* appear in an EquivalenceClass, because of our special treatment
|
||||
* of boolean equality conditions --- see the comment for
|
||||
* indexcol_is_bool_constant_for_query(). If that applies, we can
|
||||
* continue to examine lower-order index columns. Otherwise, the
|
||||
* sort key is not an interesting sort order for this query, so we
|
||||
* should stop considering index columns; any lower-order sort
|
||||
* keys won't be useful either.
|
||||
*/
|
||||
if (!indexcol_is_bool_constant_for_query(index, i))
|
||||
break;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user