12
12
You should have received a copy of the GNU General Public License
13
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
18
18
#define DRIZZLE_LEX 1
20
#include <drizzled/item/num.h>
21
#include <drizzled/abort_exception.h>
22
20
#include <drizzled/my_hash.h>
23
21
#include <drizzled/error.h>
24
22
#include <drizzled/nested_join.h>
25
23
#include <drizzled/query_id.h>
26
#include <drizzled/transaction_services.h>
27
24
#include <drizzled/sql_parse.h>
28
25
#include <drizzled/data_home.h>
29
26
#include <drizzled/sql_base.h>
30
27
#include <drizzled/show.h>
28
#include <drizzled/db.h>
29
#include <drizzled/plugin/info_schema_table.h>
31
30
#include <drizzled/function/time/unix_timestamp.h>
32
31
#include <drizzled/function/get_system_var.h>
33
32
#include <drizzled/item/cmpfunc.h>
34
33
#include <drizzled/item/null.h>
35
34
#include <drizzled/session.h>
36
#include <drizzled/session/cache.h>
37
35
#include <drizzled/sql_load.h>
38
36
#include <drizzled/lock.h>
39
37
#include <drizzled/select_send.h>
40
38
#include <drizzled/plugin/client.h>
41
39
#include <drizzled/statement.h>
42
40
#include <drizzled/statement/alter_table.h>
43
#include <drizzled/probes.h>
44
#include <drizzled/global_charset_info.h>
46
#include <drizzled/plugin/logging.h>
47
#include <drizzled/plugin/query_rewrite.h>
48
#include <drizzled/plugin/query_cache.h>
49
#include <drizzled/plugin/authorization.h>
50
#include <drizzled/optimizer/explain_plan.h>
51
#include <drizzled/pthread_globals.h>
52
#include <drizzled/plugin/event_observer.h>
53
#include <drizzled/visibility.h>
55
#include <drizzled/schema.h>
41
#include "drizzled/probes.h"
42
#include "drizzled/session_list.h"
43
#include "drizzled/global_charset_info.h"
44
#include "drizzled/transaction_services.h"
46
#include "drizzled/plugin/logging.h"
47
#include "drizzled/plugin/info_schema_table.h"
48
#include "drizzled/optimizer/explain_plan.h"
49
#include "drizzled/pthread_globals.h"
57
51
#include <limits.h>
60
54
#include <algorithm>
61
#include <boost/date_time.hpp>
62
#include <drizzled/internal/my_sys.h>
56
#include "drizzled/internal/my_sys.h"
64
58
using namespace std;
66
extern int base_sql_parse(drizzled::Session *session); // from sql_yacc.cc
60
extern int DRIZZLEparse(void *session); // from sql_yacc.cc
72
bool my_yyoverflow(short **a, ParserType **b, ulong *yystacksize);
66
bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
73
67
static bool parse_sql(Session *session, Lex_input_stream *lip);
74
void parse(Session *session, const char *inBuf, uint32_t length);
68
static void mysql_parse(Session *session, const char *inBuf, uint32_t length,
69
const char ** found_semicolon);
77
72
@defgroup Runtime_Environment Runtime Environment
81
76
extern size_t my_thread_stack_size;
82
77
extern const CHARSET_INFO *character_set_filesystem;
87
static const std::string command_name[COM_END+1]={
95
"Error" // Last command number
79
const LEX_STRING command_name[COM_END+1]={
80
{ C_STRING_WITH_LEN("Sleep") },
81
{ C_STRING_WITH_LEN("Quit") },
82
{ C_STRING_WITH_LEN("Init DB") },
83
{ C_STRING_WITH_LEN("Query") },
84
{ C_STRING_WITH_LEN("Shutdown") },
85
{ C_STRING_WITH_LEN("Connect") },
86
{ C_STRING_WITH_LEN("Ping") },
87
{ C_STRING_WITH_LEN("Error") } // Last command number
100
90
const char *xa_state_names[]={
101
91
"NON-EXISTING", "ACTIVE", "IDLE", "PREPARED"
145
130
sql_command_flags[SQLCOM_REPLACE]= CF_CHANGES_DATA | CF_HAS_ROW_COUNT;
146
131
sql_command_flags[SQLCOM_REPLACE_SELECT]= CF_CHANGES_DATA | CF_HAS_ROW_COUNT;
133
sql_command_flags[SQLCOM_SHOW_STATUS]= CF_STATUS_COMMAND;
134
sql_command_flags[SQLCOM_SHOW_DATABASES]= CF_STATUS_COMMAND;
135
sql_command_flags[SQLCOM_SHOW_FIELDS]= CF_STATUS_COMMAND;
136
sql_command_flags[SQLCOM_SHOW_KEYS]= CF_STATUS_COMMAND;
137
sql_command_flags[SQLCOM_SHOW_VARIABLES]= CF_STATUS_COMMAND;
148
138
sql_command_flags[SQLCOM_SHOW_WARNS]= CF_STATUS_COMMAND;
149
139
sql_command_flags[SQLCOM_SHOW_ERRORS]= CF_STATUS_COMMAND;
140
sql_command_flags[SQLCOM_SHOW_PROCESSLIST]= CF_STATUS_COMMAND;
150
141
sql_command_flags[SQLCOM_SHOW_CREATE_DB]= CF_STATUS_COMMAND;
151
142
sql_command_flags[SQLCOM_SHOW_CREATE]= CF_STATUS_COMMAND;
144
sql_command_flags[SQLCOM_SHOW_TABLES]= (CF_STATUS_COMMAND |
145
CF_SHOW_TABLE_COMMAND);
146
sql_command_flags[SQLCOM_SHOW_TABLE_STATUS]= (CF_STATUS_COMMAND |
147
CF_SHOW_TABLE_COMMAND);
154
149
The following admin table operations are allowed
198
194
/* Increase id and count all other statements. */
200
session->status_var.questions++;
196
statistic_increment(session->status_var.questions, &LOCK_status);
204
/* @todo set session->getLex()->sql_command to SQLCOM_END here */
200
/* TODO: set session->lex->sql_command to SQLCOM_END here */
206
202
plugin::Logging::preDo(session);
207
if (unlikely(plugin::EventObserver::beforeStatement(*session)))
209
// We should do something about an error...
212
204
session->server_status&=
213
205
~(SERVER_QUERY_NO_INDEX_USED | SERVER_QUERY_NO_GOOD_INDEX_USED);
214
206
switch (command) {
215
207
case COM_INIT_DB:
217
if (packet_length == 0)
219
my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0));
223
string tmp(packet, packet_length);
225
identifier::Schema identifier(tmp);
227
if (not schema::change(*session, identifier))
210
status_var_increment(session->status_var.com_stat[SQLCOM_CHANGE_DB]);
212
tmp.length= packet_length;
213
if (!mysql_change_db(session, &tmp, false))
229
215
session->my_ok();
235
if (not session->readAndStoreQuery(packet, packet_length))
221
if (! session->readAndStoreQuery(packet, packet_length))
236
222
break; // fatal error is set
237
DRIZZLE_QUERY_START(session->getQueryString()->c_str(),
223
DRIZZLE_QUERY_START(session->query,
238
224
session->thread_id,
239
const_cast<const char *>(session->schema()->c_str()));
225
const_cast<const char *>(session->db.empty() ? "" : session->db.c_str()));
226
const char* end_of_stmt= NULL;
241
parse(session, session->getQueryString()->c_str(), session->getQueryString()->length());
228
mysql_parse(session, session->query, session->query_length, &end_of_stmt);
297
284
case Diagnostics_area::DA_ERROR:
298
285
/* The query failed, send error to log and abort bootstrap. */
299
session->getClient()->sendError(session->main_da.sql_errno(),
286
session->client->sendError(session->main_da.sql_errno(),
300
287
session->main_da.message());
303
290
case Diagnostics_area::DA_EOF:
304
session->getClient()->sendEOF();
291
session->client->sendEOF();
307
294
case Diagnostics_area::DA_OK:
308
session->getClient()->sendOK();
295
session->client->sendOK();
311
298
case Diagnostics_area::DA_DISABLED:
324
311
session->close_thread_tables();
326
313
plugin::Logging::postDo(session);
327
if (unlikely(plugin::EventObserver::afterStatement(*session)))
329
// We should do something about an error...
332
315
/* Store temp state for processlist */
333
316
session->set_proc_info("cleaning up");
334
317
session->command= COM_SLEEP;
335
session->resetQueryString();
318
memset(session->process_list_info, 0, PROCESS_LIST_WIDTH);
320
session->query_length= 0;
337
322
session->set_proc_info(NULL);
338
session->mem_root->free_root(MYF(memory::KEEP_PREALLOC));
323
free_root(session->mem_root,MYF(memory::KEEP_PREALLOC));
340
325
if (DRIZZLE_QUERY_DONE_ENABLED() || DRIZZLE_COMMAND_DONE_ENABLED())
375
360
1 out of memory or SHOW commands are not allowed
376
361
in this version of the server.
378
static bool _schema_select(Session *session, Select_Lex *sel,
379
const string& schema_table_name)
381
LEX_STRING db, table;
382
bitset<NUM_OF_TABLE_OPTIONS> table_options;
384
We have to make non const db_name & table_name
385
because of lower_case_table_names
387
session->make_lex_string(&db, "data_dictionary", sizeof("data_dictionary"), false);
388
session->make_lex_string(&table, schema_table_name, false);
390
if (! sel->add_table_to_list(session, new Table_ident(db, table),
391
NULL, table_options, TL_READ))
398
int prepare_new_schema_table(Session *session, LEX *lex,
399
const string& schema_table_name)
364
int prepare_schema_table(Session *session, LEX *lex, Table_ident *table_ident,
365
const string& schema_table_name)
401
367
Select_Lex *schema_select_lex= NULL;
370
if (schema_table_name.compare("TABLES") == 0 ||
371
schema_table_name.compare("TABLE_NAMES") == 0)
375
if (lex->select_lex.db == NULL &&
376
lex->copy_db_to(&lex->select_lex.db, &dummy))
380
schema_select_lex= new Select_Lex();
381
db.str= schema_select_lex->db= lex->select_lex.db;
382
schema_select_lex->table_list.first= NULL;
383
db.length= strlen(db.str);
385
if (check_db_name(&db))
387
my_error(ER_WRONG_DB_NAME, MYF(0), db.str);
391
else if (schema_table_name.compare("COLUMNS") == 0 ||
392
schema_table_name.compare("STATISTICS") == 0)
395
TableList **query_tables_last= lex->query_tables_last;
396
schema_select_lex= new Select_Lex();
397
/* 'parent_lex' is used in init_query() so it must be before it. */
398
schema_select_lex->parent_lex= lex;
399
schema_select_lex->init_query();
400
if (! schema_select_lex->add_table_to_list(session, table_ident, 0, 0, TL_READ))
404
lex->query_tables_last= query_tables_last;
403
407
Select_Lex *select_lex= lex->current_select;
404
408
assert(select_lex);
405
if (_schema_select(session, select_lex, schema_table_name))
409
if (make_schema_select(session, select_lex, schema_table_name))
446
static int execute_command(Session *session)
451
mysql_execute_command(Session *session)
454
LEX *lex= session->lex;
450
455
/* first Select_Lex (have special meaning for many of non-SELECTcommands) */
451
Select_Lex *select_lex= &session->getLex()->select_lex;
456
Select_Lex *select_lex= &lex->select_lex;
453
457
/* list of all tables in query */
454
458
TableList *all_tables;
459
/* A peek into the query string */
460
size_t proc_info_len= session->query_length > PROCESS_LIST_WIDTH ?
461
PROCESS_LIST_WIDTH : session->query_length;
463
memcpy(session->process_list_info, session->query, proc_info_len);
464
session->process_list_info[proc_info_len]= '\0';
457
467
In many cases first table of main Select_Lex have special meaning =>
483
493
variables, but for now this is probably good enough.
484
494
Don't reset warnings when executing a stored routine.
486
if (all_tables || ! session->getLex()->is_single_level_stmt())
496
if (all_tables || ! lex->is_single_level_stmt())
488
498
drizzle_reset_errors(session, 0);
501
status_var_increment(session->status_var.com_stat[lex->sql_command]);
491
503
assert(session->transaction.stmt.hasModifiedNonTransData() == false);
493
if (! (session->server_status & SERVER_STATUS_AUTOCOMMIT)
494
&& ! session->inTransaction()
495
&& session->getLex()->statement->isTransactional())
497
if (session->startTransaction() == false)
499
my_error(drizzled::ER_UNKNOWN_ERROR, MYF(0));
504
505
/* now we are ready to execute the statement */
505
res= session->getLex()->statement->execute();
506
res= lex->statement->execute();
506
508
session->set_proc_info("query end");
508
511
The return value for ROW_COUNT() is "implementation dependent" if the
509
512
statement is not DELETE, INSERT or UPDATE, but -1 is what JDBC and ODBC
510
513
wants. We also keep the last value in case of SQLCOM_CALL or
513
if (! (sql_command_flags[session->getLex()->sql_command].test(CF_BIT_HAS_ROW_COUNT)))
516
if (! (sql_command_flags[lex->sql_command].test(CF_BIT_HAS_ROW_COUNT)))
515
518
session->row_count_func= -1;
518
521
return (res || session->is_error());
520
524
bool execute_sqlcom_select(Session *session, TableList *all_tables)
522
LEX *lex= session->getLex();
526
LEX *lex= session->lex;
523
527
select_result *result=lex->result;
525
529
/* assign global limit variable if limit is not given */
557
548
session->send_explain_fields(result);
558
549
optimizer::ExplainPlan planner;
559
res= planner.explainUnion(session, &session->getLex()->unit, result);
550
res= planner.explainUnion(session, &session->lex->unit, result);
560
551
if (lex->describe & DESCRIBE_EXTENDED)
563
554
String str(buff,(uint32_t) sizeof(buff), system_charset_info);
565
session->getLex()->unit.print(&str, QT_ORDINARY);
556
session->lex->unit.print(&str, QT_ORDINARY);
566
557
str.append('\0');
567
558
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
568
559
ER_YES, str.ptr());
644
new_select(LEX *lex, bool move_down)
628
mysql_new_select(LEX *lex, bool move_down)
646
630
Select_Lex *select_lex;
647
631
Session *session= lex->session;
649
633
if (!(select_lex= new (session->mem_root) Select_Lex()))
652
635
select_lex->select_number= ++session->select_number;
653
636
select_lex->parent_lex= lex; /* Used in init_query. */
654
637
select_lex->init_query();
655
638
select_lex->init_select();
656
639
lex->nest_level++;
658
640
if (lex->nest_level > (int) MAX_SELECT_NESTING)
660
642
my_error(ER_TOO_HIGH_LEVEL_OF_NESTING_FOR_SELECT,MYF(0),MAX_SELECT_NESTING);
664
645
select_lex->nest_level= lex->nest_level;
756
736
@param session Current thread
757
737
@param inBuf Begining of the query text
758
738
@param length Length of the query text
739
@param[out] found_semicolon For multi queries, position of the character of
740
the next query in the query text.
761
void parse(Session *session, const char *inBuf, uint32_t length)
743
static void mysql_parse(Session *session, const char *inBuf, uint32_t length,
744
const char ** found_semicolon)
763
session->getLex()->start(session);
748
The purpose of query_cache_send_result_to_client() is to lookup the
749
query in the query cache first, to avoid parsing and executing it.
750
So, the natural implementation would be to:
751
- first, call query_cache_send_result_to_client,
752
- second, if caching failed, initialise the lexical and syntactic parser.
753
The problem is that the query cache depends on a clean initialization
754
of (among others) lex->safe_to_cache_query and session->server_status,
755
which are reset respectively in
757
- mysql_reset_session_for_next_command()
758
So, initializing the lexical analyser *before* using the query cache
759
is required for the cache to work properly.
760
FIXME: cleanup the dependencies in the code to simplify this.
765
763
session->reset_for_next_command();
766
/* Check if the Query is Cached if and return true if yes
767
* TODO the plugin has to make sure that the query is cacheble
768
* by setting the query_safe_cache param to TRUE
771
if (plugin::QueryCache::isCached(session))
773
res= plugin::QueryCache::sendCachedResultset(session);
779
LEX *lex= session->getLex();
780
Lex_input_stream lip(session, inBuf, length);
781
bool err= parse_sql(session, &lip);
766
LEX *lex= session->lex;
768
Lex_input_stream lip(session, inBuf, length);
770
bool err= parse_sql(session, &lip);
771
*found_semicolon= lip.found_semicolon;
785
if (not session->is_error())
787
DRIZZLE_QUERY_EXEC_START(session->getQueryString()->c_str(),
789
const_cast<const char *>(session->schema()->c_str()));
790
// Implement Views here --Brian
791
/* Actually execute the query */
794
execute_command(session);
798
// Just try to catch any random failures that could have come
802
DRIZZLE_QUERY_EXEC_DONE(0);
776
if (! session->is_error())
779
Binlog logs a string starting from session->query and having length
780
session->query_length; so we set session->query_length correctly (to not
781
log several statements in one event, when we executed only first).
782
We set it to not see the ';' (otherwise it would get into binlog
783
and Query_log_event::print() would give ';;' output).
784
This also helps display only the current query in SHOW
786
Note that we don't need LOCK_thread_count to modify query_length.
788
if (*found_semicolon &&
789
(session->query_length= (ulong)(*found_semicolon - session->query)))
790
session->query_length--;
791
DRIZZLE_QUERY_EXEC_START(session->query,
793
const_cast<const char *>(session->db.empty() ? "" : session->db.c_str()));
794
/* Actually execute the query */
795
mysql_execute_command(session);
796
DRIZZLE_QUERY_EXEC_DONE(0);
808
assert(session->is_error());
811
session->set_proc_info("freeing items");
812
session->end_statement();
813
session->cleanup_after_query();
814
session->set_end_timer();
802
assert(session->is_error());
805
session->set_proc_info("freeing items");
806
session->end_statement();
807
session->cleanup_after_query();
933
937
TableList *Select_Lex::add_table_to_list(Session *session,
936
const bitset<NUM_OF_TABLE_OPTIONS>& table_options,
937
thr_lock_type lock_type,
938
List<Index_hint> *index_hints_arg,
940
uint32_t table_options,
941
thr_lock_type lock_type,
942
List<Index_hint> *index_hints_arg,
945
register TableList *ptr;
942
946
TableList *previous_table_ref; /* The table preceding the current one. */
944
LEX *lex= session->getLex();
948
LEX *lex= session->lex;
947
951
return NULL; // End of memory
948
952
alias_str= alias ? alias->str : table->table.str;
949
if (! table_options.test(TL_OPTION_ALIAS) &&
953
if (!test(table_options & TL_OPTION_ALIAS) &&
950
954
check_table_name(table->table.str, table->table.length))
952
956
my_error(ER_WRONG_TABLE_NAME, MYF(0), table->table.str);
956
if (table->is_derived_table() == false && table->db.str)
960
if (table->is_derived_table() == false && table->db.str &&
961
check_db_name(&table->db))
958
my_casedn_str(files_charset_info, table->db.str);
960
identifier::Schema schema_identifier(string(table->db.str));
961
if (not schema::check(*session, schema_identifier))
964
my_error(ER_WRONG_DB_NAME, MYF(0), table->db.str);
963
my_error(ER_WRONG_DB_NAME, MYF(0), table->db.str);
969
967
if (!alias) /* Alias is case sensitive */
974
972
ER(ER_DERIVED_MUST_HAVE_ALIAS), MYF(0));
977
if (!(alias_str= (char*) session->getMemRoot()->duplicate(alias_str,table->table.length+1)))
975
if (!(alias_str= (char*) session->memdup(alias_str,table->table.length+1)))
980
978
if (!(ptr = (TableList *) session->calloc(sizeof(TableList))))
983
980
if (table->db.str)
985
ptr->setIsFqtn(true);
986
ptr->setSchemaName(table->db.str);
983
ptr->db= table->db.str;
987
984
ptr->db_length= table->db.length;
989
else if (lex->copy_db_to(ptr->getSchemaNamePtr(), &ptr->db_length))
986
else if (lex->copy_db_to(&ptr->db, &ptr->db_length))
992
ptr->setIsFqtn(false);
994
991
ptr->alias= alias_str;
995
ptr->setIsAlias(alias ? true : false);
996
ptr->setTableName(table->table.str);
992
ptr->is_alias= alias ? true : false;
993
if (table->table.length)
994
table->table.length= my_casedn_str(files_charset_info, table->table.str);
995
ptr->table_name=table->table.str;
997
996
ptr->table_name_length=table->table.length;
998
997
ptr->lock_type= lock_type;
999
ptr->force_index= table_options.test(TL_OPTION_FORCE_INDEX);
1000
ptr->ignore_leaves= table_options.test(TL_OPTION_IGNORE_LEAVES);
998
ptr->updating= test(table_options & TL_OPTION_UPDATING);
999
ptr->force_index= test(table_options & TL_OPTION_FORCE_INDEX);
1000
ptr->ignore_leaves= test(table_options & TL_OPTION_IGNORE_LEAVES);
1001
1001
ptr->derived= table->sel;
1002
if (!ptr->derived && !my_strcasecmp(system_charset_info, ptr->db,
1003
INFORMATION_SCHEMA_NAME.c_str()))
1005
plugin::InfoSchemaTable *schema_table= plugin::InfoSchemaTable::getTable(ptr->table_name);
1006
if (!schema_table ||
1007
(schema_table->isHidden() &&
1008
((sql_command_flags[lex->sql_command].test(CF_BIT_STATUS_COMMAND)) == 0 ||
1010
this check is used for show columns|keys from I_S hidden table
1012
lex->sql_command == SQLCOM_SHOW_FIELDS ||
1013
lex->sql_command == SQLCOM_SHOW_KEYS)))
1015
my_error(ER_UNKNOWN_TABLE, MYF(0),
1016
ptr->table_name, INFORMATION_SCHEMA_NAME.c_str());
1002
1020
ptr->select_lex= lex->current_select;
1003
1021
ptr->index_hints= index_hints_arg;
1004
1022
ptr->option= option ? option->str : 0;
1075
1093
bool Select_Lex::init_nested_join(Session *session)
1077
1095
TableList *ptr;
1078
NestedJoin *nested_join;
1096
nested_join_st *nested_join;
1080
1098
if (!(ptr= (TableList*) session->calloc(ALIGN_SIZE(sizeof(TableList))+
1081
sizeof(NestedJoin))))
1099
sizeof(nested_join_st))))
1083
ptr->setNestedJoin(((NestedJoin*) ((unsigned char*) ptr + ALIGN_SIZE(sizeof(TableList)))));
1084
nested_join= ptr->getNestedJoin();
1101
nested_join= ptr->nested_join=
1102
((nested_join_st*) ((unsigned char*) ptr + ALIGN_SIZE(sizeof(TableList))));
1085
1104
join_list->push_front(ptr);
1086
ptr->setEmbedding(embedding);
1087
ptr->setJoinList(join_list);
1105
ptr->embedding= embedding;
1106
ptr->join_list= join_list;
1088
1107
ptr->alias= (char*) "(nested_join)";
1089
1108
embedding= ptr;
1090
1109
join_list= &nested_join->join_list;
1110
1129
TableList *Select_Lex::end_nested_join(Session *)
1112
1131
TableList *ptr;
1113
NestedJoin *nested_join;
1132
nested_join_st *nested_join;
1115
1134
assert(embedding);
1116
1135
ptr= embedding;
1117
join_list= ptr->getJoinList();
1118
embedding= ptr->getEmbedding();
1119
nested_join= ptr->getNestedJoin();
1136
join_list= ptr->join_list;
1137
embedding= ptr->embedding;
1138
nested_join= ptr->nested_join;
1120
1139
if (nested_join->join_list.elements == 1)
1122
1141
TableList *embedded= nested_join->join_list.head();
1123
1142
join_list->pop();
1124
embedded->setJoinList(join_list);
1125
embedded->setEmbedding(embedding);
1143
embedded->join_list= join_list;
1144
embedded->embedding= embedding;
1126
1145
join_list->push_front(embedded);
1151
1170
TableList *Select_Lex::nest_last_join(Session *session)
1153
1172
TableList *ptr;
1154
NestedJoin *nested_join;
1173
nested_join_st *nested_join;
1155
1174
List<TableList> *embedded_list;
1157
1176
if (!(ptr= (TableList*) session->calloc(ALIGN_SIZE(sizeof(TableList))+
1158
sizeof(NestedJoin))))
1177
sizeof(nested_join_st))))
1160
ptr->setNestedJoin(((NestedJoin*) ((unsigned char*) ptr + ALIGN_SIZE(sizeof(TableList)))));
1161
nested_join= ptr->getNestedJoin();
1162
ptr->setEmbedding(embedding);
1163
ptr->setJoinList(join_list);
1179
nested_join= ptr->nested_join=
1180
((nested_join_st*) ((unsigned char*) ptr + ALIGN_SIZE(sizeof(TableList))));
1182
ptr->embedding= embedding;
1183
ptr->join_list= join_list;
1164
1184
ptr->alias= (char*) "(nest_last_join)";
1165
1185
embedded_list= &nested_join->join_list;
1166
embedded_list->clear();
1186
embedded_list->empty();
1168
1188
for (uint32_t i=0; i < 2; i++)
1170
1190
TableList *table= join_list->pop();
1171
table->setJoinList(embedded_list);
1172
table->setEmbedding(ptr);
1191
table->join_list= embedded_list;
1192
table->embedding= ptr;
1173
1193
embedded_list->push_back(table);
1174
1194
if (table->natural_join)
1311
1335
fake_select_lex->include_standalone(this,
1312
1336
(Select_Lex_Node**)&fake_select_lex);
1313
1337
fake_select_lex->select_number= INT_MAX;
1314
fake_select_lex->parent_lex= session_arg->getLex(); /* Used in init_query. */
1338
fake_select_lex->parent_lex= session_arg->lex; /* Used in init_query. */
1315
1339
fake_select_lex->make_empty_select();
1316
1340
fake_select_lex->linkage= GLOBAL_OPTIONS_TYPE;
1317
1341
fake_select_lex->select_limit= 0;
1319
1343
fake_select_lex->context.outer_context=first_sl->context.outer_context;
1320
/* allow item list resolving in fake select for ORDER BY */
1344
/* allow item list resolving in fake select for order_st BY */
1321
1345
fake_select_lex->context.resolve_in_select_list= true;
1322
1346
fake_select_lex->context.select_lex= fake_select_lex;
1327
1351
This works only for
1328
(SELECT ... ORDER BY list [LIMIT n]) ORDER BY order_list [LIMIT m],
1329
(SELECT ... LIMIT n) ORDER BY order_list [LIMIT m]
1352
(SELECT ... order_st BY list [LIMIT n]) order_st BY order_list [LIMIT m],
1353
(SELECT ... LIMIT n) order_st BY order_list [LIMIT m]
1330
1354
just before the parser starts processing order_list
1332
1356
global_parameters= fake_select_lex;
1333
1357
fake_select_lex->no_table_names_allowed= 1;
1334
session_arg->getLex()->current_select= fake_select_lex;
1358
session_arg->lex->current_select= fake_select_lex;
1336
session_arg->getLex()->pop_context();
1360
session_arg->lex->pop_context();
1478
@param session Thread class
1480
@param only_kill_query Should it kill the query or the connection
1483
This is written such that we have a short lock on LOCK_thread_count
1487
kill_one_thread(Session *, ulong id, bool only_kill_query)
1490
uint32_t error=ER_NO_SUCH_THREAD;
1491
pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
1493
for( vector<Session*>::iterator it= getSessionList().begin(); it != getSessionList().end(); ++it )
1495
if ((*it)->thread_id == id)
1498
pthread_mutex_lock(&tmp->LOCK_delete); // Lock from delete
1502
pthread_mutex_unlock(&LOCK_thread_count);
1505
tmp->awake(only_kill_query ? Session::KILL_QUERY : Session::KILL_CONNECTION);
1507
pthread_mutex_unlock(&tmp->LOCK_delete);
1514
kills a thread and sends response
1518
session Thread class
1520
only_kill_query Should it kill the query or the connection
1523
void sql_kill(Session *session, ulong id, bool only_kill_query)
1526
if (!(error= kill_one_thread(session, id, only_kill_query)))
1529
my_error(error, MYF(0), id);
1452
1534
Check if the select is a simple select (not an union).