@@ -56,21 +56,17 @@ static WrapperNode *handle_boolexpr(const BoolExpr *expr, WalkerContext *context
56
56
static WrapperNode * handle_arrexpr (const ScalarArrayOpExpr * expr , WalkerContext * context );
57
57
static WrapperNode * handle_opexpr (const OpExpr * expr , WalkerContext * context );
58
58
59
- static void handle_binary_opexpr (WalkerContext * context ,
60
- WrapperNode * result ,
61
- const Node * varnode ,
62
- const Const * c );
59
+ static void handle_binary_opexpr (const Const * c , WalkerContext * context ,
60
+ WrapperNode * result );
63
61
64
62
static void handle_binary_opexpr_param (const PartRelationInfo * prel ,
65
- WrapperNode * result ,
66
- const Node * varnode );
63
+ WrapperNode * result );
67
64
68
- static bool pull_var_param (const WalkerContext * context ,
69
- const OpExpr * expr ,
70
- Node * * var_ptr ,
71
- Node * * param_ptr );
65
+ static bool is_key_op_param (const OpExpr * expr ,
66
+ const WalkerContext * context ,
67
+ Node * * param_ptr );
72
68
73
- static Const * extract_const (WalkerContext * wcxt , Param * param );
69
+ static Const * extract_const (Param * param , WalkerContext * wcxt );
74
70
75
71
76
72
/* Copied from PostgreSQL (allpaths.c) */
@@ -93,13 +89,13 @@ static void generate_mergeappend_paths(PlannerInfo *root,
93
89
94
90
95
91
/* We can transform Param into Const provided that 'econtext' is available */
96
- #define IsConstValue (wcxt , node ) \
92
+ #define IsConstValue (node , wcxt ) \
97
93
( IsA((node), Const) || (WcxtHasExprContext(wcxt) ? IsA((node), Param) : false) )
98
94
99
- #define ExtractConst (wcxt , node ) \
95
+ #define ExtractConst (node , wcxt ) \
100
96
( \
101
97
IsA((node), Param) ? \
102
- extract_const((wcxt), ( Param *) (node)) : \
98
+ extract_const((Param *) (node), (wcxt )) : \
103
99
((Const *) (node)) \
104
100
)
105
101
@@ -994,25 +990,26 @@ static WrapperNode *
994
990
handle_opexpr (const OpExpr * expr , WalkerContext * context )
995
991
{
996
992
WrapperNode * result = (WrapperNode * ) palloc0 (sizeof (WrapperNode ));
997
- Node * var , * param ;
993
+ Node * param ;
998
994
const PartRelationInfo * prel = context -> prel ;
999
995
1000
996
result -> orig = (const Node * ) expr ;
1001
997
result -> args = NIL ;
1002
998
1003
999
if (list_length (expr -> args ) == 2 )
1004
1000
{
1005
- if (pull_var_param (context , expr , & var , & param ))
1001
+ /* Is it KEY OP PARAM or PARAM OP KEY? */
1002
+ if (is_key_op_param (expr , context , & param ))
1006
1003
{
1007
- if (IsConstValue (context , param ))
1004
+ if (IsConstValue (param , context ))
1008
1005
{
1009
- handle_binary_opexpr (context , result , var ,
1010
- ExtractConst (context , param ));
1006
+ handle_binary_opexpr (ExtractConst (param , context ), context , result );
1011
1007
return result ;
1012
1008
}
1009
+ /* TODO: estimate selectivity for param if it's Var */
1013
1010
else if (IsA (param , Param ) || IsA (param , Var ))
1014
1011
{
1015
- handle_binary_opexpr_param (prel , result , var );
1012
+ handle_binary_opexpr_param (prel , result );
1016
1013
return result ;
1017
1014
}
1018
1015
}
@@ -1024,10 +1021,10 @@ handle_opexpr(const OpExpr *expr, WalkerContext *context)
1024
1021
}
1025
1022
1026
1023
/* Binary operator handler */
1027
- /* FIXME: varnode */
1028
1024
static void
1029
- handle_binary_opexpr (WalkerContext * context , WrapperNode * result ,
1030
- const Node * varnode , const Const * c )
1025
+ handle_binary_opexpr (const Const * c ,
1026
+ WalkerContext * context ,
1027
+ WrapperNode * result )
1031
1028
{
1032
1029
int strategy ;
1033
1030
TypeCacheEntry * tce ;
@@ -1112,10 +1109,9 @@ handle_binary_opexpr(WalkerContext *context, WrapperNode *result,
1112
1109
}
1113
1110
1114
1111
/* Estimate selectivity of parametrized quals */
1115
- /* FIXME: varnode */
1116
1112
static void
1117
1113
handle_binary_opexpr_param (const PartRelationInfo * prel ,
1118
- WrapperNode * result , const Node * varnode )
1114
+ WrapperNode * result )
1119
1115
{
1120
1116
const OpExpr * expr = (const OpExpr * ) result -> orig ;
1121
1117
TypeCacheEntry * tce ;
@@ -1131,30 +1127,27 @@ handle_binary_opexpr_param(const PartRelationInfo *prel,
1131
1127
1132
1128
1133
1129
/*
1134
- * Checks if expression is a KEY OP PARAM or PARAM OP KEY, where KEY is
1135
- * partition expression and PARAM is whatever.
1130
+ * Checks if expression is a KEY OP PARAM or PARAM OP KEY, where
1131
+ * KEY is partitioning expression and PARAM is whatever.
1136
1132
*
1137
1133
* NOTE: returns false if partition key is not in expression.
1138
1134
*/
1139
1135
static bool
1140
- pull_var_param (const WalkerContext * context ,
1141
- const OpExpr * expr ,
1142
- Node * * var_ptr ,
1143
- Node * * param_ptr )
1136
+ is_key_op_param (const OpExpr * expr ,
1137
+ const WalkerContext * context ,
1138
+ Node * * param_ptr ) /* ret value #1 */
1144
1139
{
1145
1140
Node * left = linitial (expr -> args ),
1146
1141
* right = lsecond (expr -> args );
1147
1142
1148
1143
if (match_expr_to_operand (context -> prel_expr , left ))
1149
1144
{
1150
- * var_ptr = left ;
1151
1145
* param_ptr = right ;
1152
1146
return true;
1153
1147
}
1154
1148
1155
1149
if (match_expr_to_operand (context -> prel_expr , right ))
1156
1150
{
1157
- * var_ptr = right ;
1158
1151
* param_ptr = left ;
1159
1152
return true;
1160
1153
}
@@ -1164,7 +1157,7 @@ pull_var_param(const WalkerContext *context,
1164
1157
1165
1158
/* Extract (evaluate) Const from Param node */
1166
1159
static Const *
1167
- extract_const (WalkerContext * wcxt , Param * param )
1160
+ extract_const (Param * param , WalkerContext * wcxt )
1168
1161
{
1169
1162
ExprState * estate = ExecInitExpr ((Expr * ) param , NULL );
1170
1163
bool isnull ;
0 commit comments