From 8f9fe6edce358f7904e0db119416b4d1080a83aa Mon Sep 17 00:00:00 2001 From: Robert Haas Date: Tue, 21 Jun 2011 22:15:24 -0400 Subject: 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 --- src/backend/parser/parse_clause.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/backend/parser/parse_clause.c') 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); +} -- cgit v1.2.3