@ -36,6 +36,12 @@
# include "utils/selfuncs.h"
# include "utils/selfuncs.h"
/* source-code-compatibility hacks for pull_varnos() API change */
# define pull_varnos(a,b) pull_varnos_new(a,b)
# undef make_simple_restrictinfo
# define make_simple_restrictinfo(root, clause) \
make_restrictinfo_new ( root , clause , true , false , false , 0 , NULL , NULL , NULL )
/* XXX see PartCollMatchesExprColl */
/* XXX see PartCollMatchesExprColl */
# define IndexCollMatchesExprColl(idxcollation, exprcollation) \
# define IndexCollMatchesExprColl(idxcollation, exprcollation) \
( ( idxcollation ) = = InvalidOid | | ( idxcollation ) = = ( exprcollation ) )
( ( idxcollation ) = = InvalidOid | | ( idxcollation ) = = ( exprcollation ) )
@ -153,7 +159,8 @@ static IndexClause *match_clause_to_indexcol(PlannerInfo *root,
RestrictInfo * rinfo ,
RestrictInfo * rinfo ,
int indexcol ,
int indexcol ,
IndexOptInfo * index ) ;
IndexOptInfo * index ) ;
static IndexClause * match_boolean_index_clause ( RestrictInfo * rinfo ,
static IndexClause * match_boolean_index_clause ( PlannerInfo * root ,
RestrictInfo * rinfo ,
int indexcol , IndexOptInfo * index ) ;
int indexcol , IndexOptInfo * index ) ;
static IndexClause * match_opclause_to_indexcol ( PlannerInfo * root ,
static IndexClause * match_opclause_to_indexcol ( PlannerInfo * root ,
RestrictInfo * rinfo ,
RestrictInfo * rinfo ,
@ -169,13 +176,16 @@ static IndexClause *get_index_clause_from_support(PlannerInfo *root,
int indexarg ,
int indexarg ,
int indexcol ,
int indexcol ,
IndexOptInfo * index ) ;
IndexOptInfo * index ) ;
static IndexClause * match_saopclause_to_indexcol ( RestrictInfo * rinfo ,
static IndexClause * match_saopclause_to_indexcol ( PlannerInfo * root ,
RestrictInfo * rinfo ,
int indexcol ,
int indexcol ,
IndexOptInfo * index ) ;
IndexOptInfo * index ) ;
static IndexClause * match_rowcompare_to_indexcol ( RestrictInfo * rinfo ,
static IndexClause * match_rowcompare_to_indexcol ( PlannerInfo * root ,
RestrictInfo * rinfo ,
int indexcol ,
int indexcol ,
IndexOptInfo * index ) ;
IndexOptInfo * index ) ;
static IndexClause * expand_indexqual_rowcompare ( RestrictInfo * rinfo ,
static IndexClause * expand_indexqual_rowcompare ( PlannerInfo * root ,
RestrictInfo * rinfo ,
int indexcol ,
int indexcol ,
IndexOptInfo * index ,
IndexOptInfo * index ,
Oid expr_op ,
Oid expr_op ,
@ -2305,7 +2315,7 @@ match_clause_to_indexcol(PlannerInfo *root,
opfamily = index - > opfamily [ indexcol ] ;
opfamily = index - > opfamily [ indexcol ] ;
if ( IsBooleanOpfamily ( opfamily ) )
if ( IsBooleanOpfamily ( opfamily ) )
{
{
iclause = match_boolean_index_clause ( rinfo , indexcol , index ) ;
iclause = match_boolean_index_clause ( root , r info , indexcol , index ) ;
if ( iclause )
if ( iclause )
return iclause ;
return iclause ;
}
}
@ -2325,11 +2335,11 @@ match_clause_to_indexcol(PlannerInfo *root,
}
}
else if ( IsA ( clause , ScalarArrayOpExpr ) )
else if ( IsA ( clause , ScalarArrayOpExpr ) )
{
{
return match_saopclause_to_indexcol ( rinfo , indexcol , index ) ;
return match_saopclause_to_indexcol ( root , r info , indexcol , index ) ;
}
}
else if ( IsA ( clause , RowCompareExpr ) )
else if ( IsA ( clause , RowCompareExpr ) )
{
{
return match_rowcompare_to_indexcol ( rinfo , indexcol , index ) ;
return match_rowcompare_to_indexcol ( root , r info , indexcol , index ) ;
}
}
else if ( index - > amsearchnulls & & IsA ( clause , NullTest ) )
else if ( index - > amsearchnulls & & IsA ( clause , NullTest ) )
{
{
@ -2368,7 +2378,8 @@ match_clause_to_indexcol(PlannerInfo *root,
* index ' s key , and if so , build a suitable IndexClause .
* index ' s key , and if so , build a suitable IndexClause .
*/
*/
static IndexClause *
static IndexClause *
match_boolean_index_clause ( RestrictInfo * rinfo ,
match_boolean_index_clause ( PlannerInfo * root ,
RestrictInfo * rinfo ,
int indexcol ,
int indexcol ,
IndexOptInfo * index )
IndexOptInfo * index )
{
{
@ -2438,7 +2449,7 @@ match_boolean_index_clause(RestrictInfo *rinfo,
IndexClause * iclause = makeNode ( IndexClause ) ;
IndexClause * iclause = makeNode ( IndexClause ) ;
iclause - > rinfo = rinfo ;
iclause - > rinfo = rinfo ;
iclause - > indexquals = list_make1 ( make_simple_restrictinfo ( op ) ) ;
iclause - > indexquals = list_make1 ( make_simple_restrictinfo ( root , op ) ) ;
iclause - > lossy = false ;
iclause - > lossy = false ;
iclause - > indexcol = indexcol ;
iclause - > indexcol = indexcol ;
iclause - > indexcols = NIL ;
iclause - > indexcols = NIL ;
@ -2663,7 +2674,8 @@ get_index_clause_from_support(PlannerInfo *root,
{
{
Expr * clause = ( Expr * ) lfirst ( lc ) ;
Expr * clause = ( Expr * ) lfirst ( lc ) ;
indexquals = lappend ( indexquals , make_simple_restrictinfo ( clause ) ) ;
indexquals = lappend ( indexquals ,
make_simple_restrictinfo ( root , clause ) ) ;
}
}
iclause - > rinfo = rinfo ;
iclause - > rinfo = rinfo ;
@ -2684,7 +2696,8 @@ get_index_clause_from_support(PlannerInfo *root,
* which see for comments .
* which see for comments .
*/
*/
static IndexClause *
static IndexClause *
match_saopclause_to_indexcol ( RestrictInfo * rinfo ,
match_saopclause_to_indexcol ( PlannerInfo * root ,
RestrictInfo * rinfo ,
int indexcol ,
int indexcol ,
IndexOptInfo * index )
IndexOptInfo * index )
{
{
@ -2703,7 +2716,7 @@ match_saopclause_to_indexcol(RestrictInfo *rinfo,
return NULL ;
return NULL ;
leftop = ( Node * ) linitial ( saop - > args ) ;
leftop = ( Node * ) linitial ( saop - > args ) ;
rightop = ( Node * ) lsecond ( saop - > args ) ;
rightop = ( Node * ) lsecond ( saop - > args ) ;
right_relids = pull_varnos ( rightop ) ;
right_relids = pull_varnos ( root , r ightop ) ;
expr_op = saop - > opno ;
expr_op = saop - > opno ;
expr_coll = saop - > inputcollid ;
expr_coll = saop - > inputcollid ;
@ -2751,7 +2764,8 @@ match_saopclause_to_indexcol(RestrictInfo *rinfo,
* is handled by expand_indexqual_rowcompare ( ) .
* is handled by expand_indexqual_rowcompare ( ) .
*/
*/
static IndexClause *
static IndexClause *
match_rowcompare_to_indexcol ( RestrictInfo * rinfo ,
match_rowcompare_to_indexcol ( PlannerInfo * root ,
RestrictInfo * rinfo ,
int indexcol ,
int indexcol ,
IndexOptInfo * index )
IndexOptInfo * index )
{
{
@ -2796,14 +2810,14 @@ match_rowcompare_to_indexcol(RestrictInfo *rinfo,
* These syntactic tests are the same as in match_opclause_to_indexcol ( )
* These syntactic tests are the same as in match_opclause_to_indexcol ( )
*/
*/
if ( match_index_to_operand ( leftop , indexcol , index ) & &
if ( match_index_to_operand ( leftop , indexcol , index ) & &
! bms_is_member ( index_relid , pull_varnos ( rightop ) ) & &
! bms_is_member ( index_relid , pull_varnos ( root , r ightop ) ) & &
! contain_volatile_functions ( rightop ) )
! contain_volatile_functions ( rightop ) )
{
{
/* OK, indexkey is on left */
/* OK, indexkey is on left */
var_on_left = true ;
var_on_left = true ;
}
}
else if ( match_index_to_operand ( rightop , indexcol , index ) & &
else if ( match_index_to_operand ( rightop , indexcol , index ) & &
! bms_is_member ( index_relid , pull_varnos ( leftop ) ) & &
! bms_is_member ( index_relid , pull_varnos ( root , leftop ) ) & &
! contain_volatile_functions ( leftop ) )
! contain_volatile_functions ( leftop ) )
{
{
/* indexkey is on right, so commute the operator */
/* indexkey is on right, so commute the operator */
@ -2822,7 +2836,8 @@ match_rowcompare_to_indexcol(RestrictInfo *rinfo,
case BTLessEqualStrategyNumber :
case BTLessEqualStrategyNumber :
case BTGreaterEqualStrategyNumber :
case BTGreaterEqualStrategyNumber :
case BTGreaterStrategyNumber :
case BTGreaterStrategyNumber :
return expand_indexqual_rowcompare ( rinfo ,
return expand_indexqual_rowcompare ( root ,
rinfo ,
indexcol ,
indexcol ,
index ,
index ,
expr_op ,
expr_op ,
@ -2856,7 +2871,8 @@ match_rowcompare_to_indexcol(RestrictInfo *rinfo,
* but we split it out for comprehensibility .
* but we split it out for comprehensibility .
*/
*/
static IndexClause *
static IndexClause *
expand_indexqual_rowcompare ( RestrictInfo * rinfo ,
expand_indexqual_rowcompare ( PlannerInfo * root ,
RestrictInfo * rinfo ,
int indexcol ,
int indexcol ,
IndexOptInfo * index ,
IndexOptInfo * index ,
Oid expr_op ,
Oid expr_op ,
@ -2926,7 +2942,7 @@ expand_indexqual_rowcompare(RestrictInfo *rinfo,
if ( expr_op = = InvalidOid )
if ( expr_op = = InvalidOid )
break ; /* operator is not usable */
break ; /* operator is not usable */
}
}
if ( bms_is_member ( index - > rel - > relid , pull_varnos ( constop ) ) )
if ( bms_is_member ( index - > rel - > relid , pull_varnos ( root , constop ) ) )
break ; /* no good, Var on wrong side */
break ; /* no good, Var on wrong side */
if ( contain_volatile_functions ( constop ) )
if ( contain_volatile_functions ( constop ) )
break ; /* no good, volatile comparison value */
break ; /* no good, volatile comparison value */
@ -3036,7 +3052,8 @@ expand_indexqual_rowcompare(RestrictInfo *rinfo,
matching_cols ) ;
matching_cols ) ;
rc - > rargs = list_truncate ( copyObject ( non_var_args ) ,
rc - > rargs = list_truncate ( copyObject ( non_var_args ) ,
matching_cols ) ;
matching_cols ) ;
iclause - > indexquals = list_make1 ( make_simple_restrictinfo ( ( Expr * ) rc ) ) ;
iclause - > indexquals = list_make1 ( make_simple_restrictinfo ( root ,
( Expr * ) rc ) ) ;
}
}
else
else
{
{
@ -3050,7 +3067,7 @@ expand_indexqual_rowcompare(RestrictInfo *rinfo,
copyObject ( linitial ( non_var_args ) ) ,
copyObject ( linitial ( non_var_args ) ) ,
InvalidOid ,
InvalidOid ,
linitial_oid ( clause - > inputcollids ) ) ;
linitial_oid ( clause - > inputcollids ) ) ;
iclause - > indexquals = list_make1 ( make_simple_restrictinfo ( op ) ) ;
iclause - > indexquals = list_make1 ( make_simple_restrictinfo ( root , op ) ) ;
}
}
}
}
@ -3667,7 +3684,9 @@ relation_has_unique_index_for(PlannerInfo *root, RelOptInfo *rel,
* specified index column matches a boolean restriction clause .
* specified index column matches a boolean restriction clause .
*/
*/
bool
bool
indexcol_is_bool_constant_for_query ( IndexOptInfo * index , int indexcol )
indexcol_is_bool_constant_for_query ( PlannerInfo * root ,
IndexOptInfo * index ,
int indexcol )
{
{
ListCell * lc ;
ListCell * lc ;
@ -3689,7 +3708,7 @@ indexcol_is_bool_constant_for_query(IndexOptInfo *index, int indexcol)
continue ;
continue ;
/* See if we can match the clause's expression to the index column */
/* See if we can match the clause's expression to the index column */
if ( match_boolean_index_clause ( rinfo , indexcol , index ) )
if ( match_boolean_index_clause ( root , r info , indexcol , index ) )
return true ;
return true ;
}
}
@ -3802,9 +3821,15 @@ match_index_to_operand(Node *operand,
*/
*/
bool
bool
is_pseudo_constant_for_index ( Node * expr , IndexOptInfo * index )
is_pseudo_constant_for_index ( Node * expr , IndexOptInfo * index )
{
return is_pseudo_constant_for_index_new ( NULL , expr , index ) ;
}
bool
is_pseudo_constant_for_index_new ( PlannerInfo * root , Node * expr , IndexOptInfo * index )
{
{
/* pull_varnos is cheaper than volatility check, so do that first */
/* pull_varnos is cheaper than volatility check, so do that first */
if ( bms_is_member ( index - > rel - > relid , pull_varnos ( expr ) ) )
if ( bms_is_member ( index - > rel - > relid , pull_varnos ( root , expr ) ) )
return false ; /* no good, contains Var of table */
return false ; /* no good, contains Var of table */
if ( contain_volatile_functions ( expr ) )
if ( contain_volatile_functions ( expr ) )
return false ; /* no good, volatile comparison value */
return false ; /* no good, volatile comparison value */