pgpool2.git / summary / log / commit / refs

commit    29c8a015bee708af00a9abb97a210765dcedd2af
Author:   Tatsuo Ishii <ishii at sraoss.co.jp>
Date:     Wed Jun 02 10:06:51 2010 +0000

    Refactoring simpleQuery part 1. Move some parallel query processing
    to pool_rewrite_query.c.
    Also fix sloppy coding (no "#ifdef...") of pool_rewrite_query.h.


pool_proto_modules.c | 64 +++++----------------------------------------------- pool_rewrite_query.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++ pool_rewrite_query.h | 11 ++++++++- 3 files changed, 80 insertions(+), 59 deletions(-) diff --git a/pool_proto_modules.c b/pool_proto_modules.c index a242ecdea..a22ef7890 100644 --- a/pool_proto_modules.c +++ b/pool_proto_modules.c @@ -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 diff --git a/pool_rewrite_query.c b/pool_rewrite_query.c index 98be12eca..eb3c83239 100644 --- a/pool_rewrite_query.c +++ b/pool_rewrite_query.c @@ -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; +} diff --git a/pool_rewrite_query.h b/pool_rewrite_query.h index 2ab76d258..97c85c41d 100644 --- a/pool_rewrite_query.h +++ b/pool_rewrite_query.h @@ -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 */ + [parent: 0f8aa7781857]