mirror of
https://github.com/postgres/postgres.git
synced 2025-06-13 07:41:39 +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:
@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user