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:47:23 +0000 (17:47 +0900)
per bug551.

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

index 7e561d0e4f2de950d585c1387721c3c27ce8fc78..7bcaf048a1d4a72d7a980ac0e104e382368cc51b 100644 (file)
@@ -600,7 +600,7 @@ POOL_STATUS SimpleQuery(POOL_CONNECTION *frontend,
                 */
                if (!commit)
                {
-                       char *rewrite_query;
+                       char       *rewrite_query = NULL;
 
                        if (node)
                        {
@@ -618,7 +618,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 ec984239bfd5e2dbf0d1646d0f69cd16839ead45..b08e0daadf4d7159f477cecad16609007edeb952 100644 (file)
@@ -803,8 +803,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;
 
@@ -898,6 +925,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