|
8 | 8 | * |
9 | 9 | * |
10 | 10 | * IDENTIFICATION |
11 | | - * $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.250 2009/01/01 17:23:44 momjian Exp $ |
| 11 | + * $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.251 2009/01/09 15:46:10 tgl Exp $ |
12 | 12 | * |
13 | 13 | *------------------------------------------------------------------------- |
14 | 14 | */ |
@@ -2576,3 +2576,39 @@ get_column_info_for_window(PlannerInfo *root, WindowClause *wc, List *tlist, |
2576 | 2576 | elog(ERROR, "failed to deconstruct sort operators into partitioning/ordering operators"); |
2577 | 2577 | } |
2578 | 2578 | } |
| 2579 | + |
| 2580 | + |
| 2581 | +/* |
| 2582 | + * expression_planner |
| 2583 | + * Perform planner's transformations on a standalone expression. |
| 2584 | + * |
| 2585 | + * Various utility commands need to evaluate expressions that are not part |
| 2586 | + * of a plannable query. They can do so using the executor's regular |
| 2587 | + * expression-execution machinery, but first the expression has to be fed |
| 2588 | + * through here to transform it from parser output to something executable. |
| 2589 | + * |
| 2590 | + * Currently, we disallow sublinks in standalone expressions, so there's no |
| 2591 | + * real "planning" involved here. (That might not always be true though.) |
| 2592 | + * What we must do is run eval_const_expressions to ensure that any function |
| 2593 | + * default arguments get inserted. The fact that constant subexpressions |
| 2594 | + * get simplified is a side-effect that is useful when the expression will |
| 2595 | + * get evaluated more than once. Also, we must fix operator function IDs. |
| 2596 | + * |
| 2597 | + * Note: this must not make any damaging changes to the passed-in expression |
| 2598 | + * tree. (It would actually be okay to apply fix_opfuncids to it, but since |
| 2599 | + * we first do an expression_tree_mutator-based walk, what is returned will |
| 2600 | + * be a new node tree.) |
| 2601 | + */ |
| 2602 | +Expr * |
| 2603 | +expression_planner(Expr *expr) |
| 2604 | +{ |
| 2605 | + Node *result; |
| 2606 | + |
| 2607 | + /* Insert default arguments and simplify constant subexprs */ |
| 2608 | + result = eval_const_expressions(NULL, (Node *) expr); |
| 2609 | + |
| 2610 | + /* Fill in opfuncid values if missing */ |
| 2611 | + fix_opfuncids(result); |
| 2612 | + |
| 2613 | + return (Expr *) result; |
| 2614 | +} |
0 commit comments