Ah, so we now we can get rid of the TState * being passed around separately for expression execution, too?
Indeed.I would have thought that the compiler would have warned if it is unused, but because of the recursion it is uselessly used.
Ok, maybe the sentence above is not very clear. Attached a patch which simplifies further.
-- Fabien.
diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c index e5078af796..bcc2138c73 100644 --- a/src/bin/pgbench/pgbench.c +++ b/src/bin/pgbench/pgbench.c @@ -575,7 +575,7 @@ static void setNullValue(PgBenchValue *pv); static void setBoolValue(PgBenchValue *pv, bool bval); static void setIntValue(PgBenchValue *pv, int64 ival); static void setDoubleValue(PgBenchValue *pv, double dval); -static bool evaluateExpr(TState *thread, CState *st, PgBenchExpr *expr, +static bool evaluateExpr(CState *st, PgBenchExpr *expr, PgBenchValue *retval); static ConnectionStateEnum executeMetaCommand(TState *thread, CState *st, instr_time *now); @@ -1744,7 +1744,7 @@ isLazyFunc(PgBenchFunction func) /* lazy evaluation of some functions */ static bool -evalLazyFunc(TState *thread, CState *st, +evalLazyFunc(CState *st, PgBenchFunction func, PgBenchExprLink *args, PgBenchValue *retval) { PgBenchValue a1, @@ -1755,7 +1755,7 @@ evalLazyFunc(TState *thread, CState *st, Assert(isLazyFunc(func) && args != NULL && args->next != NULL); /* args points to first condition */ - if (!evaluateExpr(thread, st, args->expr, &a1)) + if (!evaluateExpr(st, args->expr, &a1)) return false; /* second condition for AND/OR and corresponding branch for CASE */ @@ -1779,7 +1779,7 @@ evalLazyFunc(TState *thread, CState *st, return true; } - if (!evaluateExpr(thread, st, args->expr, &a2)) + if (!evaluateExpr(st, args->expr, &a2)) return false; if (a2.type == PGBT_NULL) @@ -1814,7 +1814,7 @@ evalLazyFunc(TState *thread, CState *st, return true; } - if (!evaluateExpr(thread, st, args->expr, &a2)) + if (!evaluateExpr(st, args->expr, &a2)) return false; if (a2.type == PGBT_NULL) @@ -1833,17 +1833,17 @@ evalLazyFunc(TState *thread, CState *st, case PGBENCH_CASE: /* when true, execute branch */ if (valueTruth(&a1)) - return evaluateExpr(thread, st, args->expr, retval); + return evaluateExpr(st, args->expr, retval); /* now args contains next condition or final else expression */ args = args->next; /* final else case? */ if (args->next == NULL) - return evaluateExpr(thread, st, args->expr, retval); + return evaluateExpr(st, args->expr, retval); /* no, another when, proceed */ - return evalLazyFunc(thread, st, PGBENCH_CASE, args, retval); + return evalLazyFunc(st, PGBENCH_CASE, args, retval); default: /* internal error, cannot get here */ @@ -1861,7 +1861,7 @@ evalLazyFunc(TState *thread, CState *st, * which do not require lazy evaluation. */ static bool -evalStandardFunc(TState *thread, CState *st, +evalStandardFunc(CState *st, PgBenchFunction func, PgBenchExprLink *args, PgBenchValue *retval) { @@ -1873,7 +1873,7 @@ evalStandardFunc(TState *thread, CState *st, for (nargs = 0; nargs < MAX_FARGS && l != NULL; nargs++, l = l->next) { - if (!evaluateExpr(thread, st, l->expr, &vargs[nargs])) + if (!evaluateExpr(st, l->expr, &vargs[nargs])) return false; has_null |= vargs[nargs].type == PGBT_NULL; } @@ -2408,13 +2408,13 @@ evalStandardFunc(TState *thread, CState *st, /* evaluate some function */ static bool -evalFunc(TState *thread, CState *st, +evalFunc(CState *st, PgBenchFunction func, PgBenchExprLink *args, PgBenchValue *retval) { if (isLazyFunc(func)) - return evalLazyFunc(thread, st, func, args, retval); + return evalLazyFunc(st, func, args, retval); else - return evalStandardFunc(thread, st, func, args, retval); + return evalStandardFunc(st, func, args, retval); } /* @@ -2424,7 +2424,7 @@ evalFunc(TState *thread, CState *st, * the value itself is returned through the retval pointer. */ static bool -evaluateExpr(TState *thread, CState *st, PgBenchExpr *expr, PgBenchValue *retval) +evaluateExpr(CState *st, PgBenchExpr *expr, PgBenchValue *retval) { switch (expr->etype) { @@ -2453,7 +2453,7 @@ evaluateExpr(TState *thread, CState *st, PgBenchExpr *expr, PgBenchValue *retval } case ENODE_FUNCTION: - return evalFunc(thread, st, + return evalFunc(st, expr->u.function.function, expr->u.function.args, retval); @@ -3348,7 +3348,7 @@ executeMetaCommand(TState *thread, CState *st, instr_time *now) PgBenchExpr *expr = command->expr; PgBenchValue result; - if (!evaluateExpr(thread, st, expr, &result)) + if (!evaluateExpr(st, expr, &result)) { commandFailed(st, argv[0], "evaluation of meta-command failed"); return CSTATE_ABORTED; @@ -3367,7 +3367,7 @@ executeMetaCommand(TState *thread, CState *st, instr_time *now) PgBenchValue result; bool cond; - if (!evaluateExpr(thread, st, expr, &result)) + if (!evaluateExpr(st, expr, &result)) { commandFailed(st, argv[0], "evaluation of meta-command failed"); return CSTATE_ABORTED; @@ -3390,7 +3390,7 @@ executeMetaCommand(TState *thread, CState *st, instr_time *now) return CSTATE_END_COMMAND; } - if (!evaluateExpr(thread, st, expr, &result)) + if (!evaluateExpr(st, expr, &result)) { commandFailed(st, argv[0], "evaluation of meta-command failed"); return CSTATE_ABORTED;