From ae7068ae4cb5cf2111071177c0d609ffb947fbb7 Mon Sep 17 00:00:00 2001 From: Bo Peng Date: Tue, 18 Feb 2020 17:43:23 +0900 Subject: [PATCH] Fix rewriting query errors in native replication mode. per bug551. --- src/protocol/pool_proto_modules.c | 6 ++++-- src/rewrite/pool_timestamp.c | 34 +++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/protocol/pool_proto_modules.c b/src/protocol/pool_proto_modules.c index 39e906e5a..fb8941e71 100644 --- a/src/protocol/pool_proto_modules.c +++ b/src/protocol/pool_proto_modules.c @@ -628,7 +628,7 @@ SimpleQuery(POOL_CONNECTION * frontend, */ if (!commit) { - char *rewrite_query; + char *rewrite_query = NULL; if (node) { @@ -646,7 +646,9 @@ 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 BEGIN ... SERIALIZABLE diff --git a/src/rewrite/pool_timestamp.c b/src/rewrite/pool_timestamp.c index 45e7ea4a5..61a927aef 100644 --- a/src/rewrite/pool_timestamp.c +++ b/src/rewrite/pool_timestamp.c @@ -814,8 +814,35 @@ rewrite_timestamp(POOL_CONNECTION_POOL * backend, Node *node, stmt = ((PrepareStmt *) node)->query; ctx.rewrite_to_params = true; } + /* + * 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; @@ -932,6 +959,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 -- 2.39.5