Fix incorrect query rewrite in replication mode.
authorBo Peng <pengbo@sraoss.co.jp>
Fri, 25 Oct 2019 08:22:22 +0000 (17:22 +0900)
committerBo Peng <pengbo@sraoss.co.jp>
Fri, 25 Oct 2019 08:26:22 +0000 (17:26 +0900)
For example:
- CREATE TABLE t1 AS SELECT now();
- SELECT now() INTO t1;
- WITH ins AS ( INSERT INTO t1 SELECT now()) SELECT;

src/rewrite/pool_timestamp.c

index 51f87540bb7aba74d6123677a710997b9746c441..d2df4e0682493d1db008b688ef5364b04e9aba0b 100644 (file)
@@ -867,6 +867,43 @@ rewrite_timestamp(POOL_CONNECTION_POOL *backend, Node *node,
                        }
                }
        }
+       else if (IsA(stmt, CreateTableAsStmt))
+       {
+               CreateTableAsStmt *c_stmt = (CreateTableAsStmt *) stmt;
+
+               /*
+                * CREATE TABLE t1 AS SELECT now();
+                */
+               if (IsA(c_stmt->query, SelectStmt))
+               {
+                       /* rewrite params */
+                       raw_expression_tree_walker(
+                                                                          (Node *) c_stmt->query,
+                                                                          rewrite_timestamp_walker, (void *) &ctx);
+
+                       rewrite = ctx.rewrite;
+               }
+       }
+       else if (IsA(stmt, SelectStmt))
+       {
+               SelectStmt *s_stmt = (SelectStmt *) stmt;
+
+               /*
+                * SELECT now() INTO t1;
+                */
+               raw_expression_tree_walker(
+                                                                  (Node *) s_stmt,
+                                                                  rewrite_timestamp_walker, (void *) &ctx);
+
+               /*
+                * WITH ins AS ( INSERT INTO t1 SELECT now()) SELECT;
+                */
+               raw_expression_tree_walker(
+                                                                  (Node *) s_stmt->withClause,
+                                                                  rewrite_timestamp_walker, (void *) &ctx);
+
+               rewrite = ctx.rewrite;
+       }
        else
                ;