751
assert(first_table == all_tables && first_table != 0);
752
res = mysql_check_table(session, first_table, &lex->check_opt);
753
select_lex->table_list.first= (unsigned char*) first_table;
754
lex->query_tables=all_tables;
759
assert(first_table == all_tables && first_table != 0);
760
res= mysql_analyze_table(session, first_table, &lex->check_opt);
761
/* ! we write after unlocking the table */
762
write_bin_log(session, true, session->query, session->query_length);
763
select_lex->table_list.first= (unsigned char*) first_table;
764
lex->query_tables=all_tables;
768
case SQLCOM_OPTIMIZE:
770
assert(first_table == all_tables && first_table != 0);
771
res= mysql_optimize_table(session, first_table, &lex->check_opt);
772
/* ! we write after unlocking the table */
773
write_bin_log(session, true, session->query, session->query_length);
774
select_lex->table_list.first= (unsigned char*) first_table;
775
lex->query_tables=all_tables;
779
assert(first_table == all_tables && first_table != 0);
780
if ((res= update_precheck(session, all_tables)))
782
assert(select_lex->offset_limit == 0);
783
unit->set_limit(select_lex);
784
res= mysql_update(session, all_tables,
785
select_lex->item_list,
788
select_lex->order_list.elements,
789
(order_st *) select_lex->order_list.first,
790
unit->select_limit_cnt,
791
lex->duplicates, lex->ignore);
793
748
case SQLCOM_REPLACE:
794
749
case SQLCOM_INSERT:
870
case SQLCOM_TRUNCATE:
871
if (! session->endActiveTransaction())
876
assert(first_table == all_tables && first_table != 0);
878
Don't allow this within a transaction because we want to use
881
if (session->inTransaction())
883
my_message(ER_LOCK_OR_ACTIVE_TRANSACTION, ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0));
887
res= mysql_truncate(session, first_table, 0);
890
case SQLCOM_DROP_TABLE:
892
assert(first_table == all_tables && first_table != 0);
893
if (!lex->drop_temporary)
895
if (! session->endActiveTransaction())
900
/* So that DROP TEMPORARY TABLE gets to binlog at commit/rollback */
901
session->options|= OPTION_KEEP_LOG;
903
/* DDL and binlog write order protected by LOCK_open */
904
res= mysql_rm_table(session, first_table, lex->drop_if_exists, lex->drop_temporary);
907
case SQLCOM_CHANGE_DB:
909
LEX_STRING db_str= { (char *) select_lex->db, strlen(select_lex->db) };
911
if (!mysql_change_db(session, &db_str, false))
916
case SQLCOM_SET_OPTION:
918
List<set_var_base> *lex_var_list= &lex->var_list;
920
if (session->openTablesLock(all_tables))
922
if (!(res= sql_set_variables(session, lex_var_list)))
929
We encountered some sort of error, but no message was sent.
930
Send something semi-generic here since we don't know which
931
assignment in the list caused the error.
933
if (!session->is_error())
934
my_error(ER_WRONG_ARGUMENTS,MYF(0),"SET");
940
case SQLCOM_CREATE_DB:
943
As mysql_create_db() may modify HA_CREATE_INFO structure passed to
944
it, we need to use a copy of LEX::create_info to make execution
945
prepared statement- safe.
947
HA_CREATE_INFO create_info(lex->create_info);
948
if (! session->endActiveTransaction())
954
if (!(alias=session->strmake(lex->name.str, lex->name.length)) ||
955
check_db_name(&lex->name))
957
my_error(ER_WRONG_DB_NAME, MYF(0), lex->name.str);
960
res= mysql_create_db(session,(lex->name.str), &create_info);
965
if (! session->endActiveTransaction())
970
if (check_db_name(&lex->name))
972
my_error(ER_WRONG_DB_NAME, MYF(0), lex->name.str);
975
if (session->inTransaction())
977
my_message(ER_LOCK_OR_ACTIVE_TRANSACTION, ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0));
980
res= mysql_rm_db(session, lex->name.str, lex->drop_if_exists);
983
case SQLCOM_ALTER_DB:
985
LEX_STRING *db= &lex->name;
986
HA_CREATE_INFO create_info(lex->create_info);
987
if (check_db_name(db))
989
my_error(ER_WRONG_DB_NAME, MYF(0), db->str);
992
if (session->inTransaction())
994
my_message(ER_LOCK_OR_ACTIVE_TRANSACTION, ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0));
997
res= mysql_alter_db(session, db->str, &create_info);
1003
reload_cache() will tell us if we are allowed to write to the
1006
if (!reload_cache(session, lex->type, first_table))
1009
We WANT to write and we CAN write.
1010
! we write after unlocking the table.
1013
Presumably, RESET and binlog writing doesn't require synchronization
1015
write_bin_log(session, false, session->query, session->query_length);
1023
Item *it= (Item *)lex->value_list.head();
1025
if ((!it->fixed && it->fix_fields(lex->session, &it)) || it->check_cols(1))
1027
my_message(ER_SET_CONSTANTS_ONLY, ER(ER_SET_CONSTANTS_ONLY),
1031
sql_kill(session, (ulong)it->val_int(), lex->type & ONLY_KILL_QUERY);
1034
825
case SQLCOM_BEGIN:
1035
826
if (session->transaction.xid_state.xa_state != XA_NOTR)
2140
Reload/resets privileges and the different caches.
2142
@param session Thread handler (can be NULL!)
2143
@param options What should be reset/reloaded (tables, privileges, slave...)
2144
@param tables Tables to flush (if any)
2145
@param write_to_binlog True if we can write to the binlog.
2147
@note Depending on 'options', it may be very bad to write the
2148
query to the binlog (e.g. FLUSH SLAVE); this is a
2149
pointer where reload_cache() will put 0 if
2150
it thinks we really should not write to the binlog.
2151
Otherwise it will put 1.
2153
@return Error status code
2155
@retval !=0 Error; session->killed is set or session->is_error() is true
2158
static bool reload_cache(Session *session, ulong options, TableList *tables)
2162
if (options & REFRESH_LOG)
2164
if (ha_flush_logs(NULL))
2168
Note that if REFRESH_READ_LOCK bit is set then REFRESH_TABLES is set too
2171
if (options & (REFRESH_TABLES | REFRESH_READ_LOCK))
2173
if ((options & REFRESH_READ_LOCK) && session)
2175
if (lock_global_read_lock(session))
2176
return true; // Killed
2177
result= session->close_cached_tables(tables, (options & REFRESH_FAST) ? false : true, true);
2178
if (make_global_read_lock_block_commit(session)) // Killed
2180
/* Don't leave things in a half-locked state */
2181
unlock_global_read_lock(session);
2187
result= session->close_cached_tables(tables, (options & REFRESH_FAST) ? false : true, false);
2189
if (session && (options & REFRESH_STATUS))
2190
session->refresh_status();
2197
1933
kill on thread.
2199
1935
@param session Thread class