diff options
author | Robert Haas <rhaas@postgresql.org> | 2011-06-21 22:15:24 -0400 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2011-06-21 22:21:24 -0400 |
commit | 8f9fe6edce358f7904e0db119416b4d1080a83aa (patch) | |
tree | a0a828d221e85af6c6bf5bc74a6c6c7190352cbf /src/backend/parser/parse_clause.c | |
parent | 771a9f69f70e0b4fa95347df7ab346e5bdbc85f2 (diff) | |
download | postgresql-8f9fe6edce358f7904e0db119416b4d1080a83aa.tar.gz postgresql-8f9fe6edce358f7904e0db119416b4d1080a83aa.zip |
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
Diffstat (limited to 'src/backend/parser/parse_clause.c')
-rw-r--r-- | src/backend/parser/parse_clause.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/backend/parser/parse_clause.c b/src/backend/parser/parse_clause.c index c5fe6b6a3fd..a8549e0c2a7 100644 --- a/src/backend/parser/parse_clause.c +++ b/src/backend/parser/parse_clause.c @@ -2278,3 +2278,25 @@ transformFrameOffset(ParseState *pstate, int frameOptions, Node *clause) return node; } + +/* + * relabel_to_typmod + * Add a RelabelType node that changes just the typmod, and remove all + * now-superfluous RelabelType nodes beneath it. + */ +Node * +relabel_to_typmod(Node *expr, int32 typmod) +{ + Oid type = exprType(expr); + Oid coll = exprCollation(expr); + + /* + * Strip any existing RelabelType, then add one. This is to preserve the + * invariant of no redundant RelabelTypes. + */ + while (IsA(expr, RelabelType)) + expr = (Node *) ((RelabelType *) expr)->arg; + + return (Node *) makeRelabelType((Expr *) expr, type, typmod, coll, + COERCE_DONTCARE); +} |