* Let's evaluate all STABLE functions that have constant args before * dispatch, so we get a consistent view across QEs * * Also, if this is a single_row insert, let's evaluate nextval() and * currval() before dispatching */
| 1519 | * currval() before dispatching |
| 1520 | */ |
| 1521 | static Node * |
| 1522 | pre_dispatch_function_evaluation_mutator(Node *node, |
| 1523 | pre_dispatch_function_evaluation_context *context) |
| 1524 | { |
| 1525 | Node *new_node = 0; |
| 1526 | |
| 1527 | if (node == NULL) |
| 1528 | return NULL; |
| 1529 | |
| 1530 | if (IsA(node, Param)) |
| 1531 | { |
| 1532 | Param *param = (Param *) node; |
| 1533 | |
| 1534 | /* Not replaceable, so just copy the Param (no need to recurse) */ |
| 1535 | return (Node *) copyObject(param); |
| 1536 | } |
| 1537 | else if (IsA(node, FuncExpr)) |
| 1538 | { |
| 1539 | FuncExpr *expr = (FuncExpr *) node; |
| 1540 | List *args; |
| 1541 | ListCell *arg; |
| 1542 | Expr *simple; |
| 1543 | FuncExpr *newexpr; |
| 1544 | bool has_nonconst_input; |
| 1545 | |
| 1546 | Form_pg_proc funcform; |
| 1547 | EState *estate; |
| 1548 | ExprState *exprstate; |
| 1549 | MemoryContext oldcontext; |
| 1550 | Datum const_val; |
| 1551 | bool const_is_null; |
| 1552 | int16 resultTypLen; |
| 1553 | bool resultTypByVal; |
| 1554 | |
| 1555 | Oid funcid; |
| 1556 | HeapTuple func_tuple; |
| 1557 | |
| 1558 | /* |
| 1559 | * Reduce constants in the FuncExpr's arguments. We know args is |
| 1560 | * either NIL or a List node, so we can call expression_tree_mutator |
| 1561 | * directly rather than recursing to self. |
| 1562 | */ |
| 1563 | args = (List *) expression_tree_mutator((Node *) expr->args, |
| 1564 | pre_dispatch_function_evaluation_mutator, |
| 1565 | (void *) context); |
| 1566 | |
| 1567 | funcid = expr->funcid; |
| 1568 | |
| 1569 | newexpr = makeNode(FuncExpr); |
| 1570 | newexpr->funcid = expr->funcid; |
| 1571 | newexpr->funcresulttype = expr->funcresulttype; |
| 1572 | newexpr->funcretset = expr->funcretset; |
| 1573 | newexpr->funcvariadic = expr->funcvariadic; |
| 1574 | newexpr->funcformat = expr->funcformat; |
| 1575 | newexpr->funccollid = expr->funccollid; |
| 1576 | newexpr->inputcollid = expr->inputcollid; |
| 1577 | newexpr->args = args; |
| 1578 | newexpr->location = expr->location; |
no test coverage detected