1
by brian
clean slate |
1 |
/* Copyright (C) 2000-2003 MySQL AB
|
2 |
||
3 |
This program is free software; you can redistribute it and/or modify
|
|
4 |
it under the terms of the GNU General Public License as published by
|
|
5 |
the Free Software Foundation; version 2 of the License.
|
|
6 |
||
7 |
This program is distributed in the hope that it will be useful,
|
|
8 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10 |
GNU General Public License for more details.
|
|
11 |
||
12 |
You should have received a copy of the GNU General Public License
|
|
13 |
along with this program; if not, write to the Free Software
|
|
14 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
15 |
||
319.1.1
by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_ |
16 |
#define DRIZZLE_LEX 1
|
243.1.17
by Jay Pipes
FINAL PHASE removal of mysql_priv.h (Bye, bye my friend.) |
17 |
#include <drizzled/server_includes.h> |
614
by Brian Aker
Remove filtering (wrong layer, belongs in plugin). |
18 |
#include <mysys/hash.h> |
575.4.6
by Monty Taylor
Removed my_getwd. |
19 |
#include <drizzled/db.h> |
549
by Monty Taylor
Took gettext.h out of header files. |
20 |
#include <drizzled/error.h> |
553.1.3
by Monty Taylor
Split out nested_join.h. |
21 |
#include <drizzled/nested_join.h> |
561.1.3
by Monty Taylor
Split some more things out of common_includes.h. |
22 |
#include <drizzled/query_id.h> |
520.8.2
by Monty Taylor
Moved sql_parse.h and sql_error.h out of common_includes. |
23 |
#include <drizzled/sql_parse.h> |
520.6.7
by Monty Taylor
Moved a bunch of crap out of common_includes. |
24 |
#include <drizzled/data_home.h> |
575.4.7
by Monty Taylor
More header cleanup. |
25 |
#include <drizzled/sql_base.h> |
26 |
#include <drizzled/show.h> |
|
1130.1.7
by Monty Taylor
Renamed plugin::InfoSchema to plugin::InfoSchemaTable as per Jay. |
27 |
#include <drizzled/plugin/info_schema_table.h> |
670.1.20
by Monty Taylor
Renamed functions to function... everything else is singular. |
28 |
#include <drizzled/function/time/unix_timestamp.h> |
29 |
#include <drizzled/function/get_system_var.h> |
|
584.4.7
by Monty Taylor
Removed a big bank of includes from item.h. |
30 |
#include <drizzled/item/cmpfunc.h> |
642.1.20
by Lee
header file clean up |
31 |
#include <drizzled/item/null.h> |
584.1.15
by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes. |
32 |
#include <drizzled/session.h> |
33 |
#include <drizzled/sql_load.h> |
|
670.2.4
by Monty Taylor
Removed more stuff from the headers. |
34 |
#include <drizzled/lock.h> |
837
by Brian Aker
Reworked some classes out of session.h |
35 |
#include <drizzled/select_send.h> |
971.6.1
by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way. |
36 |
#include <drizzled/plugin/client.h> |
1100.3.30
by Padraig O'Sullivan
Renamed the Command class to be Statement. Renamed the command directory to |
37 |
#include <drizzled/statement.h> |
1128.2.4
by Brian Aker
AlterInfo refactor back to class. |
38 |
#include <drizzled/statement/alter_table.h> |
1126.10.18
by Padraig O'Sullivan
Various small build fixes for when dtrace is enabled. |
39 |
#include "drizzled/probes.h" |
1100.3.1
by Padraig O'Sullivan
Beginnings of reworking the mysql_execute_command() method. |
40 |
|
1130.1.12
by Monty Taylor
Moved service stuff into plugin/ |
41 |
#include "drizzled/plugin/logging.h" |
42 |
#include "drizzled/plugin/info_schema_table.h" |
|
1130.1.1
by Monty Taylor
Merged in plugin-slot-reorg patches. |
43 |
|
590.2.18
by Monty Taylor
Changed the bitset<32> to a bitset<5>. Made the int constants into bitset constants. |
44 |
#include <bitset> |
1067.4.4
by Nathan Williams
The rest of the files in the drizzled directory were purged of the cmin macro and replace with std::min (except for the definition in globals.h and 1 usage in stacktrace.cc). |
45 |
#include <algorithm> |
590.2.18
by Monty Taylor
Changed the bitset<32> to a bitset<5>. Made the int constants into bitset constants. |
46 |
|
1130.1.1
by Monty Taylor
Merged in plugin-slot-reorg patches. |
47 |
using namespace drizzled; |
590.2.18
by Monty Taylor
Changed the bitset<32> to a bitset<5>. Made the int constants into bitset constants. |
48 |
using namespace std; |
584.1.15
by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes. |
49 |
|
1039.1.16
by Brian Aker
A lot of little cleanups (most based off lcov) |
50 |
/* Prototypes */
|
1085.1.2
by Monty Taylor
Fixed -Wmissing-declarations |
51 |
bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); |
1165.1.48
by Stewart Smith
make parse_sql static to sql_parse.cc |
52 |
static bool parse_sql(Session *session, Lex_input_stream *lip); |
1165.1.49
by Stewart Smith
make mysql_parse static to sql_parse.cc |
53 |
static void mysql_parse(Session *session, const char *inBuf, uint32_t length, |
54 |
const char ** found_semicolon); |
|
1085.1.2
by Monty Taylor
Fixed -Wmissing-declarations |
55 |
|
1
by brian
clean slate |
56 |
/**
|
57 |
@defgroup Runtime_Environment Runtime Environment
|
|
58 |
@{
|
|
59 |
*/
|
|
60 |
||
629.2.7
by Monty Taylor
Fixed a couple of memory buffer size issues. |
61 |
extern size_t my_thread_stack_size; |
520.6.7
by Monty Taylor
Moved a bunch of crap out of common_includes. |
62 |
extern const CHARSET_INFO *character_set_filesystem; |
1
by brian
clean slate |
63 |
|
230.1.8
by Monty Taylor
Set length to catch errors in adding or removing COM_* constants. |
64 |
const LEX_STRING command_name[COM_END+1]={ |
1
by brian
clean slate |
65 |
{ C_STRING_WITH_LEN("Sleep") }, |
66 |
{ C_STRING_WITH_LEN("Quit") }, |
|
67 |
{ C_STRING_WITH_LEN("Init DB") }, |
|
68 |
{ C_STRING_WITH_LEN("Query") }, |
|
69 |
{ C_STRING_WITH_LEN("Shutdown") }, |
|
70 |
{ C_STRING_WITH_LEN("Connect") }, |
|
71 |
{ C_STRING_WITH_LEN("Ping") }, |
|
72 |
{ C_STRING_WITH_LEN("Error") } // Last command number |
|
73 |
};
|
|
74 |
||
75 |
const char *xa_state_names[]={ |
|
76 |
"NON-EXISTING", "ACTIVE", "IDLE", "PREPARED" |
|
77 |
};
|
|
78 |
||
79 |
/**
|
|
80 |
Mark all commands that somehow changes a table.
|
|
81 |
||
82 |
This is used to check number of updates / hour.
|
|
83 |
||
84 |
sql_command is actually set to SQLCOM_END sometimes
|
|
85 |
so we need the +1 to include it in the array.
|
|
86 |
||
87 |
See COMMAND_FLAG_xxx for different type of commands
|
|
88 |
2 - query that returns meaningful ROW_COUNT() -
|
|
89 |
a number of modified rows
|
|
90 |
*/
|
|
590.2.18
by Monty Taylor
Changed the bitset<32> to a bitset<5>. Made the int constants into bitset constants. |
91 |
bitset<CF_BIT_SIZE> sql_command_flags[SQLCOM_END+1]; |
1
by brian
clean slate |
92 |
|
93 |
void init_update_queries(void) |
|
94 |
{
|
|
610
by Brian Aker
Merge of Monty's (plus fix for increment style/useless +1) |
95 |
uint32_t x; |
96 |
||
97 |
for (x= 0; x <= SQLCOM_END; x++) |
|
98 |
sql_command_flags[x].reset(); |
|
1
by brian
clean slate |
99 |
|
100 |
sql_command_flags[SQLCOM_CREATE_TABLE]= CF_CHANGES_DATA; |
|
101 |
sql_command_flags[SQLCOM_CREATE_INDEX]= CF_CHANGES_DATA; |
|
102 |
sql_command_flags[SQLCOM_ALTER_TABLE]= CF_CHANGES_DATA | CF_WRITE_LOGS_COMMAND; |
|
103 |
sql_command_flags[SQLCOM_TRUNCATE]= CF_CHANGES_DATA | CF_WRITE_LOGS_COMMAND; |
|
104 |
sql_command_flags[SQLCOM_DROP_TABLE]= CF_CHANGES_DATA; |
|
105 |
sql_command_flags[SQLCOM_LOAD]= CF_CHANGES_DATA; |
|
106 |
sql_command_flags[SQLCOM_CREATE_DB]= CF_CHANGES_DATA; |
|
107 |
sql_command_flags[SQLCOM_DROP_DB]= CF_CHANGES_DATA; |
|
108 |
sql_command_flags[SQLCOM_RENAME_TABLE]= CF_CHANGES_DATA; |
|
109 |
sql_command_flags[SQLCOM_DROP_INDEX]= CF_CHANGES_DATA; |
|
110 |
||
111 |
sql_command_flags[SQLCOM_UPDATE]= CF_CHANGES_DATA | CF_HAS_ROW_COUNT; |
|
112 |
sql_command_flags[SQLCOM_INSERT]= CF_CHANGES_DATA | CF_HAS_ROW_COUNT; |
|
113 |
sql_command_flags[SQLCOM_INSERT_SELECT]= CF_CHANGES_DATA | CF_HAS_ROW_COUNT; |
|
114 |
sql_command_flags[SQLCOM_DELETE]= CF_CHANGES_DATA | CF_HAS_ROW_COUNT; |
|
115 |
sql_command_flags[SQLCOM_REPLACE]= CF_CHANGES_DATA | CF_HAS_ROW_COUNT; |
|
116 |
sql_command_flags[SQLCOM_REPLACE_SELECT]= CF_CHANGES_DATA | CF_HAS_ROW_COUNT; |
|
117 |
||
118 |
sql_command_flags[SQLCOM_SHOW_STATUS]= CF_STATUS_COMMAND; |
|
119 |
sql_command_flags[SQLCOM_SHOW_DATABASES]= CF_STATUS_COMMAND; |
|
120 |
sql_command_flags[SQLCOM_SHOW_OPEN_TABLES]= CF_STATUS_COMMAND; |
|
121 |
sql_command_flags[SQLCOM_SHOW_FIELDS]= CF_STATUS_COMMAND; |
|
122 |
sql_command_flags[SQLCOM_SHOW_KEYS]= CF_STATUS_COMMAND; |
|
123 |
sql_command_flags[SQLCOM_SHOW_VARIABLES]= CF_STATUS_COMMAND; |
|
124 |
sql_command_flags[SQLCOM_SHOW_WARNS]= CF_STATUS_COMMAND; |
|
125 |
sql_command_flags[SQLCOM_SHOW_ERRORS]= CF_STATUS_COMMAND; |
|
126 |
sql_command_flags[SQLCOM_SHOW_ENGINE_STATUS]= CF_STATUS_COMMAND; |
|
127 |
sql_command_flags[SQLCOM_SHOW_PROCESSLIST]= CF_STATUS_COMMAND; |
|
128 |
sql_command_flags[SQLCOM_SHOW_CREATE_DB]= CF_STATUS_COMMAND; |
|
129 |
sql_command_flags[SQLCOM_SHOW_CREATE]= CF_STATUS_COMMAND; |
|
130 |
||
131 |
sql_command_flags[SQLCOM_SHOW_TABLES]= (CF_STATUS_COMMAND | |
|
132 |
CF_SHOW_TABLE_COMMAND); |
|
133 |
sql_command_flags[SQLCOM_SHOW_TABLE_STATUS]= (CF_STATUS_COMMAND | |
|
134 |
CF_SHOW_TABLE_COMMAND); |
|
135 |
/*
|
|
136 |
The following admin table operations are allowed
|
|
137 |
on log tables.
|
|
138 |
*/
|
|
139 |
sql_command_flags[SQLCOM_ANALYZE]= CF_WRITE_LOGS_COMMAND; |
|
140 |
}
|
|
141 |
||
142 |
/**
|
|
143 |
Perform one connection-level (COM_XXXX) command.
|
|
144 |
||
145 |
@param command type of command to perform
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
146 |
@param session connection handle
|
1
by brian
clean slate |
147 |
@param packet data for the command, packet is always null-terminated
|
148 |
@param packet_length length of packet + 1 (to show that data is
|
|
149 |
null-terminated) except for COM_SLEEP, where it
|
|
150 |
can be zero.
|
|
151 |
||
152 |
@todo
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
153 |
set session->lex->sql_command to SQLCOM_END here.
|
1
by brian
clean slate |
154 |
@todo
|
155 |
The following has to be changed to an 8 byte integer
|
|
156 |
||
157 |
@retval
|
|
158 |
0 ok
|
|
159 |
@retval
|
|
160 |
1 request of thread shutdown, i. e. if command is
|
|
161 |
COM_QUIT/COM_SHUTDOWN
|
|
162 |
*/
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
163 |
bool dispatch_command(enum enum_server_command command, Session *session, |
561.1.3
by Monty Taylor
Split some more things out of common_includes.h. |
164 |
char* packet, uint32_t packet_length) |
1
by brian
clean slate |
165 |
{
|
166 |
bool error= 0; |
|
561.1.3
by Monty Taylor
Split some more things out of common_includes.h. |
167 |
Query_id &query_id= Query_id::get_query_id(); |
1
by brian
clean slate |
168 |
|
1126.10.2
by Padraig O'Sullivan
Added hooks into the command start and query start dtrace probes. |
169 |
DRIZZLE_COMMAND_START(session->thread_id, |
170 |
command); |
|
171 |
||
172 |
session->command= command; |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
173 |
session->lex->sql_command= SQLCOM_END; /* to avoid confusing VIEW detectors */ |
174 |
session->set_time(); |
|
561.1.3
by Monty Taylor
Split some more things out of common_includes.h. |
175 |
session->query_id= query_id.value(); |
1
by brian
clean slate |
176 |
|
177 |
switch( command ) { |
|
178 |
/* Ignore these statements. */
|
|
179 |
case COM_PING: |
|
180 |
break; |
|
181 |
/* Increase id and count all other statements. */
|
|
182 |
default: |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
183 |
statistic_increment(session->status_var.questions, &LOCK_status); |
561.1.3
by Monty Taylor
Split some more things out of common_includes.h. |
184 |
query_id.next(); |
1
by brian
clean slate |
185 |
}
|
186 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
187 |
/* TODO: set session->lex->sql_command to SQLCOM_END here */
|
1
by brian
clean slate |
188 |
|
1130.1.16
by Monty Taylor
Fixed naming issue. |
189 |
plugin::Logging::preDo(session); |
383.6.4
by Mark Atwood
more make plug logging work |
190 |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
191 |
session->server_status&= |
1
by brian
clean slate |
192 |
~(SERVER_QUERY_NO_INDEX_USED | SERVER_QUERY_NO_GOOD_INDEX_USED); |
193 |
switch (command) { |
|
194 |
case COM_INIT_DB: |
|
195 |
{
|
|
196 |
LEX_STRING tmp; |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
197 |
status_var_increment(session->status_var.com_stat[SQLCOM_CHANGE_DB]); |
1054.2.11
by Monty Taylor
Removed copy_and_convert. |
198 |
tmp.str= packet; |
199 |
tmp.length= packet_length; |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
200 |
if (!mysql_change_db(session, &tmp, false)) |
1
by brian
clean slate |
201 |
{
|
836
by Brian Aker
Fixed session call from function to method. |
202 |
session->my_ok(); |
1
by brian
clean slate |
203 |
}
|
204 |
break; |
|
205 |
}
|
|
206 |
case COM_QUERY: |
|
207 |
{
|
|
934.2.9
by Jay Pipes
Pulls alloc_query() C function out of sql_parse.cc and adds readAndStoreQuery() member method of Session class. |
208 |
if (! session->readAndStoreQuery(packet, packet_length)) |
1
by brian
clean slate |
209 |
break; // fatal error is set |
1126.10.2
by Padraig O'Sullivan
Added hooks into the command start and query start dtrace probes. |
210 |
DRIZZLE_QUERY_START(session->query, |
211 |
session->thread_id, |
|
1126.10.25
by Padraig O'Sullivan
Updated calls to some dtrace probes to cast the parameter to const char * |
212 |
const_cast<const char *>(session->db ? session->db : "")); |
1
by brian
clean slate |
213 |
const char* end_of_stmt= NULL; |
214 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
215 |
mysql_parse(session, session->query, session->query_length, &end_of_stmt); |
1
by brian
clean slate |
216 |
|
217 |
break; |
|
218 |
}
|
|
219 |
case COM_QUIT: |
|
220 |
/* We don't calculate statistics for this command */
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
221 |
session->main_da.disable_status(); // Don't send anything back |
55
by brian
Update for using real bool types. |
222 |
error=true; // End server |
1
by brian
clean slate |
223 |
break; |
224 |
case COM_SHUTDOWN: |
|
225 |
{
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
226 |
status_var_increment(session->status_var.com_other); |
836
by Brian Aker
Fixed session call from function to method. |
227 |
session->my_eof(); |
1039.1.16
by Brian Aker
A lot of little cleanups (most based off lcov) |
228 |
session->close_thread_tables(); // Free before kill |
575.4.4
by Yoshinori Sano
Rename mysql to drizzle. |
229 |
kill_drizzle(); |
55
by brian
Update for using real bool types. |
230 |
error=true; |
1
by brian
clean slate |
231 |
break; |
232 |
}
|
|
233 |
case COM_PING: |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
234 |
status_var_increment(session->status_var.com_other); |
836
by Brian Aker
Fixed session call from function to method. |
235 |
session->my_ok(); // Tell client we are alive |
1
by brian
clean slate |
236 |
break; |
237 |
case COM_SLEEP: |
|
238 |
case COM_CONNECT: // Impossible here |
|
239 |
case COM_END: |
|
240 |
default: |
|
241 |
my_message(ER_UNKNOWN_COM_ERROR, ER(ER_UNKNOWN_COM_ERROR), MYF(0)); |
|
242 |
break; |
|
243 |
}
|
|
244 |
||
245 |
/* If commit fails, we should be able to reset the OK status. */
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
246 |
session->main_da.can_overwrite_status= true; |
247 |
ha_autocommit_or_rollback(session, session->is_error()); |
|
248 |
session->main_da.can_overwrite_status= false; |
|
1
by brian
clean slate |
249 |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
250 |
session->transaction.stmt.reset(); |
1
by brian
clean slate |
251 |
|
252 |
||
253 |
/* report error issued during command execution */
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
254 |
if (session->killed_errno()) |
255 |
{
|
|
256 |
if (! session->main_da.is_set()) |
|
257 |
session->send_kill_message(); |
|
258 |
}
|
|
259 |
if (session->killed == Session::KILL_QUERY || session->killed == Session::KILL_BAD_DATA) |
|
260 |
{
|
|
261 |
session->killed= Session::NOT_KILLED; |
|
262 |
session->mysys_var->abort= 0; |
|
263 |
}
|
|
264 |
||
971.3.12
by Eric Day
Started abstracting Protocol, removed init_connect, init_file. |
265 |
/* Can not be true, but do not take chances in production. */
|
266 |
assert(! session->main_da.is_sent); |
|
267 |
||
268 |
switch (session->main_da.status()) |
|
269 |
{
|
|
270 |
case Diagnostics_area::DA_ERROR: |
|
271 |
/* The query failed, send error to log and abort bootstrap. */
|
|
971.6.1
by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way. |
272 |
session->client->sendError(session->main_da.sql_errno(), |
273 |
session->main_da.message()); |
|
971.3.12
by Eric Day
Started abstracting Protocol, removed init_connect, init_file. |
274 |
break; |
275 |
||
276 |
case Diagnostics_area::DA_EOF: |
|
971.6.1
by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way. |
277 |
session->client->sendEOF(); |
971.3.12
by Eric Day
Started abstracting Protocol, removed init_connect, init_file. |
278 |
break; |
279 |
||
280 |
case Diagnostics_area::DA_OK: |
|
971.6.1
by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way. |
281 |
session->client->sendOK(); |
971.3.12
by Eric Day
Started abstracting Protocol, removed init_connect, init_file. |
282 |
break; |
283 |
||
284 |
case Diagnostics_area::DA_DISABLED: |
|
285 |
break; |
|
286 |
||
287 |
case Diagnostics_area::DA_EMPTY: |
|
288 |
default: |
|
971.6.1
by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way. |
289 |
session->client->sendOK(); |
971.3.12
by Eric Day
Started abstracting Protocol, removed init_connect, init_file. |
290 |
break; |
291 |
}
|
|
292 |
||
293 |
session->main_da.is_sent= true; |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
294 |
|
295 |
session->set_proc_info("closing tables"); |
|
1
by brian
clean slate |
296 |
/* Free tables */
|
1039.1.16
by Brian Aker
A lot of little cleanups (most based off lcov) |
297 |
session->close_thread_tables(); |
520.1.22
by Brian Aker
Second pass of thd cleanup |
298 |
|
1130.1.16
by Monty Taylor
Fixed naming issue. |
299 |
plugin::Logging::postDo(session); |
520.1.22
by Brian Aker
Second pass of thd cleanup |
300 |
|
961.1.4
by Brian Aker
Remove another lock for processlist. |
301 |
/* Store temp state for processlist */
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
302 |
session->set_proc_info("cleaning up"); |
1126.10.2
by Padraig O'Sullivan
Added hooks into the command start and query start dtrace probes. |
303 |
session->command= COM_SLEEP; |
1003.1.13
by Brian Aker
Memset should be used for init (I seconded guessed myself in a patch about |
304 |
memset(session->process_list_info, 0, PROCESS_LIST_WIDTH); |
1126.10.2
by Padraig O'Sullivan
Added hooks into the command start and query start dtrace probes. |
305 |
session->query= 0; |
306 |
session->query_length= 0; |
|
961.1.4
by Brian Aker
Remove another lock for processlist. |
307 |
|
308 |
session->set_proc_info(NULL); |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
309 |
free_root(session->mem_root,MYF(MY_KEEP_PREALLOC)); |
1126.10.2
by Padraig O'Sullivan
Added hooks into the command start and query start dtrace probes. |
310 |
|
311 |
if (DRIZZLE_QUERY_DONE_ENABLED() || DRIZZLE_COMMAND_DONE_ENABLED()) |
|
312 |
{
|
|
313 |
if (command == COM_QUERY) |
|
314 |
{
|
|
1126.10.21
by Padraig O'Sullivan
Whoops, simple fix for a build warning that happens if the build is not |
315 |
DRIZZLE_QUERY_DONE(session->is_error()); |
1126.10.2
by Padraig O'Sullivan
Added hooks into the command start and query start dtrace probes. |
316 |
}
|
1126.10.21
by Padraig O'Sullivan
Whoops, simple fix for a build warning that happens if the build is not |
317 |
DRIZZLE_COMMAND_DONE(session->is_error()); |
1126.10.2
by Padraig O'Sullivan
Added hooks into the command start and query start dtrace probes. |
318 |
}
|
319 |
||
320 |
return error; |
|
1
by brian
clean slate |
321 |
}
|
322 |
||
323 |
||
324 |
/**
|
|
327.2.4
by Brian Aker
Refactoring table.h |
325 |
Create a TableList object for an INFORMATION_SCHEMA table.
|
1
by brian
clean slate |
326 |
|
327 |
This function is used in the parser to convert a SHOW or DESCRIBE
|
|
328 |
table_name command to a SELECT from INFORMATION_SCHEMA.
|
|
846
by Brian Aker
Removing on typedeffed class. |
329 |
It prepares a Select_Lex and a TableList object to represent the
|
1
by brian
clean slate |
330 |
given command as a SELECT parse tree.
|
331 |
||
1079.2.9
by Padraig O'Sullivan
Removed the dependency on knowing the position of an I_S table in the |
332 |
@param session thread handle
|
333 |
@param lex current lex
|
|
334 |
@param table_ident table alias if it's used
|
|
335 |
@param schema_table_name the name of the INFORMATION_SCHEMA table to be
|
|
336 |
created
|
|
1
by brian
clean slate |
337 |
|
338 |
@note
|
|
339 |
Due to the way this function works with memory and LEX it cannot
|
|
340 |
be used outside the parser (parse tree transformations outside
|
|
341 |
the parser break PS and SP).
|
|
342 |
||
343 |
@retval
|
|
344 |
0 success
|
|
345 |
@retval
|
|
346 |
1 out of memory or SHOW commands are not allowed
|
|
347 |
in this version of the server.
|
|
348 |
*/
|
|
349 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
350 |
int prepare_schema_table(Session *session, LEX *lex, Table_ident *table_ident, |
1079.2.9
by Padraig O'Sullivan
Removed the dependency on knowing the position of an I_S table in the |
351 |
const string& schema_table_name) |
1
by brian
clean slate |
352 |
{
|
846
by Brian Aker
Removing on typedeffed class. |
353 |
Select_Lex *schema_select_lex= NULL; |
1
by brian
clean slate |
354 |
|
1079.2.9
by Padraig O'Sullivan
Removed the dependency on knowing the position of an I_S table in the |
355 |
|
356 |
if (schema_table_name.compare("TABLES") == 0 || |
|
357 |
schema_table_name.compare("TABLE_NAMES") == 0) |
|
358 |
{
|
|
359 |
LEX_STRING db; |
|
360 |
size_t dummy; |
|
361 |
if (lex->select_lex.db == NULL && |
|
362 |
lex->copy_db_to(&lex->select_lex.db, &dummy)) |
|
363 |
{
|
|
364 |
return (1); |
|
365 |
}
|
|
366 |
schema_select_lex= new Select_Lex(); |
|
367 |
db.str= schema_select_lex->db= lex->select_lex.db; |
|
368 |
schema_select_lex->table_list.first= NULL; |
|
369 |
db.length= strlen(db.str); |
|
370 |
||
371 |
if (check_db_name(&db)) |
|
372 |
{
|
|
373 |
my_error(ER_WRONG_DB_NAME, MYF(0), db.str); |
|
374 |
return (1); |
|
375 |
}
|
|
376 |
}
|
|
377 |
else if (schema_table_name.compare("COLUMNS") == 0 || |
|
378 |
schema_table_name.compare("STATISTICS") == 0) |
|
1
by brian
clean slate |
379 |
{
|
51.1.61
by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE |
380 |
assert(table_ident); |
327.2.4
by Brian Aker
Refactoring table.h |
381 |
TableList **query_tables_last= lex->query_tables_last; |
846
by Brian Aker
Removing on typedeffed class. |
382 |
schema_select_lex= new Select_Lex(); |
1
by brian
clean slate |
383 |
/* 'parent_lex' is used in init_query() so it must be before it. */
|
384 |
schema_select_lex->parent_lex= lex; |
|
385 |
schema_select_lex->init_query(); |
|
1079.2.9
by Padraig O'Sullivan
Removed the dependency on knowing the position of an I_S table in the |
386 |
if (! schema_select_lex->add_table_to_list(session, table_ident, 0, 0, TL_READ)) |
387 |
{
|
|
388 |
return (1); |
|
389 |
}
|
|
1
by brian
clean slate |
390 |
lex->query_tables_last= query_tables_last; |
391 |
}
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
392 |
|
846
by Brian Aker
Removing on typedeffed class. |
393 |
Select_Lex *select_lex= lex->current_select; |
1
by brian
clean slate |
394 |
assert(select_lex); |
1079.2.9
by Padraig O'Sullivan
Removed the dependency on knowing the position of an I_S table in the |
395 |
if (make_schema_select(session, select_lex, schema_table_name)) |
1
by brian
clean slate |
396 |
{
|
51.1.61
by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE |
397 |
return(1); |
1
by brian
clean slate |
398 |
}
|
327.2.4
by Brian Aker
Refactoring table.h |
399 |
TableList *table_list= (TableList*) select_lex->table_list.first; |
1
by brian
clean slate |
400 |
assert(table_list); |
401 |
table_list->schema_select_lex= schema_select_lex; |
|
1039.1.16
by Brian Aker
A lot of little cleanups (most based off lcov) |
402 |
|
403 |
return 0; |
|
1
by brian
clean slate |
404 |
}
|
405 |
||
406 |
/**
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
407 |
Execute command saved in session and lex->sql_command.
|
1
by brian
clean slate |
408 |
|
409 |
Before every operation that can request a write lock for a table
|
|
410 |
wait if a global read lock exists. However do not wait if this
|
|
411 |
thread has locked tables already. No new locks can be requested
|
|
412 |
until the other locks are released. The thread that requests the
|
|
413 |
global read lock waits for write locked tables to become unlocked.
|
|
414 |
||
415 |
Note that wait_if_global_read_lock() sets a protection against a new
|
|
416 |
global read lock when it succeeds. This needs to be released by
|
|
417 |
start_waiting_global_read_lock() after the operation.
|
|
418 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
419 |
@param session Thread handle
|
1
by brian
clean slate |
420 |
|
421 |
@todo
|
|
422 |
- Invalidate the table in the query cache if something changed
|
|
423 |
after unlocking when changes become visible.
|
|
424 |
TODO: this is workaround. right way will be move invalidating in
|
|
425 |
the unlock procedure.
|
|
426 |
- TODO: use check_change_password()
|
|
427 |
- JOIN is not supported yet. TODO
|
|
428 |
- SUSPEND and FOR MIGRATE are not supported yet. TODO
|
|
429 |
||
430 |
@retval
|
|
55
by brian
Update for using real bool types. |
431 |
false OK
|
1
by brian
clean slate |
432 |
@retval
|
55
by brian
Update for using real bool types. |
433 |
true Error
|
1
by brian
clean slate |
434 |
*/
|
435 |
||
1085.1.2
by Monty Taylor
Fixed -Wmissing-declarations |
436 |
static int |
520.1.22
by Brian Aker
Second pass of thd cleanup |
437 |
mysql_execute_command(Session *session) |
1
by brian
clean slate |
438 |
{
|
1100.3.68
by Padraig O'Sullivan
Changed the type of res in mysql_execute_command() to bool instead of int |
439 |
bool res= false; |
520.1.22
by Brian Aker
Second pass of thd cleanup |
440 |
LEX *lex= session->lex; |
846
by Brian Aker
Removing on typedeffed class. |
441 |
/* first Select_Lex (have special meaning for many of non-SELECTcommands) */
|
442 |
Select_Lex *select_lex= &lex->select_lex; |
|
1
by brian
clean slate |
443 |
/* list of all tables in query */
|
327.2.4
by Brian Aker
Refactoring table.h |
444 |
TableList *all_tables; |
998
by Brian Aker
Patch on show processlist from davi@apache.org |
445 |
/* A peek into the query string */
|
446 |
size_t proc_info_len= session->query_length > PROCESS_LIST_WIDTH ? |
|
447 |
PROCESS_LIST_WIDTH : session->query_length; |
|
448 |
||
449 |
memcpy(session->process_list_info, session->query, proc_info_len); |
|
450 |
session->process_list_info[proc_info_len]= '\0'; |
|
1
by brian
clean slate |
451 |
|
452 |
/*
|
|
846
by Brian Aker
Removing on typedeffed class. |
453 |
In many cases first table of main Select_Lex have special meaning =>
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
454 |
check that it is first table in global list and relink it first in
|
1
by brian
clean slate |
455 |
queries_tables list if it is necessary (we need such relinking only
|
456 |
for queries with subqueries in select list, in this case tables of
|
|
457 |
subqueries will go to global list first)
|
|
458 |
||
846
by Brian Aker
Removing on typedeffed class. |
459 |
all_tables will differ from first_table only if most upper Select_Lex
|
1
by brian
clean slate |
460 |
do not contain tables.
|
461 |
||
462 |
Because of above in place where should be at least one table in most
|
|
846
by Brian Aker
Removing on typedeffed class. |
463 |
outer Select_Lex we have following check:
|
51.1.61
by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE |
464 |
assert(first_table == all_tables);
|
465 |
assert(first_table == all_tables && first_table != 0);
|
|
1
by brian
clean slate |
466 |
*/
|
467 |
lex->first_lists_tables_same(); |
|
468 |
/* should be assigned after making first tables same */
|
|
469 |
all_tables= lex->query_tables; |
|
470 |
/* set context for commands which do not use setup_tables */
|
|
471 |
select_lex-> |
|
327.2.4
by Brian Aker
Refactoring table.h |
472 |
context.resolve_in_table_list_only((TableList*)select_lex-> |
1
by brian
clean slate |
473 |
table_list.first); |
474 |
||
475 |
/*
|
|
476 |
Reset warning count for each query that uses tables
|
|
477 |
A better approach would be to reset this for any commands
|
|
478 |
that is not a SHOW command or a select that only access local
|
|
479 |
variables, but for now this is probably good enough.
|
|
480 |
Don't reset warnings when executing a stored routine.
|
|
481 |
*/
|
|
1100.3.63
by Padraig O'Sullivan
Extracted the ALTER TABLE command into its own class and implementation |
482 |
if (all_tables || ! lex->is_single_level_stmt()) |
1100.3.66
by Padraig O'Sullivan
Extracted the last commands....Finally removed that gigantic switch |
483 |
{
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
484 |
drizzle_reset_errors(session, 0); |
1100.3.66
by Padraig O'Sullivan
Extracted the last commands....Finally removed that gigantic switch |
485 |
}
|
1
by brian
clean slate |
486 |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
487 |
status_var_increment(session->status_var.com_stat[lex->sql_command]); |
1
by brian
clean slate |
488 |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
489 |
assert(session->transaction.stmt.modified_non_trans_table == false); |
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
490 |
|
1100.3.66
by Padraig O'Sullivan
Extracted the last commands....Finally removed that gigantic switch |
491 |
/* now we are ready to execute the statement */
|
492 |
res= lex->statement->execute(); |
|
1100.3.1
by Padraig O'Sullivan
Beginnings of reworking the mysql_execute_command() method. |
493 |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
494 |
session->set_proc_info("query end"); |
1
by brian
clean slate |
495 |
|
496 |
/*
|
|
497 |
The return value for ROW_COUNT() is "implementation dependent" if the
|
|
498 |
statement is not DELETE, INSERT or UPDATE, but -1 is what JDBC and ODBC
|
|
499 |
wants. We also keep the last value in case of SQLCOM_CALL or
|
|
500 |
SQLCOM_EXECUTE.
|
|
501 |
*/
|
|
1100.3.49
by Padraig O'Sullivan
Extracted the KILL command into its own class and implementation files. |
502 |
if (! (sql_command_flags[lex->sql_command].test(CF_BIT_HAS_ROW_COUNT))) |
503 |
{
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
504 |
session->row_count_func= -1; |
1100.3.49
by Padraig O'Sullivan
Extracted the KILL command into its own class and implementation files. |
505 |
}
|
1
by brian
clean slate |
506 |
|
1100.3.63
by Padraig O'Sullivan
Extracted the ALTER TABLE command into its own class and implementation |
507 |
return (res || session->is_error()); |
1
by brian
clean slate |
508 |
}
|
509 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
510 |
bool execute_sqlcom_select(Session *session, TableList *all_tables) |
1
by brian
clean slate |
511 |
{
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
512 |
LEX *lex= session->lex; |
1
by brian
clean slate |
513 |
select_result *result=lex->result; |
873.1.9
by Jay Pipes
This patch fixes the following functions to properly error out |
514 |
bool res= false; |
1
by brian
clean slate |
515 |
/* assign global limit variable if limit is not given */
|
516 |
{
|
|
846
by Brian Aker
Removing on typedeffed class. |
517 |
Select_Lex *param= lex->unit.global_parameters; |
1
by brian
clean slate |
518 |
if (!param->explicit_limit) |
519 |
param->select_limit= |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
520 |
new Item_int((uint64_t) session->variables.select_limit); |
1
by brian
clean slate |
521 |
}
|
1109.1.3
by Brian Aker
Move names around a bit (to align similar methods) |
522 |
if (!(res= session->openTablesLock(all_tables))) |
1
by brian
clean slate |
523 |
{
|
524 |
if (lex->describe) |
|
525 |
{
|
|
526 |
/*
|
|
527 |
We always use select_send for EXPLAIN, even if it's an EXPLAIN
|
|
528 |
for SELECT ... INTO OUTFILE: a user application should be able
|
|
529 |
to prepend EXPLAIN to any query and receive output for it,
|
|
530 |
even if the query itself redirects the output.
|
|
531 |
*/
|
|
532 |
if (!(result= new select_send())) |
|
971.6.11
by Eric Day
Removed purecov messages. |
533 |
return true; |
520.1.22
by Brian Aker
Second pass of thd cleanup |
534 |
session->send_explain_fields(result); |
535 |
res= mysql_explain_union(session, &session->lex->unit, result); |
|
1
by brian
clean slate |
536 |
if (lex->describe & DESCRIBE_EXTENDED) |
537 |
{
|
|
538 |
char buff[1024]; |
|
205
by Brian Aker
uint32 -> uin32_t |
539 |
String str(buff,(uint32_t) sizeof(buff), system_charset_info); |
1
by brian
clean slate |
540 |
str.length(0); |
520.1.22
by Brian Aker
Second pass of thd cleanup |
541 |
session->lex->unit.print(&str, QT_ORDINARY); |
1
by brian
clean slate |
542 |
str.append('\0'); |
520.1.22
by Brian Aker
Second pass of thd cleanup |
543 |
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE, |
1
by brian
clean slate |
544 |
ER_YES, str.ptr()); |
545 |
}
|
|
546 |
if (res) |
|
547 |
result->abort(); |
|
548 |
else
|
|
549 |
result->send_eof(); |
|
550 |
delete result; |
|
551 |
}
|
|
552 |
else
|
|
553 |
{
|
|
554 |
if (!result && !(result= new select_send())) |
|
971.6.11
by Eric Day
Removed purecov messages. |
555 |
return true; |
520.1.22
by Brian Aker
Second pass of thd cleanup |
556 |
res= handle_select(session, lex, result, 0); |
1
by brian
clean slate |
557 |
if (result != lex->result) |
558 |
delete result; |
|
559 |
}
|
|
560 |
}
|
|
561 |
return res; |
|
562 |
}
|
|
563 |
||
564 |
||
565 |
#define MY_YACC_INIT 1000 // Start with big alloc |
|
566 |
#define MY_YACC_MAX 32000 // Because of 'short' |
|
567 |
||
568 |
bool my_yyoverflow(short **yyss, YYSTYPE **yyvs, ulong *yystacksize) |
|
569 |
{
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
570 |
LEX *lex= current_session->lex; |
1
by brian
clean slate |
571 |
ulong old_info=0; |
438.1.13
by Brian Aker
uint cleanup. |
572 |
if ((uint32_t) *yystacksize >= MY_YACC_MAX) |
1
by brian
clean slate |
573 |
return 1; |
574 |
if (!lex->yacc_yyvs) |
|
575 |
old_info= *yystacksize; |
|
576 |
*yystacksize= set_zone((*yystacksize)*2,MY_YACC_INIT,MY_YACC_MAX); |
|
656.1.46
by Monty Taylor
More malloc return cleanups. |
577 |
unsigned char *tmpptr= NULL; |
578 |
if (!(tmpptr= (unsigned char *)realloc(lex->yacc_yyvs, |
|
579 |
*yystacksize* sizeof(**yyvs)))) |
|
580 |
return 1; |
|
581 |
lex->yacc_yyvs= tmpptr; |
|
582 |
tmpptr= NULL; |
|
583 |
if (!(tmpptr= (unsigned char*)realloc(lex->yacc_yyss, |
|
584 |
*yystacksize* sizeof(**yyss)))) |
|
585 |
return 1; |
|
586 |
lex->yacc_yyss= tmpptr; |
|
1
by brian
clean slate |
587 |
if (old_info) |
588 |
{ // Copy old info from stack |
|
212.6.6
by Mats Kindahl
Removing redundant use of casts in drizzled/ for memcmp(), memcpy(), memset(), and memmove(). |
589 |
memcpy(lex->yacc_yyss, *yyss, old_info*sizeof(**yyss)); |
590 |
memcpy(lex->yacc_yyvs, *yyvs, old_info*sizeof(**yyvs)); |
|
1
by brian
clean slate |
591 |
}
|
592 |
*yyss=(short*) lex->yacc_yyss; |
|
593 |
*yyvs=(YYSTYPE*) lex->yacc_yyvs; |
|
594 |
return 0; |
|
595 |
}
|
|
596 |
||
597 |
||
598 |
void
|
|
599 |
mysql_init_select(LEX *lex) |
|
600 |
{
|
|
846
by Brian Aker
Removing on typedeffed class. |
601 |
Select_Lex *select_lex= lex->current_select; |
1
by brian
clean slate |
602 |
select_lex->init_select(); |
603 |
lex->wild= 0; |
|
604 |
if (select_lex == &lex->select_lex) |
|
605 |
{
|
|
51.1.61
by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE |
606 |
assert(lex->result == 0); |
1
by brian
clean slate |
607 |
lex->exchange= 0; |
608 |
}
|
|
609 |
}
|
|
610 |
||
611 |
||
612 |
bool
|
|
613 |
mysql_new_select(LEX *lex, bool move_down) |
|
614 |
{
|
|
846
by Brian Aker
Removing on typedeffed class. |
615 |
Select_Lex *select_lex; |
520.1.22
by Brian Aker
Second pass of thd cleanup |
616 |
Session *session= lex->session; |
1
by brian
clean slate |
617 |
|
846
by Brian Aker
Removing on typedeffed class. |
618 |
if (!(select_lex= new (session->mem_root) Select_Lex())) |
51.1.61
by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE |
619 |
return(1); |
520.1.22
by Brian Aker
Second pass of thd cleanup |
620 |
select_lex->select_number= ++session->select_number; |
1
by brian
clean slate |
621 |
select_lex->parent_lex= lex; /* Used in init_query. */ |
622 |
select_lex->init_query(); |
|
623 |
select_lex->init_select(); |
|
624 |
lex->nest_level++; |
|
625 |
if (lex->nest_level > (int) MAX_SELECT_NESTING) |
|
626 |
{
|
|
627 |
my_error(ER_TOO_HIGH_LEVEL_OF_NESTING_FOR_SELECT,MYF(0),MAX_SELECT_NESTING); |
|
51.1.61
by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE |
628 |
return(1); |
1
by brian
clean slate |
629 |
}
|
630 |
select_lex->nest_level= lex->nest_level; |
|
631 |
if (move_down) |
|
632 |
{
|
|
848
by Brian Aker
typdef class removal (just... use the name of the class). |
633 |
Select_Lex_Unit *unit; |
1
by brian
clean slate |
634 |
/* first select_lex of subselect or derived table */
|
848
by Brian Aker
typdef class removal (just... use the name of the class). |
635 |
if (!(unit= new (session->mem_root) Select_Lex_Unit())) |
51.1.61
by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE |
636 |
return(1); |
1
by brian
clean slate |
637 |
|
638 |
unit->init_query(); |
|
639 |
unit->init_select(); |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
640 |
unit->session= session; |
1
by brian
clean slate |
641 |
unit->include_down(lex->current_select); |
642 |
unit->link_next= 0; |
|
643 |
unit->link_prev= 0; |
|
644 |
unit->return_to= lex->current_select; |
|
645 |
select_lex->include_down(unit); |
|
646 |
/*
|
|
647 |
By default we assume that it is usual subselect and we have outer name
|
|
648 |
resolution context, if no we will assign it to 0 later
|
|
649 |
*/
|
|
650 |
select_lex->context.outer_context= &select_lex->outer_select()->context; |
|
651 |
}
|
|
652 |
else
|
|
653 |
{
|
|
654 |
if (lex->current_select->order_list.first && !lex->current_select->braces) |
|
655 |
{
|
|
327.2.3
by Brian Aker
Refactoring of class Table |
656 |
my_error(ER_WRONG_USAGE, MYF(0), "UNION", "order_st BY"); |
51.1.61
by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE |
657 |
return(1); |
1
by brian
clean slate |
658 |
}
|
659 |
select_lex->include_neighbour(lex->current_select); |
|
848
by Brian Aker
typdef class removal (just... use the name of the class). |
660 |
Select_Lex_Unit *unit= select_lex->master_unit(); |
520.1.22
by Brian Aker
Second pass of thd cleanup |
661 |
if (!unit->fake_select_lex && unit->add_fake_select_lex(lex->session)) |
51.1.61
by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE |
662 |
return(1); |
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
663 |
select_lex->context.outer_context= |
1
by brian
clean slate |
664 |
unit->first_select()->context.outer_context; |
665 |
}
|
|
666 |
||
667 |
select_lex->master_unit()->global_parameters= select_lex; |
|
847
by Brian Aker
More typdef class removal. |
668 |
select_lex->include_global((Select_Lex_Node**)&lex->all_selects_list); |
1
by brian
clean slate |
669 |
lex->current_select= select_lex; |
670 |
/*
|
|
671 |
in subquery is SELECT query and we allow resolution of names in SELECT
|
|
672 |
list
|
|
673 |
*/
|
|
55
by brian
Update for using real bool types. |
674 |
select_lex->context.resolve_in_select_list= true; |
51.1.61
by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE |
675 |
return(0); |
1
by brian
clean slate |
676 |
}
|
677 |
||
678 |
/**
|
|
679 |
Create a select to return the same output as 'SELECT @@var_name'.
|
|
680 |
||
681 |
Used for SHOW COUNT(*) [ WARNINGS | ERROR].
|
|
682 |
||
683 |
This will crash with a core dump if the variable doesn't exists.
|
|
684 |
||
685 |
@param var_name Variable name
|
|
686 |
*/
|
|
687 |
||
688 |
void create_select_for_variable(const char *var_name) |
|
689 |
{
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
690 |
Session *session; |
1
by brian
clean slate |
691 |
LEX *lex; |
692 |
LEX_STRING tmp, null_lex_string; |
|
693 |
Item *var; |
|
673.2.1
by Toru Maesaka
First pass of replacing MySQL's strxmov with libc alternatives |
694 |
char buff[MAX_SYS_VAR_LENGTH*2+4+8]; |
695 |
char *end= buff; |
|
1
by brian
clean slate |
696 |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
697 |
session= current_session; |
698 |
lex= session->lex; |
|
1
by brian
clean slate |
699 |
mysql_init_select(lex); |
700 |
lex->sql_command= SQLCOM_SELECT; |
|
701 |
tmp.str= (char*) var_name; |
|
702 |
tmp.length=strlen(var_name); |
|
212.6.6
by Mats Kindahl
Removing redundant use of casts in drizzled/ for memcmp(), memcpy(), memset(), and memmove(). |
703 |
memset(&null_lex_string.str, 0, sizeof(null_lex_string)); |
1
by brian
clean slate |
704 |
/*
|
705 |
We set the name of Item to @@session.var_name because that then is used
|
|
706 |
as the column name in the output.
|
|
707 |
*/
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
708 |
if ((var= get_system_var(session, OPT_SESSION, tmp, null_lex_string))) |
1
by brian
clean slate |
709 |
{
|
673.2.1
by Toru Maesaka
First pass of replacing MySQL's strxmov with libc alternatives |
710 |
end+= sprintf(buff, "@@session.%s", var_name); |
1
by brian
clean slate |
711 |
var->set_name(buff, end-buff, system_charset_info); |
838
by Brian Aker
More class adoption/method |
712 |
session->add_item_to_list(var); |
1
by brian
clean slate |
713 |
}
|
51.1.61
by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE |
714 |
return; |
1
by brian
clean slate |
715 |
}
|
716 |
||
717 |
||
718 |
/**
|
|
719 |
Parse a query.
|
|
720 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
721 |
@param session Current thread
|
1
by brian
clean slate |
722 |
@param inBuf Begining of the query text
|
723 |
@param length Length of the query text
|
|
724 |
@param[out] found_semicolon For multi queries, position of the character of
|
|
725 |
the next query in the query text.
|
|
726 |
*/
|
|
727 |
||
1165.1.49
by Stewart Smith
make mysql_parse static to sql_parse.cc |
728 |
static void mysql_parse(Session *session, const char *inBuf, uint32_t length, |
1
by brian
clean slate |
729 |
const char ** found_semicolon) |
730 |
{
|
|
731 |
/*
|
|
732 |
Warning.
|
|
733 |
The purpose of query_cache_send_result_to_client() is to lookup the
|
|
734 |
query in the query cache first, to avoid parsing and executing it.
|
|
735 |
So, the natural implementation would be to:
|
|
736 |
- first, call query_cache_send_result_to_client,
|
|
737 |
- second, if caching failed, initialise the lexical and syntactic parser.
|
|
738 |
The problem is that the query cache depends on a clean initialization
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
739 |
of (among others) lex->safe_to_cache_query and session->server_status,
|
1
by brian
clean slate |
740 |
which are reset respectively in
|
741 |
- lex_start()
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
742 |
- mysql_reset_session_for_next_command()
|
1
by brian
clean slate |
743 |
So, initializing the lexical analyser *before* using the query cache
|
744 |
is required for the cache to work properly.
|
|
745 |
FIXME: cleanup the dependencies in the code to simplify this.
|
|
746 |
*/
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
747 |
lex_start(session); |
735
by Brian Aker
Refactor session. |
748 |
session->reset_for_next_command(); |
1
by brian
clean slate |
749 |
|
750 |
{
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
751 |
LEX *lex= session->lex; |
752 |
||
753 |
Lex_input_stream lip(session, inBuf, length); |
|
754 |
||
755 |
bool err= parse_sql(session, &lip); |
|
1
by brian
clean slate |
756 |
*found_semicolon= lip.found_semicolon; |
757 |
||
758 |
if (!err) |
|
759 |
{
|
|
760 |
{
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
761 |
if (! session->is_error()) |
1
by brian
clean slate |
762 |
{
|
763 |
/*
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
764 |
Binlog logs a string starting from session->query and having length
|
765 |
session->query_length; so we set session->query_length correctly (to not
|
|
1
by brian
clean slate |
766 |
log several statements in one event, when we executed only first).
|
767 |
We set it to not see the ';' (otherwise it would get into binlog
|
|
768 |
and Query_log_event::print() would give ';;' output).
|
|
769 |
This also helps display only the current query in SHOW
|
|
770 |
PROCESSLIST.
|
|
771 |
Note that we don't need LOCK_thread_count to modify query_length.
|
|
772 |
*/
|
|
773 |
if (*found_semicolon && |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
774 |
(session->query_length= (ulong)(*found_semicolon - session->query))) |
775 |
session->query_length--; |
|
1126.10.14
by Padraig O'Sullivan
Added calls to the query execution start/end dtrace probes. |
776 |
DRIZZLE_QUERY_EXEC_START(session->query, |
777 |
session->thread_id, |
|
1126.10.25
by Padraig O'Sullivan
Updated calls to some dtrace probes to cast the parameter to const char * |
778 |
const_cast<const char *>(session->db ? session->db : "")); |
1
by brian
clean slate |
779 |
/* Actually execute the query */
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
780 |
mysql_execute_command(session); |
1126.10.14
by Padraig O'Sullivan
Added calls to the query execution start/end dtrace probes. |
781 |
DRIZZLE_QUERY_EXEC_DONE(0); |
1
by brian
clean slate |
782 |
}
|
783 |
}
|
|
784 |
}
|
|
785 |
else
|
|
786 |
{
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
787 |
assert(session->is_error()); |
1
by brian
clean slate |
788 |
}
|
789 |
lex->unit.cleanup(); |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
790 |
session->set_proc_info("freeing items"); |
791 |
session->end_statement(); |
|
792 |
session->cleanup_after_query(); |
|
1
by brian
clean slate |
793 |
}
|
794 |
||
51.1.61
by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE |
795 |
return; |
1
by brian
clean slate |
796 |
}
|
797 |
||
798 |
||
799 |
||
800 |
/**
|
|
801 |
Store field definition for create.
|
|
802 |
||
803 |
@return
|
|
804 |
Return 0 if ok
|
|
805 |
*/
|
|
806 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
807 |
bool add_field_to_list(Session *session, LEX_STRING *field_name, enum_field_types type, |
1
by brian
clean slate |
808 |
char *length, char *decimals, |
438.1.13
by Brian Aker
uint cleanup. |
809 |
uint32_t type_modifier, |
1
by brian
clean slate |
810 |
enum column_format_type column_format, |
811 |
Item *default_value, Item *on_update_value, |
|
812 |
LEX_STRING *comment, |
|
813 |
char *change, |
|
998.1.2
by Brian Aker
First pass on removing virt columns |
814 |
List<String> *interval_list, const CHARSET_INFO * const cs) |
1
by brian
clean slate |
815 |
{
|
1052.2.3
by Nathan Williams
No actual code changes. Changed Create_field to CreateField to be consistent with coding standards. |
816 |
register CreateField *new_field; |
520.1.22
by Brian Aker
Second pass of thd cleanup |
817 |
LEX *lex= session->lex; |
1128.2.4
by Brian Aker
AlterInfo refactor back to class. |
818 |
drizzled::statement::AlterTable *statement= (drizzled::statement::AlterTable *)lex->statement; |
1
by brian
clean slate |
819 |
|
820 |
if (check_identifier_name(field_name, ER_TOO_LONG_IDENT)) |
|
1135
by Brian Aker
Merge of Lex -> Statement refactoring |
821 |
return true; |
1
by brian
clean slate |
822 |
|
823 |
if (type_modifier & PRI_KEY_FLAG) |
|
824 |
{
|
|
825 |
Key *key; |
|
826 |
lex->col_list.push_back(new Key_part_spec(*field_name, 0)); |
|
827 |
key= new Key(Key::PRIMARY, null_lex_str, |
|
828 |
&default_key_create_info, |
|
829 |
0, lex->col_list); |
|
1128.2.4
by Brian Aker
AlterInfo refactor back to class. |
830 |
statement->alter_info.key_list.push_back(key); |
1
by brian
clean slate |
831 |
lex->col_list.empty(); |
832 |
}
|
|
833 |
if (type_modifier & (UNIQUE_FLAG | UNIQUE_KEY_FLAG)) |
|
834 |
{
|
|
835 |
Key *key; |
|
836 |
lex->col_list.push_back(new Key_part_spec(*field_name, 0)); |
|
837 |
key= new Key(Key::UNIQUE, null_lex_str, |
|
838 |
&default_key_create_info, 0, |
|
839 |
lex->col_list); |
|
1128.2.4
by Brian Aker
AlterInfo refactor back to class. |
840 |
statement->alter_info.key_list.push_back(key); |
1
by brian
clean slate |
841 |
lex->col_list.empty(); |
842 |
}
|
|
843 |
||
844 |
if (default_value) |
|
845 |
{
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
846 |
/*
|
1
by brian
clean slate |
847 |
Default value should be literal => basic constants =>
|
848 |
no need fix_fields()
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
849 |
|
850 |
We allow only one function as part of default value -
|
|
1
by brian
clean slate |
851 |
NOW() as default for TIMESTAMP type.
|
852 |
*/
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
853 |
if (default_value->type() == Item::FUNC_ITEM && |
1
by brian
clean slate |
854 |
!(((Item_func*)default_value)->functype() == Item_func::NOW_FUNC && |
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
855 |
type == DRIZZLE_TYPE_TIMESTAMP)) |
1
by brian
clean slate |
856 |
{
|
857 |
my_error(ER_INVALID_DEFAULT, MYF(0), field_name->str); |
|
1128.2.4
by Brian Aker
AlterInfo refactor back to class. |
858 |
return true; |
1
by brian
clean slate |
859 |
}
|
860 |
else if (default_value->type() == Item::NULL_ITEM) |
|
861 |
{
|
|
862 |
default_value= 0; |
|
863 |
if ((type_modifier & (NOT_NULL_FLAG | AUTO_INCREMENT_FLAG)) == |
|
864 |
NOT_NULL_FLAG) |
|
865 |
{
|
|
866 |
my_error(ER_INVALID_DEFAULT, MYF(0), field_name->str); |
|
1128.2.4
by Brian Aker
AlterInfo refactor back to class. |
867 |
return true; |
1
by brian
clean slate |
868 |
}
|
869 |
}
|
|
870 |
else if (type_modifier & AUTO_INCREMENT_FLAG) |
|
871 |
{
|
|
872 |
my_error(ER_INVALID_DEFAULT, MYF(0), field_name->str); |
|
1128.2.4
by Brian Aker
AlterInfo refactor back to class. |
873 |
return true; |
1
by brian
clean slate |
874 |
}
|
875 |
}
|
|
876 |
||
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
877 |
if (on_update_value && type != DRIZZLE_TYPE_TIMESTAMP) |
1
by brian
clean slate |
878 |
{
|
879 |
my_error(ER_INVALID_ON_UPDATE, MYF(0), field_name->str); |
|
1128.2.4
by Brian Aker
AlterInfo refactor back to class. |
880 |
return true; |
1
by brian
clean slate |
881 |
}
|
882 |
||
1052.2.3
by Nathan Williams
No actual code changes. Changed Create_field to CreateField to be consistent with coding standards. |
883 |
if (!(new_field= new CreateField()) || |
520.1.22
by Brian Aker
Second pass of thd cleanup |
884 |
new_field->init(session, field_name->str, type, length, decimals, type_modifier, |
1
by brian
clean slate |
885 |
default_value, on_update_value, comment, change, |
998.1.2
by Brian Aker
First pass on removing virt columns |
886 |
interval_list, cs, 0, column_format)) |
1128.2.4
by Brian Aker
AlterInfo refactor back to class. |
887 |
return true; |
1
by brian
clean slate |
888 |
|
1128.2.4
by Brian Aker
AlterInfo refactor back to class. |
889 |
statement->alter_info.create_list.push_back(new_field); |
1
by brian
clean slate |
890 |
lex->last_field=new_field; |
1128.2.4
by Brian Aker
AlterInfo refactor back to class. |
891 |
|
892 |
return false; |
|
1
by brian
clean slate |
893 |
}
|
894 |
||
895 |
||
896 |
/** Store position for column in ALTER TABLE .. ADD column. */
|
|
897 |
||
898 |
void store_position_for_column(const char *name) |
|
899 |
{
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
900 |
current_session->lex->last_field->after=const_cast<char*> (name); |
1
by brian
clean slate |
901 |
}
|
902 |
||
903 |
/**
|
|
904 |
Add a table to list of used tables.
|
|
905 |
||
906 |
@param table Table to add
|
|
907 |
@param alias alias for table (or null if no alias)
|
|
908 |
@param table_options A set of the following bits:
|
|
909 |
- TL_OPTION_UPDATING : Table will be updated
|
|
910 |
- TL_OPTION_FORCE_INDEX : Force usage of index
|
|
911 |
- TL_OPTION_ALIAS : an alias in multi table DELETE
|
|
912 |
@param lock_type How table should be locked
|
|
913 |
@param use_index List of indexed used in USE INDEX
|
|
914 |
@param ignore_index List of indexed used in IGNORE INDEX
|
|
915 |
||
916 |
@retval
|
|
917 |
0 Error
|
|
918 |
@retval
|
|
327.2.4
by Brian Aker
Refactoring table.h |
919 |
\# Pointer to TableList element added to the total table list
|
1
by brian
clean slate |
920 |
*/
|
921 |
||
846
by Brian Aker
Removing on typedeffed class. |
922 |
TableList *Select_Lex::add_table_to_list(Session *session, |
1
by brian
clean slate |
923 |
Table_ident *table, |
924 |
LEX_STRING *alias, |
|
202
by Brian Aker
Cleanup sql_lex to modern types. |
925 |
uint32_t table_options, |
1
by brian
clean slate |
926 |
thr_lock_type lock_type, |
927 |
List<Index_hint> *index_hints_arg, |
|
928 |
LEX_STRING *option) |
|
929 |
{
|
|
327.2.4
by Brian Aker
Refactoring table.h |
930 |
register TableList *ptr; |
931 |
TableList *previous_table_ref; /* The table preceding the current one. */ |
|
1
by brian
clean slate |
932 |
char *alias_str; |
520.1.22
by Brian Aker
Second pass of thd cleanup |
933 |
LEX *lex= session->lex; |
1
by brian
clean slate |
934 |
|
935 |
if (!table) |
|
1054.1.5
by Brian Aker
Formatting/remove dead variables. |
936 |
return NULL; // End of memory |
1
by brian
clean slate |
937 |
alias_str= alias ? alias->str : table->table.str; |
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
938 |
if (!test(table_options & TL_OPTION_ALIAS) && |
1
by brian
clean slate |
939 |
check_table_name(table->table.str, table->table.length)) |
940 |
{
|
|
941 |
my_error(ER_WRONG_TABLE_NAME, MYF(0), table->table.str); |
|
1054.1.5
by Brian Aker
Formatting/remove dead variables. |
942 |
return NULL; |
1
by brian
clean slate |
943 |
}
|
944 |
||
55
by brian
Update for using real bool types. |
945 |
if (table->is_derived_table() == false && table->db.str && |
1
by brian
clean slate |
946 |
check_db_name(&table->db)) |
947 |
{
|
|
948 |
my_error(ER_WRONG_DB_NAME, MYF(0), table->db.str); |
|
1054.1.5
by Brian Aker
Formatting/remove dead variables. |
949 |
return NULL; |
1
by brian
clean slate |
950 |
}
|
951 |
||
952 |
if (!alias) /* Alias is case sensitive */ |
|
953 |
{
|
|
954 |
if (table->sel) |
|
955 |
{
|
|
956 |
my_message(ER_DERIVED_MUST_HAVE_ALIAS, |
|
957 |
ER(ER_DERIVED_MUST_HAVE_ALIAS), MYF(0)); |
|
1054.1.5
by Brian Aker
Formatting/remove dead variables. |
958 |
return NULL; |
1
by brian
clean slate |
959 |
}
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
960 |
if (!(alias_str= (char*) session->memdup(alias_str,table->table.length+1))) |
1054.1.5
by Brian Aker
Formatting/remove dead variables. |
961 |
return NULL; |
1
by brian
clean slate |
962 |
}
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
963 |
if (!(ptr = (TableList *) session->calloc(sizeof(TableList)))) |
971.6.11
by Eric Day
Removed purecov messages. |
964 |
return NULL; |
1
by brian
clean slate |
965 |
if (table->db.str) |
966 |
{
|
|
55
by brian
Update for using real bool types. |
967 |
ptr->is_fqtn= true; |
1
by brian
clean slate |
968 |
ptr->db= table->db.str; |
969 |
ptr->db_length= table->db.length; |
|
970 |
}
|
|
971 |
else if (lex->copy_db_to(&ptr->db, &ptr->db_length)) |
|
1054.1.5
by Brian Aker
Formatting/remove dead variables. |
972 |
return NULL; |
1
by brian
clean slate |
973 |
else
|
55
by brian
Update for using real bool types. |
974 |
ptr->is_fqtn= false; |
1
by brian
clean slate |
975 |
|
976 |
ptr->alias= alias_str; |
|
55
by brian
Update for using real bool types. |
977 |
ptr->is_alias= alias ? true : false; |
1039.1.5
by Brian Aker
Remove lower case filename bits (aka we just lock into the most compatible |
978 |
if (table->table.length) |
1
by brian
clean slate |
979 |
table->table.length= my_casedn_str(files_charset_info, table->table.str); |
980 |
ptr->table_name=table->table.str; |
|
981 |
ptr->table_name_length=table->table.length; |
|
982 |
ptr->lock_type= lock_type; |
|
983 |
ptr->updating= test(table_options & TL_OPTION_UPDATING); |
|
984 |
ptr->force_index= test(table_options & TL_OPTION_FORCE_INDEX); |
|
985 |
ptr->ignore_leaves= test(table_options & TL_OPTION_IGNORE_LEAVES); |
|
986 |
ptr->derived= table->sel; |
|
987 |
if (!ptr->derived && !my_strcasecmp(system_charset_info, ptr->db, |
|
575.4.7
by Monty Taylor
More header cleanup. |
988 |
INFORMATION_SCHEMA_NAME.c_str())) |
1
by brian
clean slate |
989 |
{
|
1130.1.12
by Monty Taylor
Moved service stuff into plugin/ |
990 |
plugin::InfoSchemaTable *schema_table= plugin::InfoSchemaTable::getTable(ptr->table_name); |
1
by brian
clean slate |
991 |
if (!schema_table || |
1063.4.1
by Padraig O'Sullivan
Re-factored the InfoSchemaTable structure to now be a class. Made all data |
992 |
(schema_table->isHidden() && |
602.2.2
by Yoshinori Sano
Fix bugs in params of sql_command_flags[...].test(). Previously, the value such as, 0, 1, 2, 4, 8 and 16 is given to std::bitset.test() in that place, which is misunderstanding of the spec of the test(). The test(size_t n) returns true if bit n is set. |
993 |
((sql_command_flags[lex->sql_command].test(CF_BIT_STATUS_COMMAND)) == 0 || |
1
by brian
clean slate |
994 |
/*
|
995 |
this check is used for show columns|keys from I_S hidden table
|
|
996 |
*/
|
|
997 |
lex->sql_command == SQLCOM_SHOW_FIELDS || |
|
998 |
lex->sql_command == SQLCOM_SHOW_KEYS))) |
|
999 |
{
|
|
1000 |
my_error(ER_UNKNOWN_TABLE, MYF(0), |
|
575.4.7
by Monty Taylor
More header cleanup. |
1001 |
ptr->table_name, INFORMATION_SCHEMA_NAME.c_str()); |
1054.1.5
by Brian Aker
Formatting/remove dead variables. |
1002 |
return NULL; |
1
by brian
clean slate |
1003 |
}
|
1004 |
}
|
|
1005 |
ptr->select_lex= lex->current_select; |
|
1006 |
ptr->index_hints= index_hints_arg; |
|
1007 |
ptr->option= option ? option->str : 0; |
|
1008 |
/* check that used name is unique */
|
|
1009 |
if (lock_type != TL_IGNORE) |
|
1010 |
{
|
|
327.2.4
by Brian Aker
Refactoring table.h |
1011 |
TableList *first_table= (TableList*) table_list.first; |
1012 |
for (TableList *tables= first_table ; |
|
1
by brian
clean slate |
1013 |
tables ; |
1014 |
tables=tables->next_local) |
|
1015 |
{
|
|
1016 |
if (!my_strcasecmp(table_alias_charset, alias_str, tables->alias) && |
|
1017 |
!strcmp(ptr->db, tables->db)) |
|
1018 |
{
|
|
971.6.11
by Eric Day
Removed purecov messages. |
1019 |
my_error(ER_NONUNIQ_TABLE, MYF(0), alias_str); |
1020 |
return NULL; |
|
1
by brian
clean slate |
1021 |
}
|
1022 |
}
|
|
1023 |
}
|
|
1024 |
/* Store the table reference preceding the current one. */
|
|
1025 |
if (table_list.elements > 0) |
|
1026 |
{
|
|
1027 |
/*
|
|
327.2.4
by Brian Aker
Refactoring table.h |
1028 |
table_list.next points to the last inserted TableList->next_local'
|
1
by brian
clean slate |
1029 |
element
|
1030 |
We don't use the offsetof() macro here to avoid warnings from gcc
|
|
1031 |
*/
|
|
327.2.4
by Brian Aker
Refactoring table.h |
1032 |
previous_table_ref= (TableList*) ((char*) table_list.next - |
1
by brian
clean slate |
1033 |
((char*) &(ptr->next_local) - |
1034 |
(char*) ptr)); |
|
1035 |
/*
|
|
1036 |
Set next_name_resolution_table of the previous table reference to point
|
|
1037 |
to the current table reference. In effect the list
|
|
327.2.4
by Brian Aker
Refactoring table.h |
1038 |
TableList::next_name_resolution_table coincides with
|
1039 |
TableList::next_local. Later this may be changed in
|
|
1
by brian
clean slate |
1040 |
store_top_level_join_columns() for NATURAL/USING joins.
|
1041 |
*/
|
|
1042 |
previous_table_ref->next_name_resolution_table= ptr; |
|
1043 |
}
|
|
1044 |
||
1045 |
/*
|
|
1046 |
Link the current table reference in a local list (list for current select).
|
|
1047 |
Notice that as a side effect here we set the next_local field of the
|
|
1048 |
previous table reference to 'ptr'. Here we also add one element to the
|
|
1049 |
list 'table_list'.
|
|
1050 |
*/
|
|
481
by Brian Aker
Remove all of uchar. |
1051 |
table_list.link_in_list((unsigned char*) ptr, (unsigned char**) &ptr->next_local); |
1
by brian
clean slate |
1052 |
ptr->next_name_resolution_table= NULL; |
1053 |
/* Link table in global list (all used tables) */
|
|
1054 |
lex->add_to_query_tables(ptr); |
|
1054.1.5
by Brian Aker
Formatting/remove dead variables. |
1055 |
return ptr; |
1
by brian
clean slate |
1056 |
}
|
1057 |
||
1058 |
||
1059 |
/**
|
|
1060 |
Initialize a new table list for a nested join.
|
|
1061 |
||
327.2.4
by Brian Aker
Refactoring table.h |
1062 |
The function initializes a structure of the TableList type
|
1
by brian
clean slate |
1063 |
for a nested join. It sets up its nested join list as empty.
|
1064 |
The created structure is added to the front of the current
|
|
846
by Brian Aker
Removing on typedeffed class. |
1065 |
join list in the Select_Lex object. Then the function
|
1
by brian
clean slate |
1066 |
changes the current nest level for joins to refer to the newly
|
1067 |
created empty list after having saved the info on the old level
|
|
1068 |
in the initialized structure.
|
|
1069 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
1070 |
@param session current thread
|
1
by brian
clean slate |
1071 |
|
1072 |
@retval
|
|
1073 |
0 if success
|
|
1074 |
@retval
|
|
1075 |
1 otherwise
|
|
1076 |
*/
|
|
1077 |
||
846
by Brian Aker
Removing on typedeffed class. |
1078 |
bool Select_Lex::init_nested_join(Session *session) |
1
by brian
clean slate |
1079 |
{
|
327.2.4
by Brian Aker
Refactoring table.h |
1080 |
TableList *ptr; |
1081 |
nested_join_st *nested_join; |
|
1
by brian
clean slate |
1082 |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1083 |
if (!(ptr= (TableList*) session->calloc(ALIGN_SIZE(sizeof(TableList))+ |
327.2.4
by Brian Aker
Refactoring table.h |
1084 |
sizeof(nested_join_st)))) |
1054.1.5
by Brian Aker
Formatting/remove dead variables. |
1085 |
return true; |
1
by brian
clean slate |
1086 |
nested_join= ptr->nested_join= |
481
by Brian Aker
Remove all of uchar. |
1087 |
((nested_join_st*) ((unsigned char*) ptr + ALIGN_SIZE(sizeof(TableList)))); |
1
by brian
clean slate |
1088 |
|
1089 |
join_list->push_front(ptr); |
|
1090 |
ptr->embedding= embedding; |
|
1091 |
ptr->join_list= join_list; |
|
1092 |
ptr->alias= (char*) "(nested_join)"; |
|
1093 |
embedding= ptr; |
|
1094 |
join_list= &nested_join->join_list; |
|
1095 |
join_list->empty(); |
|
1054.1.5
by Brian Aker
Formatting/remove dead variables. |
1096 |
return false; |
1
by brian
clean slate |
1097 |
}
|
1098 |
||
1099 |
||
1100 |
/**
|
|
1101 |
End a nested join table list.
|
|
1102 |
||
1103 |
The function returns to the previous join nest level.
|
|
1104 |
If the current level contains only one member, the function
|
|
1105 |
moves it one level up, eliminating the nest.
|
|
1106 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
1107 |
@param session current thread
|
1
by brian
clean slate |
1108 |
|
1109 |
@return
|
|
327.2.4
by Brian Aker
Refactoring table.h |
1110 |
- Pointer to TableList element added to the total table list, if success
|
1
by brian
clean slate |
1111 |
- 0, otherwise
|
1112 |
*/
|
|
1113 |
||
846
by Brian Aker
Removing on typedeffed class. |
1114 |
TableList *Select_Lex::end_nested_join(Session *) |
1
by brian
clean slate |
1115 |
{
|
327.2.4
by Brian Aker
Refactoring table.h |
1116 |
TableList *ptr; |
1117 |
nested_join_st *nested_join; |
|
1
by brian
clean slate |
1118 |
|
51.1.61
by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE |
1119 |
assert(embedding); |
1
by brian
clean slate |
1120 |
ptr= embedding; |
1121 |
join_list= ptr->join_list; |
|
1122 |
embedding= ptr->embedding; |
|
1123 |
nested_join= ptr->nested_join; |
|
1124 |
if (nested_join->join_list.elements == 1) |
|
1125 |
{
|
|
327.2.4
by Brian Aker
Refactoring table.h |
1126 |
TableList *embedded= nested_join->join_list.head(); |
1
by brian
clean slate |
1127 |
join_list->pop(); |
1128 |
embedded->join_list= join_list; |
|
1129 |
embedded->embedding= embedding; |
|
1130 |
join_list->push_front(embedded); |
|
1131 |
ptr= embedded; |
|
1132 |
}
|
|
1133 |
else if (nested_join->join_list.elements == 0) |
|
1134 |
{
|
|
1135 |
join_list->pop(); |
|
1054.1.5
by Brian Aker
Formatting/remove dead variables. |
1136 |
ptr= NULL; // return value |
1
by brian
clean slate |
1137 |
}
|
1054.1.5
by Brian Aker
Formatting/remove dead variables. |
1138 |
return ptr; |
1
by brian
clean slate |
1139 |
}
|
1140 |
||
1141 |
||
1142 |
/**
|
|
1143 |
Nest last join operation.
|
|
1144 |
||
1145 |
The function nest last join operation as if it was enclosed in braces.
|
|
1146 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
1147 |
@param session current thread
|
1
by brian
clean slate |
1148 |
|
1149 |
@retval
|
|
1150 |
0 Error
|
|
1151 |
@retval
|
|
327.2.4
by Brian Aker
Refactoring table.h |
1152 |
\# Pointer to TableList element created for the new nested join
|
1
by brian
clean slate |
1153 |
*/
|
1154 |
||
846
by Brian Aker
Removing on typedeffed class. |
1155 |
TableList *Select_Lex::nest_last_join(Session *session) |
1
by brian
clean slate |
1156 |
{
|
327.2.4
by Brian Aker
Refactoring table.h |
1157 |
TableList *ptr; |
1158 |
nested_join_st *nested_join; |
|
1159 |
List<TableList> *embedded_list; |
|
1
by brian
clean slate |
1160 |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1161 |
if (!(ptr= (TableList*) session->calloc(ALIGN_SIZE(sizeof(TableList))+ |
327.2.4
by Brian Aker
Refactoring table.h |
1162 |
sizeof(nested_join_st)))) |
1054.1.5
by Brian Aker
Formatting/remove dead variables. |
1163 |
return NULL; |
1
by brian
clean slate |
1164 |
nested_join= ptr->nested_join= |
481
by Brian Aker
Remove all of uchar. |
1165 |
((nested_join_st*) ((unsigned char*) ptr + ALIGN_SIZE(sizeof(TableList)))); |
1
by brian
clean slate |
1166 |
|
1167 |
ptr->embedding= embedding; |
|
1168 |
ptr->join_list= join_list; |
|
1169 |
ptr->alias= (char*) "(nest_last_join)"; |
|
1170 |
embedded_list= &nested_join->join_list; |
|
1171 |
embedded_list->empty(); |
|
1172 |
||
438.1.13
by Brian Aker
uint cleanup. |
1173 |
for (uint32_t i=0; i < 2; i++) |
1
by brian
clean slate |
1174 |
{
|
327.2.4
by Brian Aker
Refactoring table.h |
1175 |
TableList *table= join_list->pop(); |
1
by brian
clean slate |
1176 |
table->join_list= embedded_list; |
1177 |
table->embedding= ptr; |
|
1178 |
embedded_list->push_back(table); |
|
1179 |
if (table->natural_join) |
|
1180 |
{
|
|
55
by brian
Update for using real bool types. |
1181 |
ptr->is_natural_join= true; |
1
by brian
clean slate |
1182 |
/*
|
1183 |
If this is a JOIN ... USING, move the list of joined fields to the
|
|
1184 |
table reference that describes the join.
|
|
1185 |
*/
|
|
1186 |
if (prev_join_using) |
|
1187 |
ptr->join_using_fields= prev_join_using; |
|
1188 |
}
|
|
1189 |
}
|
|
1190 |
join_list->push_front(ptr); |
|
1191 |
nested_join->used_tables= nested_join->not_null_tables= (table_map) 0; |
|
1054.1.5
by Brian Aker
Formatting/remove dead variables. |
1192 |
return ptr; |
1
by brian
clean slate |
1193 |
}
|
1194 |
||
1195 |
||
1196 |
/**
|
|
1197 |
Add a table to the current join list.
|
|
1198 |
||
1199 |
The function puts a table in front of the current join list
|
|
846
by Brian Aker
Removing on typedeffed class. |
1200 |
of Select_Lex object.
|
1
by brian
clean slate |
1201 |
Thus, joined tables are put into this list in the reverse order
|
1202 |
(the most outer join operation follows first).
|
|
1203 |
||
1204 |
@param table the table to add
|
|
1205 |
||
1206 |
@return
|
|
1207 |
None
|
|
1208 |
*/
|
|
1209 |
||
846
by Brian Aker
Removing on typedeffed class. |
1210 |
void Select_Lex::add_joined_table(TableList *table) |
1
by brian
clean slate |
1211 |
{
|
1212 |
join_list->push_front(table); |
|
1213 |
table->join_list= join_list; |
|
1214 |
table->embedding= embedding; |
|
1215 |
}
|
|
1216 |
||
1217 |
||
1218 |
/**
|
|
1219 |
Convert a right join into equivalent left join.
|
|
1220 |
||
1221 |
The function takes the current join list t[0],t[1] ... and
|
|
1222 |
effectively converts it into the list t[1],t[0] ...
|
|
1223 |
Although the outer_join flag for the new nested table contains
|
|
1224 |
JOIN_TYPE_RIGHT, it will be handled as the inner table of a left join
|
|
1225 |
operation.
|
|
1226 |
||
1227 |
EXAMPLES
|
|
1228 |
@verbatim
|
|
1229 |
SELECT * FROM t1 RIGHT JOIN t2 ON on_expr =>
|
|
1230 |
SELECT * FROM t2 LEFT JOIN t1 ON on_expr
|
|
1231 |
||
1232 |
SELECT * FROM t1,t2 RIGHT JOIN t3 ON on_expr =>
|
|
1233 |
SELECT * FROM t1,t3 LEFT JOIN t2 ON on_expr
|
|
1234 |
||
1235 |
SELECT * FROM t1,t2 RIGHT JOIN (t3,t4) ON on_expr =>
|
|
1236 |
SELECT * FROM t1,(t3,t4) LEFT JOIN t2 ON on_expr
|
|
1237 |
||
1238 |
SELECT * FROM t1 LEFT JOIN t2 ON on_expr1 RIGHT JOIN t3 ON on_expr2 =>
|
|
1239 |
SELECT * FROM t3 LEFT JOIN (t1 LEFT JOIN t2 ON on_expr2) ON on_expr1
|
|
1240 |
@endverbatim
|
|
1241 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
1242 |
@param session current thread
|
1
by brian
clean slate |
1243 |
|
1244 |
@return
|
|
1245 |
- Pointer to the table representing the inner table, if success
|
|
1246 |
- 0, otherwise
|
|
1247 |
*/
|
|
1248 |
||
846
by Brian Aker
Removing on typedeffed class. |
1249 |
TableList *Select_Lex::convert_right_join() |
1
by brian
clean slate |
1250 |
{
|
327.2.4
by Brian Aker
Refactoring table.h |
1251 |
TableList *tab2= join_list->pop(); |
1252 |
TableList *tab1= join_list->pop(); |
|
1
by brian
clean slate |
1253 |
|
1254 |
join_list->push_front(tab2); |
|
1255 |
join_list->push_front(tab1); |
|
1256 |
tab1->outer_join|= JOIN_TYPE_RIGHT; |
|
1257 |
||
1054.1.5
by Brian Aker
Formatting/remove dead variables. |
1258 |
return tab1; |
1
by brian
clean slate |
1259 |
}
|
1260 |
||
1261 |
/**
|
|
1262 |
Set lock for all tables in current select level.
|
|
1263 |
||
1264 |
@param lock_type Lock to set for tables
|
|
1265 |
||
1266 |
@note
|
|
1267 |
If lock is a write lock, then tables->updating is set 1
|
|
1268 |
This is to get tables_ok to know that the table is updated by the
|
|
1269 |
query
|
|
1270 |
*/
|
|
1271 |
||
846
by Brian Aker
Removing on typedeffed class. |
1272 |
void Select_Lex::set_lock_for_tables(thr_lock_type lock_type) |
1
by brian
clean slate |
1273 |
{
|
1274 |
bool for_update= lock_type >= TL_READ_NO_INSERT; |
|
1275 |
||
327.2.4
by Brian Aker
Refactoring table.h |
1276 |
for (TableList *tables= (TableList*) table_list.first; |
1
by brian
clean slate |
1277 |
tables; |
1278 |
tables= tables->next_local) |
|
1279 |
{
|
|
1280 |
tables->lock_type= lock_type; |
|
1281 |
tables->updating= for_update; |
|
1282 |
}
|
|
51.1.61
by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE |
1283 |
return; |
1
by brian
clean slate |
1284 |
}
|
1285 |
||
1286 |
||
1287 |
/**
|
|
846
by Brian Aker
Removing on typedeffed class. |
1288 |
Create a fake Select_Lex for a unit.
|
1
by brian
clean slate |
1289 |
|
846
by Brian Aker
Removing on typedeffed class. |
1290 |
The method create a fake Select_Lex object for a unit.
|
1
by brian
clean slate |
1291 |
This object is created for any union construct containing a union
|
1292 |
operation and also for any single select union construct of the form
|
|
1293 |
@verbatim
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
1294 |
(SELECT ... order_st BY order_list [LIMIT n]) order_st BY ...
|
1
by brian
clean slate |
1295 |
@endvarbatim
|
1296 |
or of the form
|
|
1297 |
@varbatim
|
|
327.2.3
by Brian Aker
Refactoring of class Table |
1298 |
(SELECT ... order_st BY LIMIT n) order_st BY ...
|
1
by brian
clean slate |
1299 |
@endvarbatim
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
1300 |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1301 |
@param session_arg thread handle
|
1
by brian
clean slate |
1302 |
|
1303 |
@note
|
|
1304 |
The object is used to retrieve rows from the temporary table
|
|
1305 |
where the result on the union is obtained.
|
|
1306 |
||
1307 |
@retval
|
|
1308 |
1 on failure to create the object
|
|
1309 |
@retval
|
|
1310 |
0 on success
|
|
1311 |
*/
|
|
1312 |
||
848
by Brian Aker
typdef class removal (just... use the name of the class). |
1313 |
bool Select_Lex_Unit::add_fake_select_lex(Session *session_arg) |
1
by brian
clean slate |
1314 |
{
|
846
by Brian Aker
Removing on typedeffed class. |
1315 |
Select_Lex *first_sl= first_select(); |
51.1.61
by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE |
1316 |
assert(!fake_select_lex); |
1
by brian
clean slate |
1317 |
|
846
by Brian Aker
Removing on typedeffed class. |
1318 |
if (!(fake_select_lex= new (session_arg->mem_root) Select_Lex())) |
51.1.61
by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE |
1319 |
return(1); |
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
1320 |
fake_select_lex->include_standalone(this, |
847
by Brian Aker
More typdef class removal. |
1321 |
(Select_Lex_Node**)&fake_select_lex); |
1
by brian
clean slate |
1322 |
fake_select_lex->select_number= INT_MAX; |
520.1.22
by Brian Aker
Second pass of thd cleanup |
1323 |
fake_select_lex->parent_lex= session_arg->lex; /* Used in init_query. */ |
1
by brian
clean slate |
1324 |
fake_select_lex->make_empty_select(); |
1325 |
fake_select_lex->linkage= GLOBAL_OPTIONS_TYPE; |
|
1326 |
fake_select_lex->select_limit= 0; |
|
1327 |
||
1328 |
fake_select_lex->context.outer_context=first_sl->context.outer_context; |
|
327.2.3
by Brian Aker
Refactoring of class Table |
1329 |
/* allow item list resolving in fake select for order_st BY */
|
55
by brian
Update for using real bool types. |
1330 |
fake_select_lex->context.resolve_in_select_list= true; |
1
by brian
clean slate |
1331 |
fake_select_lex->context.select_lex= fake_select_lex; |
1332 |
||
1333 |
if (!is_union()) |
|
1334 |
{
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
1335 |
/*
|
1336 |
This works only for
|
|
327.2.3
by Brian Aker
Refactoring of class Table |
1337 |
(SELECT ... order_st BY list [LIMIT n]) order_st BY order_list [LIMIT m],
|
1338 |
(SELECT ... LIMIT n) order_st BY order_list [LIMIT m]
|
|
1
by brian
clean slate |
1339 |
just before the parser starts processing order_list
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
1340 |
*/
|
1
by brian
clean slate |
1341 |
global_parameters= fake_select_lex; |
1342 |
fake_select_lex->no_table_names_allowed= 1; |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1343 |
session_arg->lex->current_select= fake_select_lex; |
1
by brian
clean slate |
1344 |
}
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1345 |
session_arg->lex->pop_context(); |
51.1.61
by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE |
1346 |
return(0); |
1
by brian
clean slate |
1347 |
}
|
1348 |
||
1349 |
||
1350 |
/**
|
|
1351 |
Push a new name resolution context for a JOIN ... ON clause to the
|
|
1352 |
context stack of a query block.
|
|
1353 |
||
1354 |
Create a new name resolution context for a JOIN ... ON clause,
|
|
1355 |
set the first and last leaves of the list of table references
|
|
1356 |
to be used for name resolution, and push the newly created
|
|
1357 |
context to the stack of contexts of the query.
|
|
1358 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
1359 |
@param session pointer to current thread
|
1
by brian
clean slate |
1360 |
@param left_op left operand of the JOIN
|
1361 |
@param right_op rigth operand of the JOIN
|
|
1362 |
||
1363 |
@retval
|
|
55
by brian
Update for using real bool types. |
1364 |
false if all is OK
|
1
by brian
clean slate |
1365 |
@retval
|
55
by brian
Update for using real bool types. |
1366 |
true if a memory allocation error occured
|
1
by brian
clean slate |
1367 |
*/
|
1368 |
||
1369 |
bool
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1370 |
push_new_name_resolution_context(Session *session, |
327.2.4
by Brian Aker
Refactoring table.h |
1371 |
TableList *left_op, TableList *right_op) |
1
by brian
clean slate |
1372 |
{
|
1373 |
Name_resolution_context *on_context; |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1374 |
if (!(on_context= new (session->mem_root) Name_resolution_context)) |
55
by brian
Update for using real bool types. |
1375 |
return true; |
1
by brian
clean slate |
1376 |
on_context->init(); |
1377 |
on_context->first_name_resolution_table= |
|
1378 |
left_op->first_leaf_for_name_resolution(); |
|
1379 |
on_context->last_name_resolution_table= |
|
1380 |
right_op->last_leaf_for_name_resolution(); |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1381 |
return session->lex->push_context(on_context); |
1
by brian
clean slate |
1382 |
}
|
1383 |
||
1384 |
||
1385 |
/**
|
|
1386 |
Add an ON condition to the second operand of a JOIN ... ON.
|
|
1387 |
||
1388 |
Add an ON condition to the right operand of a JOIN ... ON clause.
|
|
1389 |
||
1390 |
@param b the second operand of a JOIN ... ON
|
|
1391 |
@param expr the condition to be added to the ON clause
|
|
1392 |
||
1393 |
@retval
|
|
55
by brian
Update for using real bool types. |
1394 |
false if there was some error
|
1
by brian
clean slate |
1395 |
@retval
|
55
by brian
Update for using real bool types. |
1396 |
true if all is OK
|
1
by brian
clean slate |
1397 |
*/
|
1398 |
||
327.2.4
by Brian Aker
Refactoring table.h |
1399 |
void add_join_on(TableList *b, Item *expr) |
1
by brian
clean slate |
1400 |
{
|
1401 |
if (expr) |
|
1402 |
{
|
|
1403 |
if (!b->on_expr) |
|
1404 |
b->on_expr= expr; |
|
1405 |
else
|
|
1406 |
{
|
|
1407 |
/*
|
|
1408 |
If called from the parser, this happens if you have both a
|
|
1409 |
right and left join. If called later, it happens if we add more
|
|
1410 |
than one condition to the ON clause.
|
|
1411 |
*/
|
|
1412 |
b->on_expr= new Item_cond_and(b->on_expr,expr); |
|
1413 |
}
|
|
1414 |
b->on_expr->top_level_item(); |
|
1415 |
}
|
|
1416 |
}
|
|
1417 |
||
1418 |
||
1419 |
/**
|
|
1420 |
Mark that there is a NATURAL JOIN or JOIN ... USING between two
|
|
1421 |
tables.
|
|
1422 |
||
1423 |
This function marks that table b should be joined with a either via
|
|
1424 |
a NATURAL JOIN or via JOIN ... USING. Both join types are special
|
|
1425 |
cases of each other, so we treat them together. The function
|
|
1426 |
setup_conds() creates a list of equal condition between all fields
|
|
1427 |
of the same name for NATURAL JOIN or the fields in 'using_fields'
|
|
1428 |
for JOIN ... USING. The list of equality conditions is stored
|
|
1429 |
either in b->on_expr, or in JOIN::conds, depending on whether there
|
|
1430 |
was an outer join.
|
|
1431 |
||
1432 |
EXAMPLE
|
|
1433 |
@verbatim
|
|
1434 |
SELECT * FROM t1 NATURAL LEFT JOIN t2
|
|
1435 |
<=>
|
|
1436 |
SELECT * FROM t1 LEFT JOIN t2 ON (t1.i=t2.i and t1.j=t2.j ... )
|
|
1437 |
||
1438 |
SELECT * FROM t1 NATURAL JOIN t2 WHERE <some_cond>
|
|
1439 |
<=>
|
|
1440 |
SELECT * FROM t1, t2 WHERE (t1.i=t2.i and t1.j=t2.j and <some_cond>)
|
|
1441 |
||
1442 |
SELECT * FROM t1 JOIN t2 USING(j) WHERE <some_cond>
|
|
1443 |
<=>
|
|
1444 |
SELECT * FROM t1, t2 WHERE (t1.j=t2.j and <some_cond>)
|
|
1445 |
@endverbatim
|
|
1446 |
||
1447 |
@param a Left join argument
|
|
1448 |
@param b Right join argument
|
|
1449 |
@param using_fields Field names from USING clause
|
|
1450 |
*/
|
|
1451 |
||
327.2.4
by Brian Aker
Refactoring table.h |
1452 |
void add_join_natural(TableList *a, TableList *b, List<String> *using_fields, |
846
by Brian Aker
Removing on typedeffed class. |
1453 |
Select_Lex *lex) |
1
by brian
clean slate |
1454 |
{
|
1455 |
b->natural_join= a; |
|
1456 |
lex->prev_join_using= using_fields; |
|
1457 |
}
|
|
1458 |
||
1459 |
||
1460 |
/**
|
|
1461 |
kill on thread.
|
|
1462 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
1463 |
@param session Thread class
|
1
by brian
clean slate |
1464 |
@param id Thread id
|
1465 |
@param only_kill_query Should it kill the query or the connection
|
|
1466 |
||
1467 |
@note
|
|
1468 |
This is written such that we have a short lock on LOCK_thread_count
|
|
1469 |
*/
|
|
1470 |
||
230.1.9
by Monty Taylor
Merged in remove-include-dir. |
1471 |
static unsigned int |
575.1.2
by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead. |
1472 |
kill_one_thread(Session *, ulong id, bool only_kill_query) |
1
by brian
clean slate |
1473 |
{
|
1014.7.3
by Nathan Williams
Reformatted refactored bits per monty's suggestion. |
1474 |
Session *tmp= NULL; |
438.1.13
by Brian Aker
uint cleanup. |
1475 |
uint32_t error=ER_NO_SUCH_THREAD; |
398.1.10
by Monty Taylor
Actually removed VOID() this time. |
1476 |
pthread_mutex_lock(&LOCK_thread_count); // For unlink from list |
1014.7.1
by Nathan Williams
Replaced global I_List<Session> with std::vector<Session*> |
1477 |
|
1014.7.3
by Nathan Williams
Reformatted refactored bits per monty's suggestion. |
1478 |
for( vector<Session*>::iterator it= session_list.begin(); it != session_list.end(); ++it ) |
1
by brian
clean slate |
1479 |
{
|
1014.7.3
by Nathan Williams
Reformatted refactored bits per monty's suggestion. |
1480 |
if ((*it)->thread_id == id) |
1
by brian
clean slate |
1481 |
{
|
1014.7.3
by Nathan Williams
Reformatted refactored bits per monty's suggestion. |
1482 |
tmp= *it; |
1
by brian
clean slate |
1483 |
pthread_mutex_lock(&tmp->LOCK_delete); // Lock from delete |
1484 |
break; |
|
1485 |
}
|
|
1486 |
}
|
|
398.1.10
by Monty Taylor
Actually removed VOID() this time. |
1487 |
pthread_mutex_unlock(&LOCK_thread_count); |
1
by brian
clean slate |
1488 |
if (tmp) |
1489 |
{
|
|
520.1.21
by Brian Aker
THD -> Session rename |
1490 |
tmp->awake(only_kill_query ? Session::KILL_QUERY : Session::KILL_CONNECTION); |
1
by brian
clean slate |
1491 |
error=0; |
1492 |
pthread_mutex_unlock(&tmp->LOCK_delete); |
|
1493 |
}
|
|
51.1.61
by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE |
1494 |
return(error); |
1
by brian
clean slate |
1495 |
}
|
1496 |
||
1497 |
||
1498 |
/*
|
|
1499 |
kills a thread and sends response
|
|
1500 |
||
1501 |
SYNOPSIS
|
|
1502 |
sql_kill()
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1503 |
session Thread class
|
1
by brian
clean slate |
1504 |
id Thread id
|
1505 |
only_kill_query Should it kill the query or the connection
|
|
1506 |
*/
|
|
1507 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
1508 |
void sql_kill(Session *session, ulong id, bool only_kill_query) |
1
by brian
clean slate |
1509 |
{
|
438.1.13
by Brian Aker
uint cleanup. |
1510 |
uint32_t error; |
520.1.22
by Brian Aker
Second pass of thd cleanup |
1511 |
if (!(error= kill_one_thread(session, id, only_kill_query))) |
836
by Brian Aker
Fixed session call from function to method. |
1512 |
session->my_ok(); |
1
by brian
clean slate |
1513 |
else
|
1514 |
my_error(error, MYF(0), id); |
|
1515 |
}
|
|
1516 |
||
1517 |
||
1518 |
/**
|
|
1519 |
Check if the select is a simple select (not an union).
|
|
1520 |
||
1521 |
@retval
|
|
1522 |
0 ok
|
|
1523 |
@retval
|
|
1524 |
1 error ; In this case the error messege is sent to the client
|
|
1525 |
*/
|
|
1526 |
||
1527 |
bool check_simple_select() |
|
1528 |
{
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1529 |
Session *session= current_session; |
1530 |
LEX *lex= session->lex; |
|
1
by brian
clean slate |
1531 |
if (lex->current_select != &lex->select_lex) |
1532 |
{
|
|
1533 |
char command[80]; |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1534 |
Lex_input_stream *lip= session->m_lip; |
629.5.2
by Toru Maesaka
Second pass of replacing MySQL's strmake() with libc calls |
1535 |
strncpy(command, lip->yylval->symbol.str, |
1067.4.4
by Nathan Williams
The rest of the files in the drizzled directory were purged of the cmin macro and replace with std::min (except for the definition in globals.h and 1 usage in stacktrace.cc). |
1536 |
min(lip->yylval->symbol.length, (uint32_t)(sizeof(command)-1))); |
1537 |
command[min(lip->yylval->symbol.length, (uint32_t)(sizeof(command)-1))]=0; |
|
1
by brian
clean slate |
1538 |
my_error(ER_CANT_USE_OPTION_HERE, MYF(0), command); |
1539 |
return 1; |
|
1540 |
}
|
|
1541 |
return 0; |
|
1542 |
}
|
|
1543 |
||
1544 |
||
1545 |
/**
|
|
1546 |
Construct ALL/ANY/SOME subquery Item.
|
|
1547 |
||
1548 |
@param left_expr pointer to left expression
|
|
1549 |
@param cmp compare function creator
|
|
1550 |
@param all true if we create ALL subquery
|
|
1551 |
@param select_lex pointer on parsed subquery structure
|
|
1552 |
||
1553 |
@return
|
|
1554 |
constructed Item (or 0 if out of memory)
|
|
1555 |
*/
|
|
1556 |
Item * all_any_subquery_creator(Item *left_expr, |
|
584.1.15
by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes. |
1557 |
chooser_compare_func_creator cmp, |
1558 |
bool all, |
|
846
by Brian Aker
Removing on typedeffed class. |
1559 |
Select_Lex *select_lex) |
1
by brian
clean slate |
1560 |
{
|
1561 |
if ((cmp == &comp_eq_creator) && !all) // = ANY <=> IN |
|
1562 |
return new Item_in_subselect(left_expr, select_lex); |
|
1563 |
||
1564 |
if ((cmp == &comp_ne_creator) && all) // <> ALL <=> NOT IN |
|
1565 |
return new Item_func_not(new Item_in_subselect(left_expr, select_lex)); |
|
1566 |
||
1567 |
Item_allany_subselect *it= |
|
1568 |
new Item_allany_subselect(left_expr, cmp, select_lex, all); |
|
1569 |
if (all) |
|
1570 |
return it->upper_item= new Item_func_not_all(it); /* ALL */ |
|
1571 |
||
1572 |
return it->upper_item= new Item_func_nop_all(it); /* ANY/SOME */ |
|
1573 |
}
|
|
1574 |
||
1575 |
||
1576 |
/**
|
|
826
by Brian Aker
Simplify update |
1577 |
Update query pre-check.
|
1
by brian
clean slate |
1578 |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1579 |
@param session Thread handler
|
1
by brian
clean slate |
1580 |
@param tables Global/local table list (have to be the same)
|
1581 |
||
1582 |
@retval
|
|
55
by brian
Update for using real bool types. |
1583 |
false OK
|
1
by brian
clean slate |
1584 |
@retval
|
55
by brian
Update for using real bool types. |
1585 |
true Error
|
1
by brian
clean slate |
1586 |
*/
|
1587 |
||
826
by Brian Aker
Simplify update |
1588 |
bool update_precheck(Session *session, TableList *) |
1
by brian
clean slate |
1589 |
{
|
1590 |
const char *msg= 0; |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1591 |
LEX *lex= session->lex; |
846
by Brian Aker
Removing on typedeffed class. |
1592 |
Select_Lex *select_lex= &lex->select_lex; |
1
by brian
clean slate |
1593 |
|
826
by Brian Aker
Simplify update |
1594 |
if (session->lex->select_lex.item_list.elements != session->lex->value_list.elements) |
1
by brian
clean slate |
1595 |
{
|
1596 |
my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0)); |
|
51.1.61
by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE |
1597 |
return(true); |
1
by brian
clean slate |
1598 |
}
|
1599 |
||
826
by Brian Aker
Simplify update |
1600 |
if (session->lex->select_lex.table_list.elements > 1) |
1
by brian
clean slate |
1601 |
{
|
826
by Brian Aker
Simplify update |
1602 |
if (select_lex->order_list.elements) |
1603 |
msg= "ORDER BY"; |
|
1604 |
else if (select_lex->select_limit) |
|
1605 |
msg= "LIMIT"; |
|
1606 |
if (msg) |
|
1607 |
{
|
|
1608 |
my_error(ER_WRONG_USAGE, MYF(0), "UPDATE", msg); |
|
1609 |
return(true); |
|
1610 |
}
|
|
1
by brian
clean slate |
1611 |
}
|
51.1.61
by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE |
1612 |
return(false); |
1
by brian
clean slate |
1613 |
}
|
1614 |
||
1615 |
||
1616 |
/**
|
|
1617 |
simple INSERT query pre-check.
|
|
1618 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
1619 |
@param session Thread handler
|
1
by brian
clean slate |
1620 |
@param tables Global table list
|
1621 |
||
1622 |
@retval
|
|
55
by brian
Update for using real bool types. |
1623 |
false OK
|
1
by brian
clean slate |
1624 |
@retval
|
55
by brian
Update for using real bool types. |
1625 |
true error
|
1
by brian
clean slate |
1626 |
*/
|
1627 |
||
575.1.2
by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead. |
1628 |
bool insert_precheck(Session *session, TableList *) |
1
by brian
clean slate |
1629 |
{
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1630 |
LEX *lex= session->lex; |
1
by brian
clean slate |
1631 |
|
1632 |
/*
|
|
1633 |
Check that we have modify privileges for the first table and
|
|
1634 |
select privileges for the rest
|
|
1635 |
*/
|
|
1636 |
if (lex->update_list.elements != lex->value_list.elements) |
|
1637 |
{
|
|
1638 |
my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0)); |
|
51.1.61
by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE |
1639 |
return(true); |
1
by brian
clean slate |
1640 |
}
|
51.1.61
by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE |
1641 |
return(false); |
1
by brian
clean slate |
1642 |
}
|
1643 |
||
1644 |
||
1645 |
/**
|
|
1646 |
CREATE TABLE query pre-check.
|
|
1647 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
1648 |
@param session Thread handler
|
1
by brian
clean slate |
1649 |
@param tables Global table list
|
1650 |
@param create_table Table which will be created
|
|
1651 |
||
1652 |
@retval
|
|
55
by brian
Update for using real bool types. |
1653 |
false OK
|
1
by brian
clean slate |
1654 |
@retval
|
55
by brian
Update for using real bool types. |
1655 |
true Error
|
1
by brian
clean slate |
1656 |
*/
|
1657 |
||
1223.4.1
by Brian Aker
Table Identifier patch. |
1658 |
bool create_table_precheck(TableIdentifier &identifier) |
1
by brian
clean slate |
1659 |
{
|
1223.4.1
by Brian Aker
Table Identifier patch. |
1660 |
if (strcmp(identifier.getDBName(), "information_schema") == 0) |
1
by brian
clean slate |
1661 |
{
|
575.4.7
by Monty Taylor
More header cleanup. |
1662 |
my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), "", "", INFORMATION_SCHEMA_NAME.c_str()); |
1223.4.1
by Brian Aker
Table Identifier patch. |
1663 |
return true; |
1
by brian
clean slate |
1664 |
}
|
1665 |
||
1223.4.1
by Brian Aker
Table Identifier patch. |
1666 |
return false; |
1
by brian
clean slate |
1667 |
}
|
1668 |
||
1669 |
||
1670 |
/**
|
|
1671 |
negate given expression.
|
|
1672 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
1673 |
@param session thread handler
|
1
by brian
clean slate |
1674 |
@param expr expression for negation
|
1675 |
||
1676 |
@return
|
|
1677 |
negated expression
|
|
1678 |
*/
|
|
1679 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
1680 |
Item *negate_expression(Session *session, Item *expr) |
1
by brian
clean slate |
1681 |
{
|
1682 |
Item *negated; |
|
1683 |
if (expr->type() == Item::FUNC_ITEM && |
|
1684 |
((Item_func *) expr)->functype() == Item_func::NOT_FUNC) |
|
1685 |
{
|
|
1686 |
/* it is NOT(NOT( ... )) */
|
|
1687 |
Item *arg= ((Item_func *) expr)->arguments()[0]; |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1688 |
enum_parsing_place place= session->lex->current_select->parsing_place; |
1
by brian
clean slate |
1689 |
if (arg->is_bool_func() || place == IN_WHERE || place == IN_HAVING) |
1690 |
return arg; |
|
1691 |
/*
|
|
1692 |
if it is not boolean function then we have to emulate value of
|
|
1693 |
not(not(a)), it will be a != 0
|
|
1694 |
*/
|
|
1695 |
return new Item_func_ne(arg, new Item_int((char*) "0", 0, 1)); |
|
1696 |
}
|
|
1697 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
1698 |
if ((negated= expr->neg_transformer(session)) != 0) |
1
by brian
clean slate |
1699 |
return negated; |
1700 |
return new Item_func_not(expr); |
|
1701 |
}
|
|
1702 |
||
1703 |
||
1704 |
/*
|
|
1705 |
Check that char length of a string does not exceed some limit.
|
|
1706 |
||
1707 |
SYNOPSIS
|
|
1708 |
check_string_char_length()
|
|
1709 |
str string to be checked
|
|
1710 |
err_msg error message to be displayed if the string is too long
|
|
1711 |
max_char_length max length in symbols
|
|
1712 |
cs string charset
|
|
1713 |
||
1714 |
RETURN
|
|
55
by brian
Update for using real bool types. |
1715 |
false the passed string is not longer than max_char_length
|
1716 |
true the passed string is longer than max_char_length
|
|
1
by brian
clean slate |
1717 |
*/
|
1718 |
||
1719 |
||
1720 |
bool check_string_char_length(LEX_STRING *str, const char *err_msg, |
|
438.1.13
by Brian Aker
uint cleanup. |
1721 |
uint32_t max_char_length, const CHARSET_INFO * const cs, |
1
by brian
clean slate |
1722 |
bool no_error) |
1723 |
{
|
|
1724 |
int well_formed_error; |
|
438.1.13
by Brian Aker
uint cleanup. |
1725 |
uint32_t res= cs->cset->well_formed_len(cs, str->str, str->str + str->length, |
1
by brian
clean slate |
1726 |
max_char_length, &well_formed_error); |
1727 |
||
1728 |
if (!well_formed_error && str->length == res) |
|
55
by brian
Update for using real bool types. |
1729 |
return false; |
1
by brian
clean slate |
1730 |
|
1731 |
if (!no_error) |
|
1732 |
my_error(ER_WRONG_STRING_LENGTH, MYF(0), str->str, err_msg, max_char_length); |
|
55
by brian
Update for using real bool types. |
1733 |
return true; |
1
by brian
clean slate |
1734 |
}
|
1735 |
||
1736 |
||
575.4.7
by Monty Taylor
More header cleanup. |
1737 |
bool check_identifier_name(LEX_STRING *str, uint32_t err_code, |
1738 |
uint32_t max_char_length, |
|
1739 |
const char *param_for_err_msg) |
|
1
by brian
clean slate |
1740 |
{
|
1741 |
/*
|
|
1742 |
We don't support non-BMP characters in identifiers at the moment,
|
|
1743 |
so they should be prohibited until such support is done.
|
|
1744 |
This is why we use the 3-byte utf8 to check well-formedness here.
|
|
1745 |
*/
|
|
760
by Brian Aker
Cleanup around UTf8 code. |
1746 |
const CHARSET_INFO * const cs= &my_charset_utf8mb4_general_ci; |
1747 |
||
1
by brian
clean slate |
1748 |
int well_formed_error; |
438.1.13
by Brian Aker
uint cleanup. |
1749 |
uint32_t res= cs->cset->well_formed_len(cs, str->str, str->str + str->length, |
1
by brian
clean slate |
1750 |
max_char_length, &well_formed_error); |
1751 |
||
1752 |
if (well_formed_error) |
|
1753 |
{
|
|
1754 |
my_error(ER_INVALID_CHARACTER_STRING, MYF(0), "identifier", str->str); |
|
55
by brian
Update for using real bool types. |
1755 |
return true; |
1
by brian
clean slate |
1756 |
}
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
1757 |
|
1
by brian
clean slate |
1758 |
if (str->length == res) |
55
by brian
Update for using real bool types. |
1759 |
return false; |
1
by brian
clean slate |
1760 |
|
1761 |
switch (err_code) |
|
1762 |
{
|
|
1763 |
case 0: |
|
1764 |
break; |
|
1765 |
case ER_WRONG_STRING_LENGTH: |
|
1766 |
my_error(err_code, MYF(0), str->str, param_for_err_msg, max_char_length); |
|
1767 |
break; |
|
1768 |
case ER_TOO_LONG_IDENT: |
|
1769 |
my_error(err_code, MYF(0), str->str); |
|
1770 |
break; |
|
1771 |
default: |
|
51.1.61
by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE |
1772 |
assert(0); |
1
by brian
clean slate |
1773 |
break; |
1774 |
}
|
|
55
by brian
Update for using real bool types. |
1775 |
return true; |
1
by brian
clean slate |
1776 |
}
|
1777 |
||
520.4.50
by Monty Taylor
Finish changing the bison namespace argument from MYSQL to DRIZZLE |
1778 |
extern int DRIZZLEparse(void *session); // from sql_yacc.cc |
1
by brian
clean slate |
1779 |
|
1780 |
||
1781 |
/**
|
|
520.4.50
by Monty Taylor
Finish changing the bison namespace argument from MYSQL to DRIZZLE |
1782 |
This is a wrapper of DRIZZLEparse(). All the code should call parse_sql()
|
1783 |
instead of DRIZZLEparse().
|
|
1
by brian
clean slate |
1784 |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1785 |
@param session Thread context.
|
1
by brian
clean slate |
1786 |
@param lip Lexer context.
|
1787 |
||
1788 |
@return Error status.
|
|
55
by brian
Update for using real bool types. |
1789 |
@retval false on success.
|
1790 |
@retval true on parsing error.
|
|
1
by brian
clean slate |
1791 |
*/
|
1792 |
||
1165.1.48
by Stewart Smith
make parse_sql static to sql_parse.cc |
1793 |
static bool parse_sql(Session *session, Lex_input_stream *lip) |
1
by brian
clean slate |
1794 |
{
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1795 |
assert(session->m_lip == NULL); |
1
by brian
clean slate |
1796 |
|
1126.10.15
by Padraig O'Sullivan
Added calls to the parsing related dtrace probes. |
1797 |
DRIZZLE_QUERY_PARSE_START(session->query); |
1798 |
||
1
by brian
clean slate |
1799 |
/* Set Lex_input_stream. */
|
1800 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
1801 |
session->m_lip= lip; |
1
by brian
clean slate |
1802 |
|
1803 |
/* Parse the query. */
|
|
1804 |
||
520.4.50
by Monty Taylor
Finish changing the bison namespace argument from MYSQL to DRIZZLE |
1805 |
bool mysql_parse_status= DRIZZLEparse(session) != 0; |
520.1.22
by Brian Aker
Second pass of thd cleanup |
1806 |
|
520.4.50
by Monty Taylor
Finish changing the bison namespace argument from MYSQL to DRIZZLE |
1807 |
/* Check that if DRIZZLEparse() failed, session->is_error() is set. */
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1808 |
|
1809 |
assert(!mysql_parse_status || session->is_error()); |
|
1
by brian
clean slate |
1810 |
|
1811 |
/* Reset Lex_input_stream. */
|
|
1812 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
1813 |
session->m_lip= NULL; |
1
by brian
clean slate |
1814 |
|
1126.10.15
by Padraig O'Sullivan
Added calls to the parsing related dtrace probes. |
1815 |
DRIZZLE_QUERY_PARSE_DONE(mysql_parse_status || session->is_fatal_error); |
1816 |
||
1
by brian
clean slate |
1817 |
/* That's it. */
|
1818 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
1819 |
return mysql_parse_status || session->is_fatal_error; |
1
by brian
clean slate |
1820 |
}
|
1821 |
||
1822 |
/**
|
|
1823 |
@} (end of group Runtime_Environment)
|
|
1824 |
*/
|