13
13
along with this program; if not, write to the Free Software
14
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
18
18
#define DRIZZLE_LEX 1
20
#include <drizzled/item/num.h>
21
#include <drizzled/abort_exception.h>
20
22
#include <drizzled/my_hash.h>
21
23
#include <drizzled/error.h>
22
24
#include <drizzled/nested_join.h>
23
25
#include <drizzled/query_id.h>
24
#include "drizzled/transaction_services.h"
26
#include <drizzled/transaction_services.h>
25
27
#include <drizzled/sql_parse.h>
26
28
#include <drizzled/data_home.h>
27
29
#include <drizzled/sql_base.h>
28
30
#include <drizzled/show.h>
29
#include <drizzled/db.h>
30
31
#include <drizzled/function/time/unix_timestamp.h>
31
32
#include <drizzled/function/get_system_var.h>
32
33
#include <drizzled/item/cmpfunc.h>
33
34
#include <drizzled/item/null.h>
34
35
#include <drizzled/session.h>
36
#include <drizzled/session/cache.h>
35
37
#include <drizzled/sql_load.h>
36
38
#include <drizzled/lock.h>
37
39
#include <drizzled/select_send.h>
38
40
#include <drizzled/plugin/client.h>
39
41
#include <drizzled/statement.h>
40
42
#include <drizzled/statement/alter_table.h>
41
#include "drizzled/probes.h"
42
#include "drizzled/session/cache.h"
43
#include "drizzled/global_charset_info.h"
45
#include "drizzled/plugin/logging.h"
46
#include "drizzled/plugin/query_rewrite.h"
47
#include "drizzled/plugin/query_cache.h"
48
#include "drizzled/plugin/authorization.h"
49
#include "drizzled/optimizer/explain_plan.h"
50
#include "drizzled/pthread_globals.h"
51
#include "drizzled/plugin/event_observer.h"
43
#include <drizzled/probes.h>
44
#include <drizzled/global_charset_info.h>
45
#include <drizzled/plugin/logging.h>
46
#include <drizzled/plugin/query_rewrite.h>
47
#include <drizzled/plugin/query_cache.h>
48
#include <drizzled/plugin/authorization.h>
49
#include <drizzled/optimizer/explain_plan.h>
50
#include <drizzled/pthread_globals.h>
51
#include <drizzled/plugin/event_observer.h>
52
#include <drizzled/display.h>
53
#include <drizzled/visibility.h>
54
#include <drizzled/kill.h>
55
#include <drizzled/schema.h>
56
#include <drizzled/item/subselect.h>
53
58
#include <limits.h>
56
61
#include <algorithm>
57
62
#include <boost/date_time.hpp>
58
#include "drizzled/internal/my_sys.h"
63
#include <drizzled/internal/my_sys.h>
60
65
using namespace std;
62
extern int DRIZZLEparse(void *session); // from sql_yacc.cc
67
extern int base_sql_parse(drizzled::Session *session); // from sql_yacc.cc
68
bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
73
bool my_yyoverflow(short **a, ParserType **b, ulong *yystacksize);
69
74
static bool parse_sql(Session *session, Lex_input_stream *lip);
70
void mysql_parse(Session *session, const char *inBuf, uint32_t length);
75
void parse(Session *session, const char *inBuf, uint32_t length);
73
78
@defgroup Runtime_Environment Runtime Environment
77
82
extern size_t my_thread_stack_size;
78
83
extern const CHARSET_INFO *character_set_filesystem;
80
const LEX_STRING command_name[COM_END+1]={
81
{ C_STRING_WITH_LEN("Sleep") },
82
{ C_STRING_WITH_LEN("Quit") },
83
{ C_STRING_WITH_LEN("Init DB") },
84
{ C_STRING_WITH_LEN("Query") },
85
{ C_STRING_WITH_LEN("Shutdown") },
86
{ C_STRING_WITH_LEN("Connect") },
87
{ C_STRING_WITH_LEN("Ping") },
88
{ C_STRING_WITH_LEN("Error") } // Last command number
88
static const std::string command_name[COM_END+1]={
97
"Error" // Last command number
91
102
const char *xa_state_names[]={
92
103
"NON-EXISTING", "ACTIVE", "IDLE", "PREPARED"
224
241
session->thread_id,
225
242
const_cast<const char *>(session->schema()->c_str()));
227
mysql_parse(session, session->getQueryString()->c_str(), session->getQueryString()->length());
244
parse(session, session->getQueryString()->c_str(), session->getQueryString()->length());
232
249
/* We don't calculate statistics for this command */
233
250
session->main_da.disable_status(); // Don't send anything back
234
error=true; // End server
251
error= true; // End server
255
if (packet_length != 4)
257
my_error(ER_NO_SUCH_THREAD, MYF(0), 0);
263
memcpy(&kill_id, packet, sizeof(uint32_t));
265
kill_id= ntohl(kill_id);
266
(void)drizzled::kill(*session->user(), kill_id, true);
236
271
case COM_SHUTDOWN:
238
273
session->status_var.com_other++;
239
274
session->my_eof();
240
275
session->close_thread_tables(); // Free before kill
283
318
case Diagnostics_area::DA_ERROR:
284
319
/* The query failed, send error to log and abort bootstrap. */
285
session->client->sendError(session->main_da.sql_errno(),
320
session->getClient()->sendError(session->main_da.sql_errno(),
286
321
session->main_da.message());
289
324
case Diagnostics_area::DA_EOF:
290
session->client->sendEOF();
325
session->getClient()->sendEOF();
293
328
case Diagnostics_area::DA_OK:
294
session->client->sendOK();
329
session->getClient()->sendOK();
297
332
case Diagnostics_area::DA_DISABLED:
453
489
assert(first_table == all_tables);
454
490
assert(first_table == all_tables && first_table != 0);
456
lex->first_lists_tables_same();
492
session->getLex()->first_lists_tables_same();
457
494
/* should be assigned after making first tables same */
458
all_tables= lex->query_tables;
495
all_tables= session->getLex()->query_tables;
459
497
/* set context for commands which do not use setup_tables */
461
context.resolve_in_table_list_only((TableList*)select_lex->
498
select_lex->context.resolve_in_table_list_only((TableList*)select_lex->table_list.first);
465
501
Reset warning count for each query that uses tables
468
504
variables, but for now this is probably good enough.
469
505
Don't reset warnings when executing a stored routine.
471
if (all_tables || ! lex->is_single_level_stmt())
507
if (all_tables || ! session->getLex()->is_single_level_stmt())
473
509
drizzle_reset_errors(session, 0);
476
512
assert(session->transaction.stmt.hasModifiedNonTransData() == false);
514
if (! (session->server_status & SERVER_STATUS_AUTOCOMMIT)
515
&& ! session->inTransaction()
516
&& session->getLex()->statement->isTransactional())
518
if (session->startTransaction() == false)
520
my_error(drizzled::ER_UNKNOWN_ERROR, MYF(0));
478
525
/* now we are ready to execute the statement */
479
res= lex->statement->execute();
526
res= session->getLex()->statement->execute();
480
527
session->set_proc_info("query end");
482
529
The return value for ROW_COUNT() is "implementation dependent" if the
518
578
session->send_explain_fields(result);
519
579
optimizer::ExplainPlan planner;
520
res= planner.explainUnion(session, &session->lex->unit, result);
580
res= planner.explainUnion(session, &session->getLex()->unit, result);
521
581
if (lex->describe & DESCRIBE_EXTENDED)
524
584
String str(buff,(uint32_t) sizeof(buff), system_charset_info);
526
session->lex->unit.print(&str, QT_ORDINARY);
586
session->getLex()->unit.print(&str, QT_ORDINARY);
527
587
str.append('\0');
528
588
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
529
589
ER_YES, str.ptr());
604
mysql_new_select(LEX *lex, bool move_down)
665
new_select(LEX *lex, bool move_down)
606
667
Select_Lex *select_lex;
607
668
Session *session= lex->session;
609
670
if (!(select_lex= new (session->mem_root) Select_Lex()))
611
673
select_lex->select_number= ++session->select_number;
612
674
select_lex->parent_lex= lex; /* Used in init_query. */
613
675
select_lex->init_query();
614
676
select_lex->init_select();
615
677
lex->nest_level++;
616
679
if (lex->nest_level > (int) MAX_SELECT_NESTING)
618
681
my_error(ER_TOO_HIGH_LEVEL_OF_NESTING_FOR_SELECT,MYF(0),MAX_SELECT_NESTING);
621
685
select_lex->nest_level= lex->nest_level;
899
954
TableList *Select_Lex::add_table_to_list(Session *session,
902
const bitset<NUM_OF_TABLE_OPTIONS>& table_options,
903
thr_lock_type lock_type,
904
List<Index_hint> *index_hints_arg,
957
const bitset<NUM_OF_TABLE_OPTIONS>& table_options,
958
thr_lock_type lock_type,
959
List<Index_hint> *index_hints_arg,
905
960
LEX_STRING *option)
908
963
TableList *previous_table_ref; /* The table preceding the current one. */
910
LEX *lex= session->lex;
965
LEX *lex= session->getLex();
913
968
return NULL; // End of memory
977
1032
tables=tables->next_local)
979
if (!my_strcasecmp(table_alias_charset, alias_str, tables->alias) &&
980
!strcasecmp(ptr->getSchemaName(), tables->getSchemaName()))
1034
if (not my_strcasecmp(table_alias_charset, alias_str, tables->alias) &&
1035
not my_strcasecmp(system_charset_info, ptr->getSchemaName(), tables->getSchemaName()))
982
1037
my_error(ER_NONUNIQ_TABLE, MYF(0), alias_str);
1076
1131
TableList *Select_Lex::end_nested_join(Session *)
1078
1133
TableList *ptr;
1079
nested_join_st *nested_join;
1134
NestedJoin *nested_join;
1081
1136
assert(embedding);
1082
1137
ptr= embedding;
1083
1138
join_list= ptr->getJoinList();
1084
1139
embedding= ptr->getEmbedding();
1085
1140
nested_join= ptr->getNestedJoin();
1086
if (nested_join->join_list.elements == 1)
1141
if (nested_join->join_list.size() == 1)
1088
TableList *embedded= nested_join->join_list.head();
1143
TableList *embedded= &nested_join->join_list.front();
1089
1144
join_list->pop();
1090
1145
embedded->setJoinList(join_list);
1091
1146
embedded->setEmbedding(embedding);
1092
1147
join_list->push_front(embedded);
1095
else if (nested_join->join_list.elements == 0)
1150
else if (nested_join->join_list.size() == 0)
1097
1152
join_list->pop();
1098
1153
ptr= NULL; // return value
1117
1172
TableList *Select_Lex::nest_last_join(Session *session)
1119
1174
TableList *ptr;
1120
nested_join_st *nested_join;
1175
NestedJoin *nested_join;
1121
1176
List<TableList> *embedded_list;
1123
1178
if (!(ptr= (TableList*) session->calloc(ALIGN_SIZE(sizeof(TableList))+
1124
sizeof(nested_join_st))))
1179
sizeof(NestedJoin))))
1126
ptr->setNestedJoin(((nested_join_st*) ((unsigned char*) ptr + ALIGN_SIZE(sizeof(TableList)))));
1181
ptr->setNestedJoin(((NestedJoin*) ((unsigned char*) ptr + ALIGN_SIZE(sizeof(TableList)))));
1127
1182
nested_join= ptr->getNestedJoin();
1128
1183
ptr->setEmbedding(embedding);
1129
1184
ptr->setJoinList(join_list);
1130
1185
ptr->alias= (char*) "(nest_last_join)";
1131
1186
embedded_list= &nested_join->join_list;
1132
embedded_list->empty();
1187
embedded_list->clear();
1134
1189
for (uint32_t i=0; i < 2; i++)
1487
1540
bool update_precheck(Session *session, TableList *)
1489
1542
const char *msg= 0;
1490
LEX *lex= session->lex;
1491
Select_Lex *select_lex= &lex->select_lex;
1543
Select_Lex *select_lex= &session->getLex()->select_lex;
1493
if (session->lex->select_lex.item_list.elements != session->lex->value_list.elements)
1545
if (session->getLex()->select_lex.item_list.size() != session->getLex()->value_list.size())
1495
1547
my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0));
1499
if (session->lex->select_lex.table_list.elements > 1)
1551
if (session->getLex()->select_lex.table_list.size() > 1)
1501
if (select_lex->order_list.elements)
1553
if (select_lex->order_list.size())
1502
1554
msg= "ORDER BY";
1503
1555
else if (select_lex->select_limit)
1675
1726
/* Parse the query. */
1677
bool mysql_parse_status= DRIZZLEparse(session) != 0;
1728
bool parse_status= base_sql_parse(session) != 0;
1679
1730
/* Check that if DRIZZLEparse() failed, session->is_error() is set. */
1681
assert(!mysql_parse_status || session->is_error());
1732
assert(!parse_status || session->is_error());
1683
1734
/* Reset Lex_input_stream. */
1685
1736
session->m_lip= NULL;
1687
DRIZZLE_QUERY_PARSE_DONE(mysql_parse_status || session->is_fatal_error);
1738
DRIZZLE_QUERY_PARSE_DONE(parse_status || session->is_fatal_error);
1689
1740
/* That's it. */
1691
return mysql_parse_status || session->is_fatal_error;
1742
return parse_status || session->is_fatal_error;