This is an automated email from the ASF dual-hosted git repository.

ztao1987 pushed a commit to branch ztao
in repository https://gitbox.apache.org/repos/asf/hawq.git

commit 04b8497dc54659d237d2c4283f080819a494ca8e
Author: ztao1987 <[email protected]>
AuthorDate: Wed Apr 20 17:06:09 2022 +0800

    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 f7dde091d..a83966fbc 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 17e521c5e..55470c925 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 20fc73f57..2732483df 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 3b63e852f..5dda1e52a 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 962b15c11..3bf2dd2ba 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 854768241..f4d9750a7 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 55d6a24ee..89bb59733 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 fb92b5e59..4adc09040 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 0f2958cc3..18d05c4b6 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;
                                }
                        }

Reply via email to