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
20
#include "repl_failsafe.h"
21
#include <drizzled/drizzled_error_messages.h>
23
24
@defgroup Runtime_Environment Runtime Environment
37
38
{ C_STRING_WITH_LEN("Drop DB") },
38
39
{ C_STRING_WITH_LEN("Refresh") },
39
40
{ C_STRING_WITH_LEN("Shutdown") },
40
{ C_STRING_WITH_LEN("Statistics") },
41
41
{ C_STRING_WITH_LEN("Processlist") },
42
42
{ C_STRING_WITH_LEN("Connect") },
43
43
{ C_STRING_WITH_LEN("Kill") },
118
118
LEX *lex= thd->lex;
119
119
thd->options|= OPTION_BEGIN;
120
120
thd->server_status|= SERVER_STATUS_IN_TRANS;
121
if (lex->start_transaction_opt & MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT)
121
if (lex->start_transaction_opt & DRIZZLE_START_TRANS_OPT_WITH_CONS_SNAPSHOT)
122
122
error= ha_start_consistent_snapshot(thd);
128
128
Returns true if all tables should be ignored.
130
inline bool all_tables_not_ok(THD *thd, TABLE_LIST *tables)
130
inline bool all_tables_not_ok(THD *thd, TableList *tables)
132
132
return rpl_filter->is_on() && tables &&
133
133
!rpl_filter->tables_ok(thd->db, tables);
137
static bool some_non_temp_table_to_be_updated(THD *thd, TABLE_LIST *tables)
137
static bool some_non_temp_table_to_be_updated(THD *thd, TableList *tables)
139
for (TABLE_LIST *table= tables; table; table= table->next_global)
139
for (TableList *table= tables; table; table= table->next_global)
141
141
assert(table->db && table->table_name);
142
142
if (table->updating &&
165
165
void init_update_queries(void)
167
memset((uchar*) &sql_command_flags, 0, sizeof(sql_command_flags));
167
memset(&sql_command_flags, 0, sizeof(sql_command_flags));
169
169
sql_command_flags[SQLCOM_CREATE_TABLE]= CF_CHANGES_DATA;
170
170
sql_command_flags[SQLCOM_CREATE_INDEX]= CF_CHANGES_DATA;
565
564
status_var_increment(thd->status_var.com_other);
566
565
char *user= (char*) packet, *packet_end= packet + packet_length;
567
566
/* Safe because there is always a trailing \0 at the end of the packet */
568
char *passwd= strend(user)+1;
567
char *passwd= strchr(user, '\0')+1;
570
570
thd->clear_error(); // if errors from rollback
643
643
/* Clear variables that are allocated */
644
644
thd->user_connect= 0;
645
thd->security_ctx->priv_user= thd->security_ctx->user;
646
645
res= check_user(thd, COM_CHANGE_USER, passwd, passwd_len, db, false);
718
717
char *fields, *packet_end= packet + packet_length, *arg_end;
719
718
/* Locked closure of all tables */
720
TABLE_LIST table_list;
719
TableList table_list;
721
720
LEX_STRING conv_name;
723
722
/* used as fields initializator */
726
725
status_var_increment(thd->status_var.com_stat[SQLCOM_SHOW_FIELDS]);
727
memset((char*) &table_list, 0, sizeof(table_list));
726
memset(&table_list, 0, sizeof(table_list));
728
727
if (thd->copy_db_to(&table_list.db, &table_list.db_length))
731
730
We have name + wildcard in packet, separated by endzero
733
arg_end= strend(packet);
732
arg_end= strchr(packet, '\0');
734
733
thd->convert_string(&conv_name, system_charset_info,
735
734
packet, (uint) (arg_end - packet), thd->charset());
736
735
table_list.alias= table_list.table_name= conv_name.str;
830
STATUS_VAR current_global_status_var;
833
uint64_t queries_per_second1000;
835
uint buff_len= sizeof(buff);
837
general_log_print(thd, command, NullS);
838
status_var_increment(thd->status_var.com_stat[SQLCOM_SHOW_STATUS]);
839
calc_sum_of_all_status(¤t_global_status_var);
840
if (!(uptime= (ulong) (thd->start_time - server_start_time)))
841
queries_per_second1000= 0;
843
queries_per_second1000= thd->query_id * 1000LL / uptime;
845
length= snprintf((char*) buff, buff_len - 1,
846
"Uptime: %lu Threads: %d Questions: %lu "
847
"Slow queries: %lu Opens: %lu Flush tables: %lu "
848
"Open tables: %u Queries per second avg: %u.%u",
850
(int) thread_count, (ulong) thd->query_id,
851
current_global_status_var.long_query_count,
852
current_global_status_var.opened_tables,
854
cached_open_tables(),
855
(uint) (queries_per_second1000 / 1000),
856
(uint) (queries_per_second1000 % 1000));
857
/* Store the buffer in permanent memory */
858
my_ok(thd, 0, 0, buff);
859
VOID(my_net_write(net, (uchar*) buff, length));
860
VOID(net_flush(net));
861
thd->main_da.disable_status();
865
828
status_var_increment(thd->status_var.com_other);
866
829
my_ok(thd); // Tell client we are alive
883
846
uint opt_command= uint2korr(packet);
885
848
switch (opt_command) {
886
case (int) MYSQL_OPTION_MULTI_STATEMENTS_ON:
849
case (int) DRIZZLE_OPTION_MULTI_STATEMENTS_ON:
887
850
thd->client_capabilities|= CLIENT_MULTI_STATEMENTS;
890
case (int) MYSQL_OPTION_MULTI_STATEMENTS_OFF:
853
case (int) DRIZZLE_OPTION_MULTI_STATEMENTS_OFF:
891
854
thd->client_capabilities&= ~CLIENT_MULTI_STATEMENTS;
988
Create a TABLE_LIST object for an INFORMATION_SCHEMA table.
951
Create a TableList object for an INFORMATION_SCHEMA table.
990
953
This function is used in the parser to convert a SHOW or DESCRIBE
991
954
table_name command to a SELECT from INFORMATION_SCHEMA.
992
It prepares a SELECT_LEX and a TABLE_LIST object to represent the
955
It prepares a SELECT_LEX and a TableList object to represent the
993
956
given command as a SELECT parse tree.
995
958
@param thd thread handle
1044
1007
case SCH_STATISTICS:
1046
1009
assert(table_ident);
1047
TABLE_LIST **query_tables_last= lex->query_tables_last;
1010
TableList **query_tables_last= lex->query_tables_last;
1048
1011
schema_select_lex= new SELECT_LEX();
1049
1012
/* 'parent_lex' is used in init_query() so it must be before it. */
1050
1013
schema_select_lex->parent_lex= lex;
1075
TABLE_LIST *table_list= (TABLE_LIST*) select_lex->table_list.first;
1038
TableList *table_list= (TableList*) select_lex->table_list.first;
1076
1039
assert(table_list);
1077
1040
table_list->schema_select_lex= schema_select_lex;
1078
1041
table_list->schema_table_reformed= 1;
1183
1146
/* first SELECT_LEX (have special meaning for many of non-SELECTcommands) */
1184
1147
SELECT_LEX *select_lex= &lex->select_lex;
1185
1148
/* first table of first SELECT_LEX */
1186
TABLE_LIST *first_table= (TABLE_LIST*) select_lex->table_list.first;
1149
TableList *first_table= (TableList*) select_lex->table_list.first;
1187
1150
/* list of all tables in query */
1188
TABLE_LIST *all_tables;
1151
TableList *all_tables;
1189
1152
/* most outer SELECT_LEX_UNIT of query */
1190
1153
SELECT_LEX_UNIT *unit= &lex->unit;
1191
1154
/* Saved variable value */
1210
1173
all_tables= lex->query_tables;
1211
1174
/* set context for commands which do not use setup_tables */
1213
context.resolve_in_table_list_only((TABLE_LIST*)select_lex->
1176
context.resolve_in_table_list_only((TableList*)select_lex->
1214
1177
table_list.first);
1221
1184
Don't reset warnings when executing a stored routine.
1223
1186
if (all_tables || !lex->is_single_level_stmt())
1224
mysql_reset_errors(thd, 0);
1187
drizzle_reset_errors(thd, 0);
1226
1189
if (unlikely(thd->slave_thread))
1350
1313
case SQLCOM_SHOW_WARNS:
1352
res= mysqld_show_warnings(thd, (ulong)
1353
((1L << (uint) MYSQL_ERROR::WARN_LEVEL_NOTE) |
1354
(1L << (uint) MYSQL_ERROR::WARN_LEVEL_WARN) |
1355
(1L << (uint) MYSQL_ERROR::WARN_LEVEL_ERROR)
1315
res= mysqld_show_warnings(thd, (uint32_t)
1316
((1L << (uint) DRIZZLE_ERROR::WARN_LEVEL_NOTE) |
1317
(1L << (uint) DRIZZLE_ERROR::WARN_LEVEL_WARN) |
1318
(1L << (uint) DRIZZLE_ERROR::WARN_LEVEL_ERROR)
1359
1322
case SQLCOM_SHOW_ERRORS:
1361
res= mysqld_show_warnings(thd, (ulong)
1362
(1L << (uint) MYSQL_ERROR::WARN_LEVEL_ERROR));
1324
res= mysqld_show_warnings(thd, (uint32_t)
1325
(1L << (uint) DRIZZLE_ERROR::WARN_LEVEL_ERROR));
1365
1328
case SQLCOM_SHOW_SLAVE_HOSTS:
1398
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0,
1361
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN, 0,
1399
1362
"the master info structure does not exist");
1427
1390
assert(first_table == all_tables && first_table != 0);
1428
1391
bool link_to_local;
1429
1392
// Skip first table, which is the table we are creating
1430
TABLE_LIST *create_table= lex->unlink_first_table(&link_to_local);
1431
TABLE_LIST *select_tables= lex->query_tables;
1393
TableList *create_table= lex->unlink_first_table(&link_to_local);
1394
TableList *select_tables= lex->query_tables;
1433
1396
Code below (especially in mysql_create_table() and select_create
1434
1397
methods) may modify HA_CREATE_INFO structure in LEX, so we have to
1504
1467
select_lex->options|= SELECT_NO_UNLOCK;
1505
1468
unit->set_limit(select_lex);
1508
Disable non-empty MERGE tables with CREATE...SELECT. Too
1509
complicated. See Bug #26379. Empty MERGE tables are read-only
1510
and don't allow CREATE...SELECT anyway.
1512
if (create_info.used_fields & HA_CREATE_USED_UNION)
1514
my_error(ER_WRONG_OBJECT, MYF(0), create_table->db,
1515
create_table->table_name, "BASE TABLE");
1517
goto end_with_restore_list;
1520
1470
if (!(create_info.options & HA_LEX_CREATE_TMP_TABLE))
1522
1472
lex->link_first_table_back(create_table, link_to_local);
1532
1482
if (!(create_info.options & HA_LEX_CREATE_TMP_TABLE))
1534
TABLE_LIST *duplicate;
1484
TableList *duplicate;
1535
1485
create_table= lex->unlink_first_table(&link_to_local);
1536
1486
if ((duplicate= unique_table(thd, create_table, select_tables, 0)))
1540
1490
goto end_with_restore_list;
1543
/* If we create merge table, we have to test tables in merge, too */
1544
if (create_info.used_fields & HA_CREATE_USED_UNION)
1547
for (tab= (TABLE_LIST*) create_info.merge_list.first;
1549
tab= tab->next_local)
1551
TABLE_LIST *duplicate;
1552
if ((duplicate= unique_table(thd, tab, select_tables, 0)))
1554
update_non_unique_table_error(tab, "CREATE", duplicate);
1556
goto end_with_restore_list;
1562
1495
select_create is currently not re-execution friendly and
1636
1569
thd->enable_slow_log= opt_log_slow_admin_statements;
1638
memset((char*) &create_info, 0, sizeof(create_info));
1571
memset(&create_info, 0, sizeof(create_info));
1639
1572
create_info.db_type= 0;
1640
1573
create_info.row_type= ROW_TYPE_NOT_USED;
1641
1574
create_info.default_table_charset= thd->variables.collation_database;
1643
1576
res= mysql_alter_table(thd, first_table->db, first_table->table_name,
1644
1577
&create_info, first_table, &alter_info,
1578
0, (order_st*) 0, 0);
1648
1581
case SQLCOM_SLAVE_START:
1700
1633
assert(select_lex->db);
1702
1635
{ // Rename of table
1703
TABLE_LIST tmp_table;
1704
memset((char*) &tmp_table, 0, sizeof(tmp_table));
1636
TableList tmp_table;
1637
memset(&tmp_table, 0, sizeof(tmp_table));
1705
1638
tmp_table.table_name= lex->name.str;
1706
1639
tmp_table.db=select_lex->db;
1709
1642
/* Don't yet allow changing of symlinks with ALTER TABLE */
1710
1643
if (create_info.data_file_name)
1711
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0,
1644
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN, 0,
1712
1645
"DATA DIRECTORY option ignored");
1713
1646
if (create_info.index_file_name)
1714
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0,
1647
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN, 0,
1715
1648
"INDEX DIRECTORY option ignored");
1716
1649
create_info.data_file_name= create_info.index_file_name= NULL;
1717
1650
/* ALTER TABLE ends previous transaction */
1733
1666
select_lex->order_list.elements,
1734
(ORDER *) select_lex->order_list.first,
1667
(order_st *) select_lex->order_list.first,
1738
1671
case SQLCOM_RENAME_TABLE:
1740
1673
assert(first_table == all_tables && first_table != 0);
1742
1675
for (table= first_table; table; table= table->next_local->next_local)
1744
TABLE_LIST old_list, new_list;
1677
TableList old_list, new_list;
1746
1679
we do not need initialize old_list and new_list because we will
1747
1680
come table[0] and table->next[0] there
1822
1755
assert(first_table == all_tables && first_table != 0);
1823
1756
thd->enable_slow_log= opt_log_slow_admin_statements;
1824
res= (specialflag & (SPECIAL_SAFE_MODE | SPECIAL_NO_NEW_FUNC)) ?
1825
mysql_recreate_table(thd, first_table) :
1826
mysql_optimize_table(thd, first_table, &lex->check_opt);
1757
res= mysql_optimize_table(thd, first_table, &lex->check_opt);
1827
1758
/* ! we write after unlocking the table */
1828
1759
if (!res && !lex->no_write_to_binlog)
1847
1778
lex->value_list,
1848
1779
select_lex->where,
1849
1780
select_lex->order_list.elements,
1850
(ORDER *) select_lex->order_list.first,
1781
(order_st *) select_lex->order_list.first,
1851
1782
unit->select_limit_cnt,
1852
1783
lex->duplicates, lex->ignore));
1853
1784
/* mysql_update return 2 if we need to switch to multi-update */
1952
1883
if (!(res= open_and_lock_tables(thd, all_tables)))
1954
1885
/* Skip first table, which is the table we are inserting in */
1955
TABLE_LIST *second_table= first_table->next_local;
1886
TableList *second_table= first_table->next_local;
1956
1887
select_lex->table_list.first= (uchar*) second_table;
1957
1888
select_lex->context.table_list=
1958
1889
select_lex->context.first_name_resolution_table= second_table;
1978
1909
/* INSERT ... SELECT should invalidate only the very first table */
1979
TABLE_LIST *save_table= first_table->next_local;
1910
TableList *save_table= first_table->next_local;
1980
1911
first_table->next_local= 0;
1981
1912
first_table->next_local= save_table;
2031
1962
case SQLCOM_DELETE_MULTI:
2033
1964
assert(first_table == all_tables && first_table != 0);
2034
TABLE_LIST *aux_tables=
2035
(TABLE_LIST *)thd->lex->auxiliary_table_list.first;
1965
TableList *aux_tables=
1966
(TableList *)thd->lex->auxiliary_table_list.first;
2036
1967
multi_delete *del_result;
2038
1969
if (!thd->locked_tables &&
2066
1997
select_lex->with_wild,
2067
1998
select_lex->item_list,
2068
1999
select_lex->where,
2069
0, (ORDER *)NULL, (ORDER *)NULL, (Item *)NULL,
2000
0, (order_st *)NULL, (order_st *)NULL, (Item *)NULL,
2071
2002
select_lex->options | thd->options |
2072
2003
SELECT_NO_JOIN_CACHE | SELECT_NO_UNLOCK |
2073
2004
OPTION_SETUP_TABLES_DONE,
2498
2429
if (((thd->options & OPTION_KEEP_LOG) ||
2499
2430
thd->transaction.all.modified_non_trans_table) &&
2500
2431
!thd->slave_thread)
2501
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
2432
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2502
2433
ER_WARNING_NOT_COMPLETE_ROLLBACK,
2503
2434
ER(ER_WARNING_NOT_COMPLETE_ROLLBACK));
2604
2535
return(res || thd->is_error());
2607
bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables)
2538
bool execute_sqlcom_select(THD *thd, TableList *all_tables)
2609
2540
LEX *lex= thd->lex;
2610
2541
select_result *result=lex->result;
2638
2569
thd->lex->unit.print(&str, QT_ORDINARY);
2639
2570
str.append('\0');
2640
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
2571
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
2641
2572
ER_YES, str.ptr());
2715
2646
{ // Copy old info from stack
2716
memcpy(lex->yacc_yyss, (uchar*) *yyss, old_info*sizeof(**yyss));
2717
memcpy(lex->yacc_yyvs, (uchar*) *yyvs, old_info*sizeof(**yyvs));
2647
memcpy(lex->yacc_yyss, *yyss, old_info*sizeof(**yyss));
2648
memcpy(lex->yacc_yyvs, *yyvs, old_info*sizeof(**yyvs));
2719
2650
*yyss=(short*) lex->yacc_yyss;
2720
2651
*yyvs=(YYSTYPE*) lex->yacc_yyvs;
2847
2778
if (lex->current_select->order_list.first && !lex->current_select->braces)
2849
my_error(ER_WRONG_USAGE, MYF(0), "UNION", "ORDER BY");
2780
my_error(ER_WRONG_USAGE, MYF(0), "UNION", "order_st BY");
2852
2783
select_lex->include_neighbour(lex->current_select);
2892
2823
lex->sql_command= SQLCOM_SELECT;
2893
2824
tmp.str= (char*) var_name;
2894
2825
tmp.length=strlen(var_name);
2895
memset((char*) &null_lex_string.str, 0, sizeof(null_lex_string));
2826
memset(&null_lex_string.str, 0, sizeof(null_lex_string));
2897
2828
We set the name of Item to @@session.var_name because that then is used
2898
2829
as the column name in the output.
2963
2894
Lex_input_stream lip(thd, inBuf, length);
2965
bool err= parse_sql(thd, &lip, NULL);
2896
bool err= parse_sql(thd, &lip);
2966
2897
*found_semicolon= lip.found_semicolon;
3022
2953
lex_start(thd);
3023
2954
mysql_reset_thd_for_next_command(thd);
3025
if (!parse_sql(thd, &lip, NULL) &&
3026
all_tables_not_ok(thd,(TABLE_LIST*) lex->select_lex.table_list.first))
2956
if (!parse_sql(thd, &lip) &&
2957
all_tables_not_ok(thd,(TableList*) lex->select_lex.table_list.first))
3027
2958
error= 1; /* Ignore question */
3028
2959
thd->end_statement();
3029
2960
thd->cleanup_after_query();
3046
2977
Item *default_value, Item *on_update_value,
3047
2978
LEX_STRING *comment,
3049
List<String> *interval_list, CHARSET_INFO *cs)
2980
List<String> *interval_list, const CHARSET_INFO * const cs)
3051
2982
register Create_field *new_field;
3052
2983
LEX *lex= thd->lex;
3137
3068
add_proc_to_list(THD* thd, Item *item)
3140
3071
Item **item_ptr;
3142
if (!(order = (ORDER *) thd->alloc(sizeof(ORDER)+sizeof(Item*))))
3073
if (!(order = (order_st *) thd->alloc(sizeof(order_st)+sizeof(Item*))))
3144
3075
item_ptr = (Item**) (order+1);
3145
3076
*item_ptr= item;
3157
3088
bool add_to_list(THD *thd, SQL_LIST &list,Item *item,bool asc)
3160
if (!(order = (ORDER *) thd->alloc(sizeof(ORDER))))
3091
if (!(order = (order_st *) thd->alloc(sizeof(order_st))))
3162
3093
order->item_ptr= item;
3163
3094
order->item= &order->item_ptr;
3189
\# Pointer to TABLE_LIST element added to the total table list
3120
\# Pointer to TableList element added to the total table list
3192
TABLE_LIST *st_select_lex::add_table_to_list(THD *thd,
3123
TableList *st_select_lex::add_table_to_list(THD *thd,
3193
3124
Table_ident *table,
3194
3125
LEX_STRING *alias,
3195
3126
uint32_t table_options,
3197
3128
List<Index_hint> *index_hints_arg,
3198
3129
LEX_STRING *option)
3200
register TABLE_LIST *ptr;
3201
TABLE_LIST *previous_table_ref; /* The table preceding the current one. */
3131
register TableList *ptr;
3132
TableList *previous_table_ref; /* The table preceding the current one. */
3202
3133
char *alias_str;
3203
3134
LEX *lex= thd->lex;
3230
3161
if (!(alias_str= (char*) thd->memdup(alias_str,table->table.length+1)))
3233
if (!(ptr = (TABLE_LIST *) thd->calloc(sizeof(TABLE_LIST))))
3164
if (!(ptr = (TableList *) thd->calloc(sizeof(TableList))))
3234
3165
return(0); /* purecov: inspected */
3235
3166
if (table->db.str)
3283
3214
/* check that used name is unique */
3284
3215
if (lock_type != TL_IGNORE)
3286
TABLE_LIST *first_table= (TABLE_LIST*) table_list.first;
3287
for (TABLE_LIST *tables= first_table ;
3217
TableList *first_table= (TableList*) table_list.first;
3218
for (TableList *tables= first_table ;
3289
3220
tables=tables->next_local)
3300
3231
if (table_list.elements > 0)
3303
table_list.next points to the last inserted TABLE_LIST->next_local'
3234
table_list.next points to the last inserted TableList->next_local'
3305
3236
We don't use the offsetof() macro here to avoid warnings from gcc
3307
previous_table_ref= (TABLE_LIST*) ((char*) table_list.next -
3238
previous_table_ref= (TableList*) ((char*) table_list.next -
3308
3239
((char*) &(ptr->next_local) -
3311
3242
Set next_name_resolution_table of the previous table reference to point
3312
3243
to the current table reference. In effect the list
3313
TABLE_LIST::next_name_resolution_table coincides with
3314
TABLE_LIST::next_local. Later this may be changed in
3244
TableList::next_name_resolution_table coincides with
3245
TableList::next_local. Later this may be changed in
3315
3246
store_top_level_join_columns() for NATURAL/USING joins.
3317
3248
previous_table_ref->next_name_resolution_table= ptr;
3335
3266
Initialize a new table list for a nested join.
3337
The function initializes a structure of the TABLE_LIST type
3268
The function initializes a structure of the TableList type
3338
3269
for a nested join. It sets up its nested join list as empty.
3339
3270
The created structure is added to the front of the current
3340
3271
join list in the st_select_lex object. Then the function
3353
3284
bool st_select_lex::init_nested_join(THD *thd)
3356
NESTED_JOIN *nested_join;
3287
nested_join_st *nested_join;
3358
if (!(ptr= (TABLE_LIST*) thd->calloc(ALIGN_SIZE(sizeof(TABLE_LIST))+
3359
sizeof(NESTED_JOIN))))
3289
if (!(ptr= (TableList*) thd->calloc(ALIGN_SIZE(sizeof(TableList))+
3290
sizeof(nested_join_st))))
3361
3292
nested_join= ptr->nested_join=
3362
((NESTED_JOIN*) ((uchar*) ptr + ALIGN_SIZE(sizeof(TABLE_LIST))));
3293
((nested_join_st*) ((uchar*) ptr + ALIGN_SIZE(sizeof(TableList))));
3364
3295
join_list->push_front(ptr);
3365
3296
ptr->embedding= embedding;
3382
3313
@param thd current thread
3385
- Pointer to TABLE_LIST element added to the total table list, if success
3316
- Pointer to TableList element added to the total table list, if success
3389
TABLE_LIST *st_select_lex::end_nested_join(THD *thd __attribute__((unused)))
3320
TableList *st_select_lex::end_nested_join(THD *thd __attribute__((unused)))
3392
NESTED_JOIN *nested_join;
3323
nested_join_st *nested_join;
3394
3325
assert(embedding);
3395
3326
ptr= embedding;
3398
3329
nested_join= ptr->nested_join;
3399
3330
if (nested_join->join_list.elements == 1)
3401
TABLE_LIST *embedded= nested_join->join_list.head();
3332
TableList *embedded= nested_join->join_list.head();
3402
3333
join_list->pop();
3403
3334
embedded->join_list= join_list;
3404
3335
embedded->embedding= embedding;
3427
\# Pointer to TABLE_LIST element created for the new nested join
3358
\# Pointer to TableList element created for the new nested join
3430
TABLE_LIST *st_select_lex::nest_last_join(THD *thd)
3361
TableList *st_select_lex::nest_last_join(THD *thd)
3433
NESTED_JOIN *nested_join;
3434
List<TABLE_LIST> *embedded_list;
3364
nested_join_st *nested_join;
3365
List<TableList> *embedded_list;
3436
if (!(ptr= (TABLE_LIST*) thd->calloc(ALIGN_SIZE(sizeof(TABLE_LIST))+
3437
sizeof(NESTED_JOIN))))
3367
if (!(ptr= (TableList*) thd->calloc(ALIGN_SIZE(sizeof(TableList))+
3368
sizeof(nested_join_st))))
3439
3370
nested_join= ptr->nested_join=
3440
((NESTED_JOIN*) ((uchar*) ptr + ALIGN_SIZE(sizeof(TABLE_LIST))));
3371
((nested_join_st*) ((uchar*) ptr + ALIGN_SIZE(sizeof(TableList))));
3442
3373
ptr->embedding= embedding;
3443
3374
ptr->join_list= join_list;
3448
3379
for (uint i=0; i < 2; i++)
3450
TABLE_LIST *table= join_list->pop();
3381
TableList *table= join_list->pop();
3451
3382
table->join_list= embedded_list;
3452
3383
table->embedding= ptr;
3453
3384
embedded_list->push_back(table);
3525
TABLE_LIST *st_select_lex::convert_right_join()
3456
TableList *st_select_lex::convert_right_join()
3527
TABLE_LIST *tab2= join_list->pop();
3528
TABLE_LIST *tab1= join_list->pop();
3458
TableList *tab2= join_list->pop();
3459
TableList *tab1= join_list->pop();
3530
3461
join_list->push_front(tab2);
3531
3462
join_list->push_front(tab1);
3567
3498
This object is created for any union construct containing a union
3568
3499
operation and also for any single select union construct of the form
3570
(SELECT ... ORDER BY order_list [LIMIT n]) ORDER BY ...
3501
(SELECT ... order_st BY order_list [LIMIT n]) order_st BY ...
3574
(SELECT ... ORDER BY LIMIT n) ORDER BY ...
3505
(SELECT ... order_st BY LIMIT n) order_st BY ...
3577
3508
@param thd_arg thread handle
3602
3533
fake_select_lex->select_limit= 0;
3604
3535
fake_select_lex->context.outer_context=first_sl->context.outer_context;
3605
/* allow item list resolving in fake select for ORDER BY */
3536
/* allow item list resolving in fake select for order_st BY */
3606
3537
fake_select_lex->context.resolve_in_select_list= true;
3607
3538
fake_select_lex->context.select_lex= fake_select_lex;
3612
3543
This works only for
3613
(SELECT ... ORDER BY list [LIMIT n]) ORDER BY order_list [LIMIT m],
3614
(SELECT ... LIMIT n) ORDER BY order_list [LIMIT m]
3544
(SELECT ... order_st BY list [LIMIT n]) order_st BY order_list [LIMIT m],
3545
(SELECT ... LIMIT n) order_st BY order_list [LIMIT m]
3615
3546
just before the parser starts processing order_list
3617
3548
global_parameters= fake_select_lex;
3646
3577
push_new_name_resolution_context(THD *thd,
3647
TABLE_LIST *left_op, TABLE_LIST *right_op)
3578
TableList *left_op, TableList *right_op)
3649
3580
Name_resolution_context *on_context;
3650
3581
if (!(on_context= new (thd->mem_root) Name_resolution_context))
3725
3656
@param using_fields Field names from USING clause
3728
void add_join_natural(TABLE_LIST *a, TABLE_LIST *b, List<String> *using_fields,
3659
void add_join_natural(TableList *a, TableList *b, List<String> *using_fields,
3729
3660
SELECT_LEX *lex)
3731
3662
b->natural_join= a;
3752
3683
@retval !=0 Error; thd->killed is set or thd->is_error() is true
3755
bool reload_cache(THD *thd, ulong options, TABLE_LIST *tables,
3686
bool reload_cache(THD *thd, ulong options, TableList *tables,
3756
3687
bool *write_to_binlog)
3945
3876
/* Fix is using unix filename format on dos */
3946
strmov(buff,*filename_ptr);
3877
stpcpy(buff,*filename_ptr);
3947
3878
end=convert_dirname(buff, *filename_ptr, NullS);
3948
3879
if (!(ptr= (char*) thd->alloc((size_t) (end-buff) + strlen(table_name)+1)))
3949
3880
return 1; // End of memory
3971
3902
char command[80];
3972
3903
Lex_input_stream *lip= thd->m_lip;
3973
3904
strmake(command, lip->yylval->symbol.str,
3974
min(lip->yylval->symbol.length, sizeof(command)-1));
3905
min((ulong)lip->yylval->symbol.length, sizeof(command)-1));
3975
3906
my_error(ER_CANT_USE_OPTION_HERE, MYF(0), command);
4098
4029
bool multi_delete_precheck(THD *thd,
4099
TABLE_LIST *tables __attribute__((unused)))
4030
TableList *tables __attribute__((unused)))
4101
4032
SELECT_LEX *select_lex= &thd->lex->select_lex;
4102
TABLE_LIST **save_query_tables_own_last= thd->lex->query_tables_own_last;
4033
TableList **save_query_tables_own_last= thd->lex->query_tables_own_last;
4104
4035
thd->lex->query_tables_own_last= 0;
4105
4036
thd->lex->query_tables_own_last= save_query_tables_own_last;
4131
4062
@return Matching table, NULL otherwise.
4134
static TABLE_LIST *multi_delete_table_match(LEX *lex __attribute__((unused)),
4065
static TableList *multi_delete_table_match(LEX *lex __attribute__((unused)),
4138
TABLE_LIST *match= NULL;
4069
TableList *match= NULL;
4140
for (TABLE_LIST *elem= tables; elem; elem= elem->next_local)
4071
for (TableList *elem= tables; elem; elem= elem->next_local)
4186
4117
bool multi_delete_set_locks_and_link_aux_tables(LEX *lex)
4188
TABLE_LIST *tables= (TABLE_LIST*)lex->select_lex.table_list.first;
4189
TABLE_LIST *target_tbl;
4119
TableList *tables= (TableList*)lex->select_lex.table_list.first;
4120
TableList *target_tbl;
4191
4122
lex->table_count= 0;
4193
for (target_tbl= (TABLE_LIST *)lex->auxiliary_table_list.first;
4124
for (target_tbl= (TableList *)lex->auxiliary_table_list.first;
4194
4125
target_tbl; target_tbl= target_tbl->next_local)
4196
4127
lex->table_count++;
4197
4128
/* All tables in aux_tables must be found in FROM PART */
4198
TABLE_LIST *walk= multi_delete_table_match(lex, target_tbl, tables);
4129
TableList *walk= multi_delete_table_match(lex, target_tbl, tables);
4201
4132
if (!walk->derived)
4226
bool update_precheck(THD *thd, TABLE_LIST *tables __attribute__((unused)))
4157
bool update_precheck(THD *thd, TableList *tables __attribute__((unused)))
4228
4159
if (thd->lex->select_lex.item_list.elements != thd->lex->value_list.elements)
4279
4210
bool create_table_precheck(THD *thd,
4280
TABLE_LIST *tables __attribute__((unused)),
4281
TABLE_LIST *create_table)
4211
TableList *tables __attribute__((unused)),
4212
TableList *create_table)
4283
4214
LEX *lex= thd->lex;
4284
4215
SELECT_LEX *select_lex= &lex->select_lex;
4403
4334
bool check_string_char_length(LEX_STRING *str, const char *err_msg,
4404
uint max_char_length, CHARSET_INFO *cs,
4335
uint max_char_length, const CHARSET_INFO * const cs,
4407
4338
int well_formed_error;
4426
4357
so they should be prohibited until such support is done.
4427
4358
This is why we use the 3-byte utf8 to check well-formedness here.
4429
CHARSET_INFO *cs= &my_charset_utf8mb3_general_ci;
4360
const CHARSET_INFO * const cs= &my_charset_utf8mb3_general_ci;
4431
CHARSET_INFO *cs= system_charset_info;
4362
const CHARSET_INFO * const cs= system_charset_info;
4433
4364
int well_formed_error;
4434
4365
uint res= cs->cset->well_formed_len(cs, str->str, str->str + str->length,
4508
4439
@param thd Thread context.
4509
4440
@param lip Lexer context.
4510
@param creation_ctx Object creation context.
4512
4442
@return Error status.
4513
4443
@retval false on success.
4514
4444
@retval true on parsing error.
4517
bool parse_sql(THD *thd,
4518
Lex_input_stream *lip,
4519
Object_creation_ctx *creation_ctx)
4447
bool parse_sql(THD *thd, Lex_input_stream *lip)
4521
4449
assert(thd->m_lip == NULL);
4523
/* Backup creation context. */
4525
Object_creation_ctx *backup_ctx= NULL;
4528
backup_ctx= creation_ctx->set_n_backup(thd);
4530
4451
/* Set Lex_input_stream. */
4532
4453
thd->m_lip= lip;