20
20
#include <drizzled/sql_show.h>
21
21
#include "repl_failsafe.h"
22
22
#include <mysys/my_dir.h>
23
#include <libdrizzle/gettext.h>
26
str_or_nil(const char *str)
28
return str ? str : "<nil>";
24
#define STR_OR_NIL(S) ((S) ? (S) : "<nil>")
31
26
/* Match the values of enum ha_choice */
32
27
static const char *ha_choice_values[] = {"", "0", "1"};
34
static void store_key_options(THD *thd, String *packet, Table *table,
29
static void store_key_options(THD *thd, String *packet, TABLE *table,
89
84
static bool show_plugins(THD *thd, plugin_ref plugin,
92
Table *table= (Table*) arg;
87
TABLE *table= (TABLE*) arg;
93
88
struct st_mysql_plugin *plug= plugin_decl(plugin);
94
89
struct st_plugin_dl *plugin_dl= plugin_dlib(plugin);
95
90
const CHARSET_INFO * const cs= system_charset_info;
175
int fill_plugins(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
170
int fill_plugins(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
177
Table *table= tables->table;
172
TABLE *table= tables->table;
179
if (plugin_foreach_with_mask(thd, show_plugins, DRIZZLE_ANY_PLUGIN,
174
if (plugin_foreach_with_mask(thd, show_plugins, MYSQL_ANY_PLUGIN,
180
175
~PLUGIN_IS_FREED, table))
334
329
field_list.push_back(new Item_empty_string("Table",NAME_CHAR_LEN));
335
330
// 1024 is for not to confuse old clients
336
331
field_list.push_back(new Item_empty_string("Create Table",
337
cmax(buffer.length(),(uint32_t)1024)));
332
max(buffer.length(),(uint32_t)1024)));
340
335
if (protocol->send_fields(&field_list,
401
396
****************************************************************************/
404
mysqld_list_fields(THD *thd, TableList *table_list, const char *wild)
399
mysqld_list_fields(THD *thd, TABLE_LIST *table_list, const char *wild)
408
403
if (open_normal_and_derived_tables(thd, table_list, 0))
443
438
0 No conflicting character
446
static const char *require_quotes(const char *name, uint32_t name_length)
441
static const char *require_quotes(const char *name, uint name_length)
449
444
bool pure_digit= true;
450
445
const char *end= name + name_length;
452
447
for (; name < end ; name++)
454
unsigned char chr= (unsigned char) *name;
449
uchar chr= (uchar) *name;
455
450
length= my_mbcharlen(system_charset_info, chr);
456
451
if (length == 1 && !system_charset_info->ident_map[chr])
497
packet->reserve(length*2 + 2);
492
VOID(packet->reserve(length*2 + 2));
498
493
quote_char= (char) q;
499
494
packet->append("e_char, 1, system_charset_info);
501
496
for (name_end= name+length ; name < name_end ; name+= length)
503
unsigned char chr= (unsigned char) *name;
498
uchar chr= (uchar) *name;
504
499
length= my_mbcharlen(system_charset_info, chr);
506
501
my_mbcharlen can return 0 on a wrong multibyte
542
537
# Quote character
545
int get_quote_char_for_identifier(THD *thd, const char *name, uint32_t length)
540
int get_quote_char_for_identifier(THD *thd, const char *name, uint length)
548
543
!is_keyword(name,length) &&
549
544
!require_quotes(name, length) &&
550
545
!(thd->options & OPTION_QUOTE_SHOW_CREATE))
659
654
String type(tmp, sizeof(tmp), system_charset_info);
660
655
String def_value(def_value_buf, sizeof(def_value_buf), system_charset_info);
661
656
Field **ptr,*field;
662
uint32_t primary_key;
664
Table *table= table_list->table;
659
TABLE *table= table_list->table;
665
660
handler *file= table->file;
666
661
TABLE_SHARE *share= table->s;
667
662
HA_CREATE_INFO create_info;
695
690
We have to restore the read_set if we are called from insert in case
696
691
of row based replication.
698
old_map= table->use_all_columns(table->read_set);
693
old_map= tmp_use_all_columns(table, table->read_set);
700
695
for (ptr=table->field ; (field= *ptr); ptr++)
702
uint32_t flags = field->flags;
697
uint flags = field->flags;
704
699
if (ptr != table->field)
705
700
packet->append(STRING_WITH_LEN(",\n"));
754
749
if (column_format)
756
751
packet->append(STRING_WITH_LEN(" /*!"));
757
packet->append(STRING_WITH_LEN(DRIZZLE_VERSION_TABLESPACE_IN_FRM_STR));
752
packet->append(STRING_WITH_LEN(MYSQL_VERSION_TABLESPACE_IN_FRM_STR));
758
753
packet->append(STRING_WITH_LEN(" COLUMN_FORMAT"));
759
754
if (column_format == COLUMN_FORMAT_TYPE_FIXED)
760
755
packet->append(STRING_WITH_LEN(" FIXED */"));
888
883
packet->append(buff, (uint) (end - buff));
887
if (share->table_charset)
891
THEN add DEFAULT CHARSET only if it was used when creating the table
893
if (!create_info_arg ||
894
(create_info_arg->used_fields & HA_CREATE_USED_DEFAULT_CHARSET))
896
packet->append(STRING_WITH_LEN(" DEFAULT CHARSET="));
897
packet->append(share->table_charset->csname);
898
if (!(share->table_charset->state & MY_CS_PRIMARY))
900
packet->append(STRING_WITH_LEN(" COLLATE="));
901
packet->append(table->s->table_charset->name);
891
906
if (share->min_rows)
964
979
append_directory(thd, packet, "DATA", create_info.data_file_name);
965
980
append_directory(thd, packet, "INDEX", create_info.index_file_name);
967
table->restore_column_map(old_map);
982
tmp_restore_column_map(table->read_set, old_map);
1144
1159
thd_info->state_info= (char*) (tmp->net.reading_or_writing ?
1145
1160
(tmp->net.reading_or_writing == 2 ?
1146
1161
"Writing to net" :
1147
thd_info->command == COM_SLEEP ? NULL :
1162
thd_info->command == COM_SLEEP ? NullS :
1148
1163
"Reading from net") :
1149
tmp->get_proc_info() ? tmp->get_proc_info() :
1164
tmp->proc_info ? tmp->proc_info :
1150
1165
tmp->mysys_var &&
1151
1166
tmp->mysys_var->current_cond ?
1152
"Waiting on cond" : NULL);
1167
"Waiting on cond" : NullS);
1154
1169
pthread_mutex_unlock(&mysys_var->mutex);
1162
1177
the comment in sql_class.h why this prevents crashes in possible
1163
1178
races with query_length
1165
uint32_t length= cmin((uint32_t)max_query_length, tmp->query_length);
1180
uint length= min((uint32_t)max_query_length, tmp->query_length);
1166
1181
thd_info->query=(char*) thd->strmake(tmp->query,length);
1168
1183
thread_infos.append(thd_info);
1172
pthread_mutex_unlock(&LOCK_thread_count);
1187
VOID(pthread_mutex_unlock(&LOCK_thread_count));
1174
1189
thread_info *thd_info;
1175
1190
time_t now= my_time(0);
1200
int fill_schema_processlist(THD* thd, TableList* tables,
1215
int fill_schema_processlist(THD* thd, TABLE_LIST* tables,
1201
1216
COND* cond __attribute__((unused)))
1203
Table *table= tables->table;
1218
TABLE *table= tables->table;
1204
1219
const CHARSET_INFO * const cs= system_charset_info;
1206
1221
time_t now= my_time(0);
1210
pthread_mutex_lock(&LOCK_thread_count);
1225
VOID(pthread_mutex_lock(&LOCK_thread_count));
1212
1227
if (!thd->killed)
1254
1269
val= (char*) (tmp->net.reading_or_writing ?
1255
1270
(tmp->net.reading_or_writing == 2 ?
1256
1271
"Writing to net" :
1257
tmp->command == COM_SLEEP ? NULL :
1272
tmp->command == COM_SLEEP ? NullS :
1258
1273
"Reading from net") :
1259
tmp->get_proc_info() ? tmp->get_proc_info() :
1274
tmp->proc_info ? tmp->proc_info :
1260
1275
tmp->mysys_var &&
1261
1276
tmp->mysys_var->current_cond ?
1262
"Waiting on cond" : NULL);
1277
"Waiting on cond" : NullS);
1265
1280
table->field[6]->store(val, strlen(val), cs);
1273
1288
if (tmp->query)
1275
1290
table->field[7]->store(tmp->query,
1276
cmin((uint32_t)PROCESS_LIST_INFO_WIDTH,
1291
min((uint32_t)PROCESS_LIST_INFO_WIDTH,
1277
1292
tmp->query_length), cs);
1278
1293
table->field[7]->set_notnull();
1281
1296
if (schema_table_store_record(thd, table))
1283
pthread_mutex_unlock(&LOCK_thread_count);
1298
VOID(pthread_mutex_unlock(&LOCK_thread_count));
1289
pthread_mutex_unlock(&LOCK_thread_count);
1304
VOID(pthread_mutex_unlock(&LOCK_thread_count));
1355
1370
while (list->name)
1356
res|= insert_dynamic(&all_status_vars, (unsigned char*)list++);
1357
res|= insert_dynamic(&all_status_vars, (unsigned char*)list); // appending NULL-element
1371
res|= insert_dynamic(&all_status_vars, (uchar*)list++);
1372
res|= insert_dynamic(&all_status_vars, (uchar*)list); // appending NULL-element
1358
1373
all_status_vars.elements--; // but next insert_dynamic should overwite it
1359
1374
if (status_vars_inited)
1360
1375
sort_dynamic(&all_status_vars, show_var_cmp);
1473
1488
SHOW_VAR *variables,
1474
1489
enum enum_var_type value_type,
1475
1490
struct system_status_var *status_var,
1476
const char *prefix, Table *table,
1491
const char *prefix, TABLE *table,
1477
1492
bool ucase_names)
1479
1494
MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, long);
1488
1503
null_lex_str.str= 0; // For sys_var->value_ptr()
1489
1504
null_lex_str.length= 0;
1491
prefix_end=my_stpncpy(name_buffer, prefix, sizeof(name_buffer)-1);
1506
prefix_end=stpncpy(name_buffer, prefix, sizeof(name_buffer)-1);
1493
1508
*prefix_end++= '_';
1494
1509
len=name_buffer + sizeof(name_buffer) - prefix_end;
1496
1511
for (; variables->name; variables++)
1498
my_stpncpy(prefix_end, variables->name, len);
1513
stpncpy(prefix_end, variables->name, len);
1499
1514
name_buffer[sizeof(name_buffer)-1]=0; /* Safety */
1500
1515
if (ucase_names)
1501
1516
make_upper(name_buffer);
1560
1575
end= int64_t10_to_str((int64_t) *(ha_rows*) value, buff, 10);
1562
1577
case SHOW_BOOL:
1563
end= my_stpcpy(buff, *(bool*) value ? "ON" : "OFF");
1578
end= stpcpy(buff, *(bool*) value ? "ON" : "OFF");
1565
1580
case SHOW_MY_BOOL:
1566
end= my_stpcpy(buff, *(bool*) value ? "ON" : "OFF");
1581
end= stpcpy(buff, *(bool*) value ? "ON" : "OFF");
1569
1584
end= int10_to_str((long) *(uint32_t*) value, buff, 10);
1761
1776
/* Lookup value is database name */
1762
if (!cs->coll->strnncollsp(cs, (unsigned char *) field_name1, strlen(field_name1),
1763
(unsigned char *) item_field->field_name,
1777
if (!cs->coll->strnncollsp(cs, (uchar *) field_name1, strlen(field_name1),
1778
(uchar *) item_field->field_name,
1764
1779
strlen(item_field->field_name), 0))
1766
1781
thd->make_lex_string(&lookup_field_vals->db_value, tmp_str->ptr(),
1767
1782
tmp_str->length(), false);
1769
1784
/* Lookup value is table name */
1770
else if (!cs->coll->strnncollsp(cs, (unsigned char *) field_name2,
1785
else if (!cs->coll->strnncollsp(cs, (uchar *) field_name2,
1771
1786
strlen(field_name2),
1772
(unsigned char *) item_field->field_name,
1787
(uchar *) item_field->field_name,
1773
1788
strlen(item_field->field_name), 0))
1775
1790
thd->make_lex_string(&lookup_field_vals->table_value, tmp_str->ptr(),
1797
1812
1 error, there can be no matching records for the condition
1800
bool calc_lookup_values_from_cond(THD *thd, COND *cond, TableList *table,
1815
bool calc_lookup_values_from_cond(THD *thd, COND *cond, TABLE_LIST *table,
1801
1816
LOOKUP_FIELD_VALUES *lookup_field_vals)
1835
bool uses_only_table_name_fields(Item *item, TableList *table)
1850
bool uses_only_table_name_fields(Item *item, TABLE_LIST *table)
1837
1852
if (item->type() == Item::FUNC_ITEM)
1839
1854
Item_func *item_func= (Item_func*)item;
1840
for (uint32_t i=0; i<item_func->argument_count(); i++)
1855
for (uint i=0; i<item_func->argument_count(); i++)
1842
1857
if (!uses_only_table_name_fields(item_func->arguments()[i], table))
1854
1869
const char *field_name2= schema_table->idx_field2 >= 0 ?
1855
1870
field_info[schema_table->idx_field2].field_name : "";
1856
1871
if (table->table != item_field->field->table ||
1857
(cs->coll->strnncollsp(cs, (unsigned char *) field_name1, strlen(field_name1),
1858
(unsigned char *) item_field->field_name,
1872
(cs->coll->strnncollsp(cs, (uchar *) field_name1, strlen(field_name1),
1873
(uchar *) item_field->field_name,
1859
1874
strlen(item_field->field_name), 0) &&
1860
cs->coll->strnncollsp(cs, (unsigned char *) field_name2, strlen(field_name2),
1861
(unsigned char *) item_field->field_name,
1875
cs->coll->strnncollsp(cs, (uchar *) field_name2, strlen(field_name2),
1876
(uchar *) item_field->field_name,
1862
1877
strlen(item_field->field_name), 0)))
1946
1961
1 error, there can be no matching records for the condition
1949
bool get_lookup_field_values(THD *thd, COND *cond, TableList *tables,
1964
bool get_lookup_field_values(THD *thd, COND *cond, TABLE_LIST *tables,
1950
1965
LOOKUP_FIELD_VALUES *lookup_field_values)
1952
1967
LEX *lex= thd->lex;
1953
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
1968
const char *wild= lex->wild ? lex->wild->ptr() : NullS;
1954
1969
memset(lookup_field_values, 0, sizeof(LOOKUP_FIELD_VALUES));
1955
1970
switch (lex->sql_command) {
1956
1971
case SQLCOM_SHOW_DATABASES:
2031
2046
if (files->push_back(i_s_name_copy))
2034
return (find_files(thd, files, NULL, mysql_data_home,
2049
return (find_files(thd, files, NullS, mysql_data_home,
2035
2050
lookup_field_vals->db_value.str, 1) != FIND_FILES_OK);
2062
2077
if (files->push_back(i_s_name_copy))
2064
2079
*with_i_schema= 1;
2065
return (find_files(thd, files, NULL,
2066
mysql_data_home, NULL, 1) != FIND_FILES_OK);
2080
return (find_files(thd, files, NullS,
2081
mysql_data_home, NullS, 1) != FIND_FILES_OK);
2227
2242
@brief Fill I_S table for SHOW COLUMNS|INDEX commands
2229
2244
@param[in] thd thread handler
2230
@param[in] tables TableList for I_S table
2245
@param[in] tables TABLE_LIST for I_S table
2231
2246
@param[in] schema_table pointer to I_S structure
2232
2247
@param[in] open_tables_state_backup pointer to Open_tables_state object
2233
2248
which is used to save|restore original
2243
fill_schema_show_cols_or_idxs(THD *thd, TableList *tables,
2258
fill_schema_show_cols_or_idxs(THD *thd, TABLE_LIST *tables,
2244
2259
ST_SCHEMA_TABLE *schema_table,
2245
2260
Open_tables_state *open_tables_state_backup)
2249
2264
LEX_STRING tmp_lex_string, tmp_lex_string1, *db_name, *table_name;
2250
2265
enum_sql_command save_sql_command= lex->sql_command;
2251
TableList *show_table_list= (TableList*) tables->schema_select_lex->
2266
TABLE_LIST *show_table_list= (TABLE_LIST*) tables->schema_select_lex->
2252
2267
table_list.first;
2253
Table *table= tables->table;
2268
TABLE *table= tables->table;
2256
2271
lex->all_selects_list= tables->schema_select_lex;
2270
2285
lex->sql_command= SQLCOM_SHOW_FIELDS;
2271
2286
res= open_normal_and_derived_tables(thd, show_table_list,
2272
DRIZZLE_LOCK_IGNORE_FLUSH);
2287
MYSQL_LOCK_IGNORE_FLUSH);
2273
2288
lex->sql_command= save_sql_command;
2275
2290
get_all_tables() returns 1 on failure and 0 on success thus
2301
@brief Fill I_S table for SHOW Table NAMES commands
2316
@brief Fill I_S table for SHOW TABLE NAMES commands
2303
2318
@param[in] thd thread handler
2304
@param[in] table Table struct for I_S table
2319
@param[in] table TABLE struct for I_S table
2305
2320
@param[in] db_name database name
2306
2321
@param[in] table_name table name
2307
2322
@param[in] with_i_schema I_S table if true
2326
2341
char path[FN_REFLEN];
2327
2342
(void) build_table_filename(path, sizeof(path), db_name->str,
2328
2343
table_name->str, reg_ext, 0);
2329
if (mysql_frm_type(thd, path, ¬_used))
2331
table->field[3]->store(STRING_WITH_LEN("BASE Table"),
2332
system_charset_info);
2344
switch (mysql_frm_type(thd, path, ¬_used)) {
2336
2346
table->field[3]->store(STRING_WITH_LEN("ERROR"),
2337
2347
system_charset_info);
2350
table->field[3]->store(STRING_WITH_LEN("BASE TABLE"),
2351
system_charset_info);
2340
2356
if (thd->is_error() && thd->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2342
2358
thd->clear_error();
2365
2381
@retval SKIP_OPEN_TABLE | OPEN_FRM_ONLY | OPEN_FULL_TABLE
2368
static uint32_t get_table_open_method(TableList *tables,
2384
static uint get_table_open_method(TABLE_LIST *tables,
2369
2385
ST_SCHEMA_TABLE *schema_table,
2370
2386
enum enum_schema_tables schema_table_idx __attribute__((unused)))
2393
2409
@brief Fill I_S table with data from FRM file only
2395
2411
@param[in] thd thread handler
2396
@param[in] table Table struct for I_S table
2412
@param[in] table TABLE struct for I_S table
2397
2413
@param[in] schema_table I_S table struct
2398
2414
@param[in] db_name database name
2399
2415
@param[in] table_name table name
2406
2422
open_tables function for this table
2409
static int fill_schema_table_from_frm(THD *thd,TableList *tables,
2425
static int fill_schema_table_from_frm(THD *thd,TABLE_LIST *tables,
2410
2426
ST_SCHEMA_TABLE *schema_table,
2411
2427
LEX_STRING *db_name,
2412
2428
LEX_STRING *table_name,
2413
2429
enum enum_schema_tables schema_table_idx __attribute__((unused)))
2415
Table *table= tables->table;
2431
TABLE *table= tables->table;
2416
2432
TABLE_SHARE *share;
2418
TableList table_list;
2434
TABLE_LIST table_list;
2421
2437
char key[MAX_DBKEY_LENGTH];
2422
uint32_t key_length;
2424
memset(&table_list, 0, sizeof(TableList));
2425
memset(&tbl, 0, sizeof(Table));
2440
memset(&table_list, 0, sizeof(TABLE_LIST));
2441
memset(&tbl, 0, sizeof(TABLE));
2427
2443
table_list.table_name= table_name->str;
2428
2444
table_list.db= db_name->str;
2430
2446
key_length= create_table_def_key(thd, key, &table_list, 0);
2431
2447
pthread_mutex_lock(&LOCK_open);
2432
2448
share= get_table_share(thd, &table_list, key,
2433
key_length, 0, &error);
2449
key_length, OPEN_VIEW, &error);
2473
2489
@retval 1 error
2476
int get_all_tables(THD *thd, TableList *tables, COND *cond)
2492
int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
2478
2494
LEX *lex= thd->lex;
2479
Table *table= tables->table;
2495
TABLE *table= tables->table;
2480
2496
SELECT_LEX *old_all_select_lex= lex->all_selects_list;
2481
2497
enum_sql_command save_sql_command= lex->sql_command;
2482
2498
SELECT_LEX *lsel= tables->schema_select_lex;
2489
2505
List<LEX_STRING> db_names;
2490
2506
List_iterator_fast<LEX_STRING> it(db_names);
2491
2507
COND *partial_cond= 0;
2492
uint32_t derived_tables= lex->derived_tables;
2508
uint derived_tables= lex->derived_tables;
2494
2510
Open_tables_state open_tables_state_backup;
2495
2511
Query_tables_list query_tables_list_backup;
2496
uint32_t table_open_method;
2512
uint table_open_method;
2497
2513
bool old_value= thd->no_warnings_for_error;
2499
2515
lex->reset_n_backup_query_tables_list(&query_tables_list_backup);
2633
2649
if (make_table_list(thd, &sel, db_name, table_name))
2635
TableList *show_table_list= (TableList*) sel.table_list.first;
2651
TABLE_LIST *show_table_list= (TABLE_LIST*) sel.table_list.first;
2636
2652
lex->all_selects_list= &sel;
2637
2653
lex->derived_tables= 0;
2638
2654
lex->sql_command= SQLCOM_SHOW_FIELDS;
2639
2655
show_table_list->i_s_requested_object=
2640
2656
schema_table->i_s_requested_object;
2641
2657
res= open_normal_and_derived_tables(thd, show_table_list,
2642
DRIZZLE_LOCK_IGNORE_FLUSH);
2658
MYSQL_LOCK_IGNORE_FLUSH);
2643
2659
lex->sql_command= save_sql_command;
2645
2661
XXX: show_table_list has a flag i_is_requested,
2706
bool store_schema_shemata(THD* thd, Table *table, LEX_STRING *db_name,
2722
bool store_schema_shemata(THD* thd, TABLE *table, LEX_STRING *db_name,
2707
2723
const CHARSET_INFO * const cs)
2709
2725
restore_record(table, s->default_values);
2795
2811
if (tables->schema_table)
2796
2812
table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"), cs);
2798
table->field[3]->store(STRING_WITH_LEN("BASE Table"), cs);
2814
table->field[3]->store(STRING_WITH_LEN("BASE TABLE"), cs);
2799
2815
table->field[20]->store(error, strlen(error), cs);
2800
2816
thd->clear_error();
2804
2820
char option_buff[400],*ptr;
2805
Table *show_table= tables->table;
2821
TABLE *show_table= tables->table;
2806
2822
TABLE_SHARE *share= show_table->s;
2807
2823
handler *file= show_table->file;
2808
2824
handlerton *tmp_db_type= share->db_type();
2811
2827
else if (share->tmp_table)
2812
2828
table->field[3]->store(STRING_WITH_LEN("LOCAL TEMPORARY"), cs);
2814
table->field[3]->store(STRING_WITH_LEN("BASE Table"), cs);
2830
table->field[3]->store(STRING_WITH_LEN("BASE TABLE"), cs);
2816
2832
for (int i= 4; i < 20; i++)
2826
2842
ptr=option_buff;
2827
2843
if (share->min_rows)
2829
ptr=my_stpcpy(ptr," min_rows=");
2845
ptr=stpcpy(ptr," min_rows=");
2830
2846
ptr=int64_t10_to_str(share->min_rows,ptr,10);
2832
2848
if (share->max_rows)
2834
ptr=my_stpcpy(ptr," max_rows=");
2850
ptr=stpcpy(ptr," max_rows=");
2835
2851
ptr=int64_t10_to_str(share->max_rows,ptr,10);
2837
2853
if (share->avg_row_length)
2839
ptr=my_stpcpy(ptr," avg_row_length=");
2855
ptr=stpcpy(ptr," avg_row_length=");
2840
2856
ptr=int64_t10_to_str(share->avg_row_length,ptr,10);
2842
2858
if (share->db_create_options & HA_OPTION_PACK_KEYS)
2843
ptr=my_stpcpy(ptr," pack_keys=1");
2859
ptr=stpcpy(ptr," pack_keys=1");
2844
2860
if (share->db_create_options & HA_OPTION_NO_PACK_KEYS)
2845
ptr=my_stpcpy(ptr," pack_keys=0");
2861
ptr=stpcpy(ptr," pack_keys=0");
2846
2862
/* We use CHECKSUM, instead of TABLE_CHECKSUM, for backward compability */
2847
2863
if (share->db_create_options & HA_OPTION_CHECKSUM)
2848
ptr=my_stpcpy(ptr," checksum=1");
2864
ptr=stpcpy(ptr," checksum=1");
2849
2865
if (share->page_checksum != HA_CHOICE_UNDEF)
2850
2866
ptr= strxmov(ptr, " page_checksum=",
2851
ha_choice_values[(uint) share->page_checksum], NULL);
2867
ha_choice_values[(uint) share->page_checksum], NullS);
2852
2868
if (share->db_create_options & HA_OPTION_DELAY_KEY_WRITE)
2853
ptr=my_stpcpy(ptr," delay_key_write=1");
2869
ptr=stpcpy(ptr," delay_key_write=1");
2854
2870
if (share->row_type != ROW_TYPE_DEFAULT)
2855
2871
ptr=strxmov(ptr, " row_format=",
2856
2872
ha_row_type[(uint) share->row_type],
2858
2874
if (share->block_size)
2860
ptr= my_stpcpy(ptr, " block_size=");
2876
ptr= stpcpy(ptr, " block_size=");
2861
2877
ptr= int64_t10_to_str(share->block_size, ptr, 10);
2866
2882
ptr= strxmov(ptr, " TRANSACTIONAL=",
2867
2883
(share->transactional == HA_CHOICE_YES ? "1" : "0"),
2870
2886
if (share->transactional != HA_CHOICE_UNDEF)
2871
2887
ptr= strxmov(ptr, " transactional=",
2872
ha_choice_values[(uint) share->transactional], NULL);
2888
ha_choice_values[(uint) share->transactional], NullS);
2873
2889
table->field[19]->store(option_buff+1,
2874
2890
(ptr == option_buff ? 0 :
2875
2891
(uint) (ptr-option_buff)-1), cs);
2981
void store_column_type(Table *table, Field *field, const CHARSET_INFO * const cs,
2997
void store_column_type(TABLE *table, Field *field, const CHARSET_INFO * const cs,
2985
3001
int decimals, field_length;
3068
static int get_schema_column_record(THD *thd, TableList *tables,
3069
Table *table, bool res,
3085
static int get_schema_column_record(THD *thd, TABLE_LIST *tables,
3086
TABLE *table, bool res,
3070
3087
LEX_STRING *db_name,
3071
3088
LEX_STRING *table_name)
3073
3090
LEX *lex= thd->lex;
3074
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3091
const char *wild= lex->wild ? lex->wild->ptr() : NullS;
3075
3092
const CHARSET_INFO * const cs= system_charset_info;
3077
3094
TABLE_SHARE *show_table_share;
3078
3095
Field **ptr, *field, *timestamp_field;
3116
3133
if (!show_table->read_set)
3118
3135
/* to satisfy 'field->val_str' ASSERTs */
3119
unsigned char *bitmaps;
3120
uint32_t bitmap_size= show_table_share->column_bitmap_size;
3121
if (!(bitmaps= (unsigned char*) alloc_root(thd->mem_root, bitmap_size)))
3137
uint bitmap_size= show_table_share->column_bitmap_size;
3138
if (!(bitmaps= (uchar*) alloc_root(thd->mem_root, bitmap_size)))
3123
3140
bitmap_init(&show_table->def_read_set,
3124
3141
(my_bitmap_map*) bitmaps, show_table_share->fields, false);
3158
3175
table->field[5]->store(type.ptr(), type.length(), cs);
3159
3176
table->field[5]->set_notnull();
3161
pos=(unsigned char*) ((field->flags & NOT_NULL_FLAG) ? "NO" : "YES");
3178
pos=(uchar*) ((field->flags & NOT_NULL_FLAG) ? "NO" : "YES");
3162
3179
table->field[6]->store((const char*) pos,
3163
3180
strlen((const char*) pos), cs);
3164
3181
store_column_type(table, field, cs, 7);
3166
pos=(unsigned char*) ((field->flags & PRI_KEY_FLAG) ? "PRI" :
3183
pos=(uchar*) ((field->flags & PRI_KEY_FLAG) ? "PRI" :
3167
3184
(field->flags & UNIQUE_KEY_FLAG) ? "UNI" :
3168
3185
(field->flags & MULTIPLE_KEY_FLAG) ? "MUL":"");
3169
3186
table->field[15]->store((const char*) pos,
3182
3199
enum column_format_type column_format= (enum column_format_type)
3183
3200
((field->flags >> COLUMN_FORMAT_FLAGS) & COLUMN_FORMAT_MASK);
3184
pos=(unsigned char*)"Default";
3201
pos=(uchar*)"Default";
3185
3202
table->field[19]->store((const char*) pos,
3186
3203
strlen((const char*) pos), cs);
3187
pos=(unsigned char*)(column_format == COLUMN_FORMAT_TYPE_DEFAULT ? "Default" :
3204
pos=(uchar*)(column_format == COLUMN_FORMAT_TYPE_DEFAULT ? "Default" :
3188
3205
column_format == COLUMN_FORMAT_TYPE_FIXED ? "Fixed" :
3190
3207
table->field[20]->store((const char*) pos,
3201
int fill_schema_charsets(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3218
int fill_schema_charsets(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
3203
3220
CHARSET_INFO **cs;
3204
const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
3205
Table *table= tables->table;
3221
const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
3222
TABLE *table= tables->table;
3206
3223
const CHARSET_INFO * const scs= system_charset_info;
3208
3225
for (cs= all_charsets ; cs < all_charsets+255 ; cs++)
3232
int fill_schema_collation(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3249
int fill_schema_collation(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
3234
3251
CHARSET_INFO **cs;
3235
const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
3236
Table *table= tables->table;
3252
const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
3253
TABLE *table= tables->table;
3237
3254
const CHARSET_INFO * const scs= system_charset_info;
3238
3255
for (cs= all_charsets ; cs < all_charsets+255 ; cs++ )
3274
int fill_schema_coll_charset_app(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3291
int fill_schema_coll_charset_app(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
3276
3293
CHARSET_INFO **cs;
3277
Table *table= tables->table;
3294
TABLE *table= tables->table;
3278
3295
const CHARSET_INFO * const scs= system_charset_info;
3279
3296
for (cs= all_charsets ; cs < all_charsets+255 ; cs++ )
3327
Table *show_table= tables->table;
3344
TABLE *show_table= tables->table;
3328
3345
KEY *key_info=show_table->s->key_info;
3329
3346
if (show_table->file)
3330
3347
show_table->file->info(HA_STATUS_VARIABLE |
3331
3348
HA_STATUS_NO_LOCK |
3332
3349
HA_STATUS_TIME);
3333
for (uint32_t i=0 ; i < show_table->s->keys ; i++,key_info++)
3350
for (uint i=0 ; i < show_table->s->keys ; i++,key_info++)
3335
3352
KEY_PART_INFO *key_part= key_info->key_part;
3336
3353
const char *str;
3337
for (uint32_t j=0 ; j < key_info->key_parts ; j++,key_part++)
3354
for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
3339
3356
restore_record(table, s->default_values);
3340
3357
table->field[1]->store(db_name->str, db_name->length, cs);
3375
3392
key_part->field->charset()->mbmaxlen, true);
3376
3393
table->field[10]->set_notnull();
3378
uint32_t flags= key_part->field ? key_part->field->flags : 0;
3395
uint flags= key_part->field ? key_part->field->flags : 0;
3379
3396
const char *pos=(char*) ((flags & NOT_NULL_FLAG) ? "" : "YES");
3380
3397
table->field[12]->store(pos, strlen(pos), cs);
3381
3398
if (!show_table->s->keys_in_use.is_set(i))
3400
bool store_constraints(THD *thd, Table *table, LEX_STRING *db_name,
3417
bool store_constraints(THD *thd, TABLE *table, LEX_STRING *db_name,
3401
3418
LEX_STRING *table_name, const char *key_name,
3402
uint32_t key_len, const char *con_type, uint32_t con_len)
3419
uint key_len, const char *con_type, uint con_len)
3404
3421
const CHARSET_INFO * const cs= system_charset_info;
3405
3422
restore_record(table, s->default_values);
3430
3447
List<FOREIGN_KEY_INFO> f_key_list;
3431
Table *show_table= tables->table;
3448
TABLE *show_table= tables->table;
3432
3449
KEY *key_info=show_table->key_info;
3433
uint32_t primary_key= show_table->s->primary_key;
3450
uint primary_key= show_table->s->primary_key;
3434
3451
show_table->file->info(HA_STATUS_VARIABLE |
3435
3452
HA_STATUS_NO_LOCK |
3436
3453
HA_STATUS_TIME);
3437
for (uint32_t i=0 ; i < show_table->s->keys ; i++, key_info++)
3454
for (uint i=0 ; i < show_table->s->keys ; i++, key_info++)
3439
3456
if (i != primary_key && !(key_info->flags & HA_NOSAME))
3474
void store_key_column_usage(Table *table, LEX_STRING *db_name,
3491
void store_key_column_usage(TABLE *table, LEX_STRING *db_name,
3475
3492
LEX_STRING *table_name, const char *key_name,
3476
uint32_t key_len, const char *con_type, uint32_t con_len,
3493
uint key_len, const char *con_type, uint con_len,
3479
3496
const CHARSET_INFO * const cs= system_charset_info;
3505
3522
List<FOREIGN_KEY_INFO> f_key_list;
3506
Table *show_table= tables->table;
3523
TABLE *show_table= tables->table;
3507
3524
KEY *key_info=show_table->key_info;
3508
uint32_t primary_key= show_table->s->primary_key;
3525
uint primary_key= show_table->s->primary_key;
3509
3526
show_table->file->info(HA_STATUS_VARIABLE |
3510
3527
HA_STATUS_NO_LOCK |
3511
3528
HA_STATUS_TIME);
3512
for (uint32_t i=0 ; i < show_table->s->keys ; i++, key_info++)
3529
for (uint i=0 ; i < show_table->s->keys ; i++, key_info++)
3514
3531
if (i != primary_key && !(key_info->flags & HA_NOSAME))
3517
3534
KEY_PART_INFO *key_part= key_info->key_part;
3518
for (uint32_t j=0 ; j < key_info->key_parts ; j++,key_part++)
3535
for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
3520
3537
if (key_part->field)
3578
int fill_open_tables(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3595
int fill_open_tables(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
3580
const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
3581
Table *table= tables->table;
3597
const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
3598
TABLE *table= tables->table;
3582
3599
const CHARSET_INFO * const cs= system_charset_info;
3583
OPEN_TableList *open_list;
3600
OPEN_TABLE_LIST *open_list;
3584
3601
if (!(open_list=list_open_tables(thd,thd->lex->select_lex.db, wild))
3585
3602
&& thd->is_fatal_error)
3602
int fill_variables(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3619
int fill_variables(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
3605
3622
LEX *lex= thd->lex;
3606
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3623
const char *wild= lex->wild ? lex->wild->ptr() : NullS;
3607
3624
enum enum_schema_tables schema_table_idx=
3608
3625
get_schema_table_idx(tables->schema_table);
3609
3626
enum enum_var_type option_type= OPT_SESSION;
3625
int fill_status(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3642
int fill_status(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
3627
3644
LEX *lex= thd->lex;
3628
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3645
const char *wild= lex->wild ? lex->wild->ptr() : NullS;
3630
3647
STATUS_VAR *tmp1, tmp;
3631
3648
enum enum_schema_tables schema_table_idx=
3686
get_referential_constraints_record(THD *thd, TableList *tables,
3687
Table *table, bool res,
3703
get_referential_constraints_record(THD *thd, TABLE_LIST *tables,
3704
TABLE *table, bool res,
3688
3705
LEX_STRING *db_name, LEX_STRING *table_name)
3690
3707
const CHARSET_INFO * const cs= system_charset_info;
3808
3825
schema_table_a.table_name= table_name;
3809
3826
if (plugin_foreach(thd, find_schema_table_in_plugin,
3810
DRIZZLE_INFORMATION_SCHEMA_PLUGIN, &schema_table_a))
3827
MYSQL_INFORMATION_SCHEMA_PLUGIN, &schema_table_a))
3811
3828
return(schema_table_a.schema_table);
3835
3852
@retval NULL Can't create table
3838
Table *create_schema_table(THD *thd, TableList *table_list)
3855
TABLE *create_schema_table(THD *thd, TABLE_LIST *table_list)
3840
3857
int field_count= 0;
3843
3860
List<Item> field_list;
3844
3861
ST_SCHEMA_TABLE *schema_table= table_list->schema_table;
3845
3862
ST_FIELD_INFO *fields_info= schema_table->fields_info;
3918
3936
tmp_table_param->schema_table= 1;
3919
3937
SELECT_LEX *select_lex= thd->lex->current_select;
3920
3938
if (!(table= create_tmp_table(thd, tmp_table_param,
3921
field_list, (order_st*) 0, 0, 0,
3939
field_list, (ORDER*) 0, 0, 0,
3922
3940
(select_lex->options | thd->options |
3923
3941
TMP_TABLE_ALL_COLUMNS),
3924
3942
HA_POS_ERROR, table_list->alias)))
3958
3976
if (field_info->old_name)
3960
3978
Item_field *field= new Item_field(context,
3961
NULL, NULL, field_info->field_name);
3979
NullS, NullS, field_info->field_name);
3964
3982
field->set_name(field_info->old_name,
3985
4003
ST_FIELD_INFO *field_info= &schema_table->fields_info[1];
3986
4004
String buffer(tmp,sizeof(tmp), system_charset_info);
3987
4005
Item_field *field= new Item_field(context,
3988
NULL, NULL, field_info->field_name);
4006
NullS, NullS, field_info->field_name);
3989
4007
if (!field || add_item_to_list(thd, field))
3991
4009
buffer.length(0);
4020
4038
buffer.append(')');
4022
4040
Item_field *field= new Item_field(context,
4023
NULL, NULL, field_info->field_name);
4041
NullS, NullS, field_info->field_name);
4024
4042
if (add_item_to_list(thd, field))
4026
4044
field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
4029
4047
field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
4030
4048
field_info= &schema_table->fields_info[3];
4031
field= new Item_field(context, NULL, NULL, field_info->field_name);
4049
field= new Item_field(context, NullS, NullS, field_info->field_name);
4032
4050
if (add_item_to_list(thd, field))
4034
4052
field->set_name(field_info->old_name, strlen(field_info->old_name),
4053
4071
*field_num == 18))
4055
4073
Item_field *field= new Item_field(context,
4056
NULL, NULL, field_info->field_name);
4074
NullS, NullS, field_info->field_name);
4059
4077
field->set_name(field_info->old_name,
4079
4097
field_info= &schema_table->fields_info[*field_num];
4080
4098
Item_field *field= new Item_field(context,
4081
NULL, NULL, field_info->field_name);
4099
NullS, NullS, field_info->field_name);
4084
4102
field->set_name(field_info->old_name,
4109
int mysql_schema_table(THD *thd, LEX *lex, TableList *table_list)
4127
int mysql_schema_table(THD *thd, LEX *lex, TABLE_LIST *table_list)
4112
4130
if (!(table= table_list->schema_table->create_table(thd, table_list)))
4114
4132
table->s->tmp_table= SYSTEM_TMP_TABLE;
4582
4601
create_schema_table, fill_schema_coll_charset_app, 0, 0, -1, -1, 0, 0},
4583
4602
{"COLUMNS", columns_fields_info, create_schema_table,
4584
4603
get_all_tables, make_columns_old_format, get_schema_column_record, 1, 2, 0,
4585
OPTIMIZE_I_S_TABLE},
4604
OPTIMIZE_I_S_TABLE|OPEN_VIEW_FULL},
4586
4605
{"GLOBAL_STATUS", variables_fields_info, create_schema_table,
4587
4606
fill_status, make_old_format, 0, -1, -1, 0, 0},
4588
4607
{"GLOBAL_VARIABLES", variables_fields_info, create_schema_table,