pgpool2.git / summary / log / commit / refs

commit    3ff077b2d0fb38ee30b1d9d4b5e8f2bbcd269de3
Author:   Tatsuo Ishii <ishii at sraoss.co.jp>
Date:     Mon Jul 18 07:33:43 2011 +0000

    Make is_sequence_query, is_start_transaction_query,
    is_strict_query to bool.
    These functions have been already treated as bool
    from callers and leaving these as int is sloppy.
    So I changed these function prototypes.
    
    Rename is_commit_query to is_commit_or_rollback_query.  This is more
    appropreate.  Add is_commit_query(returns true if commit query) and
    is_rollback_query(returns true if rollback query).


pool_process_query.c | 62 ++++++++++++++++++++++++++++++++++++---------------- pool_proto_modules.c | 8 ++++--- pool_proto_modules.h | 10 +++++---- pool_query_context.c | 2 +- 4 files changed, 55 insertions(+), 27 deletions(-) diff --git a/pool_process_query.c b/pool_process_query.c index 0d31f7905..2eb8d0e78 100644 --- a/pool_process_query.c +++ b/pool_process_query.c @@ -1513,16 +1513,16 @@ int is_select_query(Node *node, char *sql) } /* - * returns non 0 if SQL is SELECT statement including nextval() or + * returns true if SQL is SELECT statement including nextval() or * setval() call */ -int is_sequence_query(Node *node) +bool is_sequence_query(Node *node) { SelectStmt *select_stmt; ListCell *lc; if (node == NULL || !IsA(node, SelectStmt)) - return 0; + return false; select_stmt = (SelectStmt *)node; foreach (lc, select_stmt->targetList) @@ -1541,45 +1541,69 @@ int is_sequence_query(Node *node) { Value *v = lfirst(c); if (strncasecmp(v->val.str, "NEXTVAL", 7) == 0) - return 1; + return true; else if (strncasecmp(v->val.str, "SETVAL", 6) == 0) - return 1; + return true; } } } } - return 0; + return false; } /* - * returns non 0 if SQL is transaction starting command (START + * Returns true if SQL is transaction starting command (START * TRANSACTION or BEGIN) */ -int is_start_transaction_query(Node *node) +bool is_start_transaction_query(Node *node) { TransactionStmt *stmt; if (node == NULL || !IsA(node, TransactionStmt)) - return 0; + return false; stmt = (TransactionStmt *)node; return stmt->kind == TRANS_STMT_START || stmt->kind == TRANS_STMT_BEGIN; } /* - * returns non 0 if SQL is transaction commit or abort command (END - * TRANSACTION or ROLLBACK or ABORT) + * Returns true if SQL is transaction commit or rollback command (COMMIT, + * END TRANSACTION, ROLLBACK or ABORT) */ -int is_commit_query(Node *node) +bool is_commit_or_rollback_query(Node *node) +{ + return is_commit_query(node) || is_rollback_query(node); +} + +/* + * Returns true if SQL is transaction commit command (COMMIT or END + * TRANSACTION) + */ +bool is_commit_query(Node *node) { TransactionStmt *stmt; if (node == NULL || !IsA(node, TransactionStmt)) - return 0; + return false; + + stmt = (TransactionStmt *)node; + return stmt->kind == TRANS_STMT_COMMIT; +} + +/* + * Returns true if SQL is transaction rollback command (ROLLBACK or + * ABORT) + */ +bool is_rollback_query(Node *node) +{ + TransactionStmt *stmt; + + if (node == NULL || !IsA(node, TransactionStmt)) + return false; stmt = (TransactionStmt *)node; - return stmt->kind == TRANS_STMT_COMMIT || stmt->kind == TRANS_STMT_ROLLBACK; + return stmt->kind == TRANS_STMT_ROLLBACK; } /* @@ -3239,27 +3263,27 @@ static int is_cache_empty(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backe /* * check if query is needed to wait completion */ -int is_strict_query(Node *node) +bool is_strict_query(Node *node) { switch (node->type) { case T_SelectStmt: { SelectStmt *stmt = (SelectStmt *)node; - return (stmt->intoClause || stmt->lockingClause) ? 1 : 0; + return stmt->intoClause != NULL|| stmt->lockingClause != NIL; } case T_UpdateStmt: case T_InsertStmt: case T_DeleteStmt: case T_LockStmt: - return 1; + return true; default: - return 0; + return false; } - return 0; + return false; } int check_copy_from_stdin(Node *node) diff --git a/pool_proto_modules.c b/pool_proto_modules.c index ec9c0b5e0..ca8e6933b 100644 --- a/pool_proto_modules.c +++ b/pool_proto_modules.c @@ -368,7 +368,7 @@ POOL_STATUS SimpleQuery(POOL_CONNECTION *frontend, if (!RAW_MODE) { /* check if query is "COMMIT" or "ROLLBACK" */ - commit = is_commit_query(node); + commit = is_commit_or_rollback_query(node); /* * Query is not commit/rollback @@ -519,7 +519,7 @@ POOL_STATUS Execute(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend, pool_where_to_send(query_context, query, node); /* check if query is "COMMIT" or "ROLLBACK" */ - commit = is_commit_query(node); + commit = is_commit_or_rollback_query(node); if (REPLICATION || PARALLEL_MODE) { @@ -1262,6 +1262,8 @@ POOL_STATUS ReadyForQuery(POOL_CONNECTION *frontend, TSTATE(backend, i) = kind; + pool_log("ReadyForQuery: transaction state:%c", state); + /* * The transaction state to be returned to frontend is * master's. @@ -1295,7 +1297,7 @@ POOL_STATUS ReadyForQuery(POOL_CONNECTION *frontend, { /* * If the query was BEGIN/START TRANSACTION, clear the - * history that we had writing command in the transaction + * history that we had a writing command in the transaction * and forget the transaction isolation level. */ if (is_start_transaction_query(node)) diff --git a/pool_proto_modules.h b/pool_proto_modules.h index c0126a358..e2d99fe77 100644 --- a/pool_proto_modules.h +++ b/pool_proto_modules.h @@ -150,10 +150,12 @@ extern int RowDescription(POOL_CONNECTION *frontend, extern POOL_STATUS wait_for_query_response(POOL_CONNECTION *frontend, POOL_CONNECTION *backend, char *string, int protoVersion); extern int is_select_query(Node *node, char *sql); -extern int is_sequence_query(Node *node); -extern int is_start_transaction_query(Node *node); -extern int is_commit_query(Node *node); -extern int is_strict_query(Node *node); /* returns non 0 if this is strict query */ +extern bool is_sequence_query(Node *node); +extern bool is_start_transaction_query(Node *node); +extern bool is_commit_query(Node *node); +extern bool is_rollback_query(Node *node); +extern bool is_commit_or_rollback_query(Node *node); +extern bool is_strict_query(Node *node); /* returns non 0 if this is strict query */ extern int need_insert_lock(POOL_CONNECTION_POOL *backend, char *query, Node *node); extern POOL_STATUS insert_lock(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend, char *query, InsertStmt *node, int lock_kind); extern char *parse_copy_data(char *buf, int len, char delimiter, int col_id); diff --git a/pool_query_context.c b/pool_query_context.c index 9bdb23874..8972b4782 100644 --- a/pool_query_context.c +++ b/pool_query_context.c @@ -528,7 +528,7 @@ POOL_STATUS pool_send_and_wait(POOL_QUERY_CONTEXT *query_context, char *string, bool is_commit; int i; - is_commit = is_commit_query(query_context->parse_tree); + is_commit = is_commit_or_rollback_query(query_context->parse_tree); session_context = pool_get_session_context(); frontend = session_context->frontend; [parent: 8f49dcf10df8]