32
32
/* Match the values of enum ha_choice */
33
33
static const char *ha_choice_values[] = {"", "0", "1"};
35
static void store_key_options(Session *thd, String *packet, Table *table,
35
static void store_key_options(Session *session, String *packet, Table *table,
87
87
** List all table types supported
88
88
***************************************************************************/
90
static bool show_plugins(Session *thd, plugin_ref plugin,
90
static bool show_plugins(Session *session, plugin_ref plugin,
93
93
Table *table= (Table*) arg;
170
170
table->field[7]->set_notnull();
172
return schema_table_store_record(thd, table);
172
return schema_table_store_record(session, table);
176
int fill_plugins(Session *thd, TableList *tables, COND *cond __attribute__((unused)))
176
int fill_plugins(Session *session, TableList *tables, COND *cond __attribute__((unused)))
178
178
Table *table= tables->table;
180
if (plugin_foreach_with_mask(thd, show_plugins, DRIZZLE_ANY_PLUGIN,
180
if (plugin_foreach_with_mask(session, show_plugins, DRIZZLE_ANY_PLUGIN,
181
181
~PLUGIN_IS_FREED, table))
208
208
find_files_result
209
find_files(Session *thd, List<LEX_STRING> *files, const char *db,
209
find_files(Session *session, List<LEX_STRING> *files, const char *db,
210
210
const char *path, const char *wild, bool dir)
264
264
if (wild && wild_compare(uname, wild, 0))
267
thd->make_lex_string(file_name, uname, file_name_len, true)))
267
session->make_lex_string(file_name, uname, file_name_len, true)))
270
270
return(FIND_FILES_OOM);
307
mysqld_show_create(Session *thd, TableList *table_list)
307
mysqld_show_create(Session *session, TableList *table_list)
309
Protocol *protocol= thd->protocol;
309
Protocol *protocol= session->protocol;
311
311
String buffer(buff, sizeof(buff), system_charset_info);
313
313
/* Only one table for now, but VIEW can involve several tables */
314
if (open_normal_and_derived_tables(thd, table_list, 0))
314
if (open_normal_and_derived_tables(session, table_list, 0))
316
if (thd->is_error() && thd->main_da.sql_errno() != ER_VIEW_INVALID)
316
if (session->is_error() && session->main_da.sql_errno() != ER_VIEW_INVALID)
321
321
issue a warning with 'warning' level status in
322
322
case of invalid view and last error is ER_VIEW_INVALID
324
drizzle_reset_errors(thd, true);
324
drizzle_reset_errors(session, true);
325
session->clear_error();
328
328
buffer.length(0);
330
if (store_create_info(thd, table_list, &buffer, NULL))
330
if (store_create_info(session, table_list, &buffer, NULL))
333
333
List<Item> field_list;
355
355
if (protocol->write())
362
bool mysqld_show_create_db(Session *thd, char *dbname,
362
bool mysqld_show_create_db(Session *session, char *dbname,
363
363
HA_CREATE_INFO *create_info)
366
366
String buffer(buff, sizeof(buff), system_charset_info);
367
Protocol *protocol=thd->protocol;
367
Protocol *protocol=session->protocol;
369
if (store_db_create_info(thd, dbname, &buffer, create_info))
369
if (store_db_create_info(session, dbname, &buffer, create_info))
372
372
This assumes that the only reason for which store_db_create_info()
402
402
****************************************************************************/
405
mysqld_list_fields(Session *thd, TableList *table_list, const char *wild)
405
mysqld_list_fields(Session *session, TableList *table_list, const char *wild)
409
if (open_normal_and_derived_tables(thd, table_list, 0))
409
if (open_normal_and_derived_tables(session, table_list, 0))
411
411
table= table_list->table;
473
473
append_identifier()
474
session thread handler
475
475
packet target string
476
476
name the identifier to be appended
477
477
name_length length of the appending identifier
481
append_identifier(Session *thd, String *packet, const char *name, uint32_t length)
481
append_identifier(Session *session, String *packet, const char *name, uint32_t length)
483
483
const char *name_end;
485
int q= get_quote_char_for_identifier(thd, name, length);
485
int q= get_quote_char_for_identifier(session, name, length);
543
543
# Quote character
546
int get_quote_char_for_identifier(Session *thd, const char *name, uint32_t length)
546
int get_quote_char_for_identifier(Session *session, const char *name, uint32_t length)
549
549
!is_keyword(name,length) &&
550
550
!require_quotes(name, length) &&
551
!(thd->options & OPTION_QUOTE_SHOW_CREATE))
551
!(session->options & OPTION_QUOTE_SHOW_CREATE))
557
557
/* Append directory name (if exists) to CREATE INFO */
559
static void append_directory(Session *thd __attribute__((unused)),
559
static void append_directory(Session *session __attribute__((unused)),
560
560
String *packet, const char *dir_type,
561
561
const char *filename)
690
690
alias= share->table_name.str;
693
append_identifier(thd, packet, alias, strlen(alias));
693
append_identifier(session, packet, alias, strlen(alias));
694
694
packet->append(STRING_WITH_LEN(" (\n"));
696
696
We need this to get default values from the table
707
707
packet->append(STRING_WITH_LEN(",\n"));
709
709
packet->append(STRING_WITH_LEN(" "));
710
append_identifier(thd,packet,field->field_name, strlen(field->field_name));
710
append_identifier(session,packet,field->field_name, strlen(field->field_name));
711
711
packet->append(' ');
712
712
// check for surprises from the previous call to Field::sql_type()
713
713
if (type.ptr() != tmp)
829
829
packet->append(STRING_WITH_LEN("KEY "));
831
831
if (!found_primary)
832
append_identifier(thd, packet, key_info->name, strlen(key_info->name));
832
append_identifier(session, packet, key_info->name, strlen(key_info->name));
834
834
packet->append(STRING_WITH_LEN(" ("));
972
972
packet->append(STRING_WITH_LEN(" CONNECTION="));
973
973
append_unescaped(packet, share->connect_string.str, share->connect_string.length);
975
append_directory(thd, packet, "DATA", create_info.data_file_name);
976
append_directory(thd, packet, "INDEX", create_info.index_file_name);
975
append_directory(session, packet, "DATA", create_info.data_file_name);
976
append_directory(session, packet, "INDEX", create_info.index_file_name);
978
978
table->restore_column_map(old_map);
992
992
the resulting CREATE statement contains "IF NOT EXISTS" clause. Other flags
993
993
in @c create_options are ignored.
995
@param thd The current thread instance.
995
@param session The current thread instance.
996
996
@param dbname The name of the database.
997
997
@param buffer A String instance where the statement is stored.
998
998
@param create_info If not NULL, the options member influences the resulting
1001
1001
@returns true if errors are detected, false otherwise.
1004
bool store_db_create_info(Session *thd, const char *dbname, String *buffer,
1004
bool store_db_create_info(Session *session, const char *dbname, String *buffer,
1005
1005
HA_CREATE_INFO *create_info)
1007
1007
HA_CREATE_INFO create;
1029
1029
if (create_options & HA_LEX_CREATE_IF_NOT_EXISTS)
1030
1030
buffer->append(STRING_WITH_LEN("/*!32312 IF NOT EXISTS*/ "));
1032
append_identifier(thd, buffer, dbname, strlen(dbname));
1032
append_identifier(session, buffer, dbname, strlen(dbname));
1034
1034
if (create.default_table_charset)
1104
1104
template class I_List<thread_info>;
1107
void mysqld_list_processes(Session *thd,const char *user, bool verbose)
1107
void mysqld_list_processes(Session *session,const char *user, bool verbose)
1110
1110
List<Item> field_list;
1111
1111
I_List<thread_info> thread_infos;
1112
ulong max_query_length= (verbose ? thd->variables.max_allowed_packet :
1112
ulong max_query_length= (verbose ? session->variables.max_allowed_packet :
1113
1113
PROCESS_LIST_WIDTH);
1114
Protocol *protocol= thd->protocol;
1114
Protocol *protocol= session->protocol;
1116
1116
field_list.push_back(new Item_int("Id", 0, MY_INT32_NUM_DECIMAL_DIGITS));
1117
1117
field_list.push_back(new Item_empty_string("User",16));
1139
1139
struct st_my_thread_var *mysys_var;
1140
1140
if ((tmp->vio_ok() || tmp->system_thread) && (!user || (tmp_sctx->user && !strcmp(tmp_sctx->user, user))))
1142
thread_info *thd_info= new thread_info;
1142
thread_info *session_info= new thread_info;
1144
thd_info->thread_id=tmp->thread_id;
1145
thd_info->user= thd->strdup(tmp_sctx->user ? tmp_sctx->user :
1144
session_info->thread_id=tmp->thread_id;
1145
session_info->user= session->strdup(tmp_sctx->user ? tmp_sctx->user :
1146
1146
(tmp->system_thread ?
1147
1147
"system user" : "unauthenticated user"));
1148
thd_info->host= thd->strdup(tmp_sctx->ip);
1149
if ((thd_info->db=tmp->db)) // Safe test
1150
thd_info->db=thd->strdup(thd_info->db);
1151
thd_info->command=(int) tmp->command;
1148
session_info->host= session->strdup(tmp_sctx->ip);
1149
if ((session_info->db=tmp->db)) // Safe test
1150
session_info->db=session->strdup(session_info->db);
1151
session_info->command=(int) tmp->command;
1152
1152
if ((mysys_var= tmp->mysys_var))
1153
1153
pthread_mutex_lock(&mysys_var->mutex);
1154
thd_info->proc_info= (char*) (tmp->killed == Session::KILL_CONNECTION? "Killed" : 0);
1155
thd_info->state_info= (char*) (tmp->net.reading_or_writing ?
1154
session_info->proc_info= (char*) (tmp->killed == Session::KILL_CONNECTION? "Killed" : 0);
1155
session_info->state_info= (char*) (tmp->net.reading_or_writing ?
1156
1156
(tmp->net.reading_or_writing == 2 ?
1157
1157
"Writing to net" :
1158
thd_info->command == COM_SLEEP ? NULL :
1158
session_info->command == COM_SLEEP ? NULL :
1159
1159
"Reading from net") :
1160
1160
tmp->get_proc_info() ? tmp->get_proc_info() :
1161
1161
tmp->mysys_var &&
1174
1174
races with query_length
1176
1176
uint32_t length= cmin((uint32_t)max_query_length, tmp->query_length);
1177
thd_info->query=(char*) thd->strmake(tmp->query,length);
1177
session_info->query=(char*) session->strmake(tmp->query,length);
1179
thread_infos.append(thd_info);
1179
thread_infos.append(session_info);
1183
1183
pthread_mutex_unlock(&LOCK_thread_count);
1185
thread_info *thd_info;
1185
thread_info *session_info;
1186
1186
time_t now= my_time(0);
1187
while ((thd_info=thread_infos.get()))
1187
while ((session_info=thread_infos.get()))
1189
1189
protocol->prepare_for_resend();
1190
protocol->store((uint64_t) thd_info->thread_id);
1191
protocol->store(thd_info->user, system_charset_info);
1192
protocol->store(thd_info->host, system_charset_info);
1193
protocol->store(thd_info->db, system_charset_info);
1194
if (thd_info->proc_info)
1195
protocol->store(thd_info->proc_info, system_charset_info);
1190
protocol->store((uint64_t) session_info->thread_id);
1191
protocol->store(session_info->user, system_charset_info);
1192
protocol->store(session_info->host, system_charset_info);
1193
protocol->store(session_info->db, system_charset_info);
1194
if (session_info->proc_info)
1195
protocol->store(session_info->proc_info, system_charset_info);
1197
protocol->store(command_name[thd_info->command].str, system_charset_info);
1198
if (thd_info->start_time)
1199
protocol->store((uint32_t) (now - thd_info->start_time));
1197
protocol->store(command_name[session_info->command].str, system_charset_info);
1198
if (session_info->start_time)
1199
protocol->store((uint32_t) (now - session_info->start_time));
1201
1201
protocol->store_null();
1202
protocol->store(thd_info->state_info, system_charset_info);
1203
protocol->store(thd_info->query, system_charset_info);
1202
protocol->store(session_info->state_info, system_charset_info);
1203
protocol->store(session_info->query, system_charset_info);
1204
1204
if (protocol->write())
1205
1205
break; /* purecov: inspected */
1211
int fill_schema_processlist(Session* thd, TableList* tables,
1211
int fill_schema_processlist(Session* session, TableList* tables,
1212
1212
COND* cond __attribute__((unused)))
1214
1214
Table *table= tables->table;
1480
1480
*buf= my_toupper(system_charset_info, *buf);
1483
static bool show_status_array(Session *thd, const char *wild,
1483
static bool show_status_array(Session *session, const char *wild,
1484
1484
SHOW_VAR *variables,
1485
1485
enum enum_var_type value_type,
1486
1486
struct system_status_var *status_var,
1516
1516
Repeat as necessary, if new var is again SHOW_FUNC
1518
1518
for (var=variables; var->type == SHOW_FUNC; var= &tmp)
1519
((mysql_show_var_func)((st_show_var_func_container *)var->value)->func)(thd, &tmp, buff);
1519
((mysql_show_var_func)((st_show_var_func_container *)var->value)->func)(session, &tmp, buff);
1521
1521
SHOW_TYPE show_type=var->type;
1522
1522
if (show_type == SHOW_ARRAY)
1524
show_status_array(thd, wild, (SHOW_VAR *) var->value, value_type,
1524
show_status_array(session, wild, (SHOW_VAR *) var->value, value_type,
1525
1525
status_var, name_buffer, table, ucase_names);
1683
bool schema_table_store_record(Session *thd, Table *table)
1683
bool schema_table_store_record(Session *session, Table *table)
1686
1686
if ((error= table->file->ha_write_row(table->record[0])))
1688
1688
TMP_TABLE_PARAM *param= table->pos_in_table_list->schema_table_param;
1690
if (create_myisam_from_heap(thd, table, param->start_recinfo,
1690
if (create_myisam_from_heap(session, table, param->start_recinfo,
1691
1691
¶m->recinfo, error, 0))
1698
int make_table_list(Session *thd, SELECT_LEX *sel,
1698
int make_table_list(Session *session, SELECT_LEX *sel,
1699
1699
LEX_STRING *db_name, LEX_STRING *table_name)
1701
1701
Table_ident *table_ident;
1702
table_ident= new Table_ident(thd, *db_name, *table_name, 1);
1702
table_ident= new Table_ident(session, *db_name, *table_name, 1);
1703
1703
sel->init_query();
1704
if (!sel->add_table_to_list(thd, table_ident, 0, 0, TL_READ))
1704
if (!sel->add_table_to_list(session, table_ident, 0, 0, TL_READ))
1715
1715
fill appropriate lookup_field_vals struct field
1716
1716
with this value.
1718
@param[in] thd thread handler
1718
@param[in] session thread handler
1719
1719
@param[in] item_func part of WHERE condition
1720
1720
@param[in] table I_S table
1721
1721
@param[in, out] lookup_field_vals Struct which holds lookup values
1725
1725
1 error, there can be no matching records for the condition
1728
bool get_lookup_value(Session *thd, Item_func *item_func,
1728
bool get_lookup_value(Session *session, Item_func *item_func,
1729
1729
TableList *table,
1730
1730
LOOKUP_FIELD_VALUES *lookup_field_vals)
1774
1774
(unsigned char *) item_field->field_name,
1775
1775
strlen(item_field->field_name), 0))
1777
thd->make_lex_string(&lookup_field_vals->db_value, tmp_str->ptr(),
1777
session->make_lex_string(&lookup_field_vals->db_value, tmp_str->ptr(),
1778
1778
tmp_str->length(), false);
1780
1780
/* Lookup value is table name */
1783
1783
(unsigned char *) item_field->field_name,
1784
1784
strlen(item_field->field_name), 0))
1786
thd->make_lex_string(&lookup_field_vals->table_value, tmp_str->ptr(),
1786
session->make_lex_string(&lookup_field_vals->table_value, tmp_str->ptr(),
1787
1787
tmp_str->length(), false);
1798
1798
from 'WHERE' condition if it's possible and
1799
1799
fill lookup_field_vals struct fields with these values.
1801
@param[in] thd thread handler
1801
@param[in] session thread handler
1802
1802
@param[in] cond WHERE condition
1803
1803
@param[in] table I_S table
1804
1804
@param[in, out] lookup_field_vals Struct which holds lookup values
1808
1808
1 error, there can be no matching records for the condition
1811
bool calc_lookup_values_from_cond(Session *thd, COND *cond, TableList *table,
1811
bool calc_lookup_values_from_cond(Session *session, COND *cond, TableList *table,
1812
1812
LOOKUP_FIELD_VALUES *lookup_field_vals)
1825
1825
if (item->type() == Item::FUNC_ITEM)
1827
if (get_lookup_value(thd, (Item_func*)item, table, lookup_field_vals))
1827
if (get_lookup_value(session, (Item_func*)item, table, lookup_field_vals))
1832
if (calc_lookup_values_from_cond(thd, item, table, lookup_field_vals))
1832
if (calc_lookup_values_from_cond(session, item, table, lookup_field_vals))
1947
1947
from LEX struct and fill lookup_field_vals struct field
1948
1948
with these values.
1950
@param[in] thd thread handler
1950
@param[in] session thread handler
1951
1951
@param[in] cond WHERE condition
1952
1952
@param[in] tables I_S table
1953
1953
@param[in, out] lookup_field_values Struct which holds lookup values
1957
1957
1 error, there can be no matching records for the condition
1960
bool get_lookup_field_values(Session *thd, COND *cond, TableList *tables,
1960
bool get_lookup_field_values(Session *session, COND *cond, TableList *tables,
1961
1961
LOOKUP_FIELD_VALUES *lookup_field_values)
1963
LEX *lex= session->lex;
1964
1964
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
1965
1965
memset(lookup_field_values, 0, sizeof(LOOKUP_FIELD_VALUES));
1966
1966
switch (lex->sql_command) {
1988
1988
The "default" is for queries over I_S.
1989
1989
All previous cases handle SHOW commands.
1991
return calc_lookup_values_from_cond(thd, cond, tables, lookup_field_values);
1991
return calc_lookup_values_from_cond(session, cond, tables, lookup_field_values);
2020
int make_db_list(Session *thd, List<LEX_STRING> *files,
2020
int make_db_list(Session *session, List<LEX_STRING> *files,
2021
2021
LOOKUP_FIELD_VALUES *lookup_field_vals,
2022
2022
bool *with_i_schema)
2024
2024
LEX_STRING *i_s_name_copy= 0;
2025
i_s_name_copy= thd->make_lex_string(i_s_name_copy,
2025
i_s_name_copy= session->make_lex_string(i_s_name_copy,
2026
2026
INFORMATION_SCHEMA_NAME.str,
2027
2027
INFORMATION_SCHEMA_NAME.length, true);
2028
2028
*with_i_schema= 0;
2042
2042
if (files->push_back(i_s_name_copy))
2045
return (find_files(thd, files, NULL, mysql_data_home,
2045
return (find_files(session, files, NULL, mysql_data_home,
2046
2046
lookup_field_vals->db_value.str, 1) != FIND_FILES_OK);
2073
2073
if (files->push_back(i_s_name_copy))
2075
2075
*with_i_schema= 1;
2076
return (find_files(thd, files, NULL,
2076
return (find_files(session, files, NULL,
2077
2077
mysql_data_home, NULL, 1) != FIND_FILES_OK);
2112
if ((file_name= thd->make_lex_string(file_name, schema_table->table_name,
2112
if ((file_name= session->make_lex_string(file_name, schema_table->table_name,
2113
2113
strlen(schema_table->table_name),
2115
2115
!file_list->push_back(file_name))
2121
int schema_tables_add(Session *thd, List<LEX_STRING> *files, const char *wild)
2121
int schema_tables_add(Session *session, List<LEX_STRING> *files, const char *wild)
2123
2123
LEX_STRING *file_name= 0;
2124
2124
ST_SCHEMA_TABLE *tmp_schema_table= schema_tables;
2143
2143
if ((file_name=
2144
thd->make_lex_string(file_name, tmp_schema_table->table_name,
2144
session->make_lex_string(file_name, tmp_schema_table->table_name,
2145
2145
strlen(tmp_schema_table->table_name), true)) &&
2146
2146
!files->push_back(file_name))
2164
2164
@details The function creates the list of table names in
2167
@param[in] thd thread handler
2167
@param[in] session thread handler
2168
2168
@param[in] table_names List of table names in database
2169
2169
@param[in] lex pointer to LEX struct
2170
2170
@param[in] lookup_field_vals pointer to LOOKUP_FIELD_VALUE struct
2181
make_table_name_list(Session *thd, List<LEX_STRING> *table_names, LEX *lex,
2181
make_table_name_list(Session *session, List<LEX_STRING> *table_names, LEX *lex,
2182
2182
LOOKUP_FIELD_VALUES *lookup_field_vals,
2183
2183
bool with_i_schema, LEX_STRING *db_name)
2210
2210
if (with_i_schema)
2211
return (schema_tables_add(thd, table_names,
2211
return (schema_tables_add(session, table_names,
2212
2212
lookup_field_vals->table_value.str));
2214
find_files_result res= find_files(thd, table_names, db_name->str, path,
2214
find_files_result res= find_files(session, table_names, db_name->str, path,
2215
2215
lookup_field_vals->table_value.str, 0);
2216
2216
if (res != FIND_FILES_OK)
2238
2238
@brief Fill I_S table for SHOW COLUMNS|INDEX commands
2240
@param[in] thd thread handler
2240
@param[in] session thread handler
2241
2241
@param[in] tables TableList for I_S table
2242
2242
@param[in] schema_table pointer to I_S structure
2243
2243
@param[in] open_tables_state_backup pointer to Open_tables_state object
2254
fill_schema_show_cols_or_idxs(Session *thd, TableList *tables,
2254
fill_schema_show_cols_or_idxs(Session *session, TableList *tables,
2255
2255
ST_SCHEMA_TABLE *schema_table,
2256
2256
Open_tables_state *open_tables_state_backup)
2258
LEX *lex= session->lex;
2260
2260
LEX_STRING tmp_lex_string, tmp_lex_string1, *db_name, *table_name;
2261
2261
enum_sql_command save_sql_command= lex->sql_command;
2267
2267
lex->all_selects_list= tables->schema_select_lex;
2269
Restore thd->temporary_tables to be able to process
2269
Restore session->temporary_tables to be able to process
2270
2270
temporary tables(only for 'show index' & 'show columns').
2271
2271
This should be changed when processing of temporary tables for
2272
2272
I_S tables will be done.
2274
thd->temporary_tables= open_tables_state_backup->temporary_tables;
2274
session->temporary_tables= open_tables_state_backup->temporary_tables;
2276
2276
Let us set fake sql_command so views won't try to merge
2277
2277
themselves into main statement. If we don't do this,
2279
2279
SQLCOM_SHOW_FIELDS is used because it satisfies 'only_view_structure()'
2281
2281
lex->sql_command= SQLCOM_SHOW_FIELDS;
2282
res= open_normal_and_derived_tables(thd, show_table_list,
2282
res= open_normal_and_derived_tables(session, show_table_list,
2283
2283
DRIZZLE_LOCK_IGNORE_FLUSH);
2284
2284
lex->sql_command= save_sql_command;
2293
2293
in this case(this part of code is used only for
2294
2294
'show columns' & 'show statistics' commands).
2296
table_name= thd->make_lex_string(&tmp_lex_string1, show_table_list->alias,
2296
table_name= session->make_lex_string(&tmp_lex_string1, show_table_list->alias,
2297
2297
strlen(show_table_list->alias), false);
2298
db_name= thd->make_lex_string(&tmp_lex_string, show_table_list->db,
2298
db_name= session->make_lex_string(&tmp_lex_string, show_table_list->db,
2299
2299
show_table_list->db_length, false);
2302
error= test(schema_table->process_table(thd, show_table_list,
2302
error= test(schema_table->process_table(session, show_table_list,
2303
2303
table, res, db_name,
2305
thd->temporary_tables= 0;
2306
close_tables_for_reopen(thd, &show_table_list);
2305
session->temporary_tables= 0;
2306
close_tables_for_reopen(session, &show_table_list);
2312
2312
@brief Fill I_S table for SHOW Table NAMES commands
2314
@param[in] thd thread handler
2314
@param[in] session thread handler
2315
2315
@param[in] table Table struct for I_S table
2316
2316
@param[in] db_name database name
2317
2317
@param[in] table_name table name
2337
2337
char path[FN_REFLEN];
2338
2338
(void) build_table_filename(path, sizeof(path), db_name->str,
2339
2339
table_name->str, reg_ext, 0);
2340
if (mysql_frm_type(thd, path, ¬_used))
2340
if (mysql_frm_type(session, path, ¬_used))
2342
2342
table->field[3]->store(STRING_WITH_LEN("BASE Table"),
2343
2343
system_charset_info);
2404
2404
@brief Fill I_S table with data from FRM file only
2406
@param[in] thd thread handler
2406
@param[in] session thread handler
2407
2407
@param[in] table Table struct for I_S table
2408
2408
@param[in] schema_table I_S table struct
2409
2409
@param[in] db_name database name
2417
2417
open_tables function for this table
2420
static int fill_schema_table_from_frm(Session *thd,TableList *tables,
2420
static int fill_schema_table_from_frm(Session *session,TableList *tables,
2421
2421
ST_SCHEMA_TABLE *schema_table,
2422
2422
LEX_STRING *db_name,
2423
2423
LEX_STRING *table_name,
2438
2438
table_list.table_name= table_name->str;
2439
2439
table_list.db= db_name->str;
2441
key_length= create_table_def_key(thd, key, &table_list, 0);
2441
key_length= create_table_def_key(session, key, &table_list, 0);
2442
2442
pthread_mutex_lock(&LOCK_open);
2443
share= get_table_share(thd, &table_list, key,
2443
share= get_table_share(session, &table_list, key,
2444
2444
key_length, 0, &error);
2453
2453
table_list.table= &tbl;
2454
res= schema_table->process_table(thd, &table_list, table,
2454
res= schema_table->process_table(session, &table_list, table,
2455
2455
res, db_name, table_name);
2484
2484
@retval 1 error
2487
int get_all_tables(Session *thd, TableList *tables, COND *cond)
2487
int get_all_tables(Session *session, TableList *tables, COND *cond)
2489
LEX *lex= session->lex;
2490
2490
Table *table= tables->table;
2491
2491
SELECT_LEX *old_all_select_lex= lex->all_selects_list;
2492
2492
enum_sql_command save_sql_command= lex->sql_command;
2505
2505
Open_tables_state open_tables_state_backup;
2506
2506
Query_tables_list query_tables_list_backup;
2507
2507
uint32_t table_open_method;
2508
bool old_value= thd->no_warnings_for_error;
2508
bool old_value= session->no_warnings_for_error;
2510
2510
lex->reset_n_backup_query_tables_list(&query_tables_list_backup);
2514
2514
tables open and locked, since we won't lock tables which we will
2515
2515
open and will ignore possible name-locks for these tables.
2517
thd->reset_n_backup_open_tables_state(&open_tables_state_backup);
2517
session->reset_n_backup_open_tables_state(&open_tables_state_backup);
2519
2519
schema_table_idx= get_schema_table_idx(schema_table);
2520
2520
tables->table_open_method= table_open_method=
2527
2527
if (lsel && lsel->table_list.first)
2529
error= fill_schema_show_cols_or_idxs(thd, tables, schema_table,
2529
error= fill_schema_show_cols_or_idxs(session, tables, schema_table,
2530
2530
&open_tables_state_backup);
2534
if (get_lookup_field_values(thd, cond, tables, &lookup_field_vals))
2534
if (get_lookup_field_values(session, cond, tables, &lookup_field_vals))
2573
if (make_db_list(thd, &db_names, &lookup_field_vals, &with_i_schema))
2573
if (make_db_list(session, &db_names, &lookup_field_vals, &with_i_schema))
2575
2575
it.rewind(); /* To get access to new elements in basis list */
2576
2576
while ((db_name= it++))
2579
thd->no_warnings_for_error= 1;
2579
session->no_warnings_for_error= 1;
2580
2580
List<LEX_STRING> table_names;
2581
int res= make_table_name_list(thd, &table_names, lex,
2581
int res= make_table_name_list(session, &table_names, lex,
2582
2582
&lookup_field_vals,
2583
2583
with_i_schema, db_name);
2584
2584
if (res == 2) /* Not fatal error, continue */
2615
2615
/* SHOW Table NAMES command */
2616
2616
if (schema_table_idx == SCH_TABLE_NAMES)
2618
if (fill_schema_table_names(thd, tables->table, db_name,
2618
if (fill_schema_table_names(session, tables->table, db_name,
2619
2619
table_name, with_i_schema))
2624
2624
if (!(table_open_method & ~OPEN_FRM_ONLY) &&
2625
2625
!with_i_schema)
2627
if (!fill_schema_table_from_frm(thd, tables, schema_table, db_name,
2627
if (!fill_schema_table_from_frm(session, tables, schema_table, db_name,
2628
2628
table_name, schema_table_idx))
2635
2635
Set the parent lex of 'sel' because it is needed by
2636
2636
sel.init_query() which is called inside make_table_list.
2638
thd->no_warnings_for_error= 1;
2638
session->no_warnings_for_error= 1;
2639
2639
sel.parent_lex= lex;
2640
2640
/* db_name can be changed in make_table_list() func */
2641
if (!thd->make_lex_string(&orig_db_name, db_name->str,
2641
if (!session->make_lex_string(&orig_db_name, db_name->str,
2642
2642
db_name->length, false))
2644
if (make_table_list(thd, &sel, db_name, table_name))
2644
if (make_table_list(session, &sel, db_name, table_name))
2646
2646
TableList *show_table_list= (TableList*) sel.table_list.first;
2647
2647
lex->all_selects_list= &sel;
2649
2649
lex->sql_command= SQLCOM_SHOW_FIELDS;
2650
2650
show_table_list->i_s_requested_object=
2651
2651
schema_table->i_s_requested_object;
2652
res= open_normal_and_derived_tables(thd, show_table_list,
2652
res= open_normal_and_derived_tables(session, show_table_list,
2653
2653
DRIZZLE_LOCK_IGNORE_FLUSH);
2654
2654
lex->sql_command= save_sql_command;
2657
2657
and when it's set, open_normal_and_derived_tables()
2658
2658
can return an error without setting an error message
2659
2659
in Session, which is a hack. This is why we have to
2660
check for res, then for thd->is_error() only then
2661
for thd->main_da.sql_errno().
2660
check for res, then for session->is_error() only then
2661
for session->main_da.sql_errno().
2663
if (res && thd->is_error() &&
2664
thd->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2663
if (res && session->is_error() &&
2664
session->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2667
2667
Hide error for not existing table.
2681
2681
to use alias because alias contains original table name
2684
thd->make_lex_string(&tmp_lex_string, show_table_list->alias,
2684
session->make_lex_string(&tmp_lex_string, show_table_list->alias,
2685
2685
strlen(show_table_list->alias), false);
2686
res= schema_table->process_table(thd, show_table_list, table,
2686
res= schema_table->process_table(session, show_table_list, table,
2687
2687
res, &orig_db_name,
2688
2688
&tmp_lex_string);
2689
close_tables_for_reopen(thd, &show_table_list);
2689
close_tables_for_reopen(session, &show_table_list);
2691
2691
assert(!lex->query_tables_own_last);
2707
thd->restore_backup_open_tables_state(&open_tables_state_backup);
2707
session->restore_backup_open_tables_state(&open_tables_state_backup);
2708
2708
lex->restore_backup_query_tables_list(&query_tables_list_backup);
2709
2709
lex->derived_tables= derived_tables;
2710
2710
lex->all_selects_list= old_all_select_lex;
2711
2711
lex->sql_command= save_sql_command;
2712
thd->no_warnings_for_error= old_value;
2712
session->no_warnings_for_error= old_value;
2717
bool store_schema_shemata(Session* thd, Table *table, LEX_STRING *db_name,
2717
bool store_schema_shemata(Session* session, Table *table, LEX_STRING *db_name,
2718
2718
const CHARSET_INFO * const cs)
2720
2720
restore_record(table, s->default_values);
2721
2721
table->field[1]->store(db_name->str, db_name->length, system_charset_info);
2722
2722
table->field[2]->store(cs->csname, strlen(cs->csname), system_charset_info);
2723
2723
table->field[3]->store(cs->name, strlen(cs->name), system_charset_info);
2724
return schema_table_store_record(thd, table);
2724
return schema_table_store_record(session, table);
2728
int fill_schema_schemata(Session *thd, TableList *tables, COND *cond)
2728
int fill_schema_schemata(Session *session, TableList *tables, COND *cond)
2731
2731
TODO: fill_schema_shemata() is called when new client is connected.
2739
2739
HA_CREATE_INFO create;
2740
2740
Table *table= tables->table;
2742
if (get_lookup_field_values(thd, cond, tables, &lookup_field_vals))
2742
if (get_lookup_field_values(session, cond, tables, &lookup_field_vals))
2744
if (make_db_list(thd, &db_names, &lookup_field_vals,
2744
if (make_db_list(session, &db_names, &lookup_field_vals,
2745
2745
&with_i_schema))
2769
2769
if (with_i_schema) // information schema name is always first in list
2771
if (store_schema_shemata(thd, table, db_name,
2771
if (store_schema_shemata(session, table, db_name,
2772
2772
system_charset_info))
2774
2774
with_i_schema= 0;
2778
load_db_opt_by_name(thd, db_name->str, &create);
2779
if (store_schema_shemata(thd, table, db_name,
2778
load_db_opt_by_name(session, db_name->str, &create);
2779
if (store_schema_shemata(session, table, db_name,
2780
2780
create.default_table_charset))
2803
2803
there was errors during opening tables
2805
const char *error= thd->is_error() ? thd->main_da.message() : "";
2805
const char *error= session->is_error() ? session->main_da.message() : "";
2806
2806
if (tables->schema_table)
2807
2807
table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"), cs);
2809
2809
table->field[3]->store(STRING_WITH_LEN("BASE Table"), cs);
2810
2810
table->field[20]->store(error, strlen(error), cs);
2811
session->clear_error();
2948
2948
if (file->stats.create_time)
2950
thd->variables.time_zone->gmt_sec_to_TIME(&time,
2950
session->variables.time_zone->gmt_sec_to_TIME(&time,
2951
2951
(my_time_t) file->stats.create_time);
2952
2952
table->field[14]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2953
2953
table->field[14]->set_notnull();
2955
2955
if (file->stats.update_time)
2957
thd->variables.time_zone->gmt_sec_to_TIME(&time,
2957
session->variables.time_zone->gmt_sec_to_TIME(&time,
2958
2958
(my_time_t) file->stats.update_time);
2959
2959
table->field[15]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2960
2960
table->field[15]->set_notnull();
2962
2962
if (file->stats.check_time)
2964
thd->variables.time_zone->gmt_sec_to_TIME(&time,
2964
session->variables.time_zone->gmt_sec_to_TIME(&time,
2965
2965
(my_time_t) file->stats.check_time);
2966
2966
table->field[16]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2967
2967
table->field[16]->set_notnull();
3078
static int get_schema_column_record(Session *thd, TableList *tables,
3078
static int get_schema_column_record(Session *session, TableList *tables,
3079
3079
Table *table, bool res,
3080
3080
LEX_STRING *db_name,
3081
3081
LEX_STRING *table_name)
3083
LEX *lex= session->lex;
3084
3084
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3085
3085
const CHARSET_INFO * const cs= system_charset_info;
3086
3086
Table *show_table;
3096
3096
I.e. we are in SELECT FROM INFORMATION_SCHEMA.COLUMS
3097
3097
rather than in SHOW COLUMNS
3099
if (thd->is_error())
3100
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3101
thd->main_da.sql_errno(), thd->main_da.message());
3099
if (session->is_error())
3100
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3101
session->main_da.sql_errno(), session->main_da.message());
3102
session->clear_error();
3128
3128
/* to satisfy 'field->val_str' ASSERTs */
3129
3129
unsigned char *bitmaps;
3130
3130
uint32_t bitmap_size= show_table_share->column_bitmap_size;
3131
if (!(bitmaps= (unsigned char*) alloc_root(thd->mem_root, bitmap_size)))
3131
if (!(bitmaps= (unsigned char*) alloc_root(session->mem_root, bitmap_size)))
3133
3133
bitmap_init(&show_table->def_read_set,
3134
3134
(my_bitmap_map*) bitmaps, show_table_share->fields, false);
3164
3164
table->field[4]->store((int64_t) count, true);
3166
if (get_field_default_value(thd, timestamp_field, field, &type, 0))
3166
if (get_field_default_value(session, timestamp_field, field, &type, 0))
3168
3168
table->field[5]->store(type.ptr(), type.length(), cs);
3169
3169
table->field[5]->set_notnull();
3212
int fill_schema_charsets(Session *thd, TableList *tables, COND *cond __attribute__((unused)))
3212
int fill_schema_charsets(Session *session, TableList *tables, COND *cond __attribute__((unused)))
3214
3214
CHARSET_INFO **cs;
3215
const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
3215
const char *wild= session->lex->wild ? session->lex->wild->ptr() : NULL;
3216
3216
Table *table= tables->table;
3217
3217
const CHARSET_INFO * const scs= system_charset_info;
3232
3232
comment= tmp_cs->comment ? tmp_cs->comment : "";
3233
3233
table->field[2]->store(comment, strlen(comment), scs);
3234
3234
table->field[3]->store((int64_t) tmp_cs->mbmaxlen, true);
3235
if (schema_table_store_record(thd, table))
3235
if (schema_table_store_record(session, table))
3243
int fill_schema_collation(Session *thd, TableList *tables, COND *cond __attribute__((unused)))
3243
int fill_schema_collation(Session *session, TableList *tables, COND *cond __attribute__((unused)))
3245
3245
CHARSET_INFO **cs;
3246
const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
3246
const char *wild= session->lex->wild ? session->lex->wild->ptr() : NULL;
3247
3247
Table *table= tables->table;
3248
3248
const CHARSET_INFO * const scs= system_charset_info;
3249
3249
for (cs= all_charsets ; cs < all_charsets+255 ; cs++ )
3273
3273
tmp_buff= (tmp_cl->state & MY_CS_COMPILED)? "Yes" : "";
3274
3274
table->field[4]->store(tmp_buff, strlen(tmp_buff), scs);
3275
3275
table->field[5]->store((int64_t) tmp_cl->strxfrm_multiply, true);
3276
if (schema_table_store_record(thd, table))
3276
if (schema_table_store_record(session, table))
3303
3303
restore_record(table, s->default_values);
3304
3304
table->field[0]->store(tmp_cl->name, strlen(tmp_cl->name), scs);
3305
3305
table->field[1]->store(tmp_cl->csname , strlen(tmp_cl->csname), scs);
3306
if (schema_table_store_record(thd, table))
3306
if (schema_table_store_record(session, table))
3319
3319
const CHARSET_INFO * const cs= system_charset_info;
3322
if (thd->lex->sql_command != SQLCOM_SHOW_KEYS)
3322
if (session->lex->sql_command != SQLCOM_SHOW_KEYS)
3325
3325
I.e. we are in SELECT FROM INFORMATION_SCHEMA.STATISTICS
3326
3326
rather than in SHOW KEYS
3328
if (thd->is_error())
3329
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3330
thd->main_da.sql_errno(), thd->main_da.message());
3328
if (session->is_error())
3329
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3330
session->main_da.sql_errno(), session->main_da.message());
3331
session->clear_error();
3399
3399
if (key_info->flags & HA_USES_COMMENT)
3400
3400
table->field[15]->store(key_info->comment.str,
3401
3401
key_info->comment.length, cs);
3402
if (schema_table_store_record(thd, table))
3402
if (schema_table_store_record(session, table))
3411
bool store_constraints(Session *thd, Table *table, LEX_STRING *db_name,
3411
bool store_constraints(Session *session, Table *table, LEX_STRING *db_name,
3412
3412
LEX_STRING *table_name, const char *key_name,
3413
3413
uint32_t key_len, const char *con_type, uint32_t con_len)
3419
3419
table->field[3]->store(db_name->str, db_name->length, cs);
3420
3420
table->field[4]->store(table_name->str, table_name->length, cs);
3421
3421
table->field[5]->store(con_type, con_len, cs);
3422
return schema_table_store_record(thd, table);
3422
return schema_table_store_record(session, table);
3426
static int get_schema_constraints_record(Session *thd, TableList *tables,
3426
static int get_schema_constraints_record(Session *session, TableList *tables,
3427
3427
Table *table, bool res,
3428
3428
LEX_STRING *db_name,
3429
3429
LEX_STRING *table_name)
3433
if (thd->is_error())
3434
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3435
thd->main_da.sql_errno(), thd->main_da.message());
3433
if (session->is_error())
3434
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3435
session->main_da.sql_errno(), session->main_da.message());
3436
session->clear_error();
3453
3453
if (i == primary_key && !strcmp(key_info->name, primary_key_name))
3455
if (store_constraints(thd, table, db_name, table_name, key_info->name,
3455
if (store_constraints(session, table, db_name, table_name, key_info->name,
3456
3456
strlen(key_info->name),
3457
3457
STRING_WITH_LEN("PRIMARY KEY")))
3460
3460
else if (key_info->flags & HA_NOSAME)
3462
if (store_constraints(thd, table, db_name, table_name, key_info->name,
3462
if (store_constraints(session, table, db_name, table_name, key_info->name,
3463
3463
strlen(key_info->name),
3464
3464
STRING_WITH_LEN("UNIQUE")))
3469
show_table->file->get_foreign_key_list(thd, &f_key_list);
3469
show_table->file->get_foreign_key_list(session, &f_key_list);
3470
3470
FOREIGN_KEY_INFO *f_key_info;
3471
3471
List_iterator_fast<FOREIGN_KEY_INFO> it(f_key_list);
3472
3472
while ((f_key_info=it++))
3474
if (store_constraints(thd, table, db_name, table_name,
3474
if (store_constraints(session, table, db_name, table_name,
3475
3475
f_key_info->forein_id->str,
3476
3476
strlen(f_key_info->forein_id->str),
3477
3477
"FOREIGN KEY", 11))
3508
if (thd->is_error())
3509
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3510
thd->main_da.sql_errno(), thd->main_da.message());
3508
if (session->is_error())
3509
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3510
session->main_da.sql_errno(), session->main_da.message());
3511
session->clear_error();
3538
3538
key_part->field->field_name,
3539
3539
strlen(key_part->field->field_name),
3540
3540
(int64_t) f_idx);
3541
if (schema_table_store_record(thd, table))
3541
if (schema_table_store_record(session, table))
3547
show_table->file->get_foreign_key_list(thd, &f_key_list);
3547
show_table->file->get_foreign_key_list(session, &f_key_list);
3548
3548
FOREIGN_KEY_INFO *f_key_info;
3549
3549
List_iterator_fast<FOREIGN_KEY_INFO> fkey_it(f_key_list);
3550
3550
while ((f_key_info= fkey_it++))
3589
int fill_open_tables(Session *thd, TableList *tables, COND *cond __attribute__((unused)))
3589
int fill_open_tables(Session *session, TableList *tables, COND *cond __attribute__((unused)))
3591
const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
3591
const char *wild= session->lex->wild ? session->lex->wild->ptr() : NULL;
3592
3592
Table *table= tables->table;
3593
3593
const CHARSET_INFO * const cs= system_charset_info;
3594
3594
OPEN_TableList *open_list;
3595
if (!(open_list=list_open_tables(thd,thd->lex->select_lex.db, wild))
3596
&& thd->is_fatal_error)
3595
if (!(open_list=list_open_tables(session,session->lex->select_lex.db, wild))
3596
&& session->is_fatal_error)
3599
3599
for (; open_list ; open_list=open_list->next)
3603
3603
table->field[1]->store(open_list->table, strlen(open_list->table), cs);
3604
3604
table->field[2]->store((int64_t) open_list->in_use, true);
3605
3605
table->field[3]->store((int64_t) open_list->locked, true);
3606
if (schema_table_store_record(thd, table))
3606
if (schema_table_store_record(session, table))
3613
int fill_variables(Session *thd, TableList *tables, COND *cond __attribute__((unused)))
3613
int fill_variables(Session *session, TableList *tables, COND *cond __attribute__((unused)))
3616
LEX *lex= session->lex;
3617
3617
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3618
3618
enum enum_schema_tables schema_table_idx=
3619
3619
get_schema_table_idx(tables->schema_table);
3626
3626
option_type= OPT_GLOBAL;
3628
3628
rw_rdlock(&LOCK_system_variables_hash);
3629
res= show_status_array(thd, wild, enumerate_sys_vars(thd, sorted_vars),
3629
res= show_status_array(session, wild, enumerate_sys_vars(session, sorted_vars),
3630
3630
option_type, NULL, "", tables->table, upper_case_names);
3631
3631
rw_unlock(&LOCK_system_variables_hash);
3636
int fill_status(Session *thd, TableList *tables, COND *cond __attribute__((unused)))
3636
int fill_status(Session *session, TableList *tables, COND *cond __attribute__((unused)))
3638
LEX *lex= session->lex;
3639
3639
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3641
3641
STATUS_VAR *tmp1, tmp;
3662
3662
option_type= OPT_SESSION;
3663
tmp1= &thd->status_var;
3663
tmp1= &session->status_var;
3666
3666
pthread_mutex_lock(&LOCK_status);
3667
3667
if (option_type == OPT_GLOBAL)
3668
3668
calc_sum_of_all_status(&tmp);
3669
res= show_status_array(thd, wild,
3669
res= show_status_array(session, wild,
3670
3670
(SHOW_VAR *)all_status_vars.buffer,
3671
3671
option_type, tmp1, "", tables->table,
3672
3672
upper_case_names);
3705
if (thd->is_error())
3706
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3707
thd->main_da.sql_errno(), thd->main_da.message());
3705
if (session->is_error())
3706
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3707
session->main_da.sql_errno(), session->main_da.message());
3708
session->clear_error();
3716
3716
HA_STATUS_NO_LOCK |
3717
3717
HA_STATUS_TIME);
3719
show_table->file->get_foreign_key_list(thd, &f_key_list);
3719
show_table->file->get_foreign_key_list(session, &f_key_list);
3720
3720
FOREIGN_KEY_INFO *f_key_info;
3721
3721
List_iterator_fast<FOREIGN_KEY_INFO> it(f_key_list);
3722
3722
while ((f_key_info= it++))
3743
3743
f_key_info->update_method->length, cs);
3744
3744
table->field[8]->store(f_key_info->delete_method->str,
3745
3745
f_key_info->delete_method->length, cs);
3746
if (schema_table_store_record(thd, table))
3746
if (schema_table_store_record(session, table))
3803
3803
# pointer to 'schema_tables' element
3806
ST_SCHEMA_TABLE *find_schema_table(Session *thd, const char* table_name)
3806
ST_SCHEMA_TABLE *find_schema_table(Session *session, const char* table_name)
3808
3808
schema_table_ref schema_table_a;
3809
3809
ST_SCHEMA_TABLE *schema_table= schema_tables;
3819
3819
schema_table_a.table_name= table_name;
3820
if (plugin_foreach(thd, find_schema_table_in_plugin,
3820
if (plugin_foreach(session, find_schema_table_in_plugin,
3821
3821
DRIZZLE_INFORMATION_SCHEMA_PLUGIN, &schema_table_a))
3822
3822
return(schema_table_a.schema_table);
3923
3923
TMP_TABLE_PARAM *tmp_table_param =
3924
(TMP_TABLE_PARAM*) (thd->alloc(sizeof(TMP_TABLE_PARAM)));
3924
(TMP_TABLE_PARAM*) (session->alloc(sizeof(TMP_TABLE_PARAM)));
3925
3925
tmp_table_param->init();
3926
3926
tmp_table_param->table_charset= cs;
3927
3927
tmp_table_param->field_count= field_count;
3928
3928
tmp_table_param->schema_table= 1;
3929
SELECT_LEX *select_lex= thd->lex->current_select;
3930
if (!(table= create_tmp_table(thd, tmp_table_param,
3929
SELECT_LEX *select_lex= session->lex->current_select;
3930
if (!(table= create_tmp_table(session, tmp_table_param,
3931
3931
field_list, (order_st*) 0, 0, 0,
3932
(select_lex->options | thd->options |
3932
(select_lex->options | session->options |
3933
3933
TMP_TABLE_ALL_COLUMNS),
3934
3934
HA_POS_ERROR, table_list->alias)))
3936
3936
my_bitmap_map* bitmaps=
3937
(my_bitmap_map*) thd->alloc(bitmap_buffer_size(field_count));
3937
(my_bitmap_map*) session->alloc(bitmap_buffer_size(field_count));
3938
3938
bitmap_init(&table->def_read_set, (my_bitmap_map*) bitmaps, field_count,
3940
3940
table->read_set= &table->def_read_set;
3962
int make_old_format(Session *thd, ST_SCHEMA_TABLE *schema_table)
3962
int make_old_format(Session *session, ST_SCHEMA_TABLE *schema_table)
3964
3964
ST_FIELD_INFO *field_info= schema_table->fields_info;
3965
Name_resolution_context *context= &thd->lex->select_lex.context;
3965
Name_resolution_context *context= &session->lex->select_lex.context;
3966
3966
for (; field_info->field_name; field_info++)
3968
3968
if (field_info->old_name)
3996
3996
String buffer(tmp,sizeof(tmp), system_charset_info);
3997
3997
Item_field *field= new Item_field(context,
3998
3998
NULL, NULL, field_info->field_name);
3999
if (!field || add_item_to_list(thd, field))
3999
if (!field || add_item_to_list(session, field))
4001
4001
buffer.length(0);
4002
4002
buffer.append(field_info->old_name);
4015
int make_table_names_old_format(Session *thd, ST_SCHEMA_TABLE *schema_table)
4015
int make_table_names_old_format(Session *session, ST_SCHEMA_TABLE *schema_table)
4018
String buffer(tmp,sizeof(tmp), thd->charset());
4018
String buffer(tmp,sizeof(tmp), session->charset());
4019
LEX *lex= session->lex;
4020
4020
Name_resolution_context *context= &lex->select_lex.context;
4022
4022
ST_FIELD_INFO *field_info= &schema_table->fields_info[2];
4032
4032
Item_field *field= new Item_field(context,
4033
4033
NULL, NULL, field_info->field_name);
4034
if (add_item_to_list(thd, field))
4034
if (add_item_to_list(session, field))
4036
4036
field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
4037
if (thd->lex->verbose)
4037
if (session->lex->verbose)
4039
4039
field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
4040
4040
field_info= &schema_table->fields_info[3];
4041
4041
field= new Item_field(context, NULL, NULL, field_info->field_name);
4042
if (add_item_to_list(thd, field))
4042
if (add_item_to_list(session, field))
4044
4044
field->set_name(field_info->old_name, strlen(field_info->old_name),
4045
4045
system_charset_info);
4051
int make_columns_old_format(Session *thd, ST_SCHEMA_TABLE *schema_table)
4051
int make_columns_old_format(Session *session, ST_SCHEMA_TABLE *schema_table)
4053
4053
int fields_arr[]= {3, 14, 13, 6, 15, 5, 16, 17, 18, -1};
4054
4054
int *field_num= fields_arr;
4055
4055
ST_FIELD_INFO *field_info;
4056
Name_resolution_context *context= &thd->lex->select_lex.context;
4056
Name_resolution_context *context= &session->lex->select_lex.context;
4058
4058
for (; *field_num >= 0; field_num++)
4060
4060
field_info= &schema_table->fields_info[*field_num];
4061
if (!thd->lex->verbose && (*field_num == 13 ||
4061
if (!session->lex->verbose && (*field_num == 13 ||
4062
4062
*field_num == 17 ||
4063
4063
*field_num == 18))
4080
int make_character_sets_old_format(Session *thd, ST_SCHEMA_TABLE *schema_table)
4080
int make_character_sets_old_format(Session *session, ST_SCHEMA_TABLE *schema_table)
4082
4082
int fields_arr[]= {0, 2, 1, 3, -1};
4083
4083
int *field_num= fields_arr;
4084
4084
ST_FIELD_INFO *field_info;
4085
Name_resolution_context *context= &thd->lex->select_lex.context;
4085
Name_resolution_context *context= &session->lex->select_lex.context;
4087
4087
for (; *field_num >= 0; field_num++)
4119
int mysql_schema_table(Session *thd, LEX *lex, TableList *table_list)
4119
int mysql_schema_table(Session *session, LEX *lex, TableList *table_list)
4122
if (!(table= table_list->schema_table->create_table(thd, table_list)))
4122
if (!(table= table_list->schema_table->create_table(session, table_list)))
4124
4124
table->s->tmp_table= SYSTEM_TMP_TABLE;
4136
4136
table_list->table_name= table->s->table_name.str;
4137
4137
table_list->table_name_length= table->s->table_name.length;
4138
4138
table_list->table= table;
4139
table->next= thd->derived_tables;
4140
thd->derived_tables= table;
4139
table->next= session->derived_tables;
4140
session->derived_tables= table;
4141
4141
table_list->select_lex->options |= OPTION_SCHEMA_TABLE;
4143
4143
if (table_list->schema_table_reformed) // show command
4152
4152
for (transl= table_list->field_translation; transl < end; transl++)
4154
4154
if (!transl->item->fixed &&
4155
transl->item->fix_fields(thd, &transl->item))
4155
transl->item->fix_fields(session, &transl->item))
4160
4160
List_iterator_fast<Item> it(sel->item_list);
4162
(Field_translator*)(thd->alloc(sel->item_list.elements *
4162
(Field_translator*)(session->alloc(sel->item_list.elements *
4163
4163
sizeof(Field_translator)))))
4198
int make_schema_select(Session *thd, SELECT_LEX *sel,
4198
int make_schema_select(Session *session, SELECT_LEX *sel,
4199
4199
enum enum_schema_tables schema_table_idx)
4201
4201
ST_SCHEMA_TABLE *schema_table= get_schema_table(schema_table_idx);
4204
4204
We have to make non const db_name & table_name
4205
4205
because of lower_case_table_names
4207
thd->make_lex_string(&db, INFORMATION_SCHEMA_NAME.str,
4207
session->make_lex_string(&db, INFORMATION_SCHEMA_NAME.str,
4208
4208
INFORMATION_SCHEMA_NAME.length, 0);
4209
thd->make_lex_string(&table, schema_table->table_name,
4209
session->make_lex_string(&table, schema_table->table_name,
4210
4210
strlen(schema_table->table_name), 0);
4211
if (schema_table->old_format(thd, schema_table) || /* Handle old syntax */
4212
!sel->add_table_to_list(thd, new Table_ident(thd, db, table, 0),
4211
if (schema_table->old_format(session, schema_table) || /* Handle old syntax */
4212
!sel->add_table_to_list(session, new Table_ident(session, db, table, 0),
4213
4213
0, 0, TL_READ))
4235
4235
enum enum_schema_table_state executed_place)
4237
4237
JOIN_TAB *tmp_join_tab= join->join_tab+join->tables;
4238
Session *thd= join->thd;
4238
Session *session= join->session;
4239
LEX *lex= session->lex;
4240
4240
bool result= 0;
4242
thd->no_warnings_for_error= 1;
4242
session->no_warnings_for_error= 1;
4243
4243
for (JOIN_TAB *tab= join->join_tab; tab < tmp_join_tab; tab++)
4245
4245
if (!tab->table || !tab->table->pos_in_table_list)