From 04b8497dc54659d237d2c4283f080819a494ca8e Mon Sep 17 00:00:00 2001 From: ztao1987 Date: Wed, 20 Apr 2022 17:06:09 +0800 Subject: [PATCH] HAWQ-1838. fix attribute typmod for CREATE TABLE AS SELECT --- src/backend/nodes/copyfuncs.c | 1 + src/backend/nodes/equalfuncs.c | 1 + src/backend/nodes/makefuncs.c | 1 + src/backend/nodes/outfast.c | 1 + src/backend/nodes/outfuncs.c | 1 + src/backend/nodes/readfast.c | 1 + src/backend/nodes/readfuncs.c | 1 + src/backend/optimizer/util/clauses.c | 3 +++ src/backend/parser/parse_expr.c | 1 + 9 files changed, 11 insertions(+) diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c index f7dde091dc..a83966fbc0 100644 --- a/src/backend/nodes/copyfuncs.c +++ b/src/backend/nodes/copyfuncs.c @@ -1375,6 +1375,7 @@ _copyConst(Const *from) Const *newnode = makeNode(Const); COPY_SCALAR_FIELD(consttype); + COPY_SCALAR_FIELD(consttypmod); COPY_SCALAR_FIELD(constlen); if (from->constbyval || from->constisnull) diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c index 17e521c5eb..55470c9258 100644 --- a/src/backend/nodes/equalfuncs.c +++ b/src/backend/nodes/equalfuncs.c @@ -195,6 +195,7 @@ static bool _equalConst(Const *a, Const *b) { COMPARE_SCALAR_FIELD(consttype); + COMPARE_SCALAR_FIELD(consttypmod); COMPARE_SCALAR_FIELD(constlen); COMPARE_SCALAR_FIELD(constisnull); COMPARE_SCALAR_FIELD(constbyval); diff --git a/src/backend/nodes/makefuncs.c b/src/backend/nodes/makefuncs.c index 20fc73f57e..2732483dfa 100644 --- a/src/backend/nodes/makefuncs.c +++ b/src/backend/nodes/makefuncs.c @@ -155,6 +155,7 @@ makeConst(Oid consttype, Const *cnst = makeNode(Const); cnst->consttype = consttype; + cnst->consttypmod = consttypmod; cnst->constlen = constlen; cnst->constvalue = constvalue; cnst->constisnull = constisnull; diff --git a/src/backend/nodes/outfast.c b/src/backend/nodes/outfast.c index 3b63e852f2..5dda1e52aa 100644 --- a/src/backend/nodes/outfast.c +++ b/src/backend/nodes/outfast.c @@ -1220,6 +1220,7 @@ _outConst(StringInfo str, Const *node) WRITE_NODE_TYPE("CONST"); WRITE_OID_FIELD(consttype); + WRITE_INT_FIELD(consttypmod); WRITE_INT_FIELD(constlen); WRITE_BOOL_FIELD(constbyval); WRITE_BOOL_FIELD(constisnull); diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c index 962b15c11a..3bf2dd2baf 100644 --- a/src/backend/nodes/outfuncs.c +++ b/src/backend/nodes/outfuncs.c @@ -1210,6 +1210,7 @@ _outConst(StringInfo str, Const *node) WRITE_NODE_TYPE("CONST"); WRITE_OID_FIELD(consttype); + WRITE_INT_FIELD(consttypmod); WRITE_INT_FIELD(constlen); WRITE_BOOL_FIELD(constbyval); WRITE_BOOL_FIELD(constisnull); diff --git a/src/backend/nodes/readfast.c b/src/backend/nodes/readfast.c index 854768241d..f4d9750a73 100644 --- a/src/backend/nodes/readfast.c +++ b/src/backend/nodes/readfast.c @@ -696,6 +696,7 @@ _readConst(const char ** str) READ_LOCALS(Const); READ_OID_FIELD(consttype); + READ_INT_FIELD(consttypmod); READ_INT_FIELD(constlen); READ_BOOL_FIELD(constbyval); READ_BOOL_FIELD(constisnull); diff --git a/src/backend/nodes/readfuncs.c b/src/backend/nodes/readfuncs.c index 55d6a24eec..89bb597337 100644 --- a/src/backend/nodes/readfuncs.c +++ b/src/backend/nodes/readfuncs.c @@ -832,6 +832,7 @@ _readConst(void) READ_LOCALS(Const); READ_OID_FIELD(consttype); + READ_INT_FIELD(consttypmod); READ_INT_FIELD(constlen); READ_BOOL_FIELD(constbyval); READ_BOOL_FIELD(constisnull); diff --git a/src/backend/optimizer/util/clauses.c b/src/backend/optimizer/util/clauses.c index fb92b5e592..4adc090404 100644 --- a/src/backend/optimizer/util/clauses.c +++ b/src/backend/optimizer/util/clauses.c @@ -1834,6 +1834,9 @@ eval_const_expressions_mutator(Node *node, */ simple = simplify_function(expr->funcid, expr->funcresulttype, args, true, context); + if (simple && IsA(simple, Const)) { + ((Const*)simple)->consttypmod = exprTypmod(expr); + } if (simple) /* successfully simplified it */ return (Node *) simple; diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c index 0f2958cc3d..18d05c4b6e 100644 --- a/src/backend/parser/parse_expr.c +++ b/src/backend/parser/parse_expr.c @@ -2579,6 +2579,7 @@ exprTypmod(Node *expr) } break; default: + return con->consttypmod; break; } }