3 * $Header: /cvsroot/pgpool/pgpool-II/pool_rewrite_query.h,v 1.8 2009/01/30 00:06:53 y-mori Exp $
5 * pgpool: a language independent connection pool server for PostgreSQL
6 * written by Tatsuo Ishii
8 * Copyright (c) 2003-2008 PgPool Global Development Group
10 * Permission to use, copy, modify, and distribute this software and
11 * its documentation for any purpose and without fee is hereby
12 * granted, provided that the above copyright notice appear in all
13 * copies and that both that copyright notice and this permission
14 * notice appear in supporting documentation, and that the name of the
15 * author not be used in advertising or publicity pertaining to
16 * distribution of the software without specific, written prior
17 * permission. The author makes no representations about the
18 * suitability of this software for any purpose. It is provided "as
19 * is" without express or implied warranty.
21 * pool_rewrite_query.h: rewrite_query
25 #include "parser/nodes.h"
26 #include "parser/parser.h"
27 #include "parser/pg_list.h"
28 #include "parser/parsenodes.h"
29 #include "parser/pool_memory.h"
30 #include "parser/pool_string.h"
33 #define INSERT_SQL_RESTRICTION 1
35 #define SELECT_BACKEND_CONNECT 3
36 #define SELECT_NOT_BACKEND_CONNECT 4
37 #define SELECT_PGCATALOG 5
38 #define SELECT_CHECK_PGCATALOG_REPLICATION 6
39 #define SELECT_DEFAULT 7
40 #define SELECT_DEFAULT_INSIDE_DBLINK 8
41 #define SELECT_AEXPR 9
42 #define SELECT_AEXPR_FALSE 10
43 #define SELECT_ONETABLE 11
44 #define SELECT_ONETABLE_FALSE 12
45 #define SELECT_RELATION_ERROR 13
46 #define INSERT_DIST_NO_RULE 14
47 #define SEND_PARALLEL_ENGINE 15
48 #define SEND_LOADBALANCE_ENGINE 16
49 #define SELECT_NOT_REPLICATION 17
50 #define SELECT_REWRITE 18
51 #define SELECT_ANALYZE 19
52 #define SELECT_DEFAULT_PREP 20
54 /* build Sub-Select`s target List */
56 char **col_list; /* column list */
57 char **type_list; /* type list */
58 int *return_list; /* order of col_list */
59 int col_num; /* column number */
60 bool valid; /* return to frontend */
63 /* This struct is used as each table/sub-select of FROM-CLUASE */
65 DistDefInfo *distinfo; /* distribution table into */
66 RepliDefInfo *repliinfo; /* replication table info */
67 SelectDefInfo *selectinfo; /* Sub-Select info */
68 char *alias; /* alias name */
69 char state; /* P = parallel, L = loadbarance S = systemdb(dblink) E = error*/
70 int ret_num; /* build column number */
73 /* build Virtual Table of FROM-Cluase */
75 char **col_list; /* column list */
76 char **type_list; /* type list */
77 char **table_list; /* table list */
78 char *state_list; /* state of each column */
79 int *column_no; /* order of column */
80 int *valid; /* valid column is true */
81 int col_num; /* virtual table column num */
84 /* this struct is used by JOIN Expr */
86 char **col_list; /* column list */
87 char **type_list; /* type list */
88 char **table_list; /* table list */
89 char state; /* P = parallel, L = loadbarance S = systemdb(dblink) E = error*/
90 int *valid; /* valid column is true */
91 int col_num; /* number of colum */
92 char **using_list; /* if join expr has using-list, column name is listed up */
93 int using_length; /* column number of using-list */
96 /* this struct is used in optimization of aggregate opr */
98 ColumnRef **usec_p; /* targetlist columns */
99 FuncCall **tfunc_p; /* targetlist funcs */
100 ColumnRef **col_p; /* group by columns */
101 FuncCall **hfunc_p; /* having funcs */
102 int *umapc; /* order of number */
103 int u_num; /* targetlist columns num */
104 int t_num; /* targetlist funcs num */
105 int c_num; /* group by column num */
106 int h_num; /* having funcs num */
107 int hc_num; /* having column num */
108 int s_num; /* sort funcs num */
109 int sc_num; /* sort column num */
110 bool opt; /* optimization flag */
113 /* main struct of alanyzing query */
115 int now_select; /* rank of select */
116 int part; /* the postion of analyzing select statement */
117 int last_select; /* caller select rank */
118 int call_part; /* caller's potion */
119 int from_num; /* number for from-cluase */
120 int larg_count; /* left arg count */
121 int rarg_count; /* right arg count */
122 int ret_count; /* return list count */
123 char state; /* final state */
124 char *table_name; /* table name or virtual table name */
125 char partstate[8]; /* state of analyzing part */
126 bool select_union; /* if UNION is used, this flag is true */
127 bool select_range; /* RangeSubSelect is used */
128 bool aggregate; /* aggregate optimaztion ? */
129 bool retlock; /* this is used */
130 Aggexpr *aggexpr; /* Aggexpr in this statement*/
131 RangeInfo **range; /* RangeInfo in from cluase */
132 int rangeinfo_num; /* RangeInfo's number in this select statement*/
133 VirtualTable *virtual; /* Virtual Table in this select statment */
134 JoinTable *join; /* sumary of join table */
135 SelectDefInfo *select_ret; /* build return list */
139 * This struct is used as Information that relates
140 * to distribution processing of parallel query
143 int r_code; /* analyze or rewrite */
144 int r_node; /* which node, query is sent */
145 int part; /* part of select statment */
146 int rewritelock; /* dblink start postion and lock rewrite */
147 int analyze_num; /* sum of AnalyzeSelect */
148 int current_select; /* postion of analyze[] */
149 int ignore_rewrite; /* dont rewrite */
150 int column; /* column number */
151 int virtual_num; /* Virtual table column number */
152 int ret_num; /* expect return cloumn number */
153 bool is_pg_catalog; /* reference of pg_catalog */
154 bool is_loadbalance; /* load ballance ? */
155 bool is_parallel; /* can paralle exec ? */
156 bool fromClause; /* having FromCluase ? */
157 char *table_relname; /* table name */
158 char *table_alias; /* table alias name */
159 char *schemaname; /* schema */
160 char *dbname; /* connect dbname */
161 char *rewrite_query; /* execute query */
162 char table_state; /* final state */
163 POOL_STATUS status; /* return POOL_STATUS */
164 NodeTag type; /* Query Type */
165 AnalyzeSelect **analyze; /* point to analyzing result */
168 /* This info is used in dblink */
170 char *hostaddr; /* hostname */
171 char *dbname; /* data base name */
172 char *user; /* access user name */
173 int port; /* access port number */
174 char *password; /* passward of connection */
177 extern RewriteQuery *rewrite_query_stmt(Node *node, POOL_CONNECTION *frontend,POOL_CONNECTION_POOL *backend,RewriteQuery *message);
178 extern void nodeToRewriteString(RewriteQuery *message, ConInfoTodblink *dblink,void *obj);
179 char *pool_error_message(char *message);
180 extern int IsSelectpgcatalog(Node *node,POOL_CONNECTION_POOL *backend);
181 extern RewriteQuery *is_parallel_query(Node *node,POOL_CONNECTION_POOL *backend);
182 extern POOL_STATUS pool_parallel_exec(POOL_CONNECTION *frontend,POOL_CONNECTION_POOL *backend, char *string,Node *node,bool send_to_frontend);