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:27:10 +0000 (17:27 +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 6bd41f45416c95cfa09d5f5e652b9c72e1250fe9..2d8045dff394f134601cb0900e6762f4b020b514 100644 (file)
@@ -746,6 +746,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
                ;