16
16
#define DRIZZLE_LEX 1
17
17
#include <drizzled/server_includes.h>
19
#include "rpl_filter.h"
20
#include "repl_failsafe.h"
21
#include <drizzled/drizzled_error_messages.h>
18
#include <libdrizzleclient/libdrizzle.h>
19
#include <mysys/hash.h>
20
#include <drizzled/logging.h>
21
#include <drizzled/db.h>
22
#include <drizzled/error.h>
23
#include <drizzled/nested_join.h>
24
#include <drizzled/query_id.h>
25
#include <drizzled/sql_parse.h>
26
#include <drizzled/data_home.h>
27
#include <drizzled/sql_base.h>
28
#include <drizzled/show.h>
29
#include <drizzled/rename.h>
30
#include <drizzled/function/time/unix_timestamp.h>
31
#include <drizzled/function/get_system_var.h>
32
#include <drizzled/item/cmpfunc.h>
33
#include <drizzled/item/null.h>
34
#include <drizzled/session.h>
35
#include <drizzled/sql_load.h>
36
#include <drizzled/connect.h>
37
#include <drizzled/lock.h>
38
#include <drizzled/select_send.h>
24
44
@defgroup Runtime_Environment Runtime Environment
48
extern size_t my_thread_stack_size;
49
extern const CHARSET_INFO *character_set_filesystem;
29
50
const char *any_db="*any*"; // Special symbol for check_access
31
52
const LEX_STRING command_name[COM_END+1]={
56
75
"NON-EXISTING", "ACTIVE", "IDLE", "PREPARED"
59
static void unlock_locked_tables(THD *thd)
78
static void unlock_locked_tables(Session *session)
61
if (thd->locked_tables)
80
if (session->locked_tables)
63
thd->lock=thd->locked_tables;
64
thd->locked_tables=0; // Will be automatically closed
65
close_thread_tables(thd); // Free tables
82
session->lock=session->locked_tables;
83
session->locked_tables=0; // Will be automatically closed
84
close_thread_tables(session); // Free tables
70
bool end_active_trans(THD *thd)
89
bool end_active_trans(Session *session)
73
if (unlikely(thd->in_sub_stmt))
75
my_error(ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG, MYF(0));
78
if (thd->transaction.xid_state.xa_state != XA_NOTR)
93
if (session->transaction.xid_state.xa_state != XA_NOTR)
80
95
my_error(ER_XAER_RMFAIL, MYF(0),
81
xa_state_names[thd->transaction.xid_state.xa_state]);
96
xa_state_names[session->transaction.xid_state.xa_state]);
84
if (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN |
99
if (session->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN |
85
100
OPTION_TABLE_LOCK))
87
102
/* Safety if one did "drop table" on locked tables */
88
if (!thd->locked_tables)
89
thd->options&= ~OPTION_TABLE_LOCK;
90
thd->server_status&= ~SERVER_STATUS_IN_TRANS;
103
if (!session->locked_tables)
104
session->options&= ~OPTION_TABLE_LOCK;
105
session->server_status&= ~SERVER_STATUS_IN_TRANS;
106
if (ha_commit(session))
94
thd->options&= ~(OPTION_BEGIN | OPTION_KEEP_LOG);
95
thd->transaction.all.modified_non_trans_table= false;
109
session->options&= ~(OPTION_BEGIN | OPTION_KEEP_LOG);
110
session->transaction.all.modified_non_trans_table= false;
100
bool begin_trans(THD *thd)
115
bool begin_trans(Session *session)
103
if (unlikely(thd->in_sub_stmt))
105
my_error(ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG, MYF(0));
108
if (thd->locked_tables)
110
thd->lock=thd->locked_tables;
111
thd->locked_tables=0; // Will be automatically closed
112
close_thread_tables(thd); // Free tables
114
if (end_active_trans(thd))
118
if (session->locked_tables)
120
session->lock=session->locked_tables;
121
session->locked_tables=0; // Will be automatically closed
122
close_thread_tables(session); // Free tables
124
if (end_active_trans(session))
119
thd->options|= OPTION_BEGIN;
120
thd->server_status|= SERVER_STATUS_IN_TRANS;
128
LEX *lex= session->lex;
129
session->options|= OPTION_BEGIN;
130
session->server_status|= SERVER_STATUS_IN_TRANS;
121
131
if (lex->start_transaction_opt & DRIZZLE_START_TRANS_OPT_WITH_CONS_SNAPSHOT)
122
error= ha_start_consistent_snapshot(thd);
132
error= ha_start_consistent_snapshot(session);
223
214
bool is_update_query(enum enum_sql_command command)
225
216
assert(command >= 0 && command <= SQLCOM_END);
226
return (sql_command_flags[command] & CF_CHANGES_DATA) != 0;
217
return (sql_command_flags[command].test(CF_BIT_CHANGES_DATA));
229
void execute_init_command(THD *thd, sys_var_str *init_command_var,
230
rw_lock_t *var_mutex)
220
void execute_init_command(Session *session, sys_var_str *init_command_var,
221
pthread_rwlock_t *var_mutex)
233
224
ulong save_client_capabilities;
235
thd_proc_info(thd, "Execution of init_command");
226
session->set_proc_info("Execution of init_command");
237
228
We need to lock init_command_var because
238
229
during execution of init_command_var query
239
230
values of init_command_var can't be changed
241
rw_rdlock(var_mutex);
242
save_client_capabilities= thd->client_capabilities;
243
thd->client_capabilities|= CLIENT_MULTI_STATEMENTS;
232
pthread_rwlock_rdlock(var_mutex);
233
save_client_capabilities= session->client_capabilities;
234
session->client_capabilities|= CLIENT_MULTI_STATEMENTS;
245
236
We don't need return result of execution to client side.
246
To forbid this we should set thd->net.vio to 0.
237
To forbid this we should set session->net.vio to 0.
248
save_vio= thd->net.vio;
250
dispatch_command(COM_QUERY, thd,
239
save_vio= session->net.vio;
241
dispatch_command(COM_QUERY, session,
251
242
init_command_var->value,
252
243
init_command_var->value_length);
253
rw_unlock(var_mutex);
254
thd->client_capabilities= save_client_capabilities;
255
thd->net.vio= save_vio;
244
pthread_rwlock_unlock(var_mutex);
245
session->client_capabilities= save_client_capabilities;
246
session->net.vio= save_vio;
259
250
Ends the current transaction and (maybe) begin the next.
261
@param thd Current thread
252
@param session Current thread
262
253
@param completion Completion type
268
int end_trans(THD *thd, enum enum_mysql_completiontype completion)
259
int end_trans(Session *session, enum enum_mysql_completiontype completion)
270
261
bool do_release= 0;
273
if (unlikely(thd->in_sub_stmt))
275
my_error(ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG, MYF(0));
278
if (thd->transaction.xid_state.xa_state != XA_NOTR)
264
if (session->transaction.xid_state.xa_state != XA_NOTR)
280
266
my_error(ER_XAER_RMFAIL, MYF(0),
281
xa_state_names[thd->transaction.xid_state.xa_state]);
267
xa_state_names[session->transaction.xid_state.xa_state]);
284
270
switch (completion) {
404
392
if (packet_length == 0) /* safety */
406
394
/* Initialize with COM_SLEEP packet */
407
packet[0]= (uchar) COM_SLEEP;
395
packet[0]= (unsigned char) COM_SLEEP;
408
396
packet_length= 1;
410
398
/* Do not rely on my_net_read, extra safety against programming errors. */
411
399
packet[packet_length]= '\0'; /* safety */
413
command= (enum enum_server_command) (uchar) packet[0];
401
command= (enum enum_server_command) (unsigned char) packet[0];
415
403
if (command >= COM_END)
416
404
command= COM_END; // Wrong command
418
406
/* Restore read timeout value */
419
my_net_set_read_timeout(net, thd->variables.net_read_timeout);
407
my_net_set_read_timeout(net, session->variables.net_read_timeout);
421
409
assert(packet_length);
422
return_value= dispatch_command(command, thd, packet+1, (uint) (packet_length-1));
410
return_value= dispatch_command(command, session, packet+1, (uint32_t) (packet_length-1));
425
413
return(return_value);
429
Determine if an attempt to update a non-temporary table while the
430
read-only option was enabled has been made.
432
This is a helper function to mysql_execute_command.
434
@note SQLCOM_MULTI_UPDATE is an exception and dealt with elsewhere.
436
@see mysql_execute_command
439
@retval true The statement should be denied.
440
@retval false The statement isn't updating any relevant tables.
443
static bool deny_updates_if_read_only_option(THD *thd,
444
TABLE_LIST *all_tables)
451
if (!(sql_command_flags[lex->sql_command] & CF_CHANGES_DATA))
454
/* Multi update is an exception and is dealt with later. */
455
if (lex->sql_command == SQLCOM_UPDATE_MULTI)
458
const bool create_temp_tables=
459
(lex->sql_command == SQLCOM_CREATE_TABLE) &&
460
(lex->create_info.options & HA_LEX_CREATE_TMP_TABLE);
462
const bool drop_temp_tables=
463
(lex->sql_command == SQLCOM_DROP_TABLE) &&
466
const bool update_real_tables=
467
some_non_temp_table_to_be_updated(thd, all_tables) &&
468
!(create_temp_tables || drop_temp_tables);
471
const bool create_or_drop_databases=
472
(lex->sql_command == SQLCOM_CREATE_DB) ||
473
(lex->sql_command == SQLCOM_DROP_DB);
475
if (update_real_tables || create_or_drop_databases)
478
An attempt was made to modify one or more non-temporary tables.
484
/* Assuming that only temporary tables are modified. */
489
417
Perform one connection-level (COM_XXXX) command.
491
419
@param command type of command to perform
492
@param thd connection handle
420
@param session connection handle
493
421
@param packet data for the command, packet is always null-terminated
494
422
@param packet_length length of packet + 1 (to show that data is
495
423
null-terminated) except for COM_SLEEP, where it
499
set thd->lex->sql_command to SQLCOM_END here.
427
set session->lex->sql_command to SQLCOM_END here.
501
429
The following has to be changed to an 8 byte integer
530
454
/* Increase id and count all other statements. */
532
statistic_increment(thd->status_var.questions, &LOCK_status);
456
statistic_increment(session->status_var.questions, &LOCK_status);
536
460
thread_running++;
537
/* TODO: set thd->lex->sql_command to SQLCOM_END here */
538
VOID(pthread_mutex_unlock(&LOCK_thread_count));
461
/* TODO: set session->lex->sql_command to SQLCOM_END here */
462
pthread_mutex_unlock(&LOCK_thread_count);
464
logging_pre_do(session);
466
session->server_status&=
541
467
~(SERVER_QUERY_NO_INDEX_USED | SERVER_QUERY_NO_GOOD_INDEX_USED);
542
468
switch (command) {
543
469
case COM_INIT_DB:
546
status_var_increment(thd->status_var.com_stat[SQLCOM_CHANGE_DB]);
547
thd->convert_string(&tmp, system_charset_info,
548
packet, packet_length, thd->charset());
549
if (!mysql_change_db(thd, &tmp, false))
472
status_var_increment(session->status_var.com_stat[SQLCOM_CHANGE_DB]);
473
session->convert_string(&tmp, system_charset_info,
474
packet, packet_length, session->charset());
475
if (!mysql_change_db(session, &tmp, false))
551
general_log_write(thd, command, thd->db, thd->db_length);
556
case COM_REGISTER_SLAVE:
558
if (!register_slave(thd, (uchar*)packet, packet_length))
562
481
case COM_CHANGE_USER:
564
status_var_increment(thd->status_var.com_other);
483
status_var_increment(session->status_var.com_other);
565
484
char *user= (char*) packet, *packet_end= packet + packet_length;
566
485
/* Safe because there is always a trailing \0 at the end of the packet */
567
char *passwd= strend(user)+1;
570
thd->clear_error(); // if errors from rollback
486
char *passwd= strchr(user, '\0')+1;
489
session->clear_error(); // if errors from rollback
573
492
Old clients send null-terminated string ('\0' for empty string) for
625
544
/* Convert database name to utf8 */
626
545
db_buff[copy_and_convert(db_buff, sizeof(db_buff)-1,
627
546
system_charset_info, db, db_length,
628
thd->charset(), &dummy_errors)]= 0;
547
session->charset(), &dummy_errors)]= 0;
631
550
/* Save user and privileges */
632
save_db_length= thd->db_length;
634
save_user_connect= thd->user_connect;
551
save_db_length= session->db_length;
552
save_db= session->db;
553
save_user_connect= session->user_connect;
636
if (!(thd->security_ctx->user= my_strdup(user, MYF(0))))
638
thd->security_ctx->user= save_security_ctx.user;
639
my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0));
555
old_username= session->security_ctx.user;
556
session->security_ctx.user.assign(user);
643
558
/* Clear variables that are allocated */
644
thd->user_connect= 0;
645
res= check_user(thd, COM_CHANGE_USER, passwd, passwd_len, db, false);
559
session->user_connect= 0;
560
res= check_user(session, passwd, passwd_len, db, false);
649
x_free(thd->security_ctx->user);
650
*thd->security_ctx= save_security_ctx;
651
thd->user_connect= save_user_connect;
653
thd->db_length= save_db_length;
564
session->security_ctx.user= old_username;
565
session->user_connect= save_user_connect;
566
session->db= save_db;
567
session->db_length= save_db_length;
658
x_free(save_security_ctx.user);
662
thd_init_client_charset(thd, cs_number);
663
thd->update_charset();
576
session->update_charset();
670
if (alloc_query(thd, packet, packet_length))
583
if (alloc_query(session, packet, packet_length))
671
584
break; // fatal error is set
672
char *packet_end= thd->query + thd->query_length;
585
char *packet_end= session->query + session->query_length;
673
586
const char* end_of_stmt= NULL;
675
general_log_write(thd, command, thd->query, thd->query_length);
677
mysql_parse(thd, thd->query, thd->query_length, &end_of_stmt);
679
while (!thd->killed && (end_of_stmt != NULL) && ! thd->is_error())
588
mysql_parse(session, session->query, session->query_length, &end_of_stmt);
590
while (!session->killed && (end_of_stmt != NULL) && ! session->is_error())
681
592
char *beginning_of_next_stmt= (char*) end_of_stmt;
683
net_end_statement(thd);
594
net_end_statement(session);
685
596
Multiple queries exits, execute them individually
687
close_thread_tables(thd);
598
close_thread_tables(session);
688
599
ulong length= (ulong)(packet_end - beginning_of_next_stmt);
690
log_slow_statement(thd);
601
log_slow_statement(session);
692
603
/* Remove garbage at start of query */
693
while (length > 0 && my_isspace(thd->charset(), *beginning_of_next_stmt))
604
while (length > 0 && my_isspace(session->charset(), *beginning_of_next_stmt))
695
606
beginning_of_next_stmt++;
699
VOID(pthread_mutex_lock(&LOCK_thread_count));
700
thd->query_length= length;
701
thd->query= beginning_of_next_stmt;
610
pthread_mutex_lock(&LOCK_thread_count);
611
session->query_length= length;
612
session->query= beginning_of_next_stmt;
703
614
Count each statement from the client.
705
statistic_increment(thd->status_var.questions, &LOCK_status);
706
thd->query_id= next_query_id();
707
thd->set_time(); /* Reset the query start time. */
708
/* TODO: set thd->lex->sql_command to SQLCOM_END here */
709
VOID(pthread_mutex_unlock(&LOCK_thread_count));
616
statistic_increment(session->status_var.questions, &LOCK_status);
617
session->query_id= query_id.next();
618
session->set_time(); /* Reset the query start time. */
619
/* TODO: set session->lex->sql_command to SQLCOM_END here */
620
pthread_mutex_unlock(&LOCK_thread_count);
711
mysql_parse(thd, beginning_of_next_stmt, length, &end_of_stmt);
622
mysql_parse(session, beginning_of_next_stmt, length, &end_of_stmt);
717
628
char *fields, *packet_end= packet + packet_length, *arg_end;
718
629
/* Locked closure of all tables */
719
TABLE_LIST table_list;
630
TableList table_list;
720
631
LEX_STRING conv_name;
722
633
/* used as fields initializator */
725
status_var_increment(thd->status_var.com_stat[SQLCOM_SHOW_FIELDS]);
636
status_var_increment(session->status_var.com_stat[SQLCOM_SHOW_FIELDS]);
726
637
memset(&table_list, 0, sizeof(table_list));
727
if (thd->copy_db_to(&table_list.db, &table_list.db_length))
638
if (session->copy_db_to(&table_list.db, &table_list.db_length))
730
641
We have name + wildcard in packet, separated by endzero
732
arg_end= strend(packet);
733
thd->convert_string(&conv_name, system_charset_info,
734
packet, (uint) (arg_end - packet), thd->charset());
643
arg_end= strchr(packet, '\0');
644
session->convert_string(&conv_name, system_charset_info,
645
packet, (uint32_t) (arg_end - packet), session->charset());
735
646
table_list.alias= table_list.table_name= conv_name.str;
736
647
packet= arg_end + 1;
738
649
if (!my_strcasecmp(system_charset_info, table_list.db,
739
INFORMATION_SCHEMA_NAME.str))
650
INFORMATION_SCHEMA_NAME.c_str()))
741
ST_SCHEMA_TABLE *schema_table= find_schema_table(thd, table_list.alias);
652
ST_SCHEMA_TABLE *schema_table= find_schema_table(session, table_list.alias);
742
653
if (schema_table)
743
654
table_list.schema_table= schema_table;
746
thd->query_length= (uint) (packet_end - packet); // Don't count end \0
747
if (!(thd->query=fields= (char*) thd->memdup(packet,thd->query_length+1)))
657
session->query_length= (uint32_t) (packet_end - packet); // Don't count end \0
658
if (!(session->query=fields= (char*) session->memdup(packet,session->query_length+1)))
749
general_log_print(thd, command, "%s %s", table_list.table_name, fields);
750
660
if (lower_case_table_names)
751
661
my_casedn_str(files_charset_info, table_list.table_name);
753
663
/* init structures for VIEW processing */
754
table_list.select_lex= &(thd->lex->select_lex);
757
mysql_reset_thd_for_next_command(thd);
760
select_lex.table_list.link_in_list((uchar*) &table_list,
761
(uchar**) &table_list.next_local);
762
thd->lex->add_to_query_tables(&table_list);
664
table_list.select_lex= &(session->lex->select_lex);
667
session->reset_for_next_command();
670
select_lex.table_list.link_in_list((unsigned char*) &table_list,
671
(unsigned char**) &table_list.next_local);
672
session->lex->add_to_query_tables(&table_list);
764
674
/* switch on VIEW optimisation: do not fill temporary tables */
765
thd->lex->sql_command= SQLCOM_SHOW_FIELDS;
766
mysqld_list_fields(thd,&table_list,fields);
767
thd->lex->unit.cleanup();
768
thd->cleanup_after_query();
675
session->lex->sql_command= SQLCOM_SHOW_FIELDS;
676
mysqld_list_fields(session,&table_list,fields);
677
session->lex->unit.cleanup();
678
session->cleanup_after_query();
772
682
/* We don't calculate statistics for this command */
773
general_log_print(thd, command, NullS);
774
683
net->error=0; // Don't give 'abort' message
775
thd->main_da.disable_status(); // Don't send anything back
684
session->main_da.disable_status(); // Don't send anything back
776
685
error=true; // End server
778
case COM_BINLOG_DUMP:
782
uint32_t slave_server_id;
784
status_var_increment(thd->status_var.com_other);
785
thd->enable_slow_log= opt_log_slow_admin_statements;
786
/* TODO: The following has to be changed to an 8 byte integer */
787
pos = uint4korr(packet);
788
flags = uint2korr(packet + 4);
789
thd->server_id=0; /* avoid suicide */
790
if ((slave_server_id= uint4korr(packet+6))) // mysqlbinlog.server_id==0
791
kill_zombie_dump_threads(slave_server_id);
792
thd->server_id = slave_server_id;
794
general_log_print(thd, command, "Log: '%s' Pos: %ld", packet+10,
796
mysql_binlog_send(thd, thd->strdup(packet + 10), (my_off_t) pos, flags);
797
unregister_slave(thd,1,1);
798
/* fake COM_QUIT -- if we get here, the thread needs to terminate */
802
687
case COM_SHUTDOWN:
804
status_var_increment(thd->status_var.com_other);
806
If the client is < 4.1.3, it is going to send us no argument; then
807
packet_length is 0, packet[0] is the end 0 of the packet. Note that
808
SHUTDOWN_DEFAULT is 0. If client is >= 4.1.3, the shutdown level is in
811
enum drizzle_enum_shutdown_level level=
812
(enum drizzle_enum_shutdown_level) (uchar) packet[0];
813
if (level == SHUTDOWN_DEFAULT)
814
level= SHUTDOWN_WAIT_ALL_BUFFERS; // soon default will be configurable
815
else if (level != SHUTDOWN_WAIT_ALL_BUFFERS)
817
my_error(ER_NOT_SUPPORTED_YET, MYF(0), "this shutdown level");
820
general_log_print(thd, command, NullS);
822
close_thread_tables(thd); // Free before kill
689
status_var_increment(session->status_var.com_other);
691
close_thread_tables(session); // Free before kill
828
status_var_increment(thd->status_var.com_other);
829
my_ok(thd); // Tell client we are alive
697
status_var_increment(session->status_var.com_other);
698
session->my_ok(); // Tell client we are alive
831
700
case COM_PROCESS_INFO:
832
status_var_increment(thd->status_var.com_stat[SQLCOM_SHOW_PROCESSLIST]);
833
general_log_print(thd, command, NullS);
834
mysqld_list_processes(thd, NullS, 0);
701
status_var_increment(session->status_var.com_stat[SQLCOM_SHOW_PROCESSLIST]);
702
mysqld_list_processes(session, NULL, 0);
836
704
case COM_PROCESS_KILL:
838
status_var_increment(thd->status_var.com_stat[SQLCOM_KILL]);
706
status_var_increment(session->status_var.com_stat[SQLCOM_KILL]);
839
707
ulong id=(ulong) uint4korr(packet);
840
sql_kill(thd,id,false);
708
sql_kill(session,id,false);
843
711
case COM_SET_OPTION:
845
status_var_increment(thd->status_var.com_stat[SQLCOM_SET_OPTION]);
846
uint opt_command= uint2korr(packet);
713
status_var_increment(session->status_var.com_stat[SQLCOM_SET_OPTION]);
714
uint32_t opt_command= uint2korr(packet);
848
716
switch (opt_command) {
849
717
case (int) DRIZZLE_OPTION_MULTI_STATEMENTS_ON:
850
thd->client_capabilities|= CLIENT_MULTI_STATEMENTS;
718
session->client_capabilities|= CLIENT_MULTI_STATEMENTS;
853
721
case (int) DRIZZLE_OPTION_MULTI_STATEMENTS_OFF:
854
thd->client_capabilities&= ~CLIENT_MULTI_STATEMENTS;
722
session->client_capabilities&= ~CLIENT_MULTI_STATEMENTS;
858
726
my_message(ER_UNKNOWN_COM_ERROR, ER(ER_UNKNOWN_COM_ERROR), MYF(0));
872
740
/* If commit fails, we should be able to reset the OK status. */
873
thd->main_da.can_overwrite_status= true;
874
ha_autocommit_or_rollback(thd, thd->is_error());
875
thd->main_da.can_overwrite_status= false;
741
session->main_da.can_overwrite_status= true;
742
ha_autocommit_or_rollback(session, session->is_error());
743
session->main_da.can_overwrite_status= false;
877
thd->transaction.stmt.reset();
745
session->transaction.stmt.reset();
880
748
/* report error issued during command execution */
881
if (thd->killed_errno())
883
if (! thd->main_da.is_set())
884
thd->send_kill_message();
886
if (thd->killed == THD::KILL_QUERY || thd->killed == THD::KILL_BAD_DATA)
888
thd->killed= THD::NOT_KILLED;
889
thd->mysys_var->abort= 0;
892
net_end_statement(thd);
894
thd->proc_info= "closing tables";
749
if (session->killed_errno())
751
if (! session->main_da.is_set())
752
session->send_kill_message();
754
if (session->killed == Session::KILL_QUERY || session->killed == Session::KILL_BAD_DATA)
756
session->killed= Session::NOT_KILLED;
757
session->mysys_var->abort= 0;
760
net_end_statement(session);
762
session->set_proc_info("closing tables");
895
763
/* Free tables */
896
close_thread_tables(thd);
898
log_slow_statement(thd);
900
thd_proc_info(thd, "cleaning up");
901
VOID(pthread_mutex_lock(&LOCK_thread_count)); // For process list
902
thd_proc_info(thd, 0);
903
thd->command=COM_SLEEP;
764
close_thread_tables(session);
766
log_slow_statement(session);
768
session->set_proc_info("cleaning up");
769
pthread_mutex_lock(&LOCK_thread_count); // For process list
770
session->set_proc_info(0);
771
session->command=COM_SLEEP;
773
session->query_length=0;
906
774
thread_running--;
907
VOID(pthread_mutex_unlock(&LOCK_thread_count));
908
thd->packet.shrink(thd->variables.net_buffer_length); // Reclaim some memory
909
free_root(thd->mem_root,MYF(MY_KEEP_PREALLOC));
775
pthread_mutex_unlock(&LOCK_thread_count);
776
session->packet.shrink(session->variables.net_buffer_length); // Reclaim some memory
777
free_root(session->mem_root,MYF(MY_KEEP_PREALLOC));
914
void log_slow_statement(THD *thd)
782
void log_slow_statement(Session *session)
917
The following should never be true with our current code base,
918
but better to keep this here so we don't accidently try to log a
919
statement in a trigger or stored function
921
if (unlikely(thd->in_sub_stmt))
922
return; // Don't set time for sub stmt
925
Do not log administrative statements unless the appropriate option is
926
set; do not log into slow log if reading from backup.
928
if (thd->enable_slow_log && !thd->user_time)
930
thd_proc_info(thd, "logging slow query");
931
uint64_t end_utime_of_query= thd->current_utime();
933
if (((end_utime_of_query - thd->utime_after_lock) >
934
thd->variables.long_query_time ||
935
((thd->server_status &
936
(SERVER_QUERY_NO_INDEX_USED | SERVER_QUERY_NO_GOOD_INDEX_USED)) &&
937
opt_log_queries_not_using_indexes &&
938
!(sql_command_flags[thd->lex->sql_command] & CF_STATUS_COMMAND))) &&
939
thd->examined_row_count >= thd->variables.min_examined_row_limit)
941
thd_proc_info(thd, "logging slow query");
942
thd->status_var.long_query_count++;
943
slow_log_print(thd, thd->query, thd->query_length, end_utime_of_query);
784
logging_post_do(session);
951
Create a TABLE_LIST object for an INFORMATION_SCHEMA table.
791
Create a TableList object for an INFORMATION_SCHEMA table.
953
793
This function is used in the parser to convert a SHOW or DESCRIBE
954
794
table_name command to a SELECT from INFORMATION_SCHEMA.
955
It prepares a SELECT_LEX and a TABLE_LIST object to represent the
795
It prepares a SELECT_LEX and a TableList object to represent the
956
796
given command as a SELECT parse tree.
958
@param thd thread handle
798
@param session thread handle
959
799
@param lex current lex
960
800
@param table_ident table alias if it's used
961
801
@param schema_table_idx the type of the INFORMATION_SCHEMA table to be
1047
Read query from packet and store in thd->query.
887
Read query from packet and store in session->query.
1048
888
Used in COM_QUERY and COM_STMT_PREPARE.
1050
Sets the following THD variables:
890
Sets the following Session variables:
1057
true error; In this case thd->fatal_error is set
897
true error; In this case session->fatal_error is set
1060
bool alloc_query(THD *thd, const char *packet, uint packet_length)
900
bool alloc_query(Session *session, const char *packet, uint32_t packet_length)
1062
902
/* Remove garbage at start and end of query */
1063
while (packet_length > 0 && my_isspace(thd->charset(), packet[0]))
903
while (packet_length > 0 && my_isspace(session->charset(), packet[0]))
1066
906
packet_length--;
1068
908
const char *pos= packet + packet_length; // Point at end null
1069
909
while (packet_length > 0 &&
1070
(pos[-1] == ';' || my_isspace(thd->charset() ,pos[-1])))
910
(pos[-1] == ';' || my_isspace(session->charset() ,pos[-1])))
1073
913
packet_length--;
1075
915
/* We must allocate some extra memory for query cache */
1076
thd->query_length= 0; // Extra safety: Avoid races
1077
if (!(thd->query= (char*) thd->memdup_w_gap((uchar*) (packet),
916
session->query_length= 0; // Extra safety: Avoid races
917
if (!(session->query= (char*) session->memdup_w_gap((unsigned char*) (packet),
1079
thd->db_length+ 1)))
919
session->db_length+ 1)))
1081
thd->query[packet_length]=0;
1082
thd->query_length= packet_length;
921
session->query[packet_length]=0;
922
session->query_length= packet_length;
1084
924
/* Reclaim some memory */
1085
thd->packet.shrink(thd->variables.net_buffer_length);
1086
thd->convert_buffer.shrink(thd->variables.net_buffer_length);
925
session->packet.shrink(session->variables.net_buffer_length);
926
session->convert_buffer.shrink(session->variables.net_buffer_length);
1091
static void reset_one_shot_variables(THD *thd)
1093
thd->variables.character_set_client=
1094
global_system_variables.character_set_client;
1095
thd->variables.collation_connection=
1096
global_system_variables.collation_connection;
1097
thd->variables.collation_database=
1098
global_system_variables.collation_database;
1099
thd->variables.collation_server=
1100
global_system_variables.collation_server;
1101
thd->update_charset();
1102
thd->variables.time_zone=
1103
global_system_variables.time_zone;
1104
thd->variables.lc_time_names= &my_locale_en_US;
1105
thd->one_shot_set= 0;
1110
Execute command saved in thd and lex->sql_command.
932
Execute command saved in session and lex->sql_command.
1112
934
Before every operation that can request a write lock for a table
1113
935
wait if a global read lock exists. However do not wait if this
1184
1005
Don't reset warnings when executing a stored routine.
1186
1007
if (all_tables || !lex->is_single_level_stmt())
1187
drizzle_reset_errors(thd, 0);
1189
if (unlikely(thd->slave_thread))
1192
Check if statment should be skipped because of slave filtering
1196
- UPDATE MULTI: For this statement, we want to check the filtering
1197
rules later in the code
1198
- SET: we always execute it (Not that many SET commands exists in
1199
the binary log anyway -- only 4.1 masters write SET statements,
1200
in 5.0 there are no SET statements in the binary log)
1201
- DROP TEMPORARY TABLE IF EXISTS: we always execute it (otherwise we
1202
have stale files on slave caused by exclusion of one tmp table).
1204
if (!(lex->sql_command == SQLCOM_UPDATE_MULTI) &&
1205
!(lex->sql_command == SQLCOM_SET_OPTION) &&
1206
!(lex->sql_command == SQLCOM_DROP_TABLE &&
1207
lex->drop_temporary && lex->drop_if_exists) &&
1208
all_tables_not_ok(thd, all_tables))
1210
/* we warn the slave SQL thread */
1211
my_message(ER_SLAVE_IGNORED_TABLE, ER(ER_SLAVE_IGNORED_TABLE), MYF(0));
1212
if (thd->one_shot_set)
1215
It's ok to check thd->one_shot_set here:
1217
The charsets in a MySQL 5.0 slave can change by both a binlogged
1218
SET ONE_SHOT statement and the event-internal charset setting,
1219
and these two ways to change charsets do not seems to work
1222
At least there seems to be problems in the rli cache for
1223
charsets if we are using ONE_SHOT. Note that this is normally no
1224
problem because either the >= 5.0 slave reads a 4.1 binlog (with
1225
ONE_SHOT) *or* or 5.0 binlog (without ONE_SHOT) but never both."
1227
reset_one_shot_variables(thd);
1235
When option readonly is set deny operations which change non-temporary
1236
tables. Except for the replication thread and the 'super' users.
1238
if (deny_updates_if_read_only_option(thd, all_tables))
1240
my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--read-only");
1243
} /* endif unlikely slave */
1244
status_var_increment(thd->status_var.com_stat[lex->sql_command]);
1246
assert(thd->transaction.stmt.modified_non_trans_table == false);
1008
drizzle_reset_errors(session, 0);
1010
status_var_increment(session->status_var.com_stat[lex->sql_command]);
1012
assert(session->transaction.stmt.modified_non_trans_table == false);
1248
1014
switch (lex->sql_command) {
1249
1015
case SQLCOM_SHOW_STATUS:
1251
system_status_var old_status_var= thd->status_var;
1252
thd->initial_status_var= &old_status_var;
1253
res= execute_sqlcom_select(thd, all_tables);
1017
system_status_var old_status_var= session->status_var;
1018
session->initial_status_var= &old_status_var;
1019
res= execute_sqlcom_select(session, all_tables);
1254
1020
/* Don't log SHOW STATUS commands to slow query log */
1255
thd->server_status&= ~(SERVER_QUERY_NO_INDEX_USED |
1021
session->server_status&= ~(SERVER_QUERY_NO_INDEX_USED |
1256
1022
SERVER_QUERY_NO_GOOD_INDEX_USED);
1258
1024
restore status variables, as we don't want 'show status' to cause
1261
1027
pthread_mutex_lock(&LOCK_status);
1262
add_diff_to_status(&global_status_var, &thd->status_var,
1028
add_diff_to_status(&global_status_var, &session->status_var,
1263
1029
&old_status_var);
1264
thd->status_var= old_status_var;
1030
session->status_var= old_status_var;
1265
1031
pthread_mutex_unlock(&LOCK_status);
1272
1038
case SQLCOM_SHOW_FIELDS:
1273
1039
case SQLCOM_SHOW_KEYS:
1274
1040
case SQLCOM_SHOW_VARIABLES:
1275
case SQLCOM_SHOW_CHARSETS:
1276
case SQLCOM_SHOW_COLLATIONS:
1277
1041
case SQLCOM_SELECT:
1279
thd->status_var.last_query_cost= 0.0;
1280
res= execute_sqlcom_select(thd, all_tables);
1043
session->status_var.last_query_cost= 0.0;
1044
res= execute_sqlcom_select(session, all_tables);
1283
1047
case SQLCOM_EMPTY_QUERY:
1289
res = purge_master_logs(thd, lex->to_log);
1292
case SQLCOM_PURGE_BEFORE:
1296
/* PURGE MASTER LOGS BEFORE 'data' */
1297
it= (Item *)lex->value_list.head();
1298
if ((!it->fixed && it->fix_fields(lex->thd, &it)) ||
1301
my_error(ER_WRONG_ARGUMENTS, MYF(0), "PURGE LOGS BEFORE");
1304
it= new Item_func_unix_timestamp(it);
1306
it is OK only emulate fix_fieds, because we need only
1309
it->quick_fix_field();
1310
res = purge_master_logs_before_date(thd, (ulong)it->val_int());
1313
1051
case SQLCOM_SHOW_WARNS:
1315
res= mysqld_show_warnings(thd, (ulong)
1316
((1L << (uint) DRIZZLE_ERROR::WARN_LEVEL_NOTE) |
1317
(1L << (uint) DRIZZLE_ERROR::WARN_LEVEL_WARN) |
1318
(1L << (uint) DRIZZLE_ERROR::WARN_LEVEL_ERROR)
1053
res= mysqld_show_warnings(session, (uint32_t)
1054
((1L << (uint32_t) DRIZZLE_ERROR::WARN_LEVEL_NOTE) |
1055
(1L << (uint32_t) DRIZZLE_ERROR::WARN_LEVEL_WARN) |
1056
(1L << (uint32_t) DRIZZLE_ERROR::WARN_LEVEL_ERROR)
1322
1060
case SQLCOM_SHOW_ERRORS:
1324
res= mysqld_show_warnings(thd, (ulong)
1325
(1L << (uint) DRIZZLE_ERROR::WARN_LEVEL_ERROR));
1328
case SQLCOM_SHOW_SLAVE_HOSTS:
1330
res = show_slave_hosts(thd);
1333
case SQLCOM_SHOW_BINLOG_EVENTS:
1335
res = mysql_show_binlog_events(thd);
1062
res= mysqld_show_warnings(session, (uint32_t)
1063
(1L << (uint32_t) DRIZZLE_ERROR::WARN_LEVEL_ERROR));
1339
1066
case SQLCOM_ASSIGN_TO_KEYCACHE:
1341
1068
assert(first_table == all_tables && first_table != 0);
1342
res= mysql_assign_to_keycache(thd, first_table, &lex->ident);
1345
case SQLCOM_CHANGE_MASTER:
1347
pthread_mutex_lock(&LOCK_active_mi);
1348
res = change_master(thd,active_mi);
1349
pthread_mutex_unlock(&LOCK_active_mi);
1352
case SQLCOM_SHOW_SLAVE_STAT:
1354
pthread_mutex_lock(&LOCK_active_mi);
1355
if (active_mi != NULL)
1357
res = show_master_info(thd, active_mi);
1361
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN, 0,
1362
"the master info structure does not exist");
1365
pthread_mutex_unlock(&LOCK_active_mi);
1368
case SQLCOM_SHOW_MASTER_STAT:
1370
res = show_binlog_info(thd);
1069
res= mysql_assign_to_keycache(session, first_table, &lex->ident);
1374
1072
case SQLCOM_SHOW_ENGINE_STATUS:
1376
res = ha_show_status(thd, lex->create_info.db_type, HA_ENGINE_STATUS);
1074
res = ha_show_status(session, lex->create_info.db_type, HA_ENGINE_STATUS);
1379
1077
case SQLCOM_CREATE_TABLE:
1554
1252
/* Prepare stack copies to be re-execution safe */
1555
1253
HA_CREATE_INFO create_info;
1556
Alter_info alter_info(lex->alter_info, thd->mem_root);
1254
Alter_info alter_info(lex->alter_info, session->mem_root);
1558
if (thd->is_fatal_error) /* out of memory creating a copy of alter_info */
1256
if (session->is_fatal_error) /* out of memory creating a copy of alter_info */
1561
1259
assert(first_table == all_tables && first_table != 0);
1562
if (end_active_trans(thd))
1260
if (end_active_trans(session))
1565
Currently CREATE INDEX or DROP INDEX cause a full table rebuild
1566
and thus classify as slow administrative statements just like
1569
thd->enable_slow_log= opt_log_slow_admin_statements;
1571
1263
memset(&create_info, 0, sizeof(create_info));
1572
1264
create_info.db_type= 0;
1573
1265
create_info.row_type= ROW_TYPE_NOT_USED;
1574
create_info.default_table_charset= thd->variables.collation_database;
1266
create_info.default_table_charset= session->variables.collation_database;
1576
res= mysql_alter_table(thd, first_table->db, first_table->table_name,
1268
res= mysql_alter_table(session, first_table->db, first_table->table_name,
1577
1269
&create_info, first_table, &alter_info,
1581
case SQLCOM_SLAVE_START:
1583
pthread_mutex_lock(&LOCK_active_mi);
1584
start_slave(thd,active_mi,1 /* net report*/);
1585
pthread_mutex_unlock(&LOCK_active_mi);
1588
case SQLCOM_SLAVE_STOP:
1590
If the client thread has locked tables, a deadlock is possible.
1592
- the client thread does LOCK TABLE t READ.
1593
- then the master updates t.
1594
- then the SQL slave thread wants to update t,
1595
so it waits for the client thread because t is locked by it.
1596
- then the client thread does SLAVE STOP.
1597
SLAVE STOP waits for the SQL slave thread to terminate its
1598
update t, which waits for the client thread because t is locked by it.
1599
To prevent that, refuse SLAVE STOP if the
1600
client thread has locked tables
1602
if (thd->locked_tables || thd->active_transaction() || thd->global_read_lock)
1604
my_message(ER_LOCK_OR_ACTIVE_TRANSACTION,
1605
ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0));
1609
pthread_mutex_lock(&LOCK_active_mi);
1610
stop_slave(thd,active_mi,1/* net report*/);
1611
pthread_mutex_unlock(&LOCK_active_mi);
1270
0, (order_st*) 0, 0);
1615
1273
case SQLCOM_ALTER_TABLE:
1616
1274
assert(first_table == all_tables && first_table != 0);
1642
1300
/* Don't yet allow changing of symlinks with ALTER TABLE */
1643
1301
if (create_info.data_file_name)
1644
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN, 0,
1302
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN, 0,
1645
1303
"DATA DIRECTORY option ignored");
1646
1304
if (create_info.index_file_name)
1647
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN, 0,
1305
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN, 0,
1648
1306
"INDEX DIRECTORY option ignored");
1649
1307
create_info.data_file_name= create_info.index_file_name= NULL;
1650
1308
/* ALTER TABLE ends previous transaction */
1651
if (end_active_trans(thd))
1309
if (end_active_trans(session))
1654
if (!thd->locked_tables &&
1655
!(need_start_waiting= !wait_if_global_read_lock(thd, 0, 1)))
1312
if (!session->locked_tables &&
1313
!(need_start_waiting= !wait_if_global_read_lock(session, 0, 1)))
1661
thd->enable_slow_log= opt_log_slow_admin_statements;
1662
res= mysql_alter_table(thd, select_lex->db, lex->name.str,
1319
res= mysql_alter_table(session, select_lex->db, lex->name.str,
1666
1323
select_lex->order_list.elements,
1667
(ORDER *) select_lex->order_list.first,
1324
(order_st *) select_lex->order_list.first,
1671
1328
case SQLCOM_RENAME_TABLE:
1673
1330
assert(first_table == all_tables && first_table != 0);
1675
1332
for (table= first_table; table; table= table->next_local->next_local)
1677
TABLE_LIST old_list, new_list;
1334
TableList old_list, new_list;
1679
1336
we do not need initialize old_list and new_list because we will
1680
1337
come table[0] and table->next[0] there
1683
1340
new_list= table->next_local[0];
1686
if (end_active_trans(thd) || mysql_rename_tables(thd, first_table, 0))
1343
if (end_active_trans(session) || drizzle_rename_tables(session, first_table, 0))
1692
case SQLCOM_SHOW_BINLOGS:
1694
res = show_binlogs(thd);
1697
1349
case SQLCOM_SHOW_CREATE:
1698
1350
assert(first_table == all_tables && first_table != 0);
1700
res= mysqld_show_create(thd, first_table);
1352
res= mysqld_show_create(session, first_table);
1703
1355
case SQLCOM_CHECKSUM:
1705
1357
assert(first_table == all_tables && first_table != 0);
1706
res = mysql_checksum_table(thd, first_table, &lex->check_opt);
1358
res = mysql_checksum_table(session, first_table, &lex->check_opt);
1709
1361
case SQLCOM_REPAIR:
1711
1363
assert(first_table == all_tables && first_table != 0);
1712
thd->enable_slow_log= opt_log_slow_admin_statements;
1713
res= mysql_repair_table(thd, first_table, &lex->check_opt);
1364
res= mysql_repair_table(session, first_table, &lex->check_opt);
1714
1365
/* ! we write after unlocking the table */
1715
if (!res && !lex->no_write_to_binlog)
1718
Presumably, REPAIR and binlog writing doesn't require synchronization
1720
write_bin_log(thd, true, thd->query, thd->query_length);
1722
select_lex->table_list.first= (uchar*) first_table;
1367
Presumably, REPAIR and binlog writing doesn't require synchronization
1369
write_bin_log(session, true, session->query, session->query_length);
1370
select_lex->table_list.first= (unsigned char*) first_table;
1723
1371
lex->query_tables=all_tables;
1726
1374
case SQLCOM_CHECK:
1728
1376
assert(first_table == all_tables && first_table != 0);
1729
thd->enable_slow_log= opt_log_slow_admin_statements;
1730
res = mysql_check_table(thd, first_table, &lex->check_opt);
1731
select_lex->table_list.first= (uchar*) first_table;
1377
res = mysql_check_table(session, first_table, &lex->check_opt);
1378
select_lex->table_list.first= (unsigned char*) first_table;
1732
1379
lex->query_tables=all_tables;
1735
1382
case SQLCOM_ANALYZE:
1737
1384
assert(first_table == all_tables && first_table != 0);
1738
thd->enable_slow_log= opt_log_slow_admin_statements;
1739
res= mysql_analyze_table(thd, first_table, &lex->check_opt);
1385
res= mysql_analyze_table(session, first_table, &lex->check_opt);
1740
1386
/* ! we write after unlocking the table */
1741
if (!res && !lex->no_write_to_binlog)
1744
Presumably, ANALYZE and binlog writing doesn't require synchronization
1746
write_bin_log(thd, true, thd->query, thd->query_length);
1748
select_lex->table_list.first= (uchar*) first_table;
1387
write_bin_log(session, true, session->query, session->query_length);
1388
select_lex->table_list.first= (unsigned char*) first_table;
1749
1389
lex->query_tables=all_tables;
1753
1393
case SQLCOM_OPTIMIZE:
1755
1395
assert(first_table == all_tables && first_table != 0);
1756
thd->enable_slow_log= opt_log_slow_admin_statements;
1757
res= (specialflag & (SPECIAL_SAFE_MODE | SPECIAL_NO_NEW_FUNC)) ?
1758
mysql_recreate_table(thd, first_table) :
1759
mysql_optimize_table(thd, first_table, &lex->check_opt);
1396
res= mysql_optimize_table(session, first_table, &lex->check_opt);
1760
1397
/* ! we write after unlocking the table */
1761
if (!res && !lex->no_write_to_binlog)
1764
Presumably, OPTIMIZE and binlog writing doesn't require synchronization
1766
write_bin_log(thd, true, thd->query, thd->query_length);
1768
select_lex->table_list.first= (uchar*) first_table;
1398
write_bin_log(session, true, session->query, session->query_length);
1399
select_lex->table_list.first= (unsigned char*) first_table;
1769
1400
lex->query_tables=all_tables;
1772
1403
case SQLCOM_UPDATE:
1773
1404
assert(first_table == all_tables && first_table != 0);
1774
if (update_precheck(thd, all_tables))
1405
if ((res= update_precheck(session, all_tables)))
1776
1407
assert(select_lex->offset_limit == 0);
1777
1408
unit->set_limit(select_lex);
1778
res= (up_result= mysql_update(thd, all_tables,
1779
select_lex->item_list,
1782
select_lex->order_list.elements,
1783
(ORDER *) select_lex->order_list.first,
1784
unit->select_limit_cnt,
1785
lex->duplicates, lex->ignore));
1786
/* mysql_update return 2 if we need to switch to multi-update */
1409
res= mysql_update(session, all_tables,
1410
select_lex->item_list,
1413
select_lex->order_list.elements,
1414
(order_st *) select_lex->order_list.first,
1415
unit->select_limit_cnt,
1416
lex->duplicates, lex->ignore);
1790
1418
case SQLCOM_UPDATE_MULTI:
1792
1420
assert(first_table == all_tables && first_table != 0);
1793
/* if we switched from normal update, rights are checked */
1796
if ((res= multi_update_precheck(thd, all_tables)))
1802
res= mysql_multi_update_prepare(thd);
1804
/* Check slave filtering rules */
1805
if (unlikely(thd->slave_thread))
1807
if (all_tables_not_ok(thd, all_tables))
1811
res= 0; /* don't care of prev failure */
1812
thd->clear_error(); /* filters are of highest prior */
1814
/* we warn the slave SQL thread */
1815
my_error(ER_SLAVE_IGNORED_TABLE, MYF(0));
1826
some_non_temp_table_to_be_updated(thd, all_tables))
1828
my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--read-only");
1833
res= mysql_multi_update(thd, all_tables,
1421
if ((res= update_precheck(session, all_tables)))
1424
if ((res= mysql_multi_update_prepare(session)))
1427
res= mysql_multi_update(session, all_tables,
1834
1428
&select_lex->item_list,
1835
1429
&lex->value_list,
1836
1430
select_lex->where,
1964
1558
case SQLCOM_DELETE_MULTI:
1966
1560
assert(first_table == all_tables && first_table != 0);
1967
TABLE_LIST *aux_tables=
1968
(TABLE_LIST *)thd->lex->auxiliary_table_list.first;
1561
TableList *aux_tables=
1562
(TableList *)session->lex->auxiliary_table_list.first;
1969
1563
multi_delete *del_result;
1971
if (!thd->locked_tables &&
1972
!(need_start_waiting= !wait_if_global_read_lock(thd, 0, 1)))
1565
if (!session->locked_tables &&
1566
!(need_start_waiting= !wait_if_global_read_lock(session, 0, 1)))
1978
if ((res= multi_delete_precheck(thd, all_tables)))
1572
if ((res= multi_delete_precheck(session, all_tables)))
1981
1575
/* condition will be true on SP re-excuting */
1982
1576
if (select_lex->item_list.elements != 0)
1983
1577
select_lex->item_list.empty();
1984
if (add_item_to_list(thd, new Item_null()))
1578
if (session->add_item_to_list(new Item_null()))
1987
thd_proc_info(thd, "init");
1988
if ((res= open_and_lock_tables(thd, all_tables)))
1581
session->set_proc_info("init");
1582
if ((res= open_and_lock_tables(session, all_tables)))
1991
if ((res= mysql_multi_delete_prepare(thd)))
1585
if ((res= mysql_multi_delete_prepare(session)))
1994
if (!thd->is_fatal_error &&
1588
if (!session->is_fatal_error &&
1995
1589
(del_result= new multi_delete(aux_tables, lex->table_count)))
1997
res= mysql_select(thd, &select_lex->ref_pointer_array,
1591
res= mysql_select(session, &select_lex->ref_pointer_array,
1998
1592
select_lex->get_table_list(),
1999
1593
select_lex->with_wild,
2000
1594
select_lex->item_list,
2001
1595
select_lex->where,
2002
0, (ORDER *)NULL, (ORDER *)NULL, (Item *)NULL,
2004
select_lex->options | thd->options |
1596
0, (order_st *)NULL, (order_st *)NULL, (Item *)NULL,
1598
select_lex->options | session->options |
2005
1599
SELECT_NO_JOIN_CACHE | SELECT_NO_UNLOCK |
2006
1600
OPTION_SETUP_TABLES_DONE,
2007
1601
del_result, unit, select_lex);
2008
res|= thd->is_error();
1602
res|= session->is_error();
2010
1604
del_result->abort();
2011
1605
delete del_result;
2019
1613
assert(first_table == all_tables && first_table != 0);
2020
1614
if (!lex->drop_temporary)
2022
if (end_active_trans(thd))
1616
if (end_active_trans(session))
2028
If this is a slave thread, we may sometimes execute some
2029
DROP / * 40005 TEMPORARY * / TABLE
2030
that come from parts of binlogs (likely if we use RESET SLAVE or CHANGE
2031
MASTER TO), while the temporary table has already been dropped.
2032
To not generate such irrelevant "table does not exist errors",
2033
we silently add IF EXISTS if TEMPORARY was used.
2035
if (thd->slave_thread)
2036
lex->drop_if_exists= 1;
2038
1621
/* So that DROP TEMPORARY TABLE gets to binlog at commit/rollback */
2039
thd->options|= OPTION_KEEP_LOG;
1622
session->options|= OPTION_KEEP_LOG;
2041
1624
/* DDL and binlog write order protected by LOCK_open */
2042
res= mysql_rm_table(thd, first_table, lex->drop_if_exists, lex->drop_temporary);
1625
res= mysql_rm_table(session, first_table, lex->drop_if_exists, lex->drop_temporary);
2045
1628
case SQLCOM_SHOW_PROCESSLIST:
2046
mysqld_list_processes(thd, NullS, lex->verbose);
1629
mysqld_list_processes(session, NULL, lex->verbose);
2048
1631
case SQLCOM_SHOW_ENGINE_LOGS:
2050
res= ha_show_status(thd, lex->create_info.db_type, HA_ENGINE_LOGS);
1633
res= ha_show_status(session, lex->create_info.db_type, HA_ENGINE_LOGS);
2053
1636
case SQLCOM_CHANGE_DB:
2055
1638
LEX_STRING db_str= { (char *) select_lex->db, strlen(select_lex->db) };
2057
if (!mysql_change_db(thd, &db_str, false))
1640
if (!mysql_change_db(session, &db_str, false))
2168
1741
requested. If yes, warn about the conversion to non-transactional
2169
1742
locks or abort in strict mode.
2171
if (check_transactional_lock(thd, all_tables))
1744
if (check_transactional_lock(session, all_tables))
2173
unlock_locked_tables(thd);
1746
unlock_locked_tables(session);
2174
1747
/* we must end the trasaction first, regardless of anything */
2175
if (end_active_trans(thd))
1748
if (end_active_trans(session))
2177
thd->in_lock_tables=1;
2178
thd->options|= OPTION_TABLE_LOCK;
1750
session->in_lock_tables=1;
1751
session->options|= OPTION_TABLE_LOCK;
2180
if (!(res= simple_open_n_lock_tables(thd, all_tables)))
1753
if (!(res= simple_open_n_lock_tables(session, all_tables)))
2182
thd->locked_tables=thd->lock;
2184
(void) set_handler_table_locks(thd, all_tables, false);
1755
session->locked_tables=session->lock;
1757
(void) set_handler_table_locks(session, all_tables, false);
2190
1763
Need to end the current transaction, so the storage engine (InnoDB)
2191
1764
can free its locks if LOCK TABLES locked some tables before finding
2192
1765
that it can't lock a table in its list
2194
ha_autocommit_or_rollback(thd, 1);
2195
end_active_trans(thd);
2196
thd->options&= ~(OPTION_TABLE_LOCK);
1767
ha_autocommit_or_rollback(session, 1);
1768
end_active_trans(session);
1769
session->options&= ~(OPTION_TABLE_LOCK);
2198
thd->in_lock_tables=0;
1771
session->in_lock_tables=0;
2200
1773
case SQLCOM_CREATE_DB:
2205
1778
prepared statement- safe.
2207
1780
HA_CREATE_INFO create_info(lex->create_info);
2208
if (end_active_trans(thd))
1781
if (end_active_trans(session))
2214
if (!(alias=thd->strmake(lex->name.str, lex->name.length)) ||
1787
if (!(alias=session->strmake(lex->name.str, lex->name.length)) ||
2215
1788
check_db_name(&lex->name))
2217
1790
my_error(ER_WRONG_DB_NAME, MYF(0), lex->name.str);
2221
If in a slave thread :
2222
CREATE DATABASE DB was certainly not preceded by USE DB.
2223
For that reason, db_ok() in sql/slave.cc did not check the
2224
do_db/ignore_db. And as this query involves no tables, tables_ok()
2225
above was not called. So we have to check rules again here.
2227
if (thd->slave_thread &&
2228
(!rpl_filter->db_ok(lex->name.str) ||
2229
!rpl_filter->db_ok_with_wild_table(lex->name.str)))
2231
my_message(ER_SLAVE_IGNORED_TABLE, ER(ER_SLAVE_IGNORED_TABLE), MYF(0));
2234
res= mysql_create_db(thd,(lower_case_table_names == 2 ? alias :
1793
res= mysql_create_db(session,(lower_case_table_names == 2 ? alias :
2235
1794
lex->name.str), &create_info, 0);
2238
1797
case SQLCOM_DROP_DB:
2240
if (end_active_trans(thd))
1799
if (end_active_trans(session))
2336
1861
Presumably, RESET and binlog writing doesn't require synchronization
2338
if (!lex->no_write_to_binlog && write_to_binlog)
2340
write_bin_log(thd, false, thd->query, thd->query_length);
1863
write_bin_log(session, false, session->query, session->query_length);
2347
1869
case SQLCOM_KILL:
2349
1871
Item *it= (Item *)lex->value_list.head();
2351
if (lex->table_or_sp_used())
2353
my_error(ER_NOT_SUPPORTED_YET, MYF(0), "Usage of subqueries or stored "
2354
"function calls as part of this statement");
2358
if ((!it->fixed && it->fix_fields(lex->thd, &it)) || it->check_cols(1))
1873
if ((!it->fixed && it->fix_fields(lex->session, &it)) || it->check_cols(1))
2360
1875
my_message(ER_SET_CONSTANTS_ONLY, ER(ER_SET_CONSTANTS_ONLY),
2364
sql_kill(thd, (ulong)it->val_int(), lex->type & ONLY_KILL_QUERY);
1879
sql_kill(session, (ulong)it->val_int(), lex->type & ONLY_KILL_QUERY);
2367
1882
case SQLCOM_BEGIN:
2368
if (thd->transaction.xid_state.xa_state != XA_NOTR)
1883
if (session->transaction.xid_state.xa_state != XA_NOTR)
2370
1885
my_error(ER_XAER_RMFAIL, MYF(0),
2371
xa_state_names[thd->transaction.xid_state.xa_state]);
1886
xa_state_names[session->transaction.xid_state.xa_state]);
2375
1890
Breakpoints for backup testing.
2377
if (begin_trans(thd))
1892
if (begin_trans(session))
2381
1896
case SQLCOM_COMMIT:
2382
if (end_trans(thd, lex->tx_release ? COMMIT_RELEASE :
1897
if (end_trans(session, lex->tx_release ? COMMIT_RELEASE :
2383
1898
lex->tx_chain ? COMMIT_AND_CHAIN : COMMIT))
2387
1902
case SQLCOM_ROLLBACK:
2388
if (end_trans(thd, lex->tx_release ? ROLLBACK_RELEASE :
1903
if (end_trans(session, lex->tx_release ? ROLLBACK_RELEASE :
2389
1904
lex->tx_chain ? ROLLBACK_AND_CHAIN : ROLLBACK))
2393
1908
case SQLCOM_RELEASE_SAVEPOINT:
2396
for (sv=thd->transaction.savepoints; sv; sv=sv->prev)
1911
for (sv=session->transaction.savepoints; sv; sv=sv->prev)
2398
1913
if (my_strnncoll(system_charset_info,
2399
(uchar *)lex->ident.str, lex->ident.length,
2400
(uchar *)sv->name, sv->length) == 0)
1914
(unsigned char *)lex->ident.str, lex->ident.length,
1915
(unsigned char *)sv->name, sv->length) == 0)
2405
if (ha_release_savepoint(thd, sv))
1920
if (ha_release_savepoint(session, sv))
2406
1921
res= true; // cannot happen
2409
thd->transaction.savepoints=sv->prev;
1924
session->transaction.savepoints=sv->prev;
2412
1927
my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "SAVEPOINT", lex->ident.str);
2415
1930
case SQLCOM_ROLLBACK_TO_SAVEPOINT:
2418
for (sv=thd->transaction.savepoints; sv; sv=sv->prev)
1933
for (sv=session->transaction.savepoints; sv; sv=sv->prev)
2420
1935
if (my_strnncoll(system_charset_info,
2421
(uchar *)lex->ident.str, lex->ident.length,
2422
(uchar *)sv->name, sv->length) == 0)
1936
(unsigned char *)lex->ident.str, lex->ident.length,
1937
(unsigned char *)sv->name, sv->length) == 0)
2427
if (ha_rollback_to_savepoint(thd, sv))
1942
if (ha_rollback_to_savepoint(session, sv))
2428
1943
res= true; // cannot happen
2431
if (((thd->options & OPTION_KEEP_LOG) ||
2432
thd->transaction.all.modified_non_trans_table) &&
2434
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1946
if ((session->options & OPTION_KEEP_LOG) || session->transaction.all.modified_non_trans_table)
1947
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2435
1948
ER_WARNING_NOT_COMPLETE_ROLLBACK,
2436
1949
ER(ER_WARNING_NOT_COMPLETE_ROLLBACK));
2439
thd->transaction.savepoints=sv;
1952
session->transaction.savepoints=sv;
2442
1955
my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "SAVEPOINT", lex->ident.str);
2445
1958
case SQLCOM_SAVEPOINT:
2446
if (!(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN) ||
2447
thd->in_sub_stmt) || !opt_using_transactions)
1959
if (!(session->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) || !opt_using_transactions)
2451
1963
SAVEPOINT **sv, *newsv;
2452
for (sv=&thd->transaction.savepoints; *sv; sv=&(*sv)->prev)
1964
for (sv=&session->transaction.savepoints; *sv; sv=&(*sv)->prev)
2454
1966
if (my_strnncoll(system_charset_info,
2455
(uchar *)lex->ident.str, lex->ident.length,
2456
(uchar *)(*sv)->name, (*sv)->length) == 0)
1967
(unsigned char *)lex->ident.str, lex->ident.length,
1968
(unsigned char *)(*sv)->name, (*sv)->length) == 0)
2459
1971
if (*sv) /* old savepoint of the same name exists */
2462
ha_release_savepoint(thd, *sv); // it cannot fail
1974
ha_release_savepoint(session, *sv); // it cannot fail
2463
1975
*sv=(*sv)->prev;
2465
else if ((newsv=(SAVEPOINT *) alloc_root(&thd->transaction.mem_root,
1977
else if ((newsv=(SAVEPOINT *) alloc_root(&session->transaction.mem_root,
2466
1978
savepoint_alloc_size)) == 0)
2468
1980
my_error(ER_OUT_OF_RESOURCES, MYF(0));
2471
newsv->name=strmake_root(&thd->transaction.mem_root,
1983
newsv->name=strmake_root(&session->transaction.mem_root,
2472
1984
lex->ident.str, lex->ident.length);
2473
1985
newsv->length=lex->ident.length;
2594
/****************************************************************************
2595
Check stack size; Send error if there isn't enough stack to continue
2596
****************************************************************************/
2597
#if STACK_DIRECTION < 0
2598
#define used_stack(A,B) (long) (A - B)
2600
#define used_stack(A,B) (long) (B - A)
2605
Note: The 'buf' parameter is necessary, even if it is unused here.
2606
- fix_fields functions has a "dummy" buffer large enough for the
2607
corresponding exec. (Thus we only have to check in fix_fields.)
2608
- Passing to check_stack_overrun() prevents the compiler from removing it.
2610
bool check_stack_overrun(THD *thd, long margin,
2611
uchar *buf __attribute__((unused)))
2614
assert(thd == current_thd);
2615
if ((stack_used=used_stack(thd->thread_stack,(char*) &stack_used)) >=
2616
(long) (my_thread_stack_size - margin))
2618
sprintf(errbuff[0],ER(ER_STACK_OVERRUN_NEED_MORE),
2619
stack_used,my_thread_stack_size,margin);
2620
my_message(ER_STACK_OVERRUN_NEED_MORE,errbuff[0],MYF(ME_FATALERROR));
2626
2089
#define MY_YACC_INIT 1000 // Start with big alloc
2627
2090
#define MY_YACC_MAX 32000 // Because of 'short'
2629
2092
bool my_yyoverflow(short **yyss, YYSTYPE **yyvs, ulong *yystacksize)
2631
LEX *lex= current_thd->lex;
2094
LEX *lex= current_session->lex;
2632
2095
ulong old_info=0;
2633
if ((uint) *yystacksize >= MY_YACC_MAX)
2096
if ((uint32_t) *yystacksize >= MY_YACC_MAX)
2635
2098
if (!lex->yacc_yyvs)
2636
2099
old_info= *yystacksize;
2637
2100
*yystacksize= set_zone((*yystacksize)*2,MY_YACC_INIT,MY_YACC_MAX);
2638
if (!(lex->yacc_yyvs= (uchar*)
2639
my_realloc(lex->yacc_yyvs,
2640
*yystacksize*sizeof(**yyvs),
2641
MYF(MY_ALLOW_ZERO_PTR | MY_FREE_ON_ERROR))) ||
2642
!(lex->yacc_yyss= (uchar*)
2643
my_realloc(lex->yacc_yyss,
2644
*yystacksize*sizeof(**yyss),
2645
MYF(MY_ALLOW_ZERO_PTR | MY_FREE_ON_ERROR))))
2101
unsigned char *tmpptr= NULL;
2102
if (!(tmpptr= (unsigned char *)realloc(lex->yacc_yyvs,
2103
*yystacksize* sizeof(**yyvs))))
2105
lex->yacc_yyvs= tmpptr;
2107
if (!(tmpptr= (unsigned char*)realloc(lex->yacc_yyss,
2108
*yystacksize* sizeof(**yyss))))
2110
lex->yacc_yyss= tmpptr;
2648
2112
{ // Copy old info from stack
2649
2113
memcpy(lex->yacc_yyss, *yyss, old_info*sizeof(**yyss));
2659
Reset THD part responsible for command processing state.
2661
This needs to be called before execution of every statement
2662
(prepared or conventional).
2663
It is not called by substatements of routines.
2666
Make it a method of THD and align its name with the rest of
2667
reset/end/start/init methods.
2669
Call it after we use THD for queries, not before.
2672
void mysql_reset_thd_for_next_command(THD *thd)
2674
assert(! thd->in_sub_stmt);
2676
thd->select_number= 1;
2678
Those two lines below are theoretically unneeded as
2679
THD::cleanup_after_query() should take care of this already.
2681
thd->auto_inc_intervals_in_cur_stmt_for_binlog.empty();
2682
thd->stmt_depends_on_first_successful_insert_id_in_prev_stmt= 0;
2684
thd->query_start_used= 0;
2685
thd->is_fatal_error= thd->time_zone_used= 0;
2686
thd->server_status&= ~ (SERVER_MORE_RESULTS_EXISTS |
2687
SERVER_QUERY_NO_INDEX_USED |
2688
SERVER_QUERY_NO_GOOD_INDEX_USED);
2690
If in autocommit mode and not in a transaction, reset
2691
OPTION_STATUS_NO_TRANS_UPDATE | OPTION_KEEP_LOG to not get warnings
2692
in ha_rollback_trans() about some tables couldn't be rolled back.
2694
if (!(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))
2696
thd->options&= ~OPTION_KEEP_LOG;
2697
thd->transaction.all.modified_non_trans_table= false;
2699
assert(thd->security_ctx== &thd->main_security_ctx);
2700
thd->thread_specific_used= false;
2704
reset_dynamic(&thd->user_var_events);
2705
thd->user_var_events_alloc= thd->mem_root;
2708
thd->main_da.reset_diagnostics_area();
2709
thd->total_warn_count=0; // Warnings for this query
2711
thd->sent_row_count= thd->examined_row_count= 0;
2714
Because we come here only for start of top-statements, binlog format is
2715
constant inside a complex statement (using stored functions) etc.
2717
thd->reset_current_stmt_binlog_row_based();
2724
2123
mysql_init_select(LEX *lex)
2879
2279
- first, call query_cache_send_result_to_client,
2880
2280
- second, if caching failed, initialise the lexical and syntactic parser.
2881
2281
The problem is that the query cache depends on a clean initialization
2882
of (among others) lex->safe_to_cache_query and thd->server_status,
2282
of (among others) lex->safe_to_cache_query and session->server_status,
2883
2283
which are reset respectively in
2885
- mysql_reset_thd_for_next_command()
2285
- mysql_reset_session_for_next_command()
2886
2286
So, initializing the lexical analyser *before* using the query cache
2887
2287
is required for the cache to work properly.
2888
2288
FIXME: cleanup the dependencies in the code to simplify this.
2891
mysql_reset_thd_for_next_command(thd);
2291
session->reset_for_next_command();
2896
Lex_input_stream lip(thd, inBuf, length);
2898
bool err= parse_sql(thd, &lip);
2294
LEX *lex= session->lex;
2296
Lex_input_stream lip(session, inBuf, length);
2298
bool err= parse_sql(session, &lip);
2899
2299
*found_semicolon= lip.found_semicolon;
2904
if (! thd->is_error())
2304
if (! session->is_error())
2907
Binlog logs a string starting from thd->query and having length
2908
thd->query_length; so we set thd->query_length correctly (to not
2307
Binlog logs a string starting from session->query and having length
2308
session->query_length; so we set session->query_length correctly (to not
2909
2309
log several statements in one event, when we executed only first).
2910
2310
We set it to not see the ';' (otherwise it would get into binlog
2911
2311
and Query_log_event::print() would give ';;' output).
3522
bool st_select_lex_unit::add_fake_select_lex(THD *thd_arg)
2924
bool st_select_lex_unit::add_fake_select_lex(Session *session_arg)
3524
2926
SELECT_LEX *first_sl= first_select();
3525
2927
assert(!fake_select_lex);
3527
if (!(fake_select_lex= new (thd_arg->mem_root) SELECT_LEX()))
2929
if (!(fake_select_lex= new (session_arg->mem_root) SELECT_LEX()))
3529
fake_select_lex->include_standalone(this,
2931
fake_select_lex->include_standalone(this,
3530
2932
(SELECT_LEX_NODE**)&fake_select_lex);
3531
2933
fake_select_lex->select_number= INT_MAX;
3532
fake_select_lex->parent_lex= thd_arg->lex; /* Used in init_query. */
2934
fake_select_lex->parent_lex= session_arg->lex; /* Used in init_query. */
3533
2935
fake_select_lex->make_empty_select();
3534
2936
fake_select_lex->linkage= GLOBAL_OPTIONS_TYPE;
3535
2937
fake_select_lex->select_limit= 0;
3537
2939
fake_select_lex->context.outer_context=first_sl->context.outer_context;
3538
/* allow item list resolving in fake select for ORDER BY */
2940
/* allow item list resolving in fake select for order_st BY */
3539
2941
fake_select_lex->context.resolve_in_select_list= true;
3540
2942
fake_select_lex->context.select_lex= fake_select_lex;
3542
2944
if (!is_union())
3546
(SELECT ... ORDER BY list [LIMIT n]) ORDER BY order_list [LIMIT m],
3547
(SELECT ... LIMIT n) ORDER BY order_list [LIMIT m]
2948
(SELECT ... order_st BY list [LIMIT n]) order_st BY order_list [LIMIT m],
2949
(SELECT ... LIMIT n) order_st BY order_list [LIMIT m]
3548
2950
just before the parser starts processing order_list
3550
2952
global_parameters= fake_select_lex;
3551
2953
fake_select_lex->no_table_names_allowed= 1;
3552
thd_arg->lex->current_select= fake_select_lex;
2954
session_arg->lex->current_select= fake_select_lex;
3554
thd_arg->lex->pop_context();
2956
session_arg->lex->pop_context();
3759
3147
tmp_write_to_binlog= 0;
3760
if (lock_global_read_lock(thd))
3148
if (lock_global_read_lock(session))
3761
3149
return 1; // Killed
3762
result= close_cached_tables(thd, tables, false, (options & REFRESH_FAST) ?
3150
result= close_cached_tables(session, tables, false, (options & REFRESH_FAST) ?
3763
3151
false : true, true);
3764
if (make_global_read_lock_block_commit(thd)) // Killed
3152
if (make_global_read_lock_block_commit(session)) // Killed
3766
3154
/* Don't leave things in a half-locked state */
3767
unlock_global_read_lock(thd);
3155
unlock_global_read_lock(session);
3772
result= close_cached_tables(thd, tables, false, (options & REFRESH_FAST) ?
3160
result= close_cached_tables(session, tables, false, (options & REFRESH_FAST) ?
3773
3161
false : true, false);
3776
if (thd && (options & REFRESH_STATUS))
3777
refresh_status(thd);
3778
if (options & REFRESH_THREADS)
3779
flush_thread_cache();
3780
if (options & REFRESH_MASTER)
3783
tmp_write_to_binlog= 0;
3784
if (reset_master(thd))
3789
if (options & REFRESH_SLAVE)
3791
tmp_write_to_binlog= 0;
3792
pthread_mutex_lock(&LOCK_active_mi);
3793
if (reset_slave(thd, active_mi))
3795
pthread_mutex_unlock(&LOCK_active_mi);
3163
if (session && (options & REFRESH_STATUS))
3164
refresh_status(session);
3797
3165
*write_to_binlog= tmp_write_to_binlog;
4212
bool create_table_precheck(THD *thd,
4213
TABLE_LIST *tables __attribute__((unused)),
4214
TABLE_LIST *create_table)
3521
bool create_table_precheck(Session *, TableList *,
3522
TableList *create_table)
4217
SELECT_LEX *select_lex= &lex->select_lex;
4218
3524
bool error= true; // Error message is given
4220
3526
if (create_table && (strcmp(create_table->db, "information_schema") == 0))
4222
my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), "", "", INFORMATION_SCHEMA_NAME.str);
3528
my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), "", "", INFORMATION_SCHEMA_NAME.c_str());
4226
if (select_lex->item_list.elements)
4228
/* Check permissions for used tables in CREATE TABLE ... SELECT */
4230
#ifdef NOT_NECESSARY_TO_CHECK_CREATE_TABLE_EXIST_WHEN_PREPARING_STATEMENT
4231
/* This code throws an ill error for CREATE TABLE t1 SELECT * FROM t1 */
4233
Only do the check for PS, because we on execute we have to check that
4234
against the opened tables to ensure we don't use a table that is part
4235
of the view (which can only be done after the table has been opened).
4237
if (thd->stmt_arena->is_stmt_prepare_or_first_sp_execute())
4240
For temporary tables we don't have to check if the created table exists
4242
if (!(lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) &&
4243
find_table_in_global_list(tables, create_table->db,
4244
create_table->table_name))