Skip to content

Commit ba578fe

Browse files
committed
light refactoring (get rid of const Node *varnode)
1 parent 8cf2371 commit ba578fe

File tree

1 file changed

+27
-34
lines changed

1 file changed

+27
-34
lines changed

src/pg_pathman.c

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,17 @@ static WrapperNode *handle_boolexpr(const BoolExpr *expr, WalkerContext *context
5656
static WrapperNode *handle_arrexpr(const ScalarArrayOpExpr *expr, WalkerContext *context);
5757
static WrapperNode *handle_opexpr(const OpExpr *expr, WalkerContext *context);
5858

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);
6361

6462
static void handle_binary_opexpr_param(const PartRelationInfo *prel,
65-
WrapperNode *result,
66-
const Node *varnode);
63+
WrapperNode *result);
6764

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);
7268

73-
static Const *extract_const(WalkerContext *wcxt, Param *param);
69+
static Const *extract_const(Param *param, WalkerContext *wcxt);
7470

7571

7672
/* Copied from PostgreSQL (allpaths.c) */
@@ -93,13 +89,13 @@ static void generate_mergeappend_paths(PlannerInfo *root,
9389

9490

9591
/* We can transform Param into Const provided that 'econtext' is available */
96-
#define IsConstValue(wcxt, node) \
92+
#define IsConstValue(node, wcxt) \
9793
( IsA((node), Const) || (WcxtHasExprContext(wcxt) ? IsA((node), Param) : false) )
9894

99-
#define ExtractConst(wcxt, node) \
95+
#define ExtractConst(node, wcxt) \
10096
( \
10197
IsA((node), Param) ? \
102-
extract_const((wcxt), (Param *) (node)) : \
98+
extract_const((Param *) (node), (wcxt)) : \
10399
((Const *) (node)) \
104100
)
105101

@@ -994,25 +990,26 @@ static WrapperNode *
994990
handle_opexpr(const OpExpr *expr, WalkerContext *context)
995991
{
996992
WrapperNode *result = (WrapperNode *) palloc0(sizeof(WrapperNode));
997-
Node *var, *param;
993+
Node *param;
998994
const PartRelationInfo *prel = context->prel;
999995

1000996
result->orig = (const Node *) expr;
1001997
result->args = NIL;
1002998

1003999
if (list_length(expr->args) == 2)
10041000
{
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))
10061003
{
1007-
if (IsConstValue(context, param))
1004+
if (IsConstValue(param, context))
10081005
{
1009-
handle_binary_opexpr(context, result, var,
1010-
ExtractConst(context, param));
1006+
handle_binary_opexpr(ExtractConst(param, context), context, result);
10111007
return result;
10121008
}
1009+
/* TODO: estimate selectivity for param if it's Var */
10131010
else if (IsA(param, Param) || IsA(param, Var))
10141011
{
1015-
handle_binary_opexpr_param(prel, result, var);
1012+
handle_binary_opexpr_param(prel, result);
10161013
return result;
10171014
}
10181015
}
@@ -1024,10 +1021,10 @@ handle_opexpr(const OpExpr *expr, WalkerContext *context)
10241021
}
10251022

10261023
/* Binary operator handler */
1027-
/* FIXME: varnode */
10281024
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)
10311028
{
10321029
int strategy;
10331030
TypeCacheEntry *tce;
@@ -1112,10 +1109,9 @@ handle_binary_opexpr(WalkerContext *context, WrapperNode *result,
11121109
}
11131110

11141111
/* Estimate selectivity of parametrized quals */
1115-
/* FIXME: varnode */
11161112
static void
11171113
handle_binary_opexpr_param(const PartRelationInfo *prel,
1118-
WrapperNode *result, const Node *varnode)
1114+
WrapperNode *result)
11191115
{
11201116
const OpExpr *expr = (const OpExpr *) result->orig;
11211117
TypeCacheEntry *tce;
@@ -1131,30 +1127,27 @@ handle_binary_opexpr_param(const PartRelationInfo *prel,
11311127

11321128

11331129
/*
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.
11361132
*
11371133
* NOTE: returns false if partition key is not in expression.
11381134
*/
11391135
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 */
11441139
{
11451140
Node *left = linitial(expr->args),
11461141
*right = lsecond(expr->args);
11471142

11481143
if (match_expr_to_operand(context->prel_expr, left))
11491144
{
1150-
*var_ptr = left;
11511145
*param_ptr = right;
11521146
return true;
11531147
}
11541148

11551149
if (match_expr_to_operand(context->prel_expr, right))
11561150
{
1157-
*var_ptr = right;
11581151
*param_ptr = left;
11591152
return true;
11601153
}
@@ -1164,7 +1157,7 @@ pull_var_param(const WalkerContext *context,
11641157

11651158
/* Extract (evaluate) Const from Param node */
11661159
static Const *
1167-
extract_const(WalkerContext *wcxt, Param *param)
1160+
extract_const(Param *param, WalkerContext *wcxt)
11681161
{
11691162
ExprState *estate = ExecInitExpr((Expr *) param, NULL);
11701163
bool isnull;

0 commit comments

Comments
 (0)