mirror of
https://github.com/postgres/postgres.git
synced 2025-06-16 06:01:02 +03:00
Add notion of a "transform function" that can simplify function calls.
Initially, we use this only to eliminate calls to the varchar() function in cases where the length is not being reduced and, therefore, the function call is equivalent to a RelabelType operation. The most significant effect of this is that we can avoid a table rewrite when changing a varchar(X) column to a varchar(Y) column, where Y > X. Noah Misch, reviewed by me and Alexey Klyukin
This commit is contained in:
@ -56,6 +56,7 @@
|
||||
#include "nodes/nodeFuncs.h"
|
||||
#include "nodes/parsenodes.h"
|
||||
#include "optimizer/clauses.h"
|
||||
#include "optimizer/planner.h"
|
||||
#include "parser/parse_clause.h"
|
||||
#include "parser/parse_coerce.h"
|
||||
#include "parser/parse_collate.h"
|
||||
@ -3495,7 +3496,8 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
|
||||
{
|
||||
NewColumnValue *ex = lfirst(l);
|
||||
|
||||
ex->exprstate = ExecPrepareExpr((Expr *) ex->expr, estate);
|
||||
/* expr already planned */
|
||||
ex->exprstate = ExecInitExpr((Expr *) ex->expr, NULL);
|
||||
}
|
||||
|
||||
notnull_attrs = NIL;
|
||||
@ -4398,7 +4400,7 @@ ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel,
|
||||
|
||||
newval = (NewColumnValue *) palloc0(sizeof(NewColumnValue));
|
||||
newval->attnum = attribute.attnum;
|
||||
newval->expr = defval;
|
||||
newval->expr = expression_planner(defval);
|
||||
|
||||
tab->newvals = lappend(tab->newvals, newval);
|
||||
tab->rewrite = true;
|
||||
@ -6707,6 +6709,9 @@ ATPrepAlterColumnType(List **wqueue,
|
||||
/* Fix collations after all else */
|
||||
assign_expr_collations(pstate, transform);
|
||||
|
||||
/* Plan the expr now so we can accurately assess the need to rewrite. */
|
||||
transform = (Node *) expression_planner((Expr *) transform);
|
||||
|
||||
/*
|
||||
* Add a work queue item to make ATRewriteTable update the column
|
||||
* contents.
|
||||
|
Reference in New Issue
Block a user