Send a single command-complete message from remote coordinator or datanode
authorPavan Deolasee <[email protected]>
Wed, 30 Dec 2015 11:27:42 +0000 (16:57 +0530)
committerPavan Deolasee <[email protected]>
Wed, 30 Dec 2015 11:27:42 +0000 (16:57 +0530)
When a client sends a multi-command string for execution, Postgres server
executes each command separately and sends a command-complete for each command.
The coordinator is not well equipped though to handle this since it sends the
whole query string as it is to the datanode and expects a single
command-complete.

What we need is a mechanism where coordinator sends each command separately to
the datanode. It already parses multi-command string into multiple parse-trees.
Earlier we did not have mechanism to deparse utility commands, but IIRC we now
have that. So we should look at using that infrastructure

src/backend/tcop/postgres.c

index 94008fecb8cbc982227308ccd766f2f9fe82fa84..551e8829f66e2bea0accdaec5bc5c8b10e531309 100644 (file)
@@ -1060,6 +1060,7 @@ exec_simple_query(const char *query_string)
        bool            was_logged = false;
        bool            isTopLevel;
        char            msec_str[32];
+       bool            multiCommands = false;
 
        /*
         * Report query to various monitoring facilities.
@@ -1133,6 +1134,14 @@ exec_simple_query(const char *query_string)
                                                                "in multi-statement queries not allowed")));
                }
        }
+
+       /*
+        * XXX We may receive multi-command string and the coordinator is not
+        * equipped to handle multiple command-complete messages. So just send a
+        * single command-complete until we fix the coordinator side of things
+        */
+       if (!IS_PGXC_LOCAL_COORDINATOR && list_length(parsetree_list) > 1)
+               multiCommands = true;
 #endif
 
        /* Log immediately if dictated by log_statement */
@@ -1375,9 +1384,12 @@ exec_simple_query(const char *query_string)
                 * command the client sent, regardless of rewriting. (But a command
                 * aborted by error will not send an EndCommand report at all.)
                 */
-               EndCommand(completionTag, dest);
+               if (!multiCommands)
+                       EndCommand(completionTag, dest);
        }                                                       /* end loop over parsetrees */
 
+       if (multiCommands)
+               EndCommand("MultiCommand", dest);
        /*
         * Close down transaction statement, if one is open.
         */