* ExecInitExpr: prepare an expression tree for execution * * This function builds and returns an ExprState implementing the given * Expr node tree. The return ExprState can then be handed to ExecEvalExpr * for execution. Because the Expr tree itself is read-only as far as * ExecInitExpr and ExecEvalExpr are concerned, several different executions * of the same plan tree can occur concurren
| 132 | * although ExecQual and ExecCheck will accept one (and treat it as "true"). |
| 133 | */ |
| 134 | ExprState * |
| 135 | ExecInitExpr(Expr *node, PlanState *parent) |
| 136 | { |
| 137 | ExprState *state; |
| 138 | ExprEvalStep scratch = {0}; |
| 139 | |
| 140 | /* Special case: NULL expression produces a NULL ExprState pointer */ |
| 141 | if (node == NULL) |
| 142 | return NULL; |
| 143 | |
| 144 | /* Initialize ExprState with empty step list */ |
| 145 | state = makeNode(ExprState); |
| 146 | state->expr = node; |
| 147 | state->parent = parent; |
| 148 | state->ext_params = NULL; |
| 149 | |
| 150 | /* Insert EEOP_*_FETCHSOME steps as needed */ |
| 151 | ExecInitExprSlots(state, (Node *) node); |
| 152 | |
| 153 | /* Compile the expression proper */ |
| 154 | ExecInitExprRec(node, state, &state->resvalue, &state->resnull); |
| 155 | |
| 156 | /* Finally, append a DONE step */ |
| 157 | scratch.opcode = EEOP_DONE; |
| 158 | ExprEvalPushStep(state, &scratch); |
| 159 | |
| 160 | ExecReadyExpr(state); |
| 161 | |
| 162 | return state; |
| 163 | } |
| 164 | |
| 165 | /* |
| 166 | * ExecInitExprWithParams: prepare a standalone expression tree for execution |