@ -787,6 +787,7 @@ build_index_paths(PlannerInfo *root, RelOptInfo *rel,
List * index_pathkeys ;
List * index_pathkeys ;
List * useful_pathkeys ;
List * useful_pathkeys ;
bool found_clause ;
bool found_clause ;
bool found_lower_saop_clause ;
bool pathkeys_possibly_useful ;
bool pathkeys_possibly_useful ;
bool index_is_ordered ;
bool index_is_ordered ;
bool index_only_scan ;
bool index_only_scan ;
@ -824,6 +825,13 @@ build_index_paths(PlannerInfo *root, RelOptInfo *rel,
* if saop_control is SAOP_REQUIRE , it has to be a ScalarArrayOpExpr
* if saop_control is SAOP_REQUIRE , it has to be a ScalarArrayOpExpr
* clause .
* clause .
*
*
* found_lower_saop_clause is set true if there ' s a ScalarArrayOpExpr
* index clause for a non - first index column . This prevents us from
* assuming that the scan result is ordered . ( Actually , the result is
* still ordered if there are equality constraints for all earlier
* columns , but it seems too expensive and non - modular for this code to be
* aware of that refinement . )
*
* We also build a Relids set showing which outer rels are required by the
* We also build a Relids set showing which outer rels are required by the
* selected clauses . Any lateral_relids are included in that , but not
* selected clauses . Any lateral_relids are included in that , but not
* otherwise accounted for .
* otherwise accounted for .
@ -831,6 +839,7 @@ build_index_paths(PlannerInfo *root, RelOptInfo *rel,
index_clauses = NIL ;
index_clauses = NIL ;
clause_columns = NIL ;
clause_columns = NIL ;
found_clause = false ;
found_clause = false ;
found_lower_saop_clause = false ;
outer_relids = bms_copy ( rel - > lateral_relids ) ;
outer_relids = bms_copy ( rel - > lateral_relids ) ;
for ( indexcol = 0 ; indexcol < index - > ncolumns ; indexcol + + )
for ( indexcol = 0 ; indexcol < index - > ncolumns ; indexcol + + )
{
{
@ -846,6 +855,8 @@ build_index_paths(PlannerInfo *root, RelOptInfo *rel,
if ( saop_control = = SAOP_PER_AM & & ! index - > amsearcharray )
if ( saop_control = = SAOP_PER_AM & & ! index - > amsearcharray )
continue ;
continue ;
found_clause = true ;
found_clause = true ;
if ( indexcol > 0 )
found_lower_saop_clause = true ;
}
}
else
else
{
{
@ -882,9 +893,11 @@ build_index_paths(PlannerInfo *root, RelOptInfo *rel,
/*
/*
* 2. Compute pathkeys describing index ' s ordering , if any , then see how
* 2. Compute pathkeys describing index ' s ordering , if any , then see how
* many of them are actually useful for this query . This is not relevant
* many of them are actually useful for this query . This is not relevant
* if we are only trying to build bitmap indexscans .
* if we are only trying to build bitmap indexscans , nor if we have to
* assume the scan is unordered .
*/
*/
pathkeys_possibly_useful = ( scantype ! = ST_BITMAPSCAN & &
pathkeys_possibly_useful = ( scantype ! = ST_BITMAPSCAN & &
! found_lower_saop_clause & &
has_useful_pathkeys ( root , rel ) ) ;
has_useful_pathkeys ( root , rel ) ) ;
index_is_ordered = ( index - > sortopfamily ! = NULL ) ;
index_is_ordered = ( index - > sortopfamily ! = NULL ) ;
if ( index_is_ordered & & pathkeys_possibly_useful )
if ( index_is_ordered & & pathkeys_possibly_useful )