Refactoring simpleQuery part 1. Move some parallel query processing
authorTatsuo Ishii <ishii at sraoss.co.jp>
Wed, 2 Jun 2010 10:06:51 +0000 (10:06 +0000)
committerTatsuo Ishii <ishii at sraoss.co.jp>
Wed, 2 Jun 2010 10:06:51 +0000 (10:06 +0000)
to pool_rewrite_query.c.
Also fix sloppy coding (no "#ifdef...") of pool_rewrite_query.h.

pool_proto_modules.c
pool_rewrite_query.c
pool_rewrite_query.h

index a242ecdea5e2c571470f82c16cccce47a38e09b8..a22ef7890a69bb7986737f61b07f98bf29b3f83d 100644 (file)
@@ -47,6 +47,7 @@
 #include "pool_signal.h"
 #include "pool_timestamp.h"
 #include "pool_proto_modules.h"
+#include "pool_rewrite_query.h"
 #include "pool_relcache.h"
 #include "pool_stream.h"
 #include "pool_config.h"
@@ -240,65 +241,12 @@ POOL_STATUS NotificationResponse(POOL_CONNECTION *frontend,
                        }
                }
 
-               if (pool_config->parallel_mode)
+               if (PARALLEL_MODE)
                {
-      /* The Query is analyzed first in a parallel mode(in_parallel_query),
-       * and, next, the Query is rewritten(rewrite_query_stmt).
-       */
-
-                       /* analyze the query */
-                       RewriteQuery *r_query = is_parallel_query(node,backend);
-
-                       if(r_query->is_loadbalance)
-                       {
-        /* Usual processing of pgpool is done by using the rewritten Query
-         * if judged a possible load-balancing as a result of analyzing
-         * the Query.
-         * Of course, the load is distributed only for load_balance_mode=true.
-         */
-                               if(r_query->r_code ==  SEND_LOADBALANCE_ENGINE)
-                               {
-                                       /* use rewritten query */
-                                       string = r_query->rewrite_query;
-                                       /* change query length */
-                                       len = strlen(string)+1;
-                               }
-                               pool_debug("SimpleQuery: loadbalance_query =%s",string);
-                       }
-                       else if (r_query->is_parallel)
-                       {
-                               /*
-                                * For the Query that the parallel processing is possible.
-                                * Call parallel exe engine and return status to the upper layer.
-                                */
-                               POOL_STATUS stats = pool_parallel_exec(frontend,backend,r_query->rewrite_query, node,true);
-                               free_parser();
-                               in_progress = 0;
-                               return stats;
-                       }
-                       else if(!r_query->is_pg_catalog)
-                       {
-                               /* rewrite query and execute */
-                               r_query = rewrite_query_stmt(node,frontend,backend,r_query);
-                               if(r_query->type == T_InsertStmt)
-                               {
-                                       free_parser();
-
-                                       if(r_query->r_code != INSERT_DIST_NO_RULE) {
-                                               in_progress = 0;
-                                               return r_query->status;
-                                       }
-                               }
-                               else if(r_query->type == T_SelectStmt)
-                               {
-                                       free_parser();
-                                       in_progress = 0;
-                                       return r_query->status;
-                               }
-                       }
-                       /*
-                        * The same processing as usual pgpool is done to other Query type.
-       */
+                       bool parallel = true;
+                       status = pool_do_parallel_query(frontend, backend, node, &parallel, &string, &len);
+                       if (parallel)
+                               return status;
                }
 
                /* check COPY FROM STDIN
index 98be12ecac1034fbfd793fd4d6876c8be3384948..eb3c832396b0a7a63e1fe9497c1737c7719d1b09 100644 (file)
@@ -25,6 +25,7 @@
 #include "pool.h"
 #include "pool_config.h"
 #include "pool_rewrite_query.h"
+#include "pool_proto_modules.h"
 
 #include <string.h>
 #include <errno.h>
@@ -648,3 +649,66 @@ RewriteQuery *is_parallel_query(Node *node, POOL_CONNECTION_POOL *backend)
 
        return &message;
 }
+
+POOL_STATUS pool_do_parallel_query(POOL_CONNECTION *frontend,
+                                                                  POOL_CONNECTION_POOL *backend,
+                                                                  Node *node, bool *parallel, char **string, int *len)
+{
+       /* The Query is analyzed first in a parallel mode(in_parallel_query),
+        * and, next, the Query is rewritten(rewrite_query_stmt).
+        */
+
+       /* analyze the query */
+       RewriteQuery *r_query = is_parallel_query(node,backend);
+
+       if(r_query->is_loadbalance)
+       {
+        /* Usual processing of pgpool is done by using the rewritten Query
+         * if judged a possible load-balancing as a result of analyzing
+         * the Query.
+         * Of course, the load is distributed only for load_balance_mode=true.
+         */
+               if(r_query->r_code ==  SEND_LOADBALANCE_ENGINE)
+               {
+                       /* use rewritten query */
+                       *string = r_query->rewrite_query;
+                       /* change query length */
+                       *len = strlen(*string)+1;
+               }
+               pool_debug("SimpleQuery: loadbalance_query =%s",*string);
+       }
+       else if (r_query->is_parallel)
+       {
+               /*
+                * For the Query that the parallel processing is possible.
+                * Call parallel exe engine and return status to the upper layer.
+                */
+               POOL_STATUS stats = pool_parallel_exec(frontend,backend,r_query->rewrite_query, node,true);
+               free_parser();
+               in_progress = 0;
+               return stats;
+       }
+       else if(!r_query->is_pg_catalog)
+       {
+               /* rewrite query and execute */
+               r_query = rewrite_query_stmt(node,frontend,backend,r_query);
+               if(r_query->type == T_InsertStmt)
+               {
+                       free_parser();
+
+                       if(r_query->r_code != INSERT_DIST_NO_RULE) {
+                               in_progress = 0;
+                               return r_query->status;
+                       }
+               }
+               else if(r_query->type == T_SelectStmt)
+               {
+                       free_parser();
+                       in_progress = 0;
+                       return r_query->status;
+               }
+       }
+
+       *parallel = false;
+       return POOL_CONTINUE;
+}
index 2ab76d258727bf41770d0534127cc3bc56bdfc7c..97c85c41da18fbf92b4f94dea5c1ffad2c2fd0f0 100644 (file)
@@ -5,7 +5,7 @@
  * pgpool: a language independent connection pool server for PostgreSQL 
  * written by Tatsuo Ishii
  *
- * Copyright (c) 2003-2008     PgPool Global Development Group
+ * Copyright (c) 2003-2010     PgPool Global Development Group
  *
  * Permission to use, copy, modify, and distribute this software and
  * its documentation for any purpose and without fee is hereby
@@ -22,6 +22,9 @@
  *
  */
 
+#ifndef POOL_REWRITE_QUERY_H
+#define POOL_REWRITE_QUERY_H
+
 #include "parser/nodes.h"
 #include "parser/parser.h"
 #include "parser/pg_list.h"
@@ -181,3 +184,9 @@ extern int IsSelectpgcatalog(Node *node,POOL_CONNECTION_POOL *backend);
 extern RewriteQuery *is_parallel_query(Node *node,POOL_CONNECTION_POOL *backend);
 extern POOL_STATUS pool_parallel_exec(POOL_CONNECTION *frontend,POOL_CONNECTION_POOL *backend, char *string,Node *node,bool send_to_frontend);
 
+POOL_STATUS pool_do_parallel_query(POOL_CONNECTION *frontend,
+                                                                  POOL_CONNECTION_POOL *backend,
+                                                                  Node *node, bool *parallel, char **string, int *len);
+
+#endif /* POOL_REWRITE_QUERY_H */
+