13
13
along with this program; if not, write to the Free Software
14
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
#include "mysql_priv.h"
17
#include <drizzled/server_includes.h>
18
18
#include "sql_repl.h"
19
19
#include "rpl_filter.h"
20
#include "repl_failsafe.h"
21
#include <drizzled/drizzled_error_messages.h>
26
24
@defgroup Runtime_Environment Runtime Environment
30
static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables);
32
29
const char *any_db="*any*"; // Special symbol for check_access
34
const LEX_STRING command_name[]={
31
const LEX_STRING command_name[COM_END+1]={
35
32
{ C_STRING_WITH_LEN("Sleep") },
36
33
{ C_STRING_WITH_LEN("Quit") },
37
34
{ C_STRING_WITH_LEN("Init DB") },
41
38
{ C_STRING_WITH_LEN("Drop DB") },
42
39
{ C_STRING_WITH_LEN("Refresh") },
43
40
{ C_STRING_WITH_LEN("Shutdown") },
44
{ C_STRING_WITH_LEN("Statistics") },
45
41
{ C_STRING_WITH_LEN("Processlist") },
46
42
{ C_STRING_WITH_LEN("Connect") },
47
43
{ C_STRING_WITH_LEN("Kill") },
48
{ C_STRING_WITH_LEN("Debug") },
49
44
{ C_STRING_WITH_LEN("Ping") },
50
45
{ C_STRING_WITH_LEN("Time") },
51
{ C_STRING_WITH_LEN("Delayed insert") },
52
46
{ C_STRING_WITH_LEN("Change user") },
53
47
{ C_STRING_WITH_LEN("Binlog Dump") },
54
{ C_STRING_WITH_LEN("Table Dump") },
55
48
{ C_STRING_WITH_LEN("Connect Out") },
56
49
{ C_STRING_WITH_LEN("Register Slave") },
57
{ C_STRING_WITH_LEN("Prepare") },
58
{ C_STRING_WITH_LEN("Execute") },
59
{ C_STRING_WITH_LEN("Long Data") },
60
{ C_STRING_WITH_LEN("Close stmt") },
61
{ C_STRING_WITH_LEN("Reset stmt") },
62
50
{ C_STRING_WITH_LEN("Set option") },
63
{ C_STRING_WITH_LEN("Fetch") },
64
51
{ C_STRING_WITH_LEN("Daemon") },
65
52
{ C_STRING_WITH_LEN("Error") } // Last command number
141
119
Returns true if all tables should be ignored.
143
inline bool all_tables_not_ok(THD *thd, TABLE_LIST *tables)
121
inline bool all_tables_not_ok(THD *thd, TableList *tables)
145
123
return rpl_filter->is_on() && tables &&
146
124
!rpl_filter->tables_ok(thd->db, tables);
150
static bool some_non_temp_table_to_be_updated(THD *thd, TABLE_LIST *tables)
128
static bool some_non_temp_table_to_be_updated(THD *thd, TableList *tables)
152
for (TABLE_LIST *table= tables; table; table= table->next_global)
130
for (TableList *table= tables; table; table= table->next_global)
154
132
assert(table->db && table->table_name);
155
133
if (table->updating &&
173
151
a number of modified rows
176
uint sql_command_flags[SQLCOM_END+1];
154
uint32_t sql_command_flags[SQLCOM_END+1];
178
156
void init_update_queries(void)
180
bzero((uchar*) &sql_command_flags, sizeof(sql_command_flags));
158
memset(&sql_command_flags, 0, sizeof(sql_command_flags));
182
160
sql_command_flags[SQLCOM_CREATE_TABLE]= CF_CHANGES_DATA;
183
161
sql_command_flags[SQLCOM_CREATE_INDEX]= CF_CHANGES_DATA;
205
183
sql_command_flags[SQLCOM_SHOW_FIELDS]= CF_STATUS_COMMAND;
206
184
sql_command_flags[SQLCOM_SHOW_KEYS]= CF_STATUS_COMMAND;
207
185
sql_command_flags[SQLCOM_SHOW_VARIABLES]= CF_STATUS_COMMAND;
208
sql_command_flags[SQLCOM_SHOW_CHARSETS]= CF_STATUS_COMMAND;
209
sql_command_flags[SQLCOM_SHOW_COLLATIONS]= CF_STATUS_COMMAND;
210
186
sql_command_flags[SQLCOM_SHOW_BINLOGS]= CF_STATUS_COMMAND;
211
sql_command_flags[SQLCOM_SHOW_SLAVE_HOSTS]= CF_STATUS_COMMAND;
212
sql_command_flags[SQLCOM_SHOW_BINLOG_EVENTS]= CF_STATUS_COMMAND;
213
187
sql_command_flags[SQLCOM_SHOW_WARNS]= CF_STATUS_COMMAND;
214
188
sql_command_flags[SQLCOM_SHOW_ERRORS]= CF_STATUS_COMMAND;
215
189
sql_command_flags[SQLCOM_SHOW_ENGINE_STATUS]= CF_STATUS_COMMAND;
417
386
if (packet_length == 0) /* safety */
419
388
/* Initialize with COM_SLEEP packet */
420
packet[0]= (uchar) COM_SLEEP;
389
packet[0]= (unsigned char) COM_SLEEP;
421
390
packet_length= 1;
423
392
/* Do not rely on my_net_read, extra safety against programming errors. */
424
393
packet[packet_length]= '\0'; /* safety */
426
command= (enum enum_server_command) (uchar) packet[0];
395
command= (enum enum_server_command) (unsigned char) packet[0];
428
397
if (command >= COM_END)
429
398
command= COM_END; // Wrong command
468
437
if (lex->sql_command == SQLCOM_UPDATE_MULTI)
471
const my_bool create_temp_tables=
440
const bool create_temp_tables=
472
441
(lex->sql_command == SQLCOM_CREATE_TABLE) &&
473
442
(lex->create_info.options & HA_LEX_CREATE_TMP_TABLE);
475
const my_bool drop_temp_tables=
444
const bool drop_temp_tables=
476
445
(lex->sql_command == SQLCOM_DROP_TABLE) &&
477
446
lex->drop_temporary;
479
const my_bool update_real_tables=
448
const bool update_real_tables=
480
449
some_non_temp_table_to_be_updated(thd, all_tables) &&
481
450
!(create_temp_tables || drop_temp_tables);
484
const my_bool create_or_drop_databases=
453
const bool create_or_drop_databases=
485
454
(lex->sql_command == SQLCOM_CREATE_DB) ||
486
455
(lex->sql_command == SQLCOM_DROP_DB);
520
489
COM_QUIT/COM_SHUTDOWN
522
491
bool dispatch_command(enum enum_server_command command, THD *thd,
523
char* packet, uint packet_length)
492
char* packet, uint32_t packet_length)
525
494
NET *net= &thd->net;
528
497
thd->command=command;
530
Commands which always take a long time are logged into
531
the slow log only if opt_log_slow_admin_statements is set.
533
thd->enable_slow_log= true;
534
498
thd->lex->sql_command= SQLCOM_END; /* to avoid confusing VIEW detectors */
536
VOID(pthread_mutex_lock(&LOCK_thread_count));
500
pthread_mutex_lock(&LOCK_thread_count);
537
501
thd->query_id= global_query_id;
539
503
switch( command ) {
540
504
/* Ignore these statements. */
544
/* Only increase id on these statements but don't count them. */
545
case COM_STMT_PREPARE:
550
507
/* Increase id and count all other statements. */
552
509
statistic_increment(thd->status_var.questions, &LOCK_status);
568
527
packet, packet_length, thd->charset());
569
528
if (!mysql_change_db(thd, &tmp, false))
571
general_log_write(thd, command, thd->db, thd->db_length);
576
case COM_REGISTER_SLAVE:
578
if (!register_slave(thd, (uchar*)packet, packet_length))
582
534
case COM_CHANGE_USER:
584
536
status_var_increment(thd->status_var.com_other);
585
537
char *user= (char*) packet, *packet_end= packet + packet_length;
586
538
/* Safe because there is always a trailing \0 at the end of the packet */
587
char *passwd= strend(user)+1;
539
char *passwd= strchr(user, '\0')+1;
589
542
thd->clear_error(); // if errors from rollback
608
561
my_message(ER_UNKNOWN_COM_ERROR, ER(ER_UNKNOWN_COM_ERROR), MYF(0));
611
uint passwd_len= (thd->client_capabilities & CLIENT_SECURE_CONNECTION ?
612
(uchar)(*passwd++) : strlen(passwd));
613
uint dummy_errors, save_db_length, db_length;
564
uint32_t passwd_len= (thd->client_capabilities & CLIENT_SECURE_CONNECTION ?
565
(unsigned char)(*passwd++) : strlen(passwd));
566
uint32_t dummy_errors, save_db_length, db_length;
615
568
Security_context save_security_ctx= *thd->security_ctx;
616
569
USER_CONN *save_user_connect;
662
615
/* Clear variables that are allocated */
663
616
thd->user_connect= 0;
664
thd->security_ctx->priv_user= thd->security_ctx->user;
665
res= check_user(thd, COM_CHANGE_USER, passwd, passwd_len, db, false);
617
res= check_user(thd, passwd, passwd_len, db, false);
669
x_free(thd->security_ctx->user);
621
if (thd->security_ctx->user)
622
free(thd->security_ctx->user);
670
623
*thd->security_ctx= save_security_ctx;
671
624
thd->user_connect= save_user_connect;
672
625
thd->db= save_db;
702
647
char *packet_end= thd->query + thd->query_length;
703
648
const char* end_of_stmt= NULL;
705
general_log_write(thd, command, thd->query, thd->query_length);
707
650
mysql_parse(thd, thd->query, thd->query_length, &end_of_stmt);
709
652
while (!thd->killed && (end_of_stmt != NULL) && ! thd->is_error())
736
679
thd->query_id= next_query_id();
737
680
thd->set_time(); /* Reset the query start time. */
738
681
/* TODO: set thd->lex->sql_command to SQLCOM_END here */
739
VOID(pthread_mutex_unlock(&LOCK_thread_count));
682
pthread_mutex_unlock(&LOCK_thread_count);
741
684
mysql_parse(thd, beginning_of_next_stmt, length, &end_of_stmt);
747
690
char *fields, *packet_end= packet + packet_length, *arg_end;
748
691
/* Locked closure of all tables */
749
TABLE_LIST table_list;
692
TableList table_list;
750
693
LEX_STRING conv_name;
752
695
/* used as fields initializator */
755
698
status_var_increment(thd->status_var.com_stat[SQLCOM_SHOW_FIELDS]);
756
bzero((char*) &table_list,sizeof(table_list));
699
memset(&table_list, 0, sizeof(table_list));
757
700
if (thd->copy_db_to(&table_list.db, &table_list.db_length))
760
703
We have name + wildcard in packet, separated by endzero
762
arg_end= strend(packet);
705
arg_end= strchr(packet, '\0');
763
706
thd->convert_string(&conv_name, system_charset_info,
764
packet, (uint) (arg_end - packet), thd->charset());
707
packet, (uint32_t) (arg_end - packet), thd->charset());
765
708
table_list.alias= table_list.table_name= conv_name.str;
766
709
packet= arg_end + 1;
773
716
table_list.schema_table= schema_table;
776
thd->query_length= (uint) (packet_end - packet); // Don't count end \0
719
thd->query_length= (uint32_t) (packet_end - packet); // Don't count end \0
777
720
if (!(thd->query=fields= (char*) thd->memdup(packet,thd->query_length+1)))
779
general_log_print(thd, command, "%s %s", table_list.table_name, fields);
780
722
if (lower_case_table_names)
781
723
my_casedn_str(files_charset_info, table_list.table_name);
787
729
mysql_reset_thd_for_next_command(thd);
790
select_lex.table_list.link_in_list((uchar*) &table_list,
791
(uchar**) &table_list.next_local);
732
select_lex.table_list.link_in_list((unsigned char*) &table_list,
733
(unsigned char**) &table_list.next_local);
792
734
thd->lex->add_to_query_tables(&table_list);
794
736
/* switch on VIEW optimisation: do not fill temporary tables */
821
761
kill_zombie_dump_threads(slave_server_id);
822
762
thd->server_id = slave_server_id;
824
general_log_print(thd, command, "Log: '%s' Pos: %ld", packet+10,
826
764
mysql_binlog_send(thd, thd->strdup(packet + 10), (my_off_t) pos, flags);
827
unregister_slave(thd,1,1);
828
765
/* fake COM_QUIT -- if we get here, the thread needs to terminate */
832
769
case COM_SHUTDOWN:
834
771
status_var_increment(thd->status_var.com_other);
836
If the client is < 4.1.3, it is going to send us no argument; then
837
packet_length is 0, packet[0] is the end 0 of the packet. Note that
838
SHUTDOWN_DEFAULT is 0. If client is >= 4.1.3, the shutdown level is in
841
enum mysql_enum_shutdown_level level=
842
(enum mysql_enum_shutdown_level) (uchar) packet[0];
843
if (level == SHUTDOWN_DEFAULT)
844
level= SHUTDOWN_WAIT_ALL_BUFFERS; // soon default will be configurable
845
else if (level != SHUTDOWN_WAIT_ALL_BUFFERS)
847
my_error(ER_NOT_SUPPORTED_YET, MYF(0), "this shutdown level");
850
general_log_print(thd, command, NullS);
852
773
close_thread_tables(thd); // Free before kill
859
STATUS_VAR current_global_status_var;
862
uint64_t queries_per_second1000;
864
uint buff_len= sizeof(buff);
866
general_log_print(thd, command, NullS);
867
status_var_increment(thd->status_var.com_stat[SQLCOM_SHOW_STATUS]);
868
calc_sum_of_all_status(¤t_global_status_var);
869
if (!(uptime= (ulong) (thd->start_time - server_start_time)))
870
queries_per_second1000= 0;
872
queries_per_second1000= thd->query_id * 1000LL / uptime;
874
length= snprintf((char*) buff, buff_len - 1,
875
"Uptime: %lu Threads: %d Questions: %lu "
876
"Slow queries: %lu Opens: %lu Flush tables: %lu "
877
"Open tables: %u Queries per second avg: %u.%u",
879
(int) thread_count, (ulong) thd->query_id,
880
current_global_status_var.long_query_count,
881
current_global_status_var.opened_tables,
883
cached_open_tables(),
884
(uint) (queries_per_second1000 / 1000),
885
(uint) (queries_per_second1000 % 1000));
886
/* Store the buffer in permanent memory */
887
my_ok(thd, 0, 0, buff);
888
VOID(my_net_write(net, (uchar*) buff, length));
889
VOID(net_flush(net));
890
thd->main_da.disable_status();
894
779
status_var_increment(thd->status_var.com_other);
895
780
my_ok(thd); // Tell client we are alive
897
782
case COM_PROCESS_INFO:
898
783
status_var_increment(thd->status_var.com_stat[SQLCOM_SHOW_PROCESSLIST]);
899
general_log_print(thd, command, NullS);
900
mysqld_list_processes(thd, NullS, 0);
784
mysqld_list_processes(thd, NULL, 0);
902
786
case COM_PROCESS_KILL:
909
793
case COM_SET_OPTION:
911
795
status_var_increment(thd->status_var.com_stat[SQLCOM_SET_OPTION]);
912
uint opt_command= uint2korr(packet);
796
uint32_t opt_command= uint2korr(packet);
914
798
switch (opt_command) {
915
case (int) MYSQL_OPTION_MULTI_STATEMENTS_ON:
799
case (int) DRIZZLE_OPTION_MULTI_STATEMENTS_ON:
916
800
thd->client_capabilities|= CLIENT_MULTI_STATEMENTS;
919
case (int) MYSQL_OPTION_MULTI_STATEMENTS_OFF:
803
case (int) DRIZZLE_OPTION_MULTI_STATEMENTS_OFF:
920
804
thd->client_capabilities&= ~CLIENT_MULTI_STATEMENTS;
958
842
net_end_statement(thd);
960
thd->proc_info= "closing tables";
844
thd->set_proc_info("closing tables");
961
845
/* Free tables */
962
846
close_thread_tables(thd);
964
848
log_slow_statement(thd);
966
thd_proc_info(thd, "cleaning up");
967
VOID(pthread_mutex_lock(&LOCK_thread_count)); // For process list
968
thd_proc_info(thd, 0);
850
thd->set_proc_info("cleaning up");
851
pthread_mutex_lock(&LOCK_thread_count); // For process list
852
thd->set_proc_info(0);
969
853
thd->command=COM_SLEEP;
971
855
thd->query_length=0;
972
856
thread_running--;
973
VOID(pthread_mutex_unlock(&LOCK_thread_count));
857
pthread_mutex_unlock(&LOCK_thread_count);
974
858
thd->packet.shrink(thd->variables.net_buffer_length); // Reclaim some memory
975
859
free_root(thd->mem_root,MYF(MY_KEEP_PREALLOC));
980
864
void log_slow_statement(THD *thd)
983
The following should never be true with our current code base,
984
but better to keep this here so we don't accidently try to log a
985
statement in a trigger or stored function
987
if (unlikely(thd->in_sub_stmt))
988
return; // Don't set time for sub stmt
991
Do not log administrative statements unless the appropriate option is
992
set; do not log into slow log if reading from backup.
994
if (thd->enable_slow_log && !thd->user_time)
996
thd_proc_info(thd, "logging slow query");
997
uint64_t end_utime_of_query= thd->current_utime();
999
if (((end_utime_of_query - thd->utime_after_lock) >
1000
thd->variables.long_query_time ||
1001
((thd->server_status &
1002
(SERVER_QUERY_NO_INDEX_USED | SERVER_QUERY_NO_GOOD_INDEX_USED)) &&
1003
opt_log_queries_not_using_indexes &&
1004
!(sql_command_flags[thd->lex->sql_command] & CF_STATUS_COMMAND))) &&
1005
thd->examined_row_count >= thd->variables.min_examined_row_limit)
1007
thd_proc_info(thd, "logging slow query");
1008
thd->status_var.long_query_count++;
1009
slow_log_print(thd, thd->query, thd->query_length, end_utime_of_query);
866
logging_post_do(thd);
1017
Create a TABLE_LIST object for an INFORMATION_SCHEMA table.
873
Create a TableList object for an INFORMATION_SCHEMA table.
1019
875
This function is used in the parser to convert a SHOW or DESCRIBE
1020
876
table_name command to a SELECT from INFORMATION_SCHEMA.
1021
It prepares a SELECT_LEX and a TABLE_LIST object to represent the
877
It prepares a SELECT_LEX and a TableList object to represent the
1022
878
given command as a SELECT parse tree.
1024
880
@param thd thread handle
1123
979
true error; In this case thd->fatal_error is set
1126
bool alloc_query(THD *thd, const char *packet, uint packet_length)
982
bool alloc_query(THD *thd, const char *packet, uint32_t packet_length)
1128
984
/* Remove garbage at start and end of query */
1129
985
while (packet_length > 0 && my_isspace(thd->charset(), packet[0]))
1212
1068
/* first SELECT_LEX (have special meaning for many of non-SELECTcommands) */
1213
1069
SELECT_LEX *select_lex= &lex->select_lex;
1214
1070
/* first table of first SELECT_LEX */
1215
TABLE_LIST *first_table= (TABLE_LIST*) select_lex->table_list.first;
1071
TableList *first_table= (TableList*) select_lex->table_list.first;
1216
1072
/* list of all tables in query */
1217
TABLE_LIST *all_tables;
1073
TableList *all_tables;
1218
1074
/* most outer SELECT_LEX_UNIT of query */
1219
1075
SELECT_LEX_UNIT *unit= &lex->unit;
1220
1076
/* Saved variable value */
1379
1233
case SQLCOM_SHOW_WARNS:
1381
res= mysqld_show_warnings(thd, (ulong)
1382
((1L << (uint) MYSQL_ERROR::WARN_LEVEL_NOTE) |
1383
(1L << (uint) MYSQL_ERROR::WARN_LEVEL_WARN) |
1384
(1L << (uint) MYSQL_ERROR::WARN_LEVEL_ERROR)
1235
res= mysqld_show_warnings(thd, (uint32_t)
1236
((1L << (uint32_t) DRIZZLE_ERROR::WARN_LEVEL_NOTE) |
1237
(1L << (uint32_t) DRIZZLE_ERROR::WARN_LEVEL_WARN) |
1238
(1L << (uint32_t) DRIZZLE_ERROR::WARN_LEVEL_ERROR)
1388
1242
case SQLCOM_SHOW_ERRORS:
1390
res= mysqld_show_warnings(thd, (ulong)
1391
(1L << (uint) MYSQL_ERROR::WARN_LEVEL_ERROR));
1394
case SQLCOM_SHOW_SLAVE_HOSTS:
1396
res = show_slave_hosts(thd);
1399
case SQLCOM_SHOW_BINLOG_EVENTS:
1401
res = mysql_show_binlog_events(thd);
1244
res= mysqld_show_warnings(thd, (uint32_t)
1245
(1L << (uint32_t) DRIZZLE_ERROR::WARN_LEVEL_ERROR));
1405
1248
case SQLCOM_ASSIGN_TO_KEYCACHE:
1407
1250
assert(first_table == all_tables && first_table != 0);
1456
1299
assert(first_table == all_tables && first_table != 0);
1457
1300
bool link_to_local;
1458
1301
// Skip first table, which is the table we are creating
1459
TABLE_LIST *create_table= lex->unlink_first_table(&link_to_local);
1460
TABLE_LIST *select_tables= lex->query_tables;
1302
TableList *create_table= lex->unlink_first_table(&link_to_local);
1303
TableList *select_tables= lex->query_tables;
1462
1305
Code below (especially in mysql_create_table() and select_create
1463
1306
methods) may modify HA_CREATE_INFO structure in LEX, so we have to
1533
1376
select_lex->options|= SELECT_NO_UNLOCK;
1534
1377
unit->set_limit(select_lex);
1537
Disable non-empty MERGE tables with CREATE...SELECT. Too
1538
complicated. See Bug #26379. Empty MERGE tables are read-only
1539
and don't allow CREATE...SELECT anyway.
1541
if (create_info.used_fields & HA_CREATE_USED_UNION)
1543
my_error(ER_WRONG_OBJECT, MYF(0), create_table->db,
1544
create_table->table_name, "BASE TABLE");
1546
goto end_with_restore_list;
1549
1379
if (!(create_info.options & HA_LEX_CREATE_TMP_TABLE))
1551
1381
lex->link_first_table_back(create_table, link_to_local);
1569
1399
goto end_with_restore_list;
1572
/* If we create merge table, we have to test tables in merge, too */
1573
if (create_info.used_fields & HA_CREATE_USED_UNION)
1576
for (tab= (TABLE_LIST*) create_info.merge_list.first;
1578
tab= tab->next_local)
1580
TABLE_LIST *duplicate;
1581
if ((duplicate= unique_table(thd, tab, select_tables, 0)))
1583
update_non_unique_table_error(tab, "CREATE", duplicate);
1585
goto end_with_restore_list;
1591
1404
select_create is currently not re-execution friendly and
1657
1470
assert(first_table == all_tables && first_table != 0);
1658
1471
if (end_active_trans(thd))
1661
Currently CREATE INDEX or DROP INDEX cause a full table rebuild
1662
and thus classify as slow administrative statements just like
1665
thd->enable_slow_log= opt_log_slow_admin_statements;
1667
bzero((char*) &create_info, sizeof(create_info));
1474
memset(&create_info, 0, sizeof(create_info));
1668
1475
create_info.db_type= 0;
1669
1476
create_info.row_type= ROW_TYPE_NOT_USED;
1670
1477
create_info.default_table_charset= thd->variables.collation_database;
1672
1479
res= mysql_alter_table(thd, first_table->db, first_table->table_name,
1673
1480
&create_info, first_table, &alter_info,
1481
0, (order_st*) 0, 0);
1677
#ifdef HAVE_REPLICATION
1678
1484
case SQLCOM_SLAVE_START:
1680
1486
pthread_mutex_lock(&LOCK_active_mi);
1731
1536
assert(select_lex->db);
1733
1538
{ // Rename of table
1734
TABLE_LIST tmp_table;
1735
bzero((char*) &tmp_table,sizeof(tmp_table));
1539
TableList tmp_table;
1540
memset(&tmp_table, 0, sizeof(tmp_table));
1736
1541
tmp_table.table_name= lex->name.str;
1737
1542
tmp_table.db=select_lex->db;
1740
1545
/* Don't yet allow changing of symlinks with ALTER TABLE */
1741
1546
if (create_info.data_file_name)
1742
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0,
1547
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN, 0,
1743
1548
"DATA DIRECTORY option ignored");
1744
1549
if (create_info.index_file_name)
1745
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0,
1550
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN, 0,
1746
1551
"INDEX DIRECTORY option ignored");
1747
1552
create_info.data_file_name= create_info.index_file_name= NULL;
1748
1553
/* ALTER TABLE ends previous transaction */
1759
thd->enable_slow_log= opt_log_slow_admin_statements;
1760
1564
res= mysql_alter_table(thd, select_lex->db, lex->name.str,
1764
1568
select_lex->order_list.elements,
1765
(ORDER *) select_lex->order_list.first,
1569
(order_st *) select_lex->order_list.first,
1769
1573
case SQLCOM_RENAME_TABLE:
1771
1575
assert(first_table == all_tables && first_table != 0);
1773
1577
for (table= first_table; table; table= table->next_local->next_local)
1775
TABLE_LIST old_list, new_list;
1579
TableList old_list, new_list;
1777
1581
we do not need initialize old_list and new_list because we will
1778
1582
come table[0] and table->next[0] there
1807
1611
case SQLCOM_REPAIR:
1809
1613
assert(first_table == all_tables && first_table != 0);
1810
thd->enable_slow_log= opt_log_slow_admin_statements;
1811
1614
res= mysql_repair_table(thd, first_table, &lex->check_opt);
1812
1615
/* ! we write after unlocking the table */
1813
if (!res && !lex->no_write_to_binlog)
1816
Presumably, REPAIR and binlog writing doesn't require synchronization
1818
write_bin_log(thd, true, thd->query, thd->query_length);
1820
select_lex->table_list.first= (uchar*) first_table;
1617
Presumably, REPAIR and binlog writing doesn't require synchronization
1619
write_bin_log(thd, true, thd->query, thd->query_length);
1620
select_lex->table_list.first= (unsigned char*) first_table;
1821
1621
lex->query_tables=all_tables;
1824
1624
case SQLCOM_CHECK:
1826
1626
assert(first_table == all_tables && first_table != 0);
1827
thd->enable_slow_log= opt_log_slow_admin_statements;
1828
1627
res = mysql_check_table(thd, first_table, &lex->check_opt);
1829
select_lex->table_list.first= (uchar*) first_table;
1628
select_lex->table_list.first= (unsigned char*) first_table;
1830
1629
lex->query_tables=all_tables;
1833
1632
case SQLCOM_ANALYZE:
1835
1634
assert(first_table == all_tables && first_table != 0);
1836
thd->enable_slow_log= opt_log_slow_admin_statements;
1837
1635
res= mysql_analyze_table(thd, first_table, &lex->check_opt);
1838
1636
/* ! we write after unlocking the table */
1839
if (!res && !lex->no_write_to_binlog)
1842
Presumably, ANALYZE and binlog writing doesn't require synchronization
1844
write_bin_log(thd, true, thd->query, thd->query_length);
1846
select_lex->table_list.first= (uchar*) first_table;
1637
write_bin_log(thd, true, thd->query, thd->query_length);
1638
select_lex->table_list.first= (unsigned char*) first_table;
1847
1639
lex->query_tables=all_tables;
1851
1643
case SQLCOM_OPTIMIZE:
1853
1645
assert(first_table == all_tables && first_table != 0);
1854
thd->enable_slow_log= opt_log_slow_admin_statements;
1855
res= (specialflag & (SPECIAL_SAFE_MODE | SPECIAL_NO_NEW_FUNC)) ?
1856
mysql_recreate_table(thd, first_table) :
1857
mysql_optimize_table(thd, first_table, &lex->check_opt);
1646
res= mysql_optimize_table(thd, first_table, &lex->check_opt);
1858
1647
/* ! we write after unlocking the table */
1859
if (!res && !lex->no_write_to_binlog)
1862
Presumably, OPTIMIZE and binlog writing doesn't require synchronization
1864
write_bin_log(thd, true, thd->query, thd->query_length);
1866
select_lex->table_list.first= (uchar*) first_table;
1648
write_bin_log(thd, true, thd->query, thd->query_length);
1649
select_lex->table_list.first= (unsigned char*) first_table;
1867
1650
lex->query_tables=all_tables;
1987
1766
if (!(res= open_and_lock_tables(thd, all_tables)))
1989
1768
/* Skip first table, which is the table we are inserting in */
1990
TABLE_LIST *second_table= first_table->next_local;
1991
select_lex->table_list.first= (uchar*) second_table;
1769
TableList *second_table= first_table->next_local;
1770
select_lex->table_list.first= (unsigned char*) second_table;
1992
1771
select_lex->context.table_list=
1993
1772
select_lex->context.first_name_resolution_table= second_table;
1994
1773
res= mysql_insert_select_prepare(thd);
2013
1792
/* INSERT ... SELECT should invalidate only the very first table */
2014
TABLE_LIST *save_table= first_table->next_local;
1793
TableList *save_table= first_table->next_local;
2015
1794
first_table->next_local= 0;
2016
1795
first_table->next_local= save_table;
2018
1797
delete sel_result;
2020
1799
/* revert changes for SP */
2021
select_lex->table_list.first= (uchar*) first_table;
1800
select_lex->table_list.first= (unsigned char*) first_table;
2101
1880
select_lex->with_wild,
2102
1881
select_lex->item_list,
2103
1882
select_lex->where,
2104
0, (ORDER *)NULL, (ORDER *)NULL, (Item *)NULL,
1883
0, (order_st *)NULL, (order_st *)NULL, (Item *)NULL,
2106
1885
select_lex->options | thd->options |
2107
1886
SELECT_NO_JOIN_CACHE | SELECT_NO_UNLOCK |
2108
1887
OPTION_SETUP_TABLES_DONE,
2141
1920
thd->options|= OPTION_KEEP_LOG;
2143
1922
/* DDL and binlog write order protected by LOCK_open */
2144
res= mysql_rm_table(thd, first_table, lex->drop_if_exists,
2145
lex->drop_temporary);
1923
res= mysql_rm_table(thd, first_table, lex->drop_if_exists, lex->drop_temporary);
2148
1926
case SQLCOM_SHOW_PROCESSLIST:
2149
mysqld_list_processes(thd, NullS, lex->verbose);
1927
mysqld_list_processes(thd, NULL, lex->verbose);
2151
1929
case SQLCOM_SHOW_ENGINE_LOGS:
2375
2151
res= mysql_rm_db(thd, lex->name.str, lex->drop_if_exists, 0);
2378
case SQLCOM_ALTER_DB_UPGRADE:
2380
LEX_STRING *db= & lex->name;
2381
if (end_active_trans(thd))
2386
#ifdef HAVE_REPLICATION
2387
if (thd->slave_thread &&
2388
(!rpl_filter->db_ok(db->str) ||
2389
!rpl_filter->db_ok_with_wild_table(db->str)))
2392
my_message(ER_SLAVE_IGNORED_TABLE, ER(ER_SLAVE_IGNORED_TABLE), MYF(0));
2396
if (check_db_name(db))
2398
my_error(ER_WRONG_DB_NAME, MYF(0), db->str);
2401
if (thd->locked_tables || thd->active_transaction())
2404
my_message(ER_LOCK_OR_ACTIVE_TRANSACTION,
2405
ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0));
2409
res= mysql_upgrade_db(thd, db);
2414
2154
case SQLCOM_ALTER_DB:
2416
2156
LEX_STRING *db= &lex->name;
2479
2212
Presumably, RESET and binlog writing doesn't require synchronization
2481
if (!lex->no_write_to_binlog && write_to_binlog)
2483
write_bin_log(thd, false, thd->query, thd->query_length);
2214
write_bin_log(thd, false, thd->query, thd->query_length);
2539
2269
for (sv=thd->transaction.savepoints; sv; sv=sv->prev)
2541
2271
if (my_strnncoll(system_charset_info,
2542
(uchar *)lex->ident.str, lex->ident.length,
2543
(uchar *)sv->name, sv->length) == 0)
2272
(unsigned char *)lex->ident.str, lex->ident.length,
2273
(unsigned char *)sv->name, sv->length) == 0)
2561
2291
for (sv=thd->transaction.savepoints; sv; sv=sv->prev)
2563
2293
if (my_strnncoll(system_charset_info,
2564
(uchar *)lex->ident.str, lex->ident.length,
2565
(uchar *)sv->name, sv->length) == 0)
2294
(unsigned char *)lex->ident.str, lex->ident.length,
2295
(unsigned char *)sv->name, sv->length) == 0)
2574
2304
if (((thd->options & OPTION_KEEP_LOG) ||
2575
2305
thd->transaction.all.modified_non_trans_table) &&
2576
2306
!thd->slave_thread)
2577
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
2307
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2578
2308
ER_WARNING_NOT_COMPLETE_ROLLBACK,
2579
2309
ER(ER_WARNING_NOT_COMPLETE_ROLLBACK));
2595
2324
for (sv=&thd->transaction.savepoints; *sv; sv=&(*sv)->prev)
2597
2326
if (my_strnncoll(system_charset_info,
2598
(uchar *)lex->ident.str, lex->ident.length,
2599
(uchar *)(*sv)->name, (*sv)->length) == 0)
2327
(unsigned char *)lex->ident.str, lex->ident.length,
2328
(unsigned char *)(*sv)->name, (*sv)->length) == 0)
2602
2331
if (*sv) /* old savepoint of the same name exists */
2710
2438
if (lex->describe & DESCRIBE_EXTENDED)
2712
2440
char buff[1024];
2713
String str(buff,(uint32) sizeof(buff), system_charset_info);
2441
String str(buff,(uint32_t) sizeof(buff), system_charset_info);
2715
2443
thd->lex->unit.print(&str, QT_ORDINARY);
2716
2444
str.append('\0');
2717
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
2445
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
2718
2446
ER_YES, str.ptr());
2775
2503
LEX *lex= current_thd->lex;
2776
2504
ulong old_info=0;
2777
if ((uint) *yystacksize >= MY_YACC_MAX)
2505
if ((uint32_t) *yystacksize >= MY_YACC_MAX)
2779
2507
if (!lex->yacc_yyvs)
2780
2508
old_info= *yystacksize;
2781
2509
*yystacksize= set_zone((*yystacksize)*2,MY_YACC_INIT,MY_YACC_MAX);
2782
if (!(lex->yacc_yyvs= (uchar*)
2510
if (!(lex->yacc_yyvs= (unsigned char*)
2783
2511
my_realloc(lex->yacc_yyvs,
2784
2512
*yystacksize*sizeof(**yyvs),
2785
2513
MYF(MY_ALLOW_ZERO_PTR | MY_FREE_ON_ERROR))) ||
2786
!(lex->yacc_yyss= (uchar*)
2514
!(lex->yacc_yyss= (unsigned char*)
2787
2515
my_realloc(lex->yacc_yyss,
2788
2516
*yystacksize*sizeof(**yyss),
2789
2517
MYF(MY_ALLOW_ZERO_PTR | MY_FREE_ON_ERROR))))
2792
2520
{ // Copy old info from stack
2793
memcpy(lex->yacc_yyss, (uchar*) *yyss, old_info*sizeof(**yyss));
2794
memcpy(lex->yacc_yyvs, (uchar*) *yyvs, old_info*sizeof(**yyvs));
2521
memcpy(lex->yacc_yyss, *yyss, old_info*sizeof(**yyss));
2522
memcpy(lex->yacc_yyvs, *yyvs, old_info*sizeof(**yyvs));
2796
2524
*yyss=(short*) lex->yacc_yyss;
2797
2525
*yyvs=(YYSTYPE*) lex->yacc_yyvs;
2924
2651
if (lex->current_select->order_list.first && !lex->current_select->braces)
2926
my_error(ER_WRONG_USAGE, MYF(0), "UNION", "ORDER BY");
2653
my_error(ER_WRONG_USAGE, MYF(0), "UNION", "order_st BY");
2929
2656
select_lex->include_neighbour(lex->current_select);
2969
2696
lex->sql_command= SQLCOM_SELECT;
2970
2697
tmp.str= (char*) var_name;
2971
2698
tmp.length=strlen(var_name);
2972
bzero((char*) &null_lex_string.str, sizeof(null_lex_string));
2699
memset(&null_lex_string.str, 0, sizeof(null_lex_string));
2974
2701
We set the name of Item to @@session.var_name because that then is used
2975
2702
as the column name in the output.
2977
2704
if ((var= get_system_var(thd, OPT_SESSION, tmp, null_lex_string)))
2979
end= strxmov(buff, "@@session.", var_name, NullS);
2706
end= strxmov(buff, "@@session.", var_name, NULL);
2980
2707
var->set_name(buff, end-buff, system_charset_info);
2981
2708
add_item_to_list(thd, var);
3100
2826
lex_start(thd);
3101
2827
mysql_reset_thd_for_next_command(thd);
3103
if (!parse_sql(thd, &lip, NULL) &&
3104
all_tables_not_ok(thd,(TABLE_LIST*) lex->select_lex.table_list.first))
2829
if (!parse_sql(thd, &lip) &&
2830
all_tables_not_ok(thd,(TableList*) lex->select_lex.table_list.first))
3105
2831
error= 1; /* Ignore question */
3106
2832
thd->end_statement();
3107
2833
thd->cleanup_after_query();
3121
2846
bool add_field_to_list(THD *thd, LEX_STRING *field_name, enum_field_types type,
3122
2847
char *length, char *decimals,
2848
uint32_t type_modifier,
3124
2849
enum column_format_type column_format,
3125
2850
Item *default_value, Item *on_update_value,
3126
2851
LEX_STRING *comment,
3128
List<String> *interval_list, CHARSET_INFO *cs)
2853
List<String> *interval_list, const CHARSET_INFO * const cs,
2854
virtual_column_info *vcol_info)
3130
2856
register Create_field *new_field;
3131
2857
LEX *lex= thd->lex;
3196
2922
if (!(new_field= new Create_field()) ||
3197
2923
new_field->init(thd, field_name->str, type, length, decimals, type_modifier,
3198
2924
default_value, on_update_value, comment, change,
3199
interval_list, cs, 0, column_format))
2925
interval_list, cs, 0, column_format,
3202
2929
lex->alter_info.create_list.push_back(new_field);
3210
2937
void store_position_for_column(const char *name)
3212
current_thd->lex->last_field->after=my_const_cast(char*) (name);
2939
current_thd->lex->last_field->after=const_cast<char*> (name);
3216
2943
add_proc_to_list(THD* thd, Item *item)
3219
2946
Item **item_ptr;
3221
if (!(order = (ORDER *) thd->alloc(sizeof(ORDER)+sizeof(Item*))))
2948
if (!(order = (order_st *) thd->alloc(sizeof(order_st)+sizeof(Item*))))
3223
2950
item_ptr = (Item**) (order+1);
3224
2951
*item_ptr= item;
3225
2952
order->item=item_ptr;
3226
2953
order->free_me=0;
3227
thd->lex->proc_list.link_in_list((uchar*) order,(uchar**) &order->next);
2954
thd->lex->proc_list.link_in_list((unsigned char*) order,(unsigned char**) &order->next);
3268
\# Pointer to TABLE_LIST element added to the total table list
2995
\# Pointer to TableList element added to the total table list
3271
TABLE_LIST *st_select_lex::add_table_to_list(THD *thd,
2998
TableList *st_select_lex::add_table_to_list(THD *thd,
3272
2999
Table_ident *table,
3273
3000
LEX_STRING *alias,
3274
ulong table_options,
3001
uint32_t table_options,
3275
3002
thr_lock_type lock_type,
3276
3003
List<Index_hint> *index_hints_arg,
3277
3004
LEX_STRING *option)
3279
register TABLE_LIST *ptr;
3280
TABLE_LIST *previous_table_ref; /* The table preceding the current one. */
3006
register TableList *ptr;
3007
TableList *previous_table_ref; /* The table preceding the current one. */
3281
3008
char *alias_str;
3282
3009
LEX *lex= thd->lex;
3362
3089
/* check that used name is unique */
3363
3090
if (lock_type != TL_IGNORE)
3365
TABLE_LIST *first_table= (TABLE_LIST*) table_list.first;
3366
for (TABLE_LIST *tables= first_table ;
3092
TableList *first_table= (TableList*) table_list.first;
3093
for (TableList *tables= first_table ;
3368
3095
tables=tables->next_local)
3379
3106
if (table_list.elements > 0)
3382
table_list.next points to the last inserted TABLE_LIST->next_local'
3109
table_list.next points to the last inserted TableList->next_local'
3384
3111
We don't use the offsetof() macro here to avoid warnings from gcc
3386
previous_table_ref= (TABLE_LIST*) ((char*) table_list.next -
3113
previous_table_ref= (TableList*) ((char*) table_list.next -
3387
3114
((char*) &(ptr->next_local) -
3390
3117
Set next_name_resolution_table of the previous table reference to point
3391
3118
to the current table reference. In effect the list
3392
TABLE_LIST::next_name_resolution_table coincides with
3393
TABLE_LIST::next_local. Later this may be changed in
3119
TableList::next_name_resolution_table coincides with
3120
TableList::next_local. Later this may be changed in
3394
3121
store_top_level_join_columns() for NATURAL/USING joins.
3396
3123
previous_table_ref->next_name_resolution_table= ptr;
3402
3129
previous table reference to 'ptr'. Here we also add one element to the
3403
3130
list 'table_list'.
3405
table_list.link_in_list((uchar*) ptr, (uchar**) &ptr->next_local);
3132
table_list.link_in_list((unsigned char*) ptr, (unsigned char**) &ptr->next_local);
3406
3133
ptr->next_name_resolution_table= NULL;
3407
3134
/* Link table in global list (all used tables) */
3408
3135
lex->add_to_query_tables(ptr);
3432
3159
bool st_select_lex::init_nested_join(THD *thd)
3435
NESTED_JOIN *nested_join;
3162
nested_join_st *nested_join;
3437
if (!(ptr= (TABLE_LIST*) thd->calloc(ALIGN_SIZE(sizeof(TABLE_LIST))+
3438
sizeof(NESTED_JOIN))))
3164
if (!(ptr= (TableList*) thd->calloc(ALIGN_SIZE(sizeof(TableList))+
3165
sizeof(nested_join_st))))
3440
3167
nested_join= ptr->nested_join=
3441
((NESTED_JOIN*) ((uchar*) ptr + ALIGN_SIZE(sizeof(TABLE_LIST))));
3168
((nested_join_st*) ((unsigned char*) ptr + ALIGN_SIZE(sizeof(TableList))));
3443
3170
join_list->push_front(ptr);
3444
3171
ptr->embedding= embedding;
3461
3188
@param thd current thread
3464
- Pointer to TABLE_LIST element added to the total table list, if success
3191
- Pointer to TableList element added to the total table list, if success
3468
TABLE_LIST *st_select_lex::end_nested_join(THD *thd __attribute__((__unused__)))
3195
TableList *st_select_lex::end_nested_join(THD *thd __attribute__((unused)))
3471
NESTED_JOIN *nested_join;
3198
nested_join_st *nested_join;
3473
3200
assert(embedding);
3474
3201
ptr= embedding;
3506
\# Pointer to TABLE_LIST element created for the new nested join
3233
\# Pointer to TableList element created for the new nested join
3509
TABLE_LIST *st_select_lex::nest_last_join(THD *thd)
3236
TableList *st_select_lex::nest_last_join(THD *thd)
3512
NESTED_JOIN *nested_join;
3513
List<TABLE_LIST> *embedded_list;
3239
nested_join_st *nested_join;
3240
List<TableList> *embedded_list;
3515
if (!(ptr= (TABLE_LIST*) thd->calloc(ALIGN_SIZE(sizeof(TABLE_LIST))+
3516
sizeof(NESTED_JOIN))))
3242
if (!(ptr= (TableList*) thd->calloc(ALIGN_SIZE(sizeof(TableList))+
3243
sizeof(nested_join_st))))
3518
3245
nested_join= ptr->nested_join=
3519
((NESTED_JOIN*) ((uchar*) ptr + ALIGN_SIZE(sizeof(TABLE_LIST))));
3246
((nested_join_st*) ((unsigned char*) ptr + ALIGN_SIZE(sizeof(TableList))));
3521
3248
ptr->embedding= embedding;
3522
3249
ptr->join_list= join_list;
3524
3251
embedded_list= &nested_join->join_list;
3525
3252
embedded_list->empty();
3527
for (uint i=0; i < 2; i++)
3254
for (uint32_t i=0; i < 2; i++)
3529
TABLE_LIST *table= join_list->pop();
3256
TableList *table= join_list->pop();
3530
3257
table->join_list= embedded_list;
3531
3258
table->embedding= ptr;
3532
3259
embedded_list->push_back(table);
3604
TABLE_LIST *st_select_lex::convert_right_join()
3331
TableList *st_select_lex::convert_right_join()
3606
TABLE_LIST *tab2= join_list->pop();
3607
TABLE_LIST *tab1= join_list->pop();
3333
TableList *tab2= join_list->pop();
3334
TableList *tab1= join_list->pop();
3609
3336
join_list->push_front(tab2);
3610
3337
join_list->push_front(tab1);
3646
3373
This object is created for any union construct containing a union
3647
3374
operation and also for any single select union construct of the form
3649
(SELECT ... ORDER BY order_list [LIMIT n]) ORDER BY ...
3376
(SELECT ... order_st BY order_list [LIMIT n]) order_st BY ...
3653
(SELECT ... ORDER BY LIMIT n) ORDER BY ...
3380
(SELECT ... order_st BY LIMIT n) order_st BY ...
3656
3383
@param thd_arg thread handle
3691
3418
This works only for
3692
(SELECT ... ORDER BY list [LIMIT n]) ORDER BY order_list [LIMIT m],
3693
(SELECT ... LIMIT n) ORDER BY order_list [LIMIT m]
3419
(SELECT ... order_st BY list [LIMIT n]) order_st BY order_list [LIMIT m],
3420
(SELECT ... LIMIT n) order_st BY order_list [LIMIT m]
3694
3421
just before the parser starts processing order_list
3696
3423
global_parameters= fake_select_lex;
3831
3558
@retval !=0 Error; thd->killed is set or thd->is_error() is true
3834
bool reload_cache(THD *thd, ulong options, TABLE_LIST *tables,
3561
bool reload_cache(THD *thd, ulong options, TableList *tables,
3835
3562
bool *write_to_binlog)
3838
3565
select_errors=0; /* Write if more errors */
3839
3566
bool tmp_write_to_binlog= 1;
3841
assert(!thd || !thd->in_sub_stmt);
3843
3568
if (options & REFRESH_LOG)
3956
3681
This is written such that we have a short lock on LOCK_thread_count
3959
uint kill_one_thread(THD *thd __attribute__((__unused__)),
3960
ulong id, bool only_kill_query)
3685
kill_one_thread(THD *thd __attribute__((unused)),
3686
ulong id, bool only_kill_query)
3963
uint error=ER_NO_SUCH_THREAD;
3964
VOID(pthread_mutex_lock(&LOCK_thread_count)); // For unlink from list
3689
uint32_t error=ER_NO_SUCH_THREAD;
3690
pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
3965
3691
I_List_iterator<THD> it(threads);
3966
3692
while ((tmp=it++))
4023
3749
/* Fix is using unix filename format on dos */
4024
strmov(buff,*filename_ptr);
4025
end=convert_dirname(buff, *filename_ptr, NullS);
3750
my_stpcpy(buff,*filename_ptr);
3751
end=convert_dirname(buff, *filename_ptr, NULL);
4026
3752
if (!(ptr= (char*) thd->alloc((size_t) (end-buff) + strlen(table_name)+1)))
4027
3753
return 1; // End of memory
4028
3754
*filename_ptr=ptr;
4029
strxmov(ptr,buff,table_name,NullS);
3755
strxmov(ptr,buff,table_name,NULL);
4049
3775
char command[80];
4050
3776
Lex_input_stream *lip= thd->m_lip;
4051
3777
strmake(command, lip->yylval->symbol.str,
4052
min(lip->yylval->symbol.length, sizeof(command)-1));
3778
cmin((ulong)lip->yylval->symbol.length, sizeof(command)-1));
4053
3779
my_error(ER_CANT_USE_OPTION_HERE, MYF(0), command);
4176
3902
bool multi_delete_precheck(THD *thd,
4177
TABLE_LIST *tables __attribute__((__unused__)))
3903
TableList *tables __attribute__((unused)))
4179
3905
SELECT_LEX *select_lex= &thd->lex->select_lex;
4180
TABLE_LIST **save_query_tables_own_last= thd->lex->query_tables_own_last;
3906
TableList **save_query_tables_own_last= thd->lex->query_tables_own_last;
4182
3908
thd->lex->query_tables_own_last= 0;
4183
3909
thd->lex->query_tables_own_last= save_query_tables_own_last;
4264
3990
bool multi_delete_set_locks_and_link_aux_tables(LEX *lex)
4266
TABLE_LIST *tables= (TABLE_LIST*)lex->select_lex.table_list.first;
4267
TABLE_LIST *target_tbl;
3992
TableList *tables= (TableList*)lex->select_lex.table_list.first;
3993
TableList *target_tbl;
4269
3995
lex->table_count= 0;
4271
for (target_tbl= (TABLE_LIST *)lex->auxiliary_table_list.first;
3997
for (target_tbl= (TableList *)lex->auxiliary_table_list.first;
4272
3998
target_tbl; target_tbl= target_tbl->next_local)
4274
4000
lex->table_count++;
4275
4001
/* All tables in aux_tables must be found in FROM PART */
4276
TABLE_LIST *walk= multi_delete_table_match(lex, target_tbl, tables);
4002
TableList *walk= multi_delete_table_match(lex, target_tbl, tables);
4279
4005
if (!walk->derived)
4357
bool create_table_precheck(THD *thd,
4358
TABLE_LIST *tables __attribute__((__unused__)),
4359
TABLE_LIST *create_table)
4083
bool create_table_precheck(THD *thd __attribute__((unused)),
4084
TableList *tables __attribute__((unused)),
4085
TableList *create_table)
4362
SELECT_LEX *select_lex= &lex->select_lex;
4363
4087
bool error= true; // Error message is given
4365
4089
if (create_table && (strcmp(create_table->db, "information_schema") == 0))
4371
if (select_lex->item_list.elements)
4373
/* Check permissions for used tables in CREATE TABLE ... SELECT */
4375
#ifdef NOT_NECESSARY_TO_CHECK_CREATE_TABLE_EXIST_WHEN_PREPARING_STATEMENT
4376
/* This code throws an ill error for CREATE TABLE t1 SELECT * FROM t1 */
4378
Only do the check for PS, because we on execute we have to check that
4379
against the opened tables to ensure we don't use a table that is part
4380
of the view (which can only be done after the table has been opened).
4382
if (thd->stmt_arena->is_stmt_prepare_or_first_sp_execute())
4385
For temporary tables we don't have to check if the created table exists
4387
if (!(lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) &&
4388
find_table_in_global_list(tables, create_table->db,
4389
create_table->table_name))
4481
4179
bool check_string_char_length(LEX_STRING *str, const char *err_msg,
4482
uint max_char_length, CHARSET_INFO *cs,
4180
uint32_t max_char_length, const CHARSET_INFO * const cs,
4485
4183
int well_formed_error;
4486
uint res= cs->cset->well_formed_len(cs, str->str, str->str + str->length,
4184
uint32_t res= cs->cset->well_formed_len(cs, str->str, str->str + str->length,
4487
4185
max_char_length, &well_formed_error);
4489
4187
if (!well_formed_error && str->length == res)
4498
bool check_identifier_name(LEX_STRING *str, uint max_char_length,
4499
uint err_code, const char *param_for_err_msg)
4196
bool check_identifier_name(LEX_STRING *str, uint32_t max_char_length,
4197
uint32_t err_code, const char *param_for_err_msg)
4501
4199
#ifdef HAVE_CHARSET_utf8mb3
4504
4202
so they should be prohibited until such support is done.
4505
4203
This is why we use the 3-byte utf8 to check well-formedness here.
4507
CHARSET_INFO *cs= &my_charset_utf8mb3_general_ci;
4205
const CHARSET_INFO * const cs= &my_charset_utf8mb3_general_ci;
4509
CHARSET_INFO *cs= system_charset_info;
4207
const CHARSET_INFO * const cs= system_charset_info;
4511
4209
int well_formed_error;
4512
uint res= cs->cset->well_formed_len(cs, str->str, str->str + str->length,
4210
uint32_t res= cs->cset->well_formed_len(cs, str->str, str->str + str->length,
4513
4211
max_char_length, &well_formed_error);
4515
4213
if (well_formed_error)
4567
4265
if (home_dir_len < dir_len)
4569
if (lower_case_file_system)
4571
if (!my_strnncoll(character_set_filesystem,
4572
(const uchar*) conv_path, home_dir_len,
4573
(const uchar*) mysql_unpacked_real_data_home,
4577
else if (!memcmp(conv_path, mysql_unpacked_real_data_home, home_dir_len))
4267
if (!my_strnncoll(character_set_filesystem,
4268
(const unsigned char*) conv_path, home_dir_len,
4269
(const unsigned char*) mysql_unpacked_real_data_home,
4591
4284
@param thd Thread context.
4592
4285
@param lip Lexer context.
4593
@param creation_ctx Object creation context.
4595
4287
@return Error status.
4596
4288
@retval false on success.
4597
4289
@retval true on parsing error.
4600
bool parse_sql(THD *thd,
4601
Lex_input_stream *lip,
4602
Object_creation_ctx *creation_ctx)
4292
bool parse_sql(THD *thd, Lex_input_stream *lip)
4604
4294
assert(thd->m_lip == NULL);
4606
/* Backup creation context. */
4608
Object_creation_ctx *backup_ctx= NULL;
4611
backup_ctx= creation_ctx->set_n_backup(thd);
4613
4296
/* Set Lex_input_stream. */
4615
4298
thd->m_lip= lip;