From: Bo Peng Date: Tue, 18 Feb 2020 08:43:23 +0000 (+0900) Subject: Fix rewriting query errors in native replication mode. X-Git-Tag: V3_6_20~4 X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=8b9eb65cd9bc3a5dc8077eb87c7c939492393a33;p=pgpool2.git Fix rewriting query errors in native replication mode. per bug551. --- diff --git a/src/protocol/pool_proto_modules.c b/src/protocol/pool_proto_modules.c index 3cd3e3a5b..d38d1a5b5 100644 --- a/src/protocol/pool_proto_modules.c +++ b/src/protocol/pool_proto_modules.c @@ -602,7 +602,7 @@ POOL_STATUS SimpleQuery(POOL_CONNECTION *frontend, */ if (!commit) { - char *rewrite_query; + char *rewrite_query = NULL; if (node) { @@ -620,7 +620,9 @@ POOL_STATUS SimpleQuery(POOL_CONNECTION *frontend, } /* rewrite `now()' to timestamp literal */ - rewrite_query = rewrite_timestamp(backend, query_context->parse_tree, false, msg); + if (!is_select_query(node, query_context->original_query) || + pool_has_function_call(node) || pool_config->replicate_select) + rewrite_query = rewrite_timestamp(backend, query_context->parse_tree, false, msg); /* * If the query is BEGIN READ WRITE or diff --git a/src/rewrite/pool_timestamp.c b/src/rewrite/pool_timestamp.c index f6e25ae5e..9c8e8d4e9 100644 --- a/src/rewrite/pool_timestamp.c +++ b/src/rewrite/pool_timestamp.c @@ -758,8 +758,35 @@ rewrite_timestamp(POOL_CONNECTION_POOL *backend, Node *node, stmt = ((PrepareStmt *) node)->query; ctx.rewrite_to_params = true; } - else if (IsA(node, CopyStmt) && ((CopyStmt *) node)->query != NULL) + /* + * CopyStmt + */ + else if (IsA(node, CopyStmt) &&((CopyStmt *) node)->query != NULL) stmt = ((CopyStmt *) node)->query; + /* + * ExplainStmt + */ + else if (IsA(node, ExplainStmt)) + { + ListCell *lc; + bool analyze = false; + + /* Check to see if this is EXPLAIN ANALYZE */ + foreach(lc, ((ExplainStmt *) node)->options) + { + DefElem *opt = (DefElem *) lfirst(lc); + + if (strcmp(opt->defname, "analyze") == 0) + { + stmt = ((ExplainStmt *) node)->query; + analyze = true; + break; + } + } + + if (!analyze) + return NULL; + } else stmt = node; @@ -853,6 +880,13 @@ rewrite_timestamp(POOL_CONNECTION_POOL *backend, Node *node, rewrite_timestamp_walker, (void *) &ctx); } + if (s_stmt->withClause) + { + raw_expression_tree_walker( + (Node *) s_stmt->withClause, + rewrite_timestamp_walker, (void *) &ctx); + } + rewrite = ctx.rewrite; } else