mirror of
https://github.com/postgres/postgres.git
synced 2025-08-19 23:22:23 +03:00
Simplify executor's handling of CaseTestExpr & CoerceToDomainValue.
Instead of deciding at runtime whether to read from casetest.value or caseValue_datum, split EEOP_CASE_TESTVAL into two opcodes and make the decision during expression compilation. Similarly for EEOP_DOMAIN_TESTVAL. This actually results in net less code, mainly because llvmjit_expr.c's code for handling these opcodes gets shorter. The performance gain is doubtless negligible, but this seems worth changing anyway on grounds of simplicity and understandability. Author: Andreas Karlsson <andreas@proxel.se> Co-authored-by: Xing Guo <higuoxing@gmail.com> Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/CACpMh+AiBYAWn+D1aU7Rsy-V1tox06Cbc0H3qA7rwL5zdJ=anQ@mail.gmail.com
This commit is contained in:
@@ -365,8 +365,7 @@ ExecReadyInterpretedExpr(ExprState *state)
|
||||
return;
|
||||
}
|
||||
else if (step0 == EEOP_CASE_TESTVAL &&
|
||||
step1 == EEOP_FUNCEXPR_STRICT &&
|
||||
state->steps[0].d.casetest.value)
|
||||
step1 == EEOP_FUNCEXPR_STRICT)
|
||||
{
|
||||
state->evalfunc_private = ExecJustApplyFuncToCase;
|
||||
return;
|
||||
@@ -524,6 +523,7 @@ ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull)
|
||||
&&CASE_EEOP_PARAM_CALLBACK,
|
||||
&&CASE_EEOP_PARAM_SET,
|
||||
&&CASE_EEOP_CASE_TESTVAL,
|
||||
&&CASE_EEOP_CASE_TESTVAL_EXT,
|
||||
&&CASE_EEOP_MAKE_READONLY,
|
||||
&&CASE_EEOP_IOCOERCE,
|
||||
&&CASE_EEOP_IOCOERCE_SAFE,
|
||||
@@ -548,6 +548,7 @@ ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull)
|
||||
&&CASE_EEOP_SBSREF_ASSIGN,
|
||||
&&CASE_EEOP_SBSREF_FETCH,
|
||||
&&CASE_EEOP_DOMAIN_TESTVAL,
|
||||
&&CASE_EEOP_DOMAIN_TESTVAL_EXT,
|
||||
&&CASE_EEOP_DOMAIN_NOTNULL,
|
||||
&&CASE_EEOP_DOMAIN_CHECK,
|
||||
&&CASE_EEOP_HASHDATUM_SET_INITVAL,
|
||||
@@ -1273,44 +1274,16 @@ ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull)
|
||||
|
||||
EEO_CASE(EEOP_CASE_TESTVAL)
|
||||
{
|
||||
/*
|
||||
* Normally upper parts of the expression tree have setup the
|
||||
* values to be returned here, but some parts of the system
|
||||
* currently misuse {caseValue,domainValue}_{datum,isNull} to set
|
||||
* run-time data. So if no values have been set-up, use
|
||||
* ExprContext's. This isn't pretty, but also not *that* ugly,
|
||||
* and this is unlikely to be performance sensitive enough to
|
||||
* worry about an extra branch.
|
||||
*/
|
||||
if (op->d.casetest.value)
|
||||
{
|
||||
*op->resvalue = *op->d.casetest.value;
|
||||
*op->resnull = *op->d.casetest.isnull;
|
||||
}
|
||||
else
|
||||
{
|
||||
*op->resvalue = econtext->caseValue_datum;
|
||||
*op->resnull = econtext->caseValue_isNull;
|
||||
}
|
||||
*op->resvalue = *op->d.casetest.value;
|
||||
*op->resnull = *op->d.casetest.isnull;
|
||||
|
||||
EEO_NEXT();
|
||||
}
|
||||
|
||||
EEO_CASE(EEOP_DOMAIN_TESTVAL)
|
||||
EEO_CASE(EEOP_CASE_TESTVAL_EXT)
|
||||
{
|
||||
/*
|
||||
* See EEOP_CASE_TESTVAL comment.
|
||||
*/
|
||||
if (op->d.casetest.value)
|
||||
{
|
||||
*op->resvalue = *op->d.casetest.value;
|
||||
*op->resnull = *op->d.casetest.isnull;
|
||||
}
|
||||
else
|
||||
{
|
||||
*op->resvalue = econtext->domainValue_datum;
|
||||
*op->resnull = econtext->domainValue_isNull;
|
||||
}
|
||||
*op->resvalue = econtext->caseValue_datum;
|
||||
*op->resnull = econtext->caseValue_isNull;
|
||||
|
||||
EEO_NEXT();
|
||||
}
|
||||
@@ -1726,6 +1699,22 @@ ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull)
|
||||
EEO_NEXT();
|
||||
}
|
||||
|
||||
EEO_CASE(EEOP_DOMAIN_TESTVAL)
|
||||
{
|
||||
*op->resvalue = *op->d.casetest.value;
|
||||
*op->resnull = *op->d.casetest.isnull;
|
||||
|
||||
EEO_NEXT();
|
||||
}
|
||||
|
||||
EEO_CASE(EEOP_DOMAIN_TESTVAL_EXT)
|
||||
{
|
||||
*op->resvalue = econtext->domainValue_datum;
|
||||
*op->resnull = econtext->domainValue_isNull;
|
||||
|
||||
EEO_NEXT();
|
||||
}
|
||||
|
||||
EEO_CASE(EEOP_DOMAIN_NOTNULL)
|
||||
{
|
||||
/* too complex for an inline implementation */
|
||||
|
Reference in New Issue
Block a user