File: pool_rewrite_query.h

package info (click to toggle)
pgpool2 3.3.4-1~bpo70%2B1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy-backports
  • size: 9,196 kB
  • sloc: ansic: 59,850; sh: 12,893; yacc: 10,787; lex: 4,637; sql: 743; makefile: 481; java: 469; php: 125; ruby: 98; asm: 5
file content (192 lines) | stat: -rw-r--r-- 7,421 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/* -*-pgsql-c-*- */
/*
 * $Header$
 *
 * pgpool: a language independent connection pool server for PostgreSQL 
 * written by Tatsuo Ishii
 *
 * 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
 * granted, provided that the above copyright notice appear in all
 * copies and that both that copyright notice and this permission
 * notice appear in supporting documentation, and that the name of the
 * author not be used in advertising or publicity pertaining to
 * distribution of the software without specific, written prior
 * permission. The author makes no representations about the
 * suitability of this software for any purpose.  It is provided "as
 * is" without express or implied warranty.
 *
 * pool_rewrite_query.h: rewrite_query
 *
 */

#ifndef POOL_REWRITE_QUERY_H
#define POOL_REWRITE_QUERY_H

#include "parser/nodes.h"
#include "parser/parser.h"
#include "parser/pg_list.h"
#include "parser/parsenodes.h"
#include "parser/pool_memory.h"
#include "parser/pool_string.h"

/* return code set */
#define INSERT_SQL_RESTRICTION 1 
#define SELECT_INIT 2
#define SELECT_BACKEND_CONNECT 3
#define SELECT_NOT_BACKEND_CONNECT 4
#define SELECT_PGCATALOG 5
#define SELECT_CHECK_PGCATALOG_REPLICATION 6
#define SELECT_DEFAULT 7
#define SELECT_DEFAULT_INSIDE_DBLINK 8
#define SELECT_AEXPR 9
#define SELECT_AEXPR_FALSE 10
#define SELECT_ONETABLE 11
#define SELECT_ONETABLE_FALSE 12
#define SELECT_RELATION_ERROR 13
#define INSERT_DIST_NO_RULE 14
#define SEND_PARALLEL_ENGINE 15
#define SEND_LOADBALANCE_ENGINE 16
#define SELECT_NOT_REPLICATION 17
#define SELECT_REWRITE 18
#define SELECT_ANALYZE 19
#define SELECT_DEFAULT_PREP 20

/* build Sub-Select`s target List */
typedef struct {
	char **col_list;    /* column list */
	char **type_list;   /* type list */
	int  *return_list;  /* order of col_list */
	int col_num;        /* column number */
	bool valid;         /* return to frontend */
} SelectDefInfo;

/* This struct is used as each table/sub-select of FROM-CLUASE */
typedef struct {
	DistDefInfo *distinfo;     /* distribution table into */
	RepliDefInfo *repliinfo;   /* replication table info */
	SelectDefInfo *selectinfo; /* Sub-Select info */
	char *alias;               /* alias name */
	char state;                /* P = parallel, L = loadbalance S = systemdb(dblink) E = error*/
	int ret_num;               /* build column number */
} RangeInfo;

/* build Virtual Table of FROM-Clause */
typedef struct {
	char **col_list;     /* column list */
	char **type_list;    /* type list */
	char **table_list;   /* table list */
	char *state_list;    /* state of each column */
	int *column_no;      /* order of column */
	int *valid;          /* valid column is true */
	int col_num;         /* virtual table column num */
} VirtualTable;

/* this struct is used by JOIN Expr */
typedef struct {
	char **col_list;      /* column list */
	char **type_list;     /* type list */
	char **table_list;    /* table list */
	char state;           /* P = parallel, L = loadbalance S = systemdb(dblink) E = error*/
	int *valid;           /* valid column is true */
	int col_num;          /* number of column */
	char **using_list;    /* if join expr has using-list, column name is listed up */
	int using_length;     /* column number of using-list */
} JoinTable;

/* this struct is used in optimization of aggregate opr */
typedef struct {
	ColumnRef **usec_p; /* targetlist columns */
	FuncCall **tfunc_p; /* targetlist funcs   */
	ColumnRef **col_p;  /* group by columns   */
	FuncCall **hfunc_p; /* having   funcs */
	int *umapc; /* order of number */ 
	int u_num;  /* targetlist columns num */
	int t_num;  /* targetlist funcs num */
	int c_num;  /* group by column num */
	int h_num;  /* having funcs num */
	int hc_num; /* having column num */
	int s_num;  /* sort funcs num */
	int sc_num; /* sort column num */
	bool opt;   /* optimization flag */
} Aggexpr;

/* main struct of analyzing query */
typedef struct {
	int now_select;  /* rank of select */
	int part;        /* the position of analyzing select statement */
	int last_select; /* caller select rank */
	int call_part;   /* caller's potion */
	int from_num;    /* number for from-clause */
	int larg_count;  /* left arg count */
	int rarg_count;  /* right arg count */
	int ret_count;   /* return list count */
	char state;      /* final state */
	char *table_name; /* table name or virtual table name */
	char partstate[8]; /* state of analyzing part */
	bool select_union; /* if UNION is used, this flag is true */
	bool select_range; /* RangeSubSelect is used  */
	bool aggregate;    /* aggregate optimization ? */
	bool retlock;      /* this is used  */ 
	Aggexpr *aggexpr;   /* Aggexpr in this statement*/
	RangeInfo **range;  /* RangeInfo in from clause */
	int rangeinfo_num;  /* RangeInfo's number in this select statement*/
	VirtualTable *virtual; /* Virtual Table in this select statement */
	JoinTable *join;       /* summary of join table */
	SelectDefInfo *select_ret; /* build return list */
} AnalyzeSelect;

/*
 * This struct is used as Information that relates 
 * to distribution processing of parallel query
 */
typedef struct {
	int r_code;           /* analyze or rewrite */
	int r_node;           /* which node, query is sent */
	int part;             /* part of select statement */
	int rewritelock;      /* dblink start position and lock rewrite */
	int analyze_num;      /* sum of AnalyzeSelect */
	int current_select;   /* position of analyze[] */  
	int ignore_rewrite;   /* dont rewrite */
	int column;           /* column number */
	int virtual_num;     /* Virtual table column number */
	int ret_num;         /* expect return column number */
	bool is_pg_catalog;  /* reference of pg_catalog */
	bool is_loadbalance; /* load balance ? */
	bool is_parallel;    /* can parallel exec ? */
	bool fromClause;     /* having FromClause ? */
	char *table_relname; /* table name */
	char *table_alias;   /* table alias name */
	char *schemaname;    /* schema */
	char *dbname;        /* connect dbname */
	char *rewrite_query; /* execute query */
	char table_state;    /* final state */
	POOL_STATUS status;  /* return POOL_STATUS */
	NodeTag type;        /* Query Type */
	AnalyzeSelect **analyze;  /* point to analyzing result */
} RewriteQuery;

/* This info is used in dblink */
typedef struct {
	char *hostaddr; /* hostname */
	char *dbname;   /* data base name */
	char *user;     /* access user name */
	int   port;     /* access port number */
	char *password;  /* password of connection */
} ConInfoTodblink;

extern RewriteQuery *rewrite_query_stmt(Node *node, POOL_CONNECTION *frontend,POOL_CONNECTION_POOL *backend,RewriteQuery *message);
extern void nodeToRewriteString(RewriteQuery *message, ConInfoTodblink *dblink,void *obj);
char *pool_error_message(char *message);
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 */