1 /* -*-pgsql-c-*- */ 2 /* 3 * 4 * $Header$ 5 * 6 * pgpool: a language independent connection pool server for PostgreSQL 7 * written by Tatsuo Ishii 8 * 9 * Copyright (c) 2003-2017 PgPool Global Development Group 10 * 11 * Permission to use, copy, modify, and distribute this software and 12 * its documentation for any purpose and without fee is hereby 13 * granted, provided that the above copyright notice appear in all 14 * copies and that both that copyright notice and this permission 15 * notice appear in supporting documentation, and that the name of the 16 * author not be used in advertising or publicity pertaining to 17 * distribution of the software without specific, written prior 18 * permission. The author makes no representations about the 19 * suitability of this software for any purpose. It is provided "as 20 * is" without express or implied warranty. 21 * 22 * pool_process_context.h.: process context information 23 * 24 */ 25 26 #ifndef POOL_QUERY_CONTEXT_H 27 #define POOL_QUERY_CONTEXT_H 28 29 #include "pool.h" 30 #include "pool_process_context.h" 31 #include "parser/nodes.h" 32 #include "parser/parsenodes.h" 33 #include "utils/palloc.h" 34 #include "query_cache/pool_memqcache.h" 35 36 /* 37 * Parse state transition. 38 * transition order is: 39 * UNPARSED < PARSE_COMPLETE < BIND_COMPLETE < EXECUTE_COMPLETE 40 */ 41 typedef enum 42 { 43 POOL_UNPARSED, 44 POOL_PARSE_COMPLETE, 45 POOL_BIND_COMPLETE, 46 POOL_EXECUTE_COMPLETE 47 } POOL_QUERY_STATE; 48 49 /* 50 * Query context: 51 * Manages per query context 52 */ 53 typedef struct 54 { 55 char *original_query; /* original query string */ 56 char *rewritten_query; /* rewritten query string if any */ 57 int original_length; /* original query length which contains 58 * '\0' */ 59 int rewritten_length; /* rewritten query length which contains 60 * '\0' if any */ 61 Node *parse_tree; /* raw parser output if any */ 62 Node *rewritten_parse_tree; /* rewritten raw parser output if any */ 63 bool where_to_send[MAX_NUM_BACKENDS]; /* DB node map to send 64 * query */ 65 int load_balance_node_id; /* load balance node id per statement */ 66 int virtual_master_node_id; /* the 1st DB node to send query */ 67 POOL_QUERY_STATE query_state[MAX_NUM_BACKENDS]; /* for extended query 68 * protocol */ 69 bool is_cache_safe; /* true if SELECT is safe to cache */ 70 POOL_TEMP_QUERY_CACHE *temp_cache; /* temporary cache */ 71 bool is_multi_statement; /* true if multi statement query */ 72 int dboid; /* DB oid which is used at DROP DATABASE */ 73 char *query_w_hex; /* original_query with bind message hex which 74 * used for committing cache of extended query */ 75 bool is_parse_error; /* if true, we could not parse the original 76 * query and parsed node is actually a dummy 77 * query. */ 78 int num_original_params; /* number of parameters in original 79 * query */ 80 ConnectionInfo *pg_terminate_backend_conn; 81 82 /* 83 * pointer to the shared memory connection info object referred by 84 * pg_terminate_backend() function. we need this to reset the flag after 85 * executing the pg_terminate_backend query, especially for the case when 86 * the query gets fail on the backend. 87 */ 88 89 bool skip_cache_commit; /* In streaming replication mode and 90 * extended query, do not commit cache if 91 * this flag is true. */ 92 93 MemoryContext memory_context; /* memory context for query context */ 94 } POOL_QUERY_CONTEXT; 95 96 extern POOL_QUERY_CONTEXT * pool_init_query_context(void); 97 extern void pool_query_context_destroy(POOL_QUERY_CONTEXT * query_context); 98 extern POOL_QUERY_CONTEXT * pool_query_context_shallow_copy(POOL_QUERY_CONTEXT * query_context); 99 extern void pool_start_query(POOL_QUERY_CONTEXT * query_context, char *query, int len, Node *node); 100 extern void pool_set_node_to_be_sent(POOL_QUERY_CONTEXT * query_context, int node_id); 101 extern bool pool_is_node_to_be_sent(POOL_QUERY_CONTEXT * query_context, int node_id); 102 extern void pool_set_node_to_be_sent(POOL_QUERY_CONTEXT * query_context, int node_id); 103 extern void pool_unset_node_to_be_sent(POOL_QUERY_CONTEXT * query_context, int node_id); 104 extern void pool_clear_node_to_be_sent(POOL_QUERY_CONTEXT * query_context); 105 extern void pool_setall_node_to_be_sent(POOL_QUERY_CONTEXT * query_context); 106 extern bool pool_multi_node_to_be_sent(POOL_QUERY_CONTEXT * query_context); 107 extern void pool_where_to_send(POOL_QUERY_CONTEXT * query_context, char *query, Node *node); 108 extern POOL_STATUS pool_send_and_wait(POOL_QUERY_CONTEXT * query_context, int send_type, int node_id); 109 extern POOL_STATUS pool_extended_send_and_wait(POOL_QUERY_CONTEXT * query_context, char *kind, int len, char *contents, int send_type, int node_id, bool nowait); 110 extern Node *pool_get_parse_tree(void); 111 extern char *pool_get_query_string(void); 112 extern bool is_set_transaction_serializable(Node *node); 113 extern bool is_start_transaction_query(Node *node); 114 extern bool is_read_write(TransactionStmt *node); 115 extern bool is_serializable(TransactionStmt *node); 116 extern bool pool_need_to_treat_as_if_default_transaction(POOL_QUERY_CONTEXT * query_context); 117 extern bool is_savepoint_query(Node *node); 118 extern bool is_2pc_transaction_query(Node *node); 119 extern void pool_set_query_state(POOL_QUERY_CONTEXT * query_context, POOL_QUERY_STATE state); 120 extern int statecmp(POOL_QUERY_STATE s1, POOL_QUERY_STATE s2); 121 extern bool pool_is_cache_safe(void); 122 extern void pool_set_cache_safe(void); 123 extern void pool_unset_cache_safe(void); 124 extern bool pool_is_cache_exceeded(void); 125 extern void pool_set_cache_exceeded(void); 126 extern void pool_unset_cache_exceeded(void); 127 extern bool pool_is_transaction_read_only(Node *node); 128 extern void pool_force_query_node_to_backend(POOL_QUERY_CONTEXT * query_context, int backend_id); 129 #endif /* POOL_QUERY_CONTEXT_H */ 130