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