60
56
"NON-EXISTING", "ACTIVE", "IDLE", "PREPARED"
63
static void unlock_locked_tables(Session *session)
59
static void unlock_locked_tables(THD *thd)
65
if (session->locked_tables)
61
if (thd->locked_tables)
67
session->lock=session->locked_tables;
68
session->locked_tables=0; // Will be automatically closed
69
close_thread_tables(session); // Free tables
63
thd->lock=thd->locked_tables;
64
thd->locked_tables=0; // Will be automatically closed
65
close_thread_tables(thd); // Free tables
74
bool end_active_trans(Session *session)
70
bool end_active_trans(THD *thd)
78
if (session->transaction.xid_state.xa_state != XA_NOTR)
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)
80
80
my_error(ER_XAER_RMFAIL, MYF(0),
81
xa_state_names[session->transaction.xid_state.xa_state]);
81
xa_state_names[thd->transaction.xid_state.xa_state]);
84
if (session->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN |
84
if (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN |
85
85
OPTION_TABLE_LOCK))
87
87
/* Safety if one did "drop table" on locked tables */
88
if (!session->locked_tables)
89
session->options&= ~OPTION_TABLE_LOCK;
90
session->server_status&= ~SERVER_STATUS_IN_TRANS;
91
if (ha_commit(session))
88
if (!thd->locked_tables)
89
thd->options&= ~OPTION_TABLE_LOCK;
90
thd->server_status&= ~SERVER_STATUS_IN_TRANS;
94
session->options&= ~(OPTION_BEGIN | OPTION_KEEP_LOG);
95
session->transaction.all.modified_non_trans_table= false;
94
thd->options&= ~(OPTION_BEGIN | OPTION_KEEP_LOG);
95
thd->transaction.all.modified_non_trans_table= false;
100
bool begin_trans(Session *session)
100
bool begin_trans(THD *thd)
103
if (session->locked_tables)
105
session->lock=session->locked_tables;
106
session->locked_tables=0; // Will be automatically closed
107
close_thread_tables(session); // Free tables
109
if (end_active_trans(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))
113
LEX *lex= session->lex;
114
session->options|= OPTION_BEGIN;
115
session->server_status|= SERVER_STATUS_IN_TRANS;
119
thd->options|= OPTION_BEGIN;
120
thd->server_status|= SERVER_STATUS_IN_TRANS;
116
121
if (lex->start_transaction_opt & DRIZZLE_START_TRANS_OPT_WITH_CONS_SNAPSHOT)
117
error= ha_start_consistent_snapshot(session);
122
error= ha_start_consistent_snapshot(thd);
217
226
return (sql_command_flags[command] & CF_CHANGES_DATA) != 0;
220
void execute_init_command(Session *session, sys_var_str *init_command_var,
229
void execute_init_command(THD *thd, sys_var_str *init_command_var,
221
230
rw_lock_t *var_mutex)
224
233
ulong save_client_capabilities;
226
session->set_proc_info("Execution of init_command");
235
thd_proc_info(thd, "Execution of init_command");
228
237
We need to lock init_command_var because
229
238
during execution of init_command_var query
230
239
values of init_command_var can't be changed
232
241
rw_rdlock(var_mutex);
233
save_client_capabilities= session->client_capabilities;
234
session->client_capabilities|= CLIENT_MULTI_STATEMENTS;
242
save_client_capabilities= thd->client_capabilities;
243
thd->client_capabilities|= CLIENT_MULTI_STATEMENTS;
236
245
We don't need return result of execution to client side.
237
To forbid this we should set session->net.vio to 0.
246
To forbid this we should set thd->net.vio to 0.
239
save_vio= session->net.vio;
241
dispatch_command(COM_QUERY, session,
248
save_vio= thd->net.vio;
250
dispatch_command(COM_QUERY, thd,
242
251
init_command_var->value,
243
252
init_command_var->value_length);
244
253
rw_unlock(var_mutex);
245
session->client_capabilities= save_client_capabilities;
246
session->net.vio= save_vio;
254
thd->client_capabilities= save_client_capabilities;
255
thd->net.vio= save_vio;
250
259
Ends the current transaction and (maybe) begin the next.
252
@param session Current thread
261
@param thd Current thread
253
262
@param completion Completion type
259
int end_trans(Session *session, enum enum_mysql_completiontype completion)
268
int end_trans(THD *thd, enum enum_mysql_completiontype completion)
261
270
bool do_release= 0;
264
if (session->transaction.xid_state.xa_state != XA_NOTR)
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)
266
280
my_error(ER_XAER_RMFAIL, MYF(0),
267
xa_state_names[session->transaction.xid_state.xa_state]);
281
xa_state_names[thd->transaction.xid_state.xa_state]);
270
284
switch (completion) {
512
530
/* Increase id and count all other statements. */
514
statistic_increment(session->status_var.questions, &LOCK_status);
532
statistic_increment(thd->status_var.questions, &LOCK_status);
518
536
thread_running++;
519
/* TODO: set session->lex->sql_command to SQLCOM_END here */
520
pthread_mutex_unlock(&LOCK_thread_count);
522
logging_pre_do(session);
524
session->server_status&=
537
/* TODO: set thd->lex->sql_command to SQLCOM_END here */
538
VOID(pthread_mutex_unlock(&LOCK_thread_count));
525
541
~(SERVER_QUERY_NO_INDEX_USED | SERVER_QUERY_NO_GOOD_INDEX_USED);
526
542
switch (command) {
527
543
case COM_INIT_DB:
530
status_var_increment(session->status_var.com_stat[SQLCOM_CHANGE_DB]);
531
session->convert_string(&tmp, system_charset_info,
532
packet, packet_length, session->charset());
533
if (!mysql_change_db(session, &tmp, false))
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))
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))
539
562
case COM_CHANGE_USER:
541
status_var_increment(session->status_var.com_other);
564
status_var_increment(thd->status_var.com_other);
542
565
char *user= (char*) packet, *packet_end= packet + packet_length;
543
566
/* Safe because there is always a trailing \0 at the end of the packet */
544
567
char *passwd= strchr(user, '\0')+1;
547
session->clear_error(); // if errors from rollback
570
thd->clear_error(); // if errors from rollback
550
573
Old clients send null-terminated string ('\0' for empty string) for
602
625
/* Convert database name to utf8 */
603
626
db_buff[copy_and_convert(db_buff, sizeof(db_buff)-1,
604
627
system_charset_info, db, db_length,
605
session->charset(), &dummy_errors)]= 0;
628
thd->charset(), &dummy_errors)]= 0;
608
631
/* Save user and privileges */
609
save_db_length= session->db_length;
610
save_db= session->db;
611
save_user_connect= session->user_connect;
632
save_db_length= thd->db_length;
634
save_user_connect= thd->user_connect;
613
if (!(session->security_ctx->user= my_strdup(user, MYF(0))))
636
if (!(thd->security_ctx->user= my_strdup(user, MYF(0))))
615
session->security_ctx->user= save_security_ctx.user;
638
thd->security_ctx->user= save_security_ctx.user;
616
639
my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0));
620
643
/* Clear variables that are allocated */
621
session->user_connect= 0;
622
res= check_user(session, passwd, passwd_len, db, false);
644
thd->user_connect= 0;
645
res= check_user(thd, COM_CHANGE_USER, passwd, passwd_len, db, false);
626
if (session->security_ctx->user)
627
free(session->security_ctx->user);
628
*session->security_ctx= save_security_ctx;
629
session->user_connect= save_user_connect;
630
session->db= save_db;
631
session->db_length= save_db_length;
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;
637
if (save_security_ctx.user)
638
free(save_security_ctx.user);
658
x_free(save_security_ctx.user);
642
session_init_client_charset(session, cs_number);
643
session->update_charset();
662
thd_init_client_charset(thd, cs_number);
663
thd->update_charset();
650
if (alloc_query(session, packet, packet_length))
670
if (alloc_query(thd, packet, packet_length))
651
671
break; // fatal error is set
652
char *packet_end= session->query + session->query_length;
672
char *packet_end= thd->query + thd->query_length;
653
673
const char* end_of_stmt= NULL;
655
mysql_parse(session, session->query, session->query_length, &end_of_stmt);
657
while (!session->killed && (end_of_stmt != NULL) && ! session->is_error())
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())
659
681
char *beginning_of_next_stmt= (char*) end_of_stmt;
661
net_end_statement(session);
683
net_end_statement(thd);
663
685
Multiple queries exits, execute them individually
665
close_thread_tables(session);
687
close_thread_tables(thd);
666
688
ulong length= (ulong)(packet_end - beginning_of_next_stmt);
668
log_slow_statement(session);
690
log_slow_statement(thd);
670
692
/* Remove garbage at start of query */
671
while (length > 0 && my_isspace(session->charset(), *beginning_of_next_stmt))
693
while (length > 0 && my_isspace(thd->charset(), *beginning_of_next_stmt))
673
695
beginning_of_next_stmt++;
677
pthread_mutex_lock(&LOCK_thread_count);
678
session->query_length= length;
679
session->query= beginning_of_next_stmt;
699
VOID(pthread_mutex_lock(&LOCK_thread_count));
700
thd->query_length= length;
701
thd->query= beginning_of_next_stmt;
681
703
Count each statement from the client.
683
statistic_increment(session->status_var.questions, &LOCK_status);
684
session->query_id= query_id.next();
685
session->set_time(); /* Reset the query start time. */
686
/* TODO: set session->lex->sql_command to SQLCOM_END here */
687
pthread_mutex_unlock(&LOCK_thread_count);
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));
689
mysql_parse(session, beginning_of_next_stmt, length, &end_of_stmt);
711
mysql_parse(thd, beginning_of_next_stmt, length, &end_of_stmt);
698
720
LEX_STRING conv_name;
700
722
/* used as fields initializator */
703
status_var_increment(session->status_var.com_stat[SQLCOM_SHOW_FIELDS]);
725
status_var_increment(thd->status_var.com_stat[SQLCOM_SHOW_FIELDS]);
704
726
memset(&table_list, 0, sizeof(table_list));
705
if (session->copy_db_to(&table_list.db, &table_list.db_length))
727
if (thd->copy_db_to(&table_list.db, &table_list.db_length))
708
730
We have name + wildcard in packet, separated by endzero
710
732
arg_end= strchr(packet, '\0');
711
session->convert_string(&conv_name, system_charset_info,
712
packet, (uint32_t) (arg_end - packet), session->charset());
733
thd->convert_string(&conv_name, system_charset_info,
734
packet, (uint) (arg_end - packet), thd->charset());
713
735
table_list.alias= table_list.table_name= conv_name.str;
714
736
packet= arg_end + 1;
716
738
if (!my_strcasecmp(system_charset_info, table_list.db,
717
739
INFORMATION_SCHEMA_NAME.str))
719
ST_SCHEMA_TABLE *schema_table= find_schema_table(session, table_list.alias);
741
ST_SCHEMA_TABLE *schema_table= find_schema_table(thd, table_list.alias);
720
742
if (schema_table)
721
743
table_list.schema_table= schema_table;
724
session->query_length= (uint32_t) (packet_end - packet); // Don't count end \0
725
if (!(session->query=fields= (char*) session->memdup(packet,session->query_length+1)))
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)))
749
general_log_print(thd, command, "%s %s", table_list.table_name, fields);
727
750
if (lower_case_table_names)
728
751
my_casedn_str(files_charset_info, table_list.table_name);
730
753
/* init structures for VIEW processing */
731
table_list.select_lex= &(session->lex->select_lex);
734
mysql_reset_session_for_next_command(session);
737
select_lex.table_list.link_in_list((unsigned char*) &table_list,
738
(unsigned char**) &table_list.next_local);
739
session->lex->add_to_query_tables(&table_list);
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);
741
764
/* switch on VIEW optimisation: do not fill temporary tables */
742
session->lex->sql_command= SQLCOM_SHOW_FIELDS;
743
mysqld_list_fields(session,&table_list,fields);
744
session->lex->unit.cleanup();
745
session->cleanup_after_query();
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();
749
772
/* We don't calculate statistics for this command */
773
general_log_print(thd, command, NullS);
750
774
net->error=0; // Don't give 'abort' message
751
session->main_da.disable_status(); // Don't send anything back
775
thd->main_da.disable_status(); // Don't send anything back
752
776
error=true; // End server
754
778
case COM_BINLOG_DUMP:
758
782
uint32_t slave_server_id;
760
status_var_increment(session->status_var.com_other);
784
status_var_increment(thd->status_var.com_other);
785
thd->enable_slow_log= opt_log_slow_admin_statements;
761
786
/* TODO: The following has to be changed to an 8 byte integer */
762
787
pos = uint4korr(packet);
763
788
flags = uint2korr(packet + 4);
764
session->server_id=0; /* avoid suicide */
789
thd->server_id=0; /* avoid suicide */
765
790
if ((slave_server_id= uint4korr(packet+6))) // mysqlbinlog.server_id==0
766
791
kill_zombie_dump_threads(slave_server_id);
767
session->server_id = slave_server_id;
792
thd->server_id = slave_server_id;
769
mysql_binlog_send(session, session->strdup(packet + 10), (my_off_t) pos, flags);
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);
770
798
/* fake COM_QUIT -- if we get here, the thread needs to terminate */
774
802
case COM_SHUTDOWN:
776
status_var_increment(session->status_var.com_other);
778
close_thread_tables(session); // Free before kill
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
784
status_var_increment(session->status_var.com_other);
785
my_ok(session); // Tell client we are alive
828
status_var_increment(thd->status_var.com_other);
829
my_ok(thd); // Tell client we are alive
787
831
case COM_PROCESS_INFO:
788
status_var_increment(session->status_var.com_stat[SQLCOM_SHOW_PROCESSLIST]);
789
mysqld_list_processes(session, NULL, 0);
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);
791
836
case COM_PROCESS_KILL:
793
status_var_increment(session->status_var.com_stat[SQLCOM_KILL]);
838
status_var_increment(thd->status_var.com_stat[SQLCOM_KILL]);
794
839
ulong id=(ulong) uint4korr(packet);
795
sql_kill(session,id,false);
840
sql_kill(thd,id,false);
798
843
case COM_SET_OPTION:
800
status_var_increment(session->status_var.com_stat[SQLCOM_SET_OPTION]);
801
uint32_t opt_command= uint2korr(packet);
845
status_var_increment(thd->status_var.com_stat[SQLCOM_SET_OPTION]);
846
uint opt_command= uint2korr(packet);
803
848
switch (opt_command) {
804
849
case (int) DRIZZLE_OPTION_MULTI_STATEMENTS_ON:
805
session->client_capabilities|= CLIENT_MULTI_STATEMENTS;
850
thd->client_capabilities|= CLIENT_MULTI_STATEMENTS;
808
853
case (int) DRIZZLE_OPTION_MULTI_STATEMENTS_OFF:
809
session->client_capabilities&= ~CLIENT_MULTI_STATEMENTS;
854
thd->client_capabilities&= ~CLIENT_MULTI_STATEMENTS;
813
858
my_message(ER_UNKNOWN_COM_ERROR, ER(ER_UNKNOWN_COM_ERROR), MYF(0));
827
872
/* If commit fails, we should be able to reset the OK status. */
828
session->main_da.can_overwrite_status= true;
829
ha_autocommit_or_rollback(session, session->is_error());
830
session->main_da.can_overwrite_status= false;
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;
832
session->transaction.stmt.reset();
877
thd->transaction.stmt.reset();
835
880
/* report error issued during command execution */
836
if (session->killed_errno())
838
if (! session->main_da.is_set())
839
session->send_kill_message();
841
if (session->killed == Session::KILL_QUERY || session->killed == Session::KILL_BAD_DATA)
843
session->killed= Session::NOT_KILLED;
844
session->mysys_var->abort= 0;
847
net_end_statement(session);
849
session->set_proc_info("closing tables");
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->set_proc_info("closing tables");
850
895
/* Free tables */
851
close_thread_tables(session);
853
log_slow_statement(session);
855
session->set_proc_info("cleaning up");
856
pthread_mutex_lock(&LOCK_thread_count); // For process list
857
session->set_proc_info(0);
858
session->command=COM_SLEEP;
860
session->query_length=0;
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;
861
906
thread_running--;
862
pthread_mutex_unlock(&LOCK_thread_count);
863
session->packet.shrink(session->variables.net_buffer_length); // Reclaim some memory
864
free_root(session->mem_root,MYF(MY_KEEP_PREALLOC));
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));
869
void log_slow_statement(Session *session)
914
void log_slow_statement(THD *thd)
871
logging_post_do(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);
974
Read query from packet and store in session->query.
1047
Read query from packet and store in thd->query.
975
1048
Used in COM_QUERY and COM_STMT_PREPARE.
977
Sets the following Session variables:
1050
Sets the following THD variables:
984
true error; In this case session->fatal_error is set
1057
true error; In this case thd->fatal_error is set
987
bool alloc_query(Session *session, const char *packet, uint32_t packet_length)
1060
bool alloc_query(THD *thd, const char *packet, uint packet_length)
989
1062
/* Remove garbage at start and end of query */
990
while (packet_length > 0 && my_isspace(session->charset(), packet[0]))
1063
while (packet_length > 0 && my_isspace(thd->charset(), packet[0]))
993
1066
packet_length--;
995
1068
const char *pos= packet + packet_length; // Point at end null
996
1069
while (packet_length > 0 &&
997
(pos[-1] == ';' || my_isspace(session->charset() ,pos[-1])))
1070
(pos[-1] == ';' || my_isspace(thd->charset() ,pos[-1])))
1000
1073
packet_length--;
1002
1075
/* We must allocate some extra memory for query cache */
1003
session->query_length= 0; // Extra safety: Avoid races
1004
if (!(session->query= (char*) session->memdup_w_gap((unsigned char*) (packet),
1076
thd->query_length= 0; // Extra safety: Avoid races
1077
if (!(thd->query= (char*) thd->memdup_w_gap((uchar*) (packet),
1006
session->db_length+ 1)))
1079
thd->db_length+ 1)))
1008
session->query[packet_length]=0;
1009
session->query_length= packet_length;
1081
thd->query[packet_length]=0;
1082
thd->query_length= packet_length;
1011
1084
/* Reclaim some memory */
1012
session->packet.shrink(session->variables.net_buffer_length);
1013
session->convert_buffer.shrink(session->variables.net_buffer_length);
1085
thd->packet.shrink(thd->variables.net_buffer_length);
1086
thd->convert_buffer.shrink(thd->variables.net_buffer_length);
1018
static void reset_one_shot_variables(Session *session)
1091
static void reset_one_shot_variables(THD *thd)
1020
session->variables.character_set_client=
1093
thd->variables.character_set_client=
1021
1094
global_system_variables.character_set_client;
1022
session->variables.collation_connection=
1095
thd->variables.collation_connection=
1023
1096
global_system_variables.collation_connection;
1024
session->variables.collation_database=
1097
thd->variables.collation_database=
1025
1098
global_system_variables.collation_database;
1026
session->variables.collation_server=
1099
thd->variables.collation_server=
1027
1100
global_system_variables.collation_server;
1028
session->update_charset();
1029
session->variables.time_zone=
1101
thd->update_charset();
1102
thd->variables.time_zone=
1030
1103
global_system_variables.time_zone;
1031
session->variables.lc_time_names= &my_locale_en_US;
1032
session->one_shot_set= 0;
1104
thd->variables.lc_time_names= &my_locale_en_US;
1105
thd->one_shot_set= 0;
1037
Execute command saved in session and lex->sql_command.
1110
Execute command saved in thd and lex->sql_command.
1039
1112
Before every operation that can request a write lock for a table
1040
1113
wait if a global read lock exists. However do not wait if this
1162
1235
When option readonly is set deny operations which change non-temporary
1163
1236
tables. Except for the replication thread and the 'super' users.
1165
if (deny_updates_if_read_only_option(session, all_tables))
1238
if (deny_updates_if_read_only_option(thd, all_tables))
1167
1240
my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--read-only");
1170
1243
} /* endif unlikely slave */
1171
status_var_increment(session->status_var.com_stat[lex->sql_command]);
1244
status_var_increment(thd->status_var.com_stat[lex->sql_command]);
1173
assert(session->transaction.stmt.modified_non_trans_table == false);
1246
assert(thd->transaction.stmt.modified_non_trans_table == false);
1175
1248
switch (lex->sql_command) {
1176
1249
case SQLCOM_SHOW_STATUS:
1178
system_status_var old_status_var= session->status_var;
1179
session->initial_status_var= &old_status_var;
1180
res= execute_sqlcom_select(session, all_tables);
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);
1181
1254
/* Don't log SHOW STATUS commands to slow query log */
1182
session->server_status&= ~(SERVER_QUERY_NO_INDEX_USED |
1255
thd->server_status&= ~(SERVER_QUERY_NO_INDEX_USED |
1183
1256
SERVER_QUERY_NO_GOOD_INDEX_USED);
1185
1258
restore status variables, as we don't want 'show status' to cause
1188
1261
pthread_mutex_lock(&LOCK_status);
1189
add_diff_to_status(&global_status_var, &session->status_var,
1262
add_diff_to_status(&global_status_var, &thd->status_var,
1190
1263
&old_status_var);
1191
session->status_var= old_status_var;
1264
thd->status_var= old_status_var;
1192
1265
pthread_mutex_unlock(&LOCK_status);
1232
1307
value of constant
1234
1309
it->quick_fix_field();
1235
res = purge_master_logs_before_date(session, (ulong)it->val_int());
1310
res = purge_master_logs_before_date(thd, (ulong)it->val_int());
1238
1313
case SQLCOM_SHOW_WARNS:
1240
res= mysqld_show_warnings(session, (uint32_t)
1241
((1L << (uint32_t) DRIZZLE_ERROR::WARN_LEVEL_NOTE) |
1242
(1L << (uint32_t) DRIZZLE_ERROR::WARN_LEVEL_WARN) |
1243
(1L << (uint32_t) DRIZZLE_ERROR::WARN_LEVEL_ERROR)
1315
res= mysqld_show_warnings(thd, (uint32_t)
1316
((1L << (uint) DRIZZLE_ERROR::WARN_LEVEL_NOTE) |
1317
(1L << (uint) DRIZZLE_ERROR::WARN_LEVEL_WARN) |
1318
(1L << (uint) DRIZZLE_ERROR::WARN_LEVEL_ERROR)
1247
1322
case SQLCOM_SHOW_ERRORS:
1249
res= mysqld_show_warnings(session, (uint32_t)
1250
(1L << (uint32_t) DRIZZLE_ERROR::WARN_LEVEL_ERROR));
1324
res= mysqld_show_warnings(thd, (uint32_t)
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);
1253
1339
case SQLCOM_ASSIGN_TO_KEYCACHE:
1255
1341
assert(first_table == all_tables && first_table != 0);
1256
res= mysql_assign_to_keycache(session, first_table, &lex->ident);
1342
res= mysql_assign_to_keycache(thd, first_table, &lex->ident);
1259
1345
case SQLCOM_CHANGE_MASTER:
1261
1347
pthread_mutex_lock(&LOCK_active_mi);
1262
res = change_master(session,active_mi);
1348
res = change_master(thd,active_mi);
1263
1349
pthread_mutex_unlock(&LOCK_active_mi);
1468
1554
/* Prepare stack copies to be re-execution safe */
1469
1555
HA_CREATE_INFO create_info;
1470
Alter_info alter_info(lex->alter_info, session->mem_root);
1556
Alter_info alter_info(lex->alter_info, thd->mem_root);
1472
if (session->is_fatal_error) /* out of memory creating a copy of alter_info */
1558
if (thd->is_fatal_error) /* out of memory creating a copy of alter_info */
1475
1561
assert(first_table == all_tables && first_table != 0);
1476
if (end_active_trans(session))
1562
if (end_active_trans(thd))
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;
1479
1571
memset(&create_info, 0, sizeof(create_info));
1480
1572
create_info.db_type= 0;
1481
1573
create_info.row_type= ROW_TYPE_NOT_USED;
1482
create_info.default_table_charset= session->variables.collation_database;
1574
create_info.default_table_charset= thd->variables.collation_database;
1484
res= mysql_alter_table(session, first_table->db, first_table->table_name,
1576
res= mysql_alter_table(thd, first_table->db, first_table->table_name,
1485
1577
&create_info, first_table, &alter_info,
1486
1578
0, (order_st*) 0, 0);
1550
1642
/* Don't yet allow changing of symlinks with ALTER TABLE */
1551
1643
if (create_info.data_file_name)
1552
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN, 0,
1644
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN, 0,
1553
1645
"DATA DIRECTORY option ignored");
1554
1646
if (create_info.index_file_name)
1555
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN, 0,
1647
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN, 0,
1556
1648
"INDEX DIRECTORY option ignored");
1557
1649
create_info.data_file_name= create_info.index_file_name= NULL;
1558
1650
/* ALTER TABLE ends previous transaction */
1559
if (end_active_trans(session))
1651
if (end_active_trans(thd))
1562
if (!session->locked_tables &&
1563
!(need_start_waiting= !wait_if_global_read_lock(session, 0, 1)))
1654
if (!thd->locked_tables &&
1655
!(need_start_waiting= !wait_if_global_read_lock(thd, 0, 1)))
1569
res= mysql_alter_table(session, select_lex->db, lex->name.str,
1661
thd->enable_slow_log= opt_log_slow_admin_statements;
1662
res= mysql_alter_table(thd, select_lex->db, lex->name.str,
1599
1692
case SQLCOM_SHOW_BINLOGS:
1601
res = show_binlogs(session);
1694
res = show_binlogs(thd);
1604
1697
case SQLCOM_SHOW_CREATE:
1605
1698
assert(first_table == all_tables && first_table != 0);
1607
res= mysqld_show_create(session, first_table);
1700
res= mysqld_show_create(thd, first_table);
1610
1703
case SQLCOM_CHECKSUM:
1612
1705
assert(first_table == all_tables && first_table != 0);
1613
res = mysql_checksum_table(session, first_table, &lex->check_opt);
1706
res = mysql_checksum_table(thd, first_table, &lex->check_opt);
1616
1709
case SQLCOM_REPAIR:
1618
1711
assert(first_table == all_tables && first_table != 0);
1619
res= mysql_repair_table(session, first_table, &lex->check_opt);
1712
thd->enable_slow_log= opt_log_slow_admin_statements;
1713
res= mysql_repair_table(thd, first_table, &lex->check_opt);
1620
1714
/* ! we write after unlocking the table */
1622
1716
Presumably, REPAIR and binlog writing doesn't require synchronization
1624
write_bin_log(session, true, session->query, session->query_length);
1625
select_lex->table_list.first= (unsigned char*) first_table;
1718
write_bin_log(thd, true, thd->query, thd->query_length);
1719
select_lex->table_list.first= (uchar*) first_table;
1626
1720
lex->query_tables=all_tables;
1629
1723
case SQLCOM_CHECK:
1631
1725
assert(first_table == all_tables && first_table != 0);
1632
res = mysql_check_table(session, first_table, &lex->check_opt);
1633
select_lex->table_list.first= (unsigned char*) first_table;
1726
thd->enable_slow_log= opt_log_slow_admin_statements;
1727
res = mysql_check_table(thd, first_table, &lex->check_opt);
1728
select_lex->table_list.first= (uchar*) first_table;
1634
1729
lex->query_tables=all_tables;
1637
1732
case SQLCOM_ANALYZE:
1639
1734
assert(first_table == all_tables && first_table != 0);
1640
res= mysql_analyze_table(session, first_table, &lex->check_opt);
1735
thd->enable_slow_log= opt_log_slow_admin_statements;
1736
res= mysql_analyze_table(thd, first_table, &lex->check_opt);
1641
1737
/* ! we write after unlocking the table */
1642
write_bin_log(session, true, session->query, session->query_length);
1643
select_lex->table_list.first= (unsigned char*) first_table;
1738
write_bin_log(thd, true, thd->query, thd->query_length);
1739
select_lex->table_list.first= (uchar*) first_table;
1644
1740
lex->query_tables=all_tables;
1648
1744
case SQLCOM_OPTIMIZE:
1650
1746
assert(first_table == all_tables && first_table != 0);
1651
res= mysql_optimize_table(session, first_table, &lex->check_opt);
1747
thd->enable_slow_log= opt_log_slow_admin_statements;
1748
res= mysql_optimize_table(thd, first_table, &lex->check_opt);
1652
1749
/* ! we write after unlocking the table */
1653
write_bin_log(session, true, session->query, session->query_length);
1654
select_lex->table_list.first= (unsigned char*) first_table;
1750
write_bin_log(thd, true, thd->query, thd->query_length);
1751
select_lex->table_list.first= (uchar*) first_table;
1655
1752
lex->query_tables=all_tables;
1658
1755
case SQLCOM_UPDATE:
1659
1756
assert(first_table == all_tables && first_table != 0);
1660
if (update_precheck(session, all_tables))
1757
if (update_precheck(thd, all_tables))
1662
1759
assert(select_lex->offset_limit == 0);
1663
1760
unit->set_limit(select_lex);
1664
res= (up_result= mysql_update(session, all_tables,
1761
res= (up_result= mysql_update(thd, all_tables,
1665
1762
select_lex->item_list,
1666
1763
lex->value_list,
1667
1764
select_lex->where,
1852
1949
assert(first_table == all_tables && first_table != 0);
1853
1950
TableList *aux_tables=
1854
(TableList *)session->lex->auxiliary_table_list.first;
1951
(TableList *)thd->lex->auxiliary_table_list.first;
1855
1952
multi_delete *del_result;
1857
if (!session->locked_tables &&
1858
!(need_start_waiting= !wait_if_global_read_lock(session, 0, 1)))
1954
if (!thd->locked_tables &&
1955
!(need_start_waiting= !wait_if_global_read_lock(thd, 0, 1)))
1864
if ((res= multi_delete_precheck(session, all_tables)))
1961
if ((res= multi_delete_precheck(thd, all_tables)))
1867
1964
/* condition will be true on SP re-excuting */
1868
1965
if (select_lex->item_list.elements != 0)
1869
1966
select_lex->item_list.empty();
1870
if (add_item_to_list(session, new Item_null()))
1967
if (add_item_to_list(thd, new Item_null()))
1873
session->set_proc_info("init");
1874
if ((res= open_and_lock_tables(session, all_tables)))
1970
thd_proc_info(thd, "init");
1971
if ((res= open_and_lock_tables(thd, all_tables)))
1877
if ((res= mysql_multi_delete_prepare(session)))
1974
if ((res= mysql_multi_delete_prepare(thd)))
1880
if (!session->is_fatal_error &&
1977
if (!thd->is_fatal_error &&
1881
1978
(del_result= new multi_delete(aux_tables, lex->table_count)))
1883
res= mysql_select(session, &select_lex->ref_pointer_array,
1980
res= mysql_select(thd, &select_lex->ref_pointer_array,
1884
1981
select_lex->get_table_list(),
1885
1982
select_lex->with_wild,
1886
1983
select_lex->item_list,
1887
1984
select_lex->where,
1888
1985
0, (order_st *)NULL, (order_st *)NULL, (Item *)NULL,
1889
1986
(order_st *)NULL,
1890
select_lex->options | session->options |
1987
select_lex->options | thd->options |
1891
1988
SELECT_NO_JOIN_CACHE | SELECT_NO_UNLOCK |
1892
1989
OPTION_SETUP_TABLES_DONE,
1893
1990
del_result, unit, select_lex);
1894
res|= session->is_error();
1991
res|= thd->is_error();
1896
1993
del_result->abort();
1897
1994
delete del_result;
1918
2015
To not generate such irrelevant "table does not exist errors",
1919
2016
we silently add IF EXISTS if TEMPORARY was used.
1921
if (session->slave_thread)
2018
if (thd->slave_thread)
1922
2019
lex->drop_if_exists= 1;
1924
2021
/* So that DROP TEMPORARY TABLE gets to binlog at commit/rollback */
1925
session->options|= OPTION_KEEP_LOG;
2022
thd->options|= OPTION_KEEP_LOG;
1927
2024
/* DDL and binlog write order protected by LOCK_open */
1928
res= mysql_rm_table(session, first_table, lex->drop_if_exists, lex->drop_temporary);
2025
res= mysql_rm_table(thd, first_table, lex->drop_if_exists, lex->drop_temporary);
1931
2028
case SQLCOM_SHOW_PROCESSLIST:
1932
mysqld_list_processes(session, NULL, lex->verbose);
2029
mysqld_list_processes(thd, NullS, lex->verbose);
1934
2031
case SQLCOM_SHOW_ENGINE_LOGS:
1936
res= ha_show_status(session, lex->create_info.db_type, HA_ENGINE_LOGS);
2033
res= ha_show_status(thd, lex->create_info.db_type, HA_ENGINE_LOGS);
1939
2036
case SQLCOM_CHANGE_DB:
1941
2038
LEX_STRING db_str= { (char *) select_lex->db, strlen(select_lex->db) };
1943
if (!mysql_change_db(session, &db_str, false))
2040
if (!mysql_change_db(thd, &db_str, false))
2236
if ((!it->fixed && it->fix_fields(lex->session, &it)) || it->check_cols(1))
2333
if ((!it->fixed && it->fix_fields(lex->thd, &it)) || it->check_cols(1))
2238
2335
my_message(ER_SET_CONSTANTS_ONLY, ER(ER_SET_CONSTANTS_ONLY),
2242
sql_kill(session, (ulong)it->val_int(), lex->type & ONLY_KILL_QUERY);
2339
sql_kill(thd, (ulong)it->val_int(), lex->type & ONLY_KILL_QUERY);
2245
2342
case SQLCOM_BEGIN:
2246
if (session->transaction.xid_state.xa_state != XA_NOTR)
2343
if (thd->transaction.xid_state.xa_state != XA_NOTR)
2248
2345
my_error(ER_XAER_RMFAIL, MYF(0),
2249
xa_state_names[session->transaction.xid_state.xa_state]);
2346
xa_state_names[thd->transaction.xid_state.xa_state]);
2253
2350
Breakpoints for backup testing.
2255
if (begin_trans(session))
2352
if (begin_trans(thd))
2259
2356
case SQLCOM_COMMIT:
2260
if (end_trans(session, lex->tx_release ? COMMIT_RELEASE :
2357
if (end_trans(thd, lex->tx_release ? COMMIT_RELEASE :
2261
2358
lex->tx_chain ? COMMIT_AND_CHAIN : COMMIT))
2265
2362
case SQLCOM_ROLLBACK:
2266
if (end_trans(session, lex->tx_release ? ROLLBACK_RELEASE :
2363
if (end_trans(thd, lex->tx_release ? ROLLBACK_RELEASE :
2267
2364
lex->tx_chain ? ROLLBACK_AND_CHAIN : ROLLBACK))
2271
2368
case SQLCOM_RELEASE_SAVEPOINT:
2274
for (sv=session->transaction.savepoints; sv; sv=sv->prev)
2371
for (sv=thd->transaction.savepoints; sv; sv=sv->prev)
2276
2373
if (my_strnncoll(system_charset_info,
2277
(unsigned char *)lex->ident.str, lex->ident.length,
2278
(unsigned char *)sv->name, sv->length) == 0)
2374
(uchar *)lex->ident.str, lex->ident.length,
2375
(uchar *)sv->name, sv->length) == 0)
2283
if (ha_release_savepoint(session, sv))
2380
if (ha_release_savepoint(thd, sv))
2284
2381
res= true; // cannot happen
2287
session->transaction.savepoints=sv->prev;
2384
thd->transaction.savepoints=sv->prev;
2290
2387
my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "SAVEPOINT", lex->ident.str);
2293
2390
case SQLCOM_ROLLBACK_TO_SAVEPOINT:
2296
for (sv=session->transaction.savepoints; sv; sv=sv->prev)
2393
for (sv=thd->transaction.savepoints; sv; sv=sv->prev)
2298
2395
if (my_strnncoll(system_charset_info,
2299
(unsigned char *)lex->ident.str, lex->ident.length,
2300
(unsigned char *)sv->name, sv->length) == 0)
2396
(uchar *)lex->ident.str, lex->ident.length,
2397
(uchar *)sv->name, sv->length) == 0)
2305
if (ha_rollback_to_savepoint(session, sv))
2402
if (ha_rollback_to_savepoint(thd, sv))
2306
2403
res= true; // cannot happen
2309
if (((session->options & OPTION_KEEP_LOG) ||
2310
session->transaction.all.modified_non_trans_table) &&
2311
!session->slave_thread)
2312
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2406
if (((thd->options & OPTION_KEEP_LOG) ||
2407
thd->transaction.all.modified_non_trans_table) &&
2409
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2313
2410
ER_WARNING_NOT_COMPLETE_ROLLBACK,
2314
2411
ER(ER_WARNING_NOT_COMPLETE_ROLLBACK));
2317
session->transaction.savepoints=sv;
2414
thd->transaction.savepoints=sv;
2320
2417
my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "SAVEPOINT", lex->ident.str);
2323
2420
case SQLCOM_SAVEPOINT:
2324
if (!(session->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) || !opt_using_transactions)
2421
if (!(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN) ||
2422
thd->in_sub_stmt) || !opt_using_transactions)
2328
2426
SAVEPOINT **sv, *newsv;
2329
for (sv=&session->transaction.savepoints; *sv; sv=&(*sv)->prev)
2427
for (sv=&thd->transaction.savepoints; *sv; sv=&(*sv)->prev)
2331
2429
if (my_strnncoll(system_charset_info,
2332
(unsigned char *)lex->ident.str, lex->ident.length,
2333
(unsigned char *)(*sv)->name, (*sv)->length) == 0)
2430
(uchar *)lex->ident.str, lex->ident.length,
2431
(uchar *)(*sv)->name, (*sv)->length) == 0)
2336
2434
if (*sv) /* old savepoint of the same name exists */
2339
ha_release_savepoint(session, *sv); // it cannot fail
2437
ha_release_savepoint(thd, *sv); // it cannot fail
2340
2438
*sv=(*sv)->prev;
2342
else if ((newsv=(SAVEPOINT *) alloc_root(&session->transaction.mem_root,
2440
else if ((newsv=(SAVEPOINT *) alloc_root(&thd->transaction.mem_root,
2343
2441
savepoint_alloc_size)) == 0)
2345
2443
my_error(ER_OUT_OF_RESOURCES, MYF(0));
2348
newsv->name=strmake_root(&session->transaction.mem_root,
2446
newsv->name=strmake_root(&thd->transaction.mem_root,
2349
2447
lex->ident.str, lex->ident.length);
2350
2448
newsv->length=lex->ident.length;
2535
Reset Session part responsible for command processing state.
2634
Reset THD part responsible for command processing state.
2537
2636
This needs to be called before execution of every statement
2538
2637
(prepared or conventional).
2539
2638
It is not called by substatements of routines.
2542
Make it a method of Session and align its name with the rest of
2641
Make it a method of THD and align its name with the rest of
2543
2642
reset/end/start/init methods.
2545
Call it after we use Session for queries, not before.
2644
Call it after we use THD for queries, not before.
2548
void mysql_reset_session_for_next_command(Session *session)
2647
void mysql_reset_thd_for_next_command(THD *thd)
2550
session->free_list= 0;
2551
session->select_number= 1;
2649
assert(! thd->in_sub_stmt);
2651
thd->select_number= 1;
2553
2653
Those two lines below are theoretically unneeded as
2554
Session::cleanup_after_query() should take care of this already.
2654
THD::cleanup_after_query() should take care of this already.
2556
session->auto_inc_intervals_in_cur_stmt_for_binlog.empty();
2557
session->stmt_depends_on_first_successful_insert_id_in_prev_stmt= 0;
2656
thd->auto_inc_intervals_in_cur_stmt_for_binlog.empty();
2657
thd->stmt_depends_on_first_successful_insert_id_in_prev_stmt= 0;
2559
session->query_start_used= 0;
2560
session->is_fatal_error= session->time_zone_used= 0;
2561
session->server_status&= ~ (SERVER_MORE_RESULTS_EXISTS |
2659
thd->query_start_used= 0;
2660
thd->is_fatal_error= thd->time_zone_used= 0;
2661
thd->server_status&= ~ (SERVER_MORE_RESULTS_EXISTS |
2562
2662
SERVER_QUERY_NO_INDEX_USED |
2563
2663
SERVER_QUERY_NO_GOOD_INDEX_USED);
2566
2666
OPTION_STATUS_NO_TRANS_UPDATE | OPTION_KEEP_LOG to not get warnings
2567
2667
in ha_rollback_trans() about some tables couldn't be rolled back.
2569
if (!(session->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))
2669
if (!(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))
2571
session->options&= ~OPTION_KEEP_LOG;
2572
session->transaction.all.modified_non_trans_table= false;
2671
thd->options&= ~OPTION_KEEP_LOG;
2672
thd->transaction.all.modified_non_trans_table= false;
2574
assert(session->security_ctx== &session->main_security_ctx);
2575
session->thread_specific_used= false;
2674
assert(thd->security_ctx== &thd->main_security_ctx);
2675
thd->thread_specific_used= false;
2577
2677
if (opt_bin_log)
2579
reset_dynamic(&session->user_var_events);
2580
session->user_var_events_alloc= session->mem_root;
2679
reset_dynamic(&thd->user_var_events);
2680
thd->user_var_events_alloc= thd->mem_root;
2582
session->clear_error();
2583
session->main_da.reset_diagnostics_area();
2584
session->total_warn_count=0; // Warnings for this query
2585
session->rand_used= 0;
2586
session->sent_row_count= session->examined_row_count= 0;
2683
thd->main_da.reset_diagnostics_area();
2684
thd->total_warn_count=0; // Warnings for this query
2686
thd->sent_row_count= thd->examined_row_count= 0;
2589
2689
Because we come here only for start of top-statements, binlog format is
2590
2690
constant inside a complex statement (using stored functions) etc.
2592
session->reset_current_stmt_binlog_row_based();
2692
thd->reset_current_stmt_binlog_row_based();
2754
2854
- first, call query_cache_send_result_to_client,
2755
2855
- second, if caching failed, initialise the lexical and syntactic parser.
2756
2856
The problem is that the query cache depends on a clean initialization
2757
of (among others) lex->safe_to_cache_query and session->server_status,
2857
of (among others) lex->safe_to_cache_query and thd->server_status,
2758
2858
which are reset respectively in
2760
- mysql_reset_session_for_next_command()
2860
- mysql_reset_thd_for_next_command()
2761
2861
So, initializing the lexical analyser *before* using the query cache
2762
2862
is required for the cache to work properly.
2763
2863
FIXME: cleanup the dependencies in the code to simplify this.
2766
mysql_reset_session_for_next_command(session);
2866
mysql_reset_thd_for_next_command(thd);
2769
LEX *lex= session->lex;
2771
Lex_input_stream lip(session, inBuf, length);
2773
bool err= parse_sql(session, &lip);
2871
Lex_input_stream lip(thd, inBuf, length);
2873
bool err= parse_sql(thd, &lip);
2774
2874
*found_semicolon= lip.found_semicolon;
2779
if (! session->is_error())
2879
if (! thd->is_error())
2782
Binlog logs a string starting from session->query and having length
2783
session->query_length; so we set session->query_length correctly (to not
2882
Binlog logs a string starting from thd->query and having length
2883
thd->query_length; so we set thd->query_length correctly (to not
2784
2884
log several statements in one event, when we executed only first).
2785
2885
We set it to not see the ';' (otherwise it would get into binlog
2786
2886
and Query_log_event::print() would give ';;' output).