Fix rewriting query errors in native replication mode.
authorBo Peng <pengbo@sraoss.co.jp>
Tue, 18 Feb 2020 08:43:23 +0000 (17:43 +0900)
committerBo Peng <pengbo@sraoss.co.jp>
Tue, 18 Feb 2020 08:48:04 +0000 (17:48 +0900)
per bug551.

src/protocol/pool_proto_modules.c
src/rewrite/pool_timestamp.c

index 3cd3e3a5bd182cca7b4d29e62dd8de5d6b264d5c..d38d1a5b519ea502b65690995c4834c1acd17a0d 100644 (file)
@@ -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
index f6e25ae5e76e28bf31e2b76baed9872c7f889950..9c8e8d4e98171b0a9e94a5f8be0e6bfa92ddd477 100644 (file)
@@ -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