From: Bo Peng Date: Fri, 25 Oct 2019 08:22:22 +0000 (+0900) Subject: Fix incorrect query rewrite in replication mode. X-Git-Tag: V3_7_12~6 X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=952ecd71665b55ef4d1fa5fafecef119c8eb56cf;p=pgpool2.git Fix incorrect query rewrite in replication mode. For example: - CREATE TABLE t1 AS SELECT now(); - SELECT now() INTO t1; - WITH ins AS ( INSERT INTO t1 SELECT now()) SELECT; --- diff --git a/src/rewrite/pool_timestamp.c b/src/rewrite/pool_timestamp.c index 51f87540b..d2df4e068 100644 --- a/src/rewrite/pool_timestamp.c +++ b/src/rewrite/pool_timestamp.c @@ -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 ;