Fix incorrect query rewrite in replication mode.
authorBo Peng <pengbo@sraoss.co.jp>
Thu, 31 Oct 2019 00:11:03 +0000 (09:11 +0900)
committerBo Peng <pengbo@sraoss.co.jp>
Thu, 31 Oct 2019 00:12:48 +0000 (09:12 +0900)
src/rewrite/pool_timestamp.c

index 2d8045dff394f134601cb0900e6762f4b020b514..67397c204cfe0881d2c43e178b12c72ac2e46284 100644 (file)
@@ -753,7 +753,7 @@ rewrite_timestamp(POOL_CONNECTION_POOL *backend, Node *node,
                /*
                 * CREATE TABLE t1 AS SELECT now();
                 */
-               if (IsA(c_stmt->query, SelectStmt))
+               if (IsA(c_stmt->query, SelectStmt) && c_stmt->relkind == OBJECT_TABLE)
                {
                        /* rewrite params */
                        raw_expression_tree_walker(
@@ -770,16 +770,12 @@ rewrite_timestamp(POOL_CONNECTION_POOL *backend, Node *node,
                /*
                 * 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);
+               if (s_stmt->intoClause)
+               {
+                       raw_expression_tree_walker(
+                                                                          (Node *) s_stmt,
+                                                                          rewrite_timestamp_walker, (void *) &ctx);
+               }
 
                rewrite = ctx.rewrite;
        }