853
/* removes all the SHOW_UNDEF elements from the vector */
854
all_status_vars.erase(std::remove_if(all_status_vars.begin(),
855
all_status_vars.end(),show_var_remove_if()),
856
all_status_vars.end());
1461
shrink_var_array(&all_status_vars);
1465
inline void make_upper(char *buf)
1468
*buf= my_toupper(system_charset_info, *buf);
1471
static bool show_status_array(THD *thd, const char *wild,
1472
SHOW_VAR *variables,
1473
enum enum_var_type value_type,
1474
struct system_status_var *status_var,
1475
const char *prefix, Table *table,
1478
MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, long);
1479
char * const buff= (char *) &buff_data;
1481
/* the variable name should not be longer than 64 characters */
1482
char name_buffer[64];
1484
LEX_STRING null_lex_str;
1487
null_lex_str.str= 0; // For sys_var->value_ptr()
1488
null_lex_str.length= 0;
1490
prefix_end=my_stpncpy(name_buffer, prefix, sizeof(name_buffer)-1);
1493
len=name_buffer + sizeof(name_buffer) - prefix_end;
1495
for (; variables->name; variables++)
1497
my_stpncpy(prefix_end, variables->name, len);
1498
name_buffer[sizeof(name_buffer)-1]=0; /* Safety */
1500
make_upper(name_buffer);
1503
if var->type is SHOW_FUNC, call the function.
1504
Repeat as necessary, if new var is again SHOW_FUNC
1506
for (var=variables; var->type == SHOW_FUNC; var= &tmp)
1507
((mysql_show_var_func)((st_show_var_func_container *)var->value)->func)(thd, &tmp, buff);
1509
SHOW_TYPE show_type=var->type;
1510
if (show_type == SHOW_ARRAY)
1512
show_status_array(thd, wild, (SHOW_VAR *) var->value, value_type,
1513
status_var, name_buffer, table, ucase_names);
1517
if (!(wild && wild[0] && wild_case_compare(system_charset_info,
1518
name_buffer, wild)))
1520
char *value=var->value;
1521
const char *pos, *end; // We assign a lot of const's
1523
pthread_mutex_lock(&LOCK_global_system_variables);
1525
if (show_type == SHOW_SYS)
1527
show_type= ((sys_var*) value)->show_type();
1528
value= (char*) ((sys_var*) value)->value_ptr(thd, value_type,
1534
note that value may be == buff. All SHOW_xxx code below
1535
should still work in this case
1537
switch (show_type) {
1538
case SHOW_DOUBLE_STATUS:
1539
value= ((char *) status_var + (ulong) value);
1542
/* 6 is the default precision for '%f' in sprintf() */
1543
end= buff + my_fcvt(*(double *) value, 6, buff, NULL);
1545
case SHOW_LONG_STATUS:
1546
value= ((char *) status_var + (ulong) value);
1549
case SHOW_LONG_NOFLUSH: // the difference lies in refresh_status()
1550
end= int10_to_str(*(long*) value, buff, 10);
1552
case SHOW_LONGLONG_STATUS:
1553
value= ((char *) status_var + (uint64_t) value);
1556
end= int64_t10_to_str(*(int64_t*) value, buff, 10);
1559
end= int64_t10_to_str((int64_t) *(ha_rows*) value, buff, 10);
1562
end= my_stpcpy(buff, *(bool*) value ? "ON" : "OFF");
1565
end= my_stpcpy(buff, *(bool*) value ? "ON" : "OFF");
1568
end= int10_to_str((long) *(uint32_t*) value, buff, 10);
1572
SHOW_COMP_OPTION tmp= *(SHOW_COMP_OPTION*) value;
1573
pos= show_comp_option_name[(int) tmp];
1574
end= strchr(pos, '\0');
1581
end= strchr(pos, '\0');
1586
if (!(pos= *(char**) value))
1588
end= strchr(pos, '\0');
1591
case SHOW_KEY_CACHE_LONG:
1592
value= (char*) dflt_key_cache + (ulong)value;
1593
end= int10_to_str(*(long*) value, buff, 10);
1595
case SHOW_KEY_CACHE_LONGLONG:
1596
value= (char*) dflt_key_cache + (ulong)value;
1597
end= int64_t10_to_str(*(int64_t*) value, buff, 10);
1600
break; // Return empty string
1601
case SHOW_SYS: // Cannot happen
1606
restore_record(table, s->default_values);
1607
table->field[0]->store(name_buffer, strlen(name_buffer),
1608
system_charset_info);
1609
table->field[1]->store(pos, (uint32_t) (end - pos), system_charset_info);
1610
table->field[1]->set_notnull();
1612
pthread_mutex_unlock(&LOCK_global_system_variables);
1614
if (schema_table_store_record(thd, table))
860
1624
/* collect status for all running threads */
862
void calc_sum_of_all_status(system_status_var *to)
1626
void calc_sum_of_all_status(STATUS_VAR *to)
864
1629
/* Ensure that thread id not killed during loop */
865
1630
pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
1632
I_List_iterator<THD> it(threads);
867
1635
/* Get global values as base */
868
1636
*to= global_status_var;
870
1638
/* Add to this status from existing threads */
871
for(SessionList::iterator it= getSessionList().begin(); it != getSessionList().end(); ++it )
873
add_to_status(to, &((*it)->status_var));
1640
add_to_status(to, &tmp->status_var);
876
1642
pthread_mutex_unlock(&LOCK_thread_count);
880
} /* namespace drizzled */
1647
/* This is only used internally, but we need it here as a forward reference */
1648
extern ST_SCHEMA_TABLE schema_tables[];
1650
typedef struct st_lookup_field_values
1652
LEX_STRING db_value, table_value;
1653
bool wild_db_value, wild_table_value;
1654
} LOOKUP_FIELD_VALUES;
1658
Store record to I_S table, convert HEAP table
1659
to MyISAM if necessary
1662
schema_table_store_record()
1664
table Information schema table to be updated
1671
bool schema_table_store_record(THD *thd, Table *table)
1674
if ((error= table->file->ha_write_row(table->record[0])))
1676
TMP_TABLE_PARAM *param= table->pos_in_table_list->schema_table_param;
1678
if (create_myisam_from_heap(thd, table, param->start_recinfo,
1679
¶m->recinfo, error, 0))
1686
int make_table_list(THD *thd, SELECT_LEX *sel,
1687
LEX_STRING *db_name, LEX_STRING *table_name)
1689
Table_ident *table_ident;
1690
table_ident= new Table_ident(thd, *db_name, *table_name, 1);
1692
if (!sel->add_table_to_list(thd, table_ident, 0, 0, TL_READ))
1699
@brief Get lookup value from the part of 'WHERE' condition
1701
@details This function gets lookup value from
1702
the part of 'WHERE' condition if it's possible and
1703
fill appropriate lookup_field_vals struct field
1706
@param[in] thd thread handler
1707
@param[in] item_func part of WHERE condition
1708
@param[in] table I_S table
1709
@param[in, out] lookup_field_vals Struct which holds lookup values
1713
1 error, there can be no matching records for the condition
1716
bool get_lookup_value(THD *thd, Item_func *item_func,
1718
LOOKUP_FIELD_VALUES *lookup_field_vals)
1720
ST_SCHEMA_TABLE *schema_table= table->schema_table;
1721
ST_FIELD_INFO *field_info= schema_table->fields_info;
1722
const char *field_name1= schema_table->idx_field1 >= 0 ?
1723
field_info[schema_table->idx_field1].field_name : "";
1724
const char *field_name2= schema_table->idx_field2 >= 0 ?
1725
field_info[schema_table->idx_field2].field_name : "";
1727
if (item_func->functype() == Item_func::EQ_FUNC ||
1728
item_func->functype() == Item_func::EQUAL_FUNC)
1730
int idx_field, idx_val;
1731
char tmp[MAX_FIELD_WIDTH];
1732
String *tmp_str, str_buff(tmp, sizeof(tmp), system_charset_info);
1733
Item_field *item_field;
1734
const CHARSET_INFO * const cs= system_charset_info;
1736
if (item_func->arguments()[0]->type() == Item::FIELD_ITEM &&
1737
item_func->arguments()[1]->const_item())
1742
else if (item_func->arguments()[1]->type() == Item::FIELD_ITEM &&
1743
item_func->arguments()[0]->const_item())
1751
item_field= (Item_field*) item_func->arguments()[idx_field];
1752
if (table->table != item_field->field->table)
1754
tmp_str= item_func->arguments()[idx_val]->val_str(&str_buff);
1756
/* impossible value */
1760
/* Lookup value is database name */
1761
if (!cs->coll->strnncollsp(cs, (unsigned char *) field_name1, strlen(field_name1),
1762
(unsigned char *) item_field->field_name,
1763
strlen(item_field->field_name), 0))
1765
thd->make_lex_string(&lookup_field_vals->db_value, tmp_str->ptr(),
1766
tmp_str->length(), false);
1768
/* Lookup value is table name */
1769
else if (!cs->coll->strnncollsp(cs, (unsigned char *) field_name2,
1770
strlen(field_name2),
1771
(unsigned char *) item_field->field_name,
1772
strlen(item_field->field_name), 0))
1774
thd->make_lex_string(&lookup_field_vals->table_value, tmp_str->ptr(),
1775
tmp_str->length(), false);
1783
@brief Calculates lookup values from 'WHERE' condition
1785
@details This function calculates lookup value(database name, table name)
1786
from 'WHERE' condition if it's possible and
1787
fill lookup_field_vals struct fields with these values.
1789
@param[in] thd thread handler
1790
@param[in] cond WHERE condition
1791
@param[in] table I_S table
1792
@param[in, out] lookup_field_vals Struct which holds lookup values
1796
1 error, there can be no matching records for the condition
1799
bool calc_lookup_values_from_cond(THD *thd, COND *cond, TableList *table,
1800
LOOKUP_FIELD_VALUES *lookup_field_vals)
1805
if (cond->type() == Item::COND_ITEM)
1807
if (((Item_cond*) cond)->functype() == Item_func::COND_AND_FUNC)
1809
List_iterator<Item> li(*((Item_cond*) cond)->argument_list());
1811
while ((item= li++))
1813
if (item->type() == Item::FUNC_ITEM)
1815
if (get_lookup_value(thd, (Item_func*)item, table, lookup_field_vals))
1820
if (calc_lookup_values_from_cond(thd, item, table, lookup_field_vals))
1827
else if (cond->type() == Item::FUNC_ITEM &&
1828
get_lookup_value(thd, (Item_func*) cond, table, lookup_field_vals))
1834
bool uses_only_table_name_fields(Item *item, TableList *table)
1836
if (item->type() == Item::FUNC_ITEM)
1838
Item_func *item_func= (Item_func*)item;
1839
for (uint32_t i=0; i<item_func->argument_count(); i++)
1841
if (!uses_only_table_name_fields(item_func->arguments()[i], table))
1845
else if (item->type() == Item::FIELD_ITEM)
1847
Item_field *item_field= (Item_field*)item;
1848
const CHARSET_INFO * const cs= system_charset_info;
1849
ST_SCHEMA_TABLE *schema_table= table->schema_table;
1850
ST_FIELD_INFO *field_info= schema_table->fields_info;
1851
const char *field_name1= schema_table->idx_field1 >= 0 ?
1852
field_info[schema_table->idx_field1].field_name : "";
1853
const char *field_name2= schema_table->idx_field2 >= 0 ?
1854
field_info[schema_table->idx_field2].field_name : "";
1855
if (table->table != item_field->field->table ||
1856
(cs->coll->strnncollsp(cs, (unsigned char *) field_name1, strlen(field_name1),
1857
(unsigned char *) item_field->field_name,
1858
strlen(item_field->field_name), 0) &&
1859
cs->coll->strnncollsp(cs, (unsigned char *) field_name2, strlen(field_name2),
1860
(unsigned char *) item_field->field_name,
1861
strlen(item_field->field_name), 0)))
1864
else if (item->type() == Item::REF_ITEM)
1865
return uses_only_table_name_fields(item->real_item(), table);
1867
if (item->type() == Item::SUBSELECT_ITEM && !item->const_item())
1874
static COND * make_cond_for_info_schema(COND *cond, TableList *table)
1878
if (cond->type() == Item::COND_ITEM)
1880
if (((Item_cond*) cond)->functype() == Item_func::COND_AND_FUNC)
1882
/* Create new top level AND item */
1883
Item_cond_and *new_cond=new Item_cond_and;
1886
List_iterator<Item> li(*((Item_cond*) cond)->argument_list());
1890
Item *fix= make_cond_for_info_schema(item, table);
1892
new_cond->argument_list()->push_back(fix);
1894
switch (new_cond->argument_list()->elements) {
1898
return new_cond->argument_list()->head();
1900
new_cond->quick_fix_field();
1906
Item_cond_or *new_cond=new Item_cond_or;
1909
List_iterator<Item> li(*((Item_cond*) cond)->argument_list());
1913
Item *fix=make_cond_for_info_schema(item, table);
1916
new_cond->argument_list()->push_back(fix);
1918
new_cond->quick_fix_field();
1919
new_cond->top_level_item();
1924
if (!uses_only_table_name_fields(cond, table))
1931
@brief Calculate lookup values(database name, table name)
1933
@details This function calculates lookup values(database name, table name)
1934
from 'WHERE' condition or wild values (for 'SHOW' commands only)
1935
from LEX struct and fill lookup_field_vals struct field
1938
@param[in] thd thread handler
1939
@param[in] cond WHERE condition
1940
@param[in] tables I_S table
1941
@param[in, out] lookup_field_values Struct which holds lookup values
1945
1 error, there can be no matching records for the condition
1948
bool get_lookup_field_values(THD *thd, COND *cond, TableList *tables,
1949
LOOKUP_FIELD_VALUES *lookup_field_values)
1952
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
1953
memset(lookup_field_values, 0, sizeof(LOOKUP_FIELD_VALUES));
1954
switch (lex->sql_command) {
1955
case SQLCOM_SHOW_DATABASES:
1958
lookup_field_values->db_value.str= (char*) wild;
1959
lookup_field_values->db_value.length= strlen(wild);
1960
lookup_field_values->wild_db_value= 1;
1963
case SQLCOM_SHOW_TABLES:
1964
case SQLCOM_SHOW_TABLE_STATUS:
1965
lookup_field_values->db_value.str= lex->select_lex.db;
1966
lookup_field_values->db_value.length=strlen(lex->select_lex.db);
1969
lookup_field_values->table_value.str= (char*)wild;
1970
lookup_field_values->table_value.length= strlen(wild);
1971
lookup_field_values->wild_table_value= 1;
1976
The "default" is for queries over I_S.
1977
All previous cases handle SHOW commands.
1979
return calc_lookup_values_from_cond(thd, cond, tables, lookup_field_values);
1984
enum enum_schema_tables get_schema_table_idx(ST_SCHEMA_TABLE *schema_table)
1986
return (enum enum_schema_tables) (schema_table - &schema_tables[0]);
1991
Create db names list. Information schema name always is first in list
1996
files list of db names
1998
idx_field_vals idx_field_vals->db_name contains db name or
2000
with_i_schema returns 1 if we added 'IS' name to list
2008
int make_db_list(THD *thd, List<LEX_STRING> *files,
2009
LOOKUP_FIELD_VALUES *lookup_field_vals,
2010
bool *with_i_schema)
2012
LEX_STRING *i_s_name_copy= 0;
2013
i_s_name_copy= thd->make_lex_string(i_s_name_copy,
2014
INFORMATION_SCHEMA_NAME.str,
2015
INFORMATION_SCHEMA_NAME.length, true);
2017
if (lookup_field_vals->wild_db_value)
2020
This part of code is only for SHOW DATABASES command.
2021
idx_field_vals->db_value can be 0 when we don't use
2022
LIKE clause (see also get_index_field_values() function)
2024
if (!lookup_field_vals->db_value.str ||
2025
!wild_case_compare(system_charset_info,
2026
INFORMATION_SCHEMA_NAME.str,
2027
lookup_field_vals->db_value.str))
2030
if (files->push_back(i_s_name_copy))
2033
return (find_files(thd, files, NULL, mysql_data_home,
2034
lookup_field_vals->db_value.str, 1) != FIND_FILES_OK);
2039
If we have db lookup vaule we just add it to list and
2040
exit from the function
2042
if (lookup_field_vals->db_value.str)
2044
if (!my_strcasecmp(system_charset_info, INFORMATION_SCHEMA_NAME.str,
2045
lookup_field_vals->db_value.str))
2048
if (files->push_back(i_s_name_copy))
2052
if (files->push_back(&lookup_field_vals->db_value))
2058
Create list of existing databases. It is used in case
2059
of select from information schema table
2061
if (files->push_back(i_s_name_copy))
2064
return (find_files(thd, files, NULL,
2065
mysql_data_home, NULL, 1) != FIND_FILES_OK);
2069
struct st_add_schema_table
2071
List<LEX_STRING> *files;
2076
static bool add_schema_table(THD *thd, plugin_ref plugin,
2079
LEX_STRING *file_name= 0;
2080
st_add_schema_table *data= (st_add_schema_table *)p_data;
2081
List<LEX_STRING> *file_list= data->files;
2082
const char *wild= data->wild;
2083
ST_SCHEMA_TABLE *schema_table= plugin_data(plugin, ST_SCHEMA_TABLE *);
2085
if (schema_table->hidden)
2089
if (lower_case_table_names)
2091
if (wild_case_compare(files_charset_info,
2092
schema_table->table_name,
2096
else if (wild_compare(schema_table->table_name, wild, 0))
2100
if ((file_name= thd->make_lex_string(file_name, schema_table->table_name,
2101
strlen(schema_table->table_name),
2103
!file_list->push_back(file_name))
2109
int schema_tables_add(THD *thd, List<LEX_STRING> *files, const char *wild)
2111
LEX_STRING *file_name= 0;
2112
ST_SCHEMA_TABLE *tmp_schema_table= schema_tables;
2113
st_add_schema_table add_data;
2115
for (; tmp_schema_table->table_name; tmp_schema_table++)
2117
if (tmp_schema_table->hidden)
2121
if (lower_case_table_names)
2123
if (wild_case_compare(files_charset_info,
2124
tmp_schema_table->table_name,
2128
else if (wild_compare(tmp_schema_table->table_name, wild, 0))
2132
thd->make_lex_string(file_name, tmp_schema_table->table_name,
2133
strlen(tmp_schema_table->table_name), true)) &&
2134
!files->push_back(file_name))
2139
add_data.files= files;
2140
add_data.wild= wild;
2141
if (plugin_foreach(thd, add_schema_table,
2142
DRIZZLE_INFORMATION_SCHEMA_PLUGIN, &add_data))
2150
@brief Create table names list
2152
@details The function creates the list of table names in
2155
@param[in] thd thread handler
2156
@param[in] table_names List of table names in database
2157
@param[in] lex pointer to LEX struct
2158
@param[in] lookup_field_vals pointer to LOOKUP_FIELD_VALUE struct
2159
@param[in] with_i_schema true means that we add I_S tables to list
2160
@param[in] db_name database name
2162
@return Operation status
2164
@retval 1 fatal error
2165
@retval 2 Not fatal error; Safe to ignore this file list
2169
make_table_name_list(THD *thd, List<LEX_STRING> *table_names, LEX *lex,
2170
LOOKUP_FIELD_VALUES *lookup_field_vals,
2171
bool with_i_schema, LEX_STRING *db_name)
2173
char path[FN_REFLEN];
2174
build_table_filename(path, sizeof(path), db_name->str, "", "", 0);
2175
if (!lookup_field_vals->wild_table_value &&
2176
lookup_field_vals->table_value.str)
2180
if (find_schema_table(thd, lookup_field_vals->table_value.str))
2182
if (table_names->push_back(&lookup_field_vals->table_value))
2188
if (table_names->push_back(&lookup_field_vals->table_value))
2195
This call will add all matching the wildcards (if specified) IS tables
2199
return (schema_tables_add(thd, table_names,
2200
lookup_field_vals->table_value.str));
2202
find_files_result res= find_files(thd, table_names, db_name->str, path,
2203
lookup_field_vals->table_value.str, 0);
2204
if (res != FIND_FILES_OK)
2207
Downgrade errors about problems with database directory to
2208
warnings if this is not a 'SHOW' command. Another thread
2209
may have dropped database, and we may still have a name
2212
if (res == FIND_FILES_DIR)
2214
if (lex->sql_command != SQLCOM_SELECT)
2226
@brief Fill I_S table for SHOW COLUMNS|INDEX commands
2228
@param[in] thd thread handler
2229
@param[in] tables TableList for I_S table
2230
@param[in] schema_table pointer to I_S structure
2231
@param[in] open_tables_state_backup pointer to Open_tables_state object
2232
which is used to save|restore original
2233
status of variables related to
2236
@return Operation status
2242
fill_schema_show_cols_or_idxs(THD *thd, TableList *tables,
2243
ST_SCHEMA_TABLE *schema_table,
2244
Open_tables_state *open_tables_state_backup)
2248
LEX_STRING tmp_lex_string, tmp_lex_string1, *db_name, *table_name;
2249
enum_sql_command save_sql_command= lex->sql_command;
2250
TableList *show_table_list= (TableList*) tables->schema_select_lex->
2252
Table *table= tables->table;
2255
lex->all_selects_list= tables->schema_select_lex;
2257
Restore thd->temporary_tables to be able to process
2258
temporary tables(only for 'show index' & 'show columns').
2259
This should be changed when processing of temporary tables for
2260
I_S tables will be done.
2262
thd->temporary_tables= open_tables_state_backup->temporary_tables;
2264
Let us set fake sql_command so views won't try to merge
2265
themselves into main statement. If we don't do this,
2266
SELECT * from information_schema.xxxx will cause problems.
2267
SQLCOM_SHOW_FIELDS is used because it satisfies 'only_view_structure()'
2269
lex->sql_command= SQLCOM_SHOW_FIELDS;
2270
res= open_normal_and_derived_tables(thd, show_table_list,
2271
DRIZZLE_LOCK_IGNORE_FLUSH);
2272
lex->sql_command= save_sql_command;
2274
get_all_tables() returns 1 on failure and 0 on success thus
2275
return only these and not the result code of ::process_table()
2277
We should use show_table_list->alias instead of
2278
show_table_list->table_name because table_name
2279
could be changed during opening of I_S tables. It's safe
2280
to use alias because alias contains original table name
2281
in this case(this part of code is used only for
2282
'show columns' & 'show statistics' commands).
2284
table_name= thd->make_lex_string(&tmp_lex_string1, show_table_list->alias,
2285
strlen(show_table_list->alias), false);
2286
db_name= thd->make_lex_string(&tmp_lex_string, show_table_list->db,
2287
show_table_list->db_length, false);
2290
error= test(schema_table->process_table(thd, show_table_list,
2291
table, res, db_name,
2293
thd->temporary_tables= 0;
2294
close_tables_for_reopen(thd, &show_table_list);
2300
@brief Fill I_S table for SHOW Table NAMES commands
2302
@param[in] thd thread handler
2303
@param[in] table Table struct for I_S table
2304
@param[in] db_name database name
2305
@param[in] table_name table name
2306
@param[in] with_i_schema I_S table if true
2308
@return Operation status
2313
static int fill_schema_table_names(THD *thd, Table *table,
2314
LEX_STRING *db_name, LEX_STRING *table_name,
2319
table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"),
2320
system_charset_info);
2324
enum legacy_db_type not_used;
2325
char path[FN_REFLEN];
2326
(void) build_table_filename(path, sizeof(path), db_name->str,
2327
table_name->str, reg_ext, 0);
2328
if (mysql_frm_type(thd, path, ¬_used))
2330
table->field[3]->store(STRING_WITH_LEN("BASE Table"),
2331
system_charset_info);
2335
table->field[3]->store(STRING_WITH_LEN("ERROR"),
2336
system_charset_info);
2339
if (thd->is_error() && thd->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2345
if (schema_table_store_record(thd, table))
2352
@brief Get open table method
2354
@details The function calculates the method which will be used
2356
SKIP_OPEN_TABLE - do not open table
2357
OPEN_FRM_ONLY - open FRM file only
2358
OPEN_FULL_TABLE - open FRM, data, index files
2359
@param[in] tables I_S table table_list
2360
@param[in] schema_table I_S table struct
2361
@param[in] schema_table_idx I_S table index
2363
@return return a set of flags
2364
@retval SKIP_OPEN_TABLE | OPEN_FRM_ONLY | OPEN_FULL_TABLE
2367
static uint32_t get_table_open_method(TableList *tables,
2368
ST_SCHEMA_TABLE *schema_table,
2369
enum enum_schema_tables schema_table_idx __attribute__((unused)))
2372
determine which method will be used for table opening
2374
if (schema_table->i_s_requested_object & OPTIMIZE_I_S_TABLE)
2376
Field **ptr, *field;
2377
int table_open_method= 0, field_indx= 0;
2378
for (ptr=tables->table->field; (field= *ptr) ; ptr++)
2380
if (bitmap_is_set(tables->table->read_set, field->field_index))
2381
table_open_method|= schema_table->fields_info[field_indx].open_method;
2384
return table_open_method;
2386
/* I_S tables which use get_all_tables but can not be optimized */
2387
return (uint) OPEN_FULL_TABLE;
2392
@brief Fill I_S table with data from FRM file only
2394
@param[in] thd thread handler
2395
@param[in] table Table struct for I_S table
2396
@param[in] schema_table I_S table struct
2397
@param[in] db_name database name
2398
@param[in] table_name table name
2399
@param[in] schema_table_idx I_S table index
2401
@return Operation status
2402
@retval 0 Table is processed and we can continue
2404
@retval 1 It's view and we have to use
2405
open_tables function for this table
2408
static int fill_schema_table_from_frm(THD *thd,TableList *tables,
2409
ST_SCHEMA_TABLE *schema_table,
2410
LEX_STRING *db_name,
2411
LEX_STRING *table_name,
2412
enum enum_schema_tables schema_table_idx __attribute__((unused)))
2414
Table *table= tables->table;
2417
TableList table_list;
2420
char key[MAX_DBKEY_LENGTH];
2421
uint32_t key_length;
2423
memset(&table_list, 0, sizeof(TableList));
2424
memset(&tbl, 0, sizeof(Table));
2426
table_list.table_name= table_name->str;
2427
table_list.db= db_name->str;
2429
key_length= create_table_def_key(thd, key, &table_list, 0);
2430
pthread_mutex_lock(&LOCK_open);
2431
share= get_table_share(thd, &table_list, key,
2432
key_length, 0, &error);
2441
table_list.table= &tbl;
2442
res= schema_table->process_table(thd, &table_list, table,
2443
res, db_name, table_name);
2446
release_table_share(share, RELEASE_NORMAL);
2449
pthread_mutex_unlock(&LOCK_open);
2457
@brief Fill I_S tables whose data are retrieved
2458
from frm files and storage engine
2460
@details The information schema tables are internally represented as
2461
temporary tables that are filled at query execution time.
2462
Those I_S tables whose data are retrieved
2463
from frm files and storage engine are filled by the function
2466
@param[in] thd thread handler
2467
@param[in] tables I_S table
2468
@param[in] cond 'WHERE' condition
2470
@return Operation status
2475
int get_all_tables(THD *thd, TableList *tables, COND *cond)
2478
Table *table= tables->table;
2479
SELECT_LEX *old_all_select_lex= lex->all_selects_list;
2480
enum_sql_command save_sql_command= lex->sql_command;
2481
SELECT_LEX *lsel= tables->schema_select_lex;
2482
ST_SCHEMA_TABLE *schema_table= tables->schema_table;
2484
LOOKUP_FIELD_VALUES lookup_field_vals;
2485
LEX_STRING *db_name, *table_name;
2487
enum enum_schema_tables schema_table_idx;
2488
List<LEX_STRING> db_names;
2489
List_iterator_fast<LEX_STRING> it(db_names);
2490
COND *partial_cond= 0;
2491
uint32_t derived_tables= lex->derived_tables;
2493
Open_tables_state open_tables_state_backup;
2494
Query_tables_list query_tables_list_backup;
2495
uint32_t table_open_method;
2496
bool old_value= thd->no_warnings_for_error;
2498
lex->reset_n_backup_query_tables_list(&query_tables_list_backup);
2501
We should not introduce deadlocks even if we already have some
2502
tables open and locked, since we won't lock tables which we will
2503
open and will ignore possible name-locks for these tables.
2505
thd->reset_n_backup_open_tables_state(&open_tables_state_backup);
2507
schema_table_idx= get_schema_table_idx(schema_table);
2508
tables->table_open_method= table_open_method=
2509
get_table_open_method(tables, schema_table, schema_table_idx);
2511
this branch processes SHOW FIELDS, SHOW INDEXES commands.
2512
see sql_parse.cc, prepare_schema_table() function where
2513
this values are initialized
2515
if (lsel && lsel->table_list.first)
2517
error= fill_schema_show_cols_or_idxs(thd, tables, schema_table,
2518
&open_tables_state_backup);
2522
if (get_lookup_field_values(thd, cond, tables, &lookup_field_vals))
2528
if (!lookup_field_vals.wild_db_value && !lookup_field_vals.wild_table_value)
2531
if lookup value is empty string then
2532
it's impossible table name or db name
2534
if ((lookup_field_vals.db_value.str && !lookup_field_vals.db_value.str[0]) ||
2535
(lookup_field_vals.table_value.str && !lookup_field_vals.table_value.str[0]))
2542
if (lookup_field_vals.db_value.length &&
2543
!lookup_field_vals.wild_db_value)
2544
tables->has_db_lookup_value= true;
2545
if (lookup_field_vals.table_value.length &&
2546
!lookup_field_vals.wild_table_value)
2547
tables->has_table_lookup_value= true;
2549
if (tables->has_db_lookup_value && tables->has_table_lookup_value)
2552
partial_cond= make_cond_for_info_schema(cond, tables);
2556
/* EXPLAIN SELECT */
2561
if (make_db_list(thd, &db_names, &lookup_field_vals, &with_i_schema))
2563
it.rewind(); /* To get access to new elements in basis list */
2564
while ((db_name= it++))
2567
thd->no_warnings_for_error= 1;
2568
List<LEX_STRING> table_names;
2569
int res= make_table_name_list(thd, &table_names, lex,
2571
with_i_schema, db_name);
2572
if (res == 2) /* Not fatal error, continue */
2577
List_iterator_fast<LEX_STRING> it_files(table_names);
2578
while ((table_name= it_files++))
2580
restore_record(table, s->default_values);
2581
table->field[schema_table->idx_field1]->
2582
store(db_name->str, db_name->length, system_charset_info);
2583
table->field[schema_table->idx_field2]->
2584
store(table_name->str, table_name->length, system_charset_info);
2586
if (!partial_cond || partial_cond->val_int())
2589
If table is I_S.tables and open_table_method is 0 (eg SKIP_OPEN)
2590
we can skip table opening and we don't have lookup value for
2591
table name or lookup value is wild string(table name list is
2592
already created by make_table_name_list() function).
2594
if (!table_open_method && schema_table_idx == SCH_TABLES &&
2595
(!lookup_field_vals.table_value.length ||
2596
lookup_field_vals.wild_table_value))
2598
if (schema_table_store_record(thd, table))
2599
goto err; /* Out of space in temporary table */
2603
/* SHOW Table NAMES command */
2604
if (schema_table_idx == SCH_TABLE_NAMES)
2606
if (fill_schema_table_names(thd, tables->table, db_name,
2607
table_name, with_i_schema))
2612
if (!(table_open_method & ~OPEN_FRM_ONLY) &&
2615
if (!fill_schema_table_from_frm(thd, tables, schema_table, db_name,
2616
table_name, schema_table_idx))
2621
LEX_STRING tmp_lex_string, orig_db_name;
2623
Set the parent lex of 'sel' because it is needed by
2624
sel.init_query() which is called inside make_table_list.
2626
thd->no_warnings_for_error= 1;
2627
sel.parent_lex= lex;
2628
/* db_name can be changed in make_table_list() func */
2629
if (!thd->make_lex_string(&orig_db_name, db_name->str,
2630
db_name->length, false))
2632
if (make_table_list(thd, &sel, db_name, table_name))
2634
TableList *show_table_list= (TableList*) sel.table_list.first;
2635
lex->all_selects_list= &sel;
2636
lex->derived_tables= 0;
2637
lex->sql_command= SQLCOM_SHOW_FIELDS;
2638
show_table_list->i_s_requested_object=
2639
schema_table->i_s_requested_object;
2640
res= open_normal_and_derived_tables(thd, show_table_list,
2641
DRIZZLE_LOCK_IGNORE_FLUSH);
2642
lex->sql_command= save_sql_command;
2644
XXX: show_table_list has a flag i_is_requested,
2645
and when it's set, open_normal_and_derived_tables()
2646
can return an error without setting an error message
2647
in THD, which is a hack. This is why we have to
2648
check for res, then for thd->is_error() only then
2649
for thd->main_da.sql_errno().
2651
if (res && thd->is_error() &&
2652
thd->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2655
Hide error for not existing table.
2656
This error can occur for example when we use
2657
where condition with db name and table name and this
2658
table does not exist.
2666
We should use show_table_list->alias instead of
2667
show_table_list->table_name because table_name
2668
could be changed during opening of I_S tables. It's safe
2669
to use alias because alias contains original table name
2672
thd->make_lex_string(&tmp_lex_string, show_table_list->alias,
2673
strlen(show_table_list->alias), false);
2674
res= schema_table->process_table(thd, show_table_list, table,
2677
close_tables_for_reopen(thd, &show_table_list);
2679
assert(!lex->query_tables_own_last);
2686
If we have information schema its always the first table and only
2687
the first table. Reset for other tables.
2695
thd->restore_backup_open_tables_state(&open_tables_state_backup);
2696
lex->restore_backup_query_tables_list(&query_tables_list_backup);
2697
lex->derived_tables= derived_tables;
2698
lex->all_selects_list= old_all_select_lex;
2699
lex->sql_command= save_sql_command;
2700
thd->no_warnings_for_error= old_value;
2705
bool store_schema_shemata(THD* thd, Table *table, LEX_STRING *db_name,
2706
const CHARSET_INFO * const cs)
2708
restore_record(table, s->default_values);
2709
table->field[1]->store(db_name->str, db_name->length, system_charset_info);
2710
table->field[2]->store(cs->csname, strlen(cs->csname), system_charset_info);
2711
table->field[3]->store(cs->name, strlen(cs->name), system_charset_info);
2712
return schema_table_store_record(thd, table);
2716
int fill_schema_schemata(THD *thd, TableList *tables, COND *cond)
2719
TODO: fill_schema_shemata() is called when new client is connected.
2720
Returning error status in this case leads to client hangup.
2723
LOOKUP_FIELD_VALUES lookup_field_vals;
2724
List<LEX_STRING> db_names;
2725
LEX_STRING *db_name;
2727
HA_CREATE_INFO create;
2728
Table *table= tables->table;
2730
if (get_lookup_field_values(thd, cond, tables, &lookup_field_vals))
2732
if (make_db_list(thd, &db_names, &lookup_field_vals,
2737
If we have lookup db value we should check that the database exists
2739
if(lookup_field_vals.db_value.str && !lookup_field_vals.wild_db_value &&
2742
char path[FN_REFLEN+16];
2744
struct stat stat_info;
2745
if (!lookup_field_vals.db_value.str[0])
2747
path_len= build_table_filename(path, sizeof(path),
2748
lookup_field_vals.db_value.str, "", "", 0);
2749
path[path_len-1]= 0;
2750
if (stat(path,&stat_info))
2754
List_iterator_fast<LEX_STRING> it(db_names);
2755
while ((db_name=it++))
2757
if (with_i_schema) // information schema name is always first in list
2759
if (store_schema_shemata(thd, table, db_name,
2760
system_charset_info))
2766
load_db_opt_by_name(thd, db_name->str, &create);
2767
if (store_schema_shemata(thd, table, db_name,
2768
create.default_table_charset))
2776
static int get_schema_tables_record(THD *thd, TableList *tables,
2777
Table *table, bool res,
2778
LEX_STRING *db_name,
2779
LEX_STRING *table_name)
2781
const char *tmp_buff;
2783
const CHARSET_INFO * const cs= system_charset_info;
2785
restore_record(table, s->default_values);
2786
table->field[1]->store(db_name->str, db_name->length, cs);
2787
table->field[2]->store(table_name->str, table_name->length, cs);
2791
there was errors during opening tables
2793
const char *error= thd->is_error() ? thd->main_da.message() : "";
2794
if (tables->schema_table)
2795
table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"), cs);
2797
table->field[3]->store(STRING_WITH_LEN("BASE Table"), cs);
2798
table->field[20]->store(error, strlen(error), cs);
2803
char option_buff[400],*ptr;
2804
Table *show_table= tables->table;
2805
TABLE_SHARE *share= show_table->s;
2806
handler *file= show_table->file;
2807
handlerton *tmp_db_type= share->db_type();
2808
if (share->tmp_table == SYSTEM_TMP_TABLE)
2809
table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"), cs);
2810
else if (share->tmp_table)
2811
table->field[3]->store(STRING_WITH_LEN("LOCAL TEMPORARY"), cs);
2813
table->field[3]->store(STRING_WITH_LEN("BASE Table"), cs);
2815
for (int i= 4; i < 20; i++)
2817
if (i == 7 || (i > 12 && i < 17) || i == 18)
2819
table->field[i]->set_notnull();
2821
tmp_buff= (char *) ha_resolve_storage_engine_name(tmp_db_type);
2822
table->field[4]->store(tmp_buff, strlen(tmp_buff), cs);
2823
table->field[5]->store((int64_t) share->frm_version, true);
2826
if (share->min_rows)
2828
ptr=my_stpcpy(ptr," min_rows=");
2829
ptr=int64_t10_to_str(share->min_rows,ptr,10);
2831
if (share->max_rows)
2833
ptr=my_stpcpy(ptr," max_rows=");
2834
ptr=int64_t10_to_str(share->max_rows,ptr,10);
2836
if (share->avg_row_length)
2838
ptr=my_stpcpy(ptr," avg_row_length=");
2839
ptr=int64_t10_to_str(share->avg_row_length,ptr,10);
2841
if (share->db_create_options & HA_OPTION_PACK_KEYS)
2842
ptr=my_stpcpy(ptr," pack_keys=1");
2843
if (share->db_create_options & HA_OPTION_NO_PACK_KEYS)
2844
ptr=my_stpcpy(ptr," pack_keys=0");
2845
/* We use CHECKSUM, instead of TABLE_CHECKSUM, for backward compability */
2846
if (share->db_create_options & HA_OPTION_CHECKSUM)
2847
ptr=my_stpcpy(ptr," checksum=1");
2848
if (share->page_checksum != HA_CHOICE_UNDEF)
2849
ptr= strxmov(ptr, " page_checksum=",
2850
ha_choice_values[(uint) share->page_checksum], NULL);
2851
if (share->db_create_options & HA_OPTION_DELAY_KEY_WRITE)
2852
ptr=my_stpcpy(ptr," delay_key_write=1");
2853
if (share->row_type != ROW_TYPE_DEFAULT)
2854
ptr=strxmov(ptr, " row_format=",
2855
ha_row_type[(uint) share->row_type],
2857
if (share->block_size)
2859
ptr= my_stpcpy(ptr, " block_size=");
2860
ptr= int64_t10_to_str(share->block_size, ptr, 10);
2863
if (share->transactional != HA_CHOICE_UNDEF)
2865
ptr= strxmov(ptr, " TRANSACTIONAL=",
2866
(share->transactional == HA_CHOICE_YES ? "1" : "0"),
2869
if (share->transactional != HA_CHOICE_UNDEF)
2870
ptr= strxmov(ptr, " transactional=",
2871
ha_choice_values[(uint) share->transactional], NULL);
2872
table->field[19]->store(option_buff+1,
2873
(ptr == option_buff ? 0 :
2874
(uint) (ptr-option_buff)-1), cs);
2876
tmp_buff= (share->table_charset ?
2877
share->table_charset->name : "default");
2878
table->field[17]->store(tmp_buff, strlen(tmp_buff), cs);
2880
if (share->comment.str)
2881
table->field[20]->store(share->comment.str, share->comment.length, cs);
2885
file->info(HA_STATUS_VARIABLE | HA_STATUS_TIME | HA_STATUS_AUTO |
2887
enum row_type row_type = file->get_row_type();
2889
case ROW_TYPE_NOT_USED:
2890
case ROW_TYPE_DEFAULT:
2891
tmp_buff= ((share->db_options_in_use &
2892
HA_OPTION_COMPRESS_RECORD) ? "Compressed" :
2893
(share->db_options_in_use & HA_OPTION_PACK_RECORD) ?
2894
"Dynamic" : "Fixed");
2896
case ROW_TYPE_FIXED:
2899
case ROW_TYPE_DYNAMIC:
2900
tmp_buff= "Dynamic";
2902
case ROW_TYPE_COMPRESSED:
2903
tmp_buff= "Compressed";
2905
case ROW_TYPE_REDUNDANT:
2906
tmp_buff= "Redundant";
2908
case ROW_TYPE_COMPACT:
2909
tmp_buff= "Compact";
2915
table->field[6]->store(tmp_buff, strlen(tmp_buff), cs);
2916
if (!tables->schema_table)
2918
table->field[7]->store((int64_t) file->stats.records, true);
2919
table->field[7]->set_notnull();
2921
table->field[8]->store((int64_t) file->stats.mean_rec_length, true);
2922
table->field[9]->store((int64_t) file->stats.data_file_length, true);
2923
if (file->stats.max_data_file_length)
2925
table->field[10]->store((int64_t) file->stats.max_data_file_length,
2928
table->field[11]->store((int64_t) file->stats.index_file_length, true);
2929
table->field[12]->store((int64_t) file->stats.delete_length, true);
2930
if (show_table->found_next_number_field)
2932
table->field[13]->store((int64_t) file->stats.auto_increment_value,
2934
table->field[13]->set_notnull();
2936
if (file->stats.create_time)
2938
thd->variables.time_zone->gmt_sec_to_TIME(&time,
2939
(my_time_t) file->stats.create_time);
2940
table->field[14]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2941
table->field[14]->set_notnull();
2943
if (file->stats.update_time)
2945
thd->variables.time_zone->gmt_sec_to_TIME(&time,
2946
(my_time_t) file->stats.update_time);
2947
table->field[15]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2948
table->field[15]->set_notnull();
2950
if (file->stats.check_time)
2952
thd->variables.time_zone->gmt_sec_to_TIME(&time,
2953
(my_time_t) file->stats.check_time);
2954
table->field[16]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2955
table->field[16]->set_notnull();
2957
if (file->ha_table_flags() & (ulong) HA_HAS_CHECKSUM)
2959
table->field[18]->store((int64_t) file->checksum(), true);
2960
table->field[18]->set_notnull();
2964
return(schema_table_store_record(thd, table));
2969
@brief Store field characteristics into appropriate I_S table columns
2971
@param[in] table I_S table
2972
@param[in] field processed field
2973
@param[in] cs I_S table charset
2974
@param[in] offset offset from beginning of table
2975
to DATE_TYPE column in I_S table
2980
void store_column_type(Table *table, Field *field, const CHARSET_INFO * const cs,
2984
int decimals, field_length;
2985
const char *tmp_buff;
2986
char column_type_buff[MAX_FIELD_WIDTH];
2987
String column_type(column_type_buff, sizeof(column_type_buff), cs);
2989
field->sql_type(column_type);
2990
/* DTD_IDENTIFIER column */
2991
table->field[offset + 7]->store(column_type.ptr(), column_type.length(), cs);
2992
table->field[offset + 7]->set_notnull();
2993
tmp_buff= strchr(column_type.ptr(), '(');
2994
/* DATA_TYPE column */
2995
table->field[offset]->store(column_type.ptr(),
2996
(tmp_buff ? tmp_buff - column_type.ptr() :
2997
column_type.length()), cs);
2998
is_blob= (field->type() == DRIZZLE_TYPE_BLOB);
2999
if (field->has_charset() || is_blob ||
3000
field->real_type() == DRIZZLE_TYPE_VARCHAR) // For varbinary type
3002
uint32_t octet_max_length= field->max_display_length();
3003
if (is_blob && octet_max_length != (uint32_t) 4294967295U)
3004
octet_max_length /= field->charset()->mbmaxlen;
3005
int64_t char_max_len= is_blob ?
3006
(int64_t) octet_max_length / field->charset()->mbminlen :
3007
(int64_t) octet_max_length / field->charset()->mbmaxlen;
3008
/* CHARACTER_MAXIMUM_LENGTH column*/
3009
table->field[offset + 1]->store(char_max_len, true);
3010
table->field[offset + 1]->set_notnull();
3011
/* CHARACTER_OCTET_LENGTH column */
3012
table->field[offset + 2]->store((int64_t) octet_max_length, true);
3013
table->field[offset + 2]->set_notnull();
3017
Calculate field_length and decimals.
3018
They are set to -1 if they should not be set (we should return NULL)
3021
decimals= field->decimals();
3022
switch (field->type()) {
3023
case DRIZZLE_TYPE_NEWDECIMAL:
3024
field_length= ((Field_new_decimal*) field)->precision;
3026
case DRIZZLE_TYPE_TINY:
3027
case DRIZZLE_TYPE_LONG:
3028
case DRIZZLE_TYPE_LONGLONG:
3029
field_length= field->max_display_length() - 1;
3031
case DRIZZLE_TYPE_DOUBLE:
3032
field_length= field->field_length;
3033
if (decimals == NOT_FIXED_DEC)
3034
decimals= -1; // return NULL
3037
field_length= decimals= -1;
3041
/* NUMERIC_PRECISION column */
3042
if (field_length >= 0)
3044
table->field[offset + 3]->store((int64_t) field_length, true);
3045
table->field[offset + 3]->set_notnull();
3047
/* NUMERIC_SCALE column */
3050
table->field[offset + 4]->store((int64_t) decimals, true);
3051
table->field[offset + 4]->set_notnull();
3053
if (field->has_charset())
3055
/* CHARACTER_SET_NAME column*/
3056
tmp_buff= field->charset()->csname;
3057
table->field[offset + 5]->store(tmp_buff, strlen(tmp_buff), cs);
3058
table->field[offset + 5]->set_notnull();
3059
/* COLLATION_NAME column */
3060
tmp_buff= field->charset()->name;
3061
table->field[offset + 6]->store(tmp_buff, strlen(tmp_buff), cs);
3062
table->field[offset + 6]->set_notnull();
3067
static int get_schema_column_record(THD *thd, TableList *tables,
3068
Table *table, bool res,
3069
LEX_STRING *db_name,
3070
LEX_STRING *table_name)
3073
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3074
const CHARSET_INFO * const cs= system_charset_info;
3076
TABLE_SHARE *show_table_share;
3077
Field **ptr, *field, *timestamp_field;
3082
if (lex->sql_command != SQLCOM_SHOW_FIELDS)
3085
I.e. we are in SELECT FROM INFORMATION_SCHEMA.COLUMS
3086
rather than in SHOW COLUMNS
3088
if (thd->is_error())
3089
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3090
thd->main_da.sql_errno(), thd->main_da.message());
3097
show_table= tables->table;
3098
show_table_share= show_table->s;
3101
if (tables->schema_table)
3103
ptr= show_table->field;
3104
timestamp_field= show_table->timestamp_field;
3105
show_table->use_all_columns(); // Required for default
3109
ptr= show_table_share->field;
3110
timestamp_field= show_table_share->timestamp_field;
3112
read_set may be inited in case of
3115
if (!show_table->read_set)
3117
/* to satisfy 'field->val_str' ASSERTs */
3118
unsigned char *bitmaps;
3119
uint32_t bitmap_size= show_table_share->column_bitmap_size;
3120
if (!(bitmaps= (unsigned char*) alloc_root(thd->mem_root, bitmap_size)))
3122
bitmap_init(&show_table->def_read_set,
3123
(my_bitmap_map*) bitmaps, show_table_share->fields, false);
3124
bitmap_set_all(&show_table->def_read_set);
3125
show_table->read_set= &show_table->def_read_set;
3127
bitmap_set_all(show_table->read_set);
3130
for (; (field= *ptr) ; ptr++)
3133
char tmp[MAX_FIELD_WIDTH];
3134
String type(tmp,sizeof(tmp), system_charset_info);
3137
/* to satisfy 'field->val_str' ASSERTs */
3138
field->table= show_table;
3139
show_table->in_use= thd;
3141
if (wild && wild[0] &&
3142
wild_case_compare(system_charset_info, field->field_name,wild))
3146
/* Get default row, with all NULL fields set to NULL */
3147
restore_record(table, s->default_values);
3149
table->field[1]->store(db_name->str, db_name->length, cs);
3150
table->field[2]->store(table_name->str, table_name->length, cs);
3151
table->field[3]->store(field->field_name, strlen(field->field_name),
3153
table->field[4]->store((int64_t) count, true);
3155
if (get_field_default_value(thd, timestamp_field, field, &type, 0))
3157
table->field[5]->store(type.ptr(), type.length(), cs);
3158
table->field[5]->set_notnull();
3160
pos=(unsigned char*) ((field->flags & NOT_NULL_FLAG) ? "NO" : "YES");
3161
table->field[6]->store((const char*) pos,
3162
strlen((const char*) pos), cs);
3163
store_column_type(table, field, cs, 7);
3165
pos=(unsigned char*) ((field->flags & PRI_KEY_FLAG) ? "PRI" :
3166
(field->flags & UNIQUE_KEY_FLAG) ? "UNI" :
3167
(field->flags & MULTIPLE_KEY_FLAG) ? "MUL":"");
3168
table->field[15]->store((const char*) pos,
3169
strlen((const char*) pos), cs);
3172
if (field->unireg_check == Field::NEXT_NUMBER)
3173
table->field[16]->store(STRING_WITH_LEN("auto_increment"), cs);
3174
if (timestamp_field == field &&
3175
field->unireg_check != Field::TIMESTAMP_DN_FIELD)
3176
table->field[16]->store(STRING_WITH_LEN("on update CURRENT_TIMESTAMP"),
3179
table->field[18]->store(field->comment.str, field->comment.length, cs);
3181
enum column_format_type column_format= (enum column_format_type)
3182
((field->flags >> COLUMN_FORMAT_FLAGS) & COLUMN_FORMAT_MASK);
3183
pos=(unsigned char*)"Default";
3184
table->field[19]->store((const char*) pos,
3185
strlen((const char*) pos), cs);
3186
pos=(unsigned char*)(column_format == COLUMN_FORMAT_TYPE_DEFAULT ? "Default" :
3187
column_format == COLUMN_FORMAT_TYPE_FIXED ? "Fixed" :
3189
table->field[20]->store((const char*) pos,
3190
strlen((const char*) pos), cs);
3192
if (schema_table_store_record(thd, table))
3200
int fill_schema_charsets(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3203
const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
3204
Table *table= tables->table;
3205
const CHARSET_INFO * const scs= system_charset_info;
3207
for (cs= all_charsets ; cs < all_charsets+255 ; cs++)
3209
const CHARSET_INFO * const tmp_cs= cs[0];
3210
if (tmp_cs && (tmp_cs->state & MY_CS_PRIMARY) &&
3211
(tmp_cs->state & MY_CS_AVAILABLE) &&
3212
!(tmp_cs->state & MY_CS_HIDDEN) &&
3213
!(wild && wild[0] &&
3214
wild_case_compare(scs, tmp_cs->csname,wild)))
3216
const char *comment;
3217
restore_record(table, s->default_values);
3218
table->field[0]->store(tmp_cs->csname, strlen(tmp_cs->csname), scs);
3219
table->field[1]->store(tmp_cs->name, strlen(tmp_cs->name), scs);
3220
comment= tmp_cs->comment ? tmp_cs->comment : "";
3221
table->field[2]->store(comment, strlen(comment), scs);
3222
table->field[3]->store((int64_t) tmp_cs->mbmaxlen, true);
3223
if (schema_table_store_record(thd, table))
3231
int fill_schema_collation(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3234
const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
3235
Table *table= tables->table;
3236
const CHARSET_INFO * const scs= system_charset_info;
3237
for (cs= all_charsets ; cs < all_charsets+255 ; cs++ )
3240
const CHARSET_INFO *tmp_cs= cs[0];
3241
if (!tmp_cs || !(tmp_cs->state & MY_CS_AVAILABLE) ||
3242
(tmp_cs->state & MY_CS_HIDDEN) ||
3243
!(tmp_cs->state & MY_CS_PRIMARY))
3245
for (cl= all_charsets; cl < all_charsets+255 ;cl ++)
3247
const CHARSET_INFO *tmp_cl= cl[0];
3248
if (!tmp_cl || !(tmp_cl->state & MY_CS_AVAILABLE) ||
3249
!my_charset_same(tmp_cs, tmp_cl))
3251
if (!(wild && wild[0] &&
3252
wild_case_compare(scs, tmp_cl->name,wild)))
3254
const char *tmp_buff;
3255
restore_record(table, s->default_values);
3256
table->field[0]->store(tmp_cl->name, strlen(tmp_cl->name), scs);
3257
table->field[1]->store(tmp_cl->csname , strlen(tmp_cl->csname), scs);
3258
table->field[2]->store((int64_t) tmp_cl->number, true);
3259
tmp_buff= (tmp_cl->state & MY_CS_PRIMARY) ? "Yes" : "";
3260
table->field[3]->store(tmp_buff, strlen(tmp_buff), scs);
3261
tmp_buff= (tmp_cl->state & MY_CS_COMPILED)? "Yes" : "";
3262
table->field[4]->store(tmp_buff, strlen(tmp_buff), scs);
3263
table->field[5]->store((int64_t) tmp_cl->strxfrm_multiply, true);
3264
if (schema_table_store_record(thd, table))
3273
int fill_schema_coll_charset_app(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3276
Table *table= tables->table;
3277
const CHARSET_INFO * const scs= system_charset_info;
3278
for (cs= all_charsets ; cs < all_charsets+255 ; cs++ )
3281
const CHARSET_INFO *tmp_cs= cs[0];
3282
if (!tmp_cs || !(tmp_cs->state & MY_CS_AVAILABLE) ||
3283
!(tmp_cs->state & MY_CS_PRIMARY))
3285
for (cl= all_charsets; cl < all_charsets+255 ;cl ++)
3287
const CHARSET_INFO *tmp_cl= cl[0];
3288
if (!tmp_cl || !(tmp_cl->state & MY_CS_AVAILABLE) ||
3289
!my_charset_same(tmp_cs,tmp_cl))
3291
restore_record(table, s->default_values);
3292
table->field[0]->store(tmp_cl->name, strlen(tmp_cl->name), scs);
3293
table->field[1]->store(tmp_cl->csname , strlen(tmp_cl->csname), scs);
3294
if (schema_table_store_record(thd, table))
3302
static int get_schema_stat_record(THD *thd, TableList *tables,
3303
Table *table, bool res,
3304
LEX_STRING *db_name,
3305
LEX_STRING *table_name)
3307
const CHARSET_INFO * const cs= system_charset_info;
3310
if (thd->lex->sql_command != SQLCOM_SHOW_KEYS)
3313
I.e. we are in SELECT FROM INFORMATION_SCHEMA.STATISTICS
3314
rather than in SHOW KEYS
3316
if (thd->is_error())
3317
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3318
thd->main_da.sql_errno(), thd->main_da.message());
3326
Table *show_table= tables->table;
3327
KEY *key_info=show_table->s->key_info;
3328
if (show_table->file)
3329
show_table->file->info(HA_STATUS_VARIABLE |
3332
for (uint32_t i=0 ; i < show_table->s->keys ; i++,key_info++)
3334
KEY_PART_INFO *key_part= key_info->key_part;
3336
for (uint32_t j=0 ; j < key_info->key_parts ; j++,key_part++)
3338
restore_record(table, s->default_values);
3339
table->field[1]->store(db_name->str, db_name->length, cs);
3340
table->field[2]->store(table_name->str, table_name->length, cs);
3341
table->field[3]->store((int64_t) ((key_info->flags &
3342
HA_NOSAME) ? 0 : 1), true);
3343
table->field[4]->store(db_name->str, db_name->length, cs);
3344
table->field[5]->store(key_info->name, strlen(key_info->name), cs);
3345
table->field[6]->store((int64_t) (j+1), true);
3346
str=(key_part->field ? key_part->field->field_name :
3348
table->field[7]->store(str, strlen(str), cs);
3349
if (show_table->file)
3351
if (show_table->file->index_flags(i, j, 0) & HA_READ_ORDER)
3353
table->field[8]->store(((key_part->key_part_flag &
3356
table->field[8]->set_notnull();
3358
KEY *key=show_table->key_info+i;
3359
if (key->rec_per_key[j])
3361
ha_rows records=(show_table->file->stats.records /
3362
key->rec_per_key[j]);
3363
table->field[9]->store((int64_t) records, true);
3364
table->field[9]->set_notnull();
3366
str= show_table->file->index_type(i);
3367
table->field[13]->store(str, strlen(str), cs);
3369
if ((key_part->field &&
3371
show_table->s->field[key_part->fieldnr-1]->key_length()))
3373
table->field[10]->store((int64_t) key_part->length /
3374
key_part->field->charset()->mbmaxlen, true);
3375
table->field[10]->set_notnull();
3377
uint32_t flags= key_part->field ? key_part->field->flags : 0;
3378
const char *pos=(char*) ((flags & NOT_NULL_FLAG) ? "" : "YES");
3379
table->field[12]->store(pos, strlen(pos), cs);
3380
if (!show_table->s->keys_in_use.is_set(i))
3381
table->field[14]->store(STRING_WITH_LEN("disabled"), cs);
3383
table->field[14]->store("", 0, cs);
3384
table->field[14]->set_notnull();
3385
assert(test(key_info->flags & HA_USES_COMMENT) ==
3386
(key_info->comment.length > 0));
3387
if (key_info->flags & HA_USES_COMMENT)
3388
table->field[15]->store(key_info->comment.str,
3389
key_info->comment.length, cs);
3390
if (schema_table_store_record(thd, table))
3399
bool store_constraints(THD *thd, Table *table, LEX_STRING *db_name,
3400
LEX_STRING *table_name, const char *key_name,
3401
uint32_t key_len, const char *con_type, uint32_t con_len)
3403
const CHARSET_INFO * const cs= system_charset_info;
3404
restore_record(table, s->default_values);
3405
table->field[1]->store(db_name->str, db_name->length, cs);
3406
table->field[2]->store(key_name, key_len, cs);
3407
table->field[3]->store(db_name->str, db_name->length, cs);
3408
table->field[4]->store(table_name->str, table_name->length, cs);
3409
table->field[5]->store(con_type, con_len, cs);
3410
return schema_table_store_record(thd, table);
3414
static int get_schema_constraints_record(THD *thd, TableList *tables,
3415
Table *table, bool res,
3416
LEX_STRING *db_name,
3417
LEX_STRING *table_name)
3421
if (thd->is_error())
3422
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3423
thd->main_da.sql_errno(), thd->main_da.message());
3429
List<FOREIGN_KEY_INFO> f_key_list;
3430
Table *show_table= tables->table;
3431
KEY *key_info=show_table->key_info;
3432
uint32_t primary_key= show_table->s->primary_key;
3433
show_table->file->info(HA_STATUS_VARIABLE |
3436
for (uint32_t i=0 ; i < show_table->s->keys ; i++, key_info++)
3438
if (i != primary_key && !(key_info->flags & HA_NOSAME))
3441
if (i == primary_key && !strcmp(key_info->name, primary_key_name))
3443
if (store_constraints(thd, table, db_name, table_name, key_info->name,
3444
strlen(key_info->name),
3445
STRING_WITH_LEN("PRIMARY KEY")))
3448
else if (key_info->flags & HA_NOSAME)
3450
if (store_constraints(thd, table, db_name, table_name, key_info->name,
3451
strlen(key_info->name),
3452
STRING_WITH_LEN("UNIQUE")))
3457
show_table->file->get_foreign_key_list(thd, &f_key_list);
3458
FOREIGN_KEY_INFO *f_key_info;
3459
List_iterator_fast<FOREIGN_KEY_INFO> it(f_key_list);
3460
while ((f_key_info=it++))
3462
if (store_constraints(thd, table, db_name, table_name,
3463
f_key_info->forein_id->str,
3464
strlen(f_key_info->forein_id->str),
3473
void store_key_column_usage(Table *table, LEX_STRING *db_name,
3474
LEX_STRING *table_name, const char *key_name,
3475
uint32_t key_len, const char *con_type, uint32_t con_len,
3478
const CHARSET_INFO * const cs= system_charset_info;
3479
table->field[1]->store(db_name->str, db_name->length, cs);
3480
table->field[2]->store(key_name, key_len, cs);
3481
table->field[4]->store(db_name->str, db_name->length, cs);
3482
table->field[5]->store(table_name->str, table_name->length, cs);
3483
table->field[6]->store(con_type, con_len, cs);
3484
table->field[7]->store((int64_t) idx, true);
3488
static int get_schema_key_column_usage_record(THD *thd,
3490
Table *table, bool res,
3491
LEX_STRING *db_name,
3492
LEX_STRING *table_name)
3496
if (thd->is_error())
3497
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3498
thd->main_da.sql_errno(), thd->main_da.message());
3504
List<FOREIGN_KEY_INFO> f_key_list;
3505
Table *show_table= tables->table;
3506
KEY *key_info=show_table->key_info;
3507
uint32_t primary_key= show_table->s->primary_key;
3508
show_table->file->info(HA_STATUS_VARIABLE |
3511
for (uint32_t i=0 ; i < show_table->s->keys ; i++, key_info++)
3513
if (i != primary_key && !(key_info->flags & HA_NOSAME))
3516
KEY_PART_INFO *key_part= key_info->key_part;
3517
for (uint32_t j=0 ; j < key_info->key_parts ; j++,key_part++)
3519
if (key_part->field)
3522
restore_record(table, s->default_values);
3523
store_key_column_usage(table, db_name, table_name,
3525
strlen(key_info->name),
3526
key_part->field->field_name,
3527
strlen(key_part->field->field_name),
3529
if (schema_table_store_record(thd, table))
3535
show_table->file->get_foreign_key_list(thd, &f_key_list);
3536
FOREIGN_KEY_INFO *f_key_info;
3537
List_iterator_fast<FOREIGN_KEY_INFO> fkey_it(f_key_list);
3538
while ((f_key_info= fkey_it++))
3542
List_iterator_fast<LEX_STRING> it(f_key_info->foreign_fields),
3543
it1(f_key_info->referenced_fields);
3545
while ((f_info= it++))
3549
restore_record(table, s->default_values);
3550
store_key_column_usage(table, db_name, table_name,
3551
f_key_info->forein_id->str,
3552
f_key_info->forein_id->length,
3553
f_info->str, f_info->length,
3555
table->field[8]->store((int64_t) f_idx, true);
3556
table->field[8]->set_notnull();
3557
table->field[9]->store(f_key_info->referenced_db->str,
3558
f_key_info->referenced_db->length,
3559
system_charset_info);
3560
table->field[9]->set_notnull();
3561
table->field[10]->store(f_key_info->referenced_table->str,
3562
f_key_info->referenced_table->length,
3563
system_charset_info);
3564
table->field[10]->set_notnull();
3565
table->field[11]->store(r_info->str, r_info->length,
3566
system_charset_info);
3567
table->field[11]->set_notnull();
3568
if (schema_table_store_record(thd, table))
3577
int fill_open_tables(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3579
const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
3580
Table *table= tables->table;
3581
const CHARSET_INFO * const cs= system_charset_info;
3582
OPEN_TableList *open_list;
3583
if (!(open_list=list_open_tables(thd,thd->lex->select_lex.db, wild))
3584
&& thd->is_fatal_error)
3587
for (; open_list ; open_list=open_list->next)
3589
restore_record(table, s->default_values);
3590
table->field[0]->store(open_list->db, strlen(open_list->db), cs);
3591
table->field[1]->store(open_list->table, strlen(open_list->table), cs);
3592
table->field[2]->store((int64_t) open_list->in_use, true);
3593
table->field[3]->store((int64_t) open_list->locked, true);
3594
if (schema_table_store_record(thd, table))
3601
int fill_variables(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3605
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3606
enum enum_schema_tables schema_table_idx=
3607
get_schema_table_idx(tables->schema_table);
3608
enum enum_var_type option_type= OPT_SESSION;
3609
bool upper_case_names= (schema_table_idx != SCH_VARIABLES);
3610
bool sorted_vars= (schema_table_idx == SCH_VARIABLES);
3612
if (lex->option_type == OPT_GLOBAL ||
3613
schema_table_idx == SCH_GLOBAL_VARIABLES)
3614
option_type= OPT_GLOBAL;
3616
rw_rdlock(&LOCK_system_variables_hash);
3617
res= show_status_array(thd, wild, enumerate_sys_vars(thd, sorted_vars),
3618
option_type, NULL, "", tables->table, upper_case_names);
3619
rw_unlock(&LOCK_system_variables_hash);
3624
int fill_status(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3627
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3629
STATUS_VAR *tmp1, tmp;
3630
enum enum_schema_tables schema_table_idx=
3631
get_schema_table_idx(tables->schema_table);
3632
enum enum_var_type option_type;
3633
bool upper_case_names= (schema_table_idx != SCH_STATUS);
3635
if (schema_table_idx == SCH_STATUS)
3637
option_type= lex->option_type;
3638
if (option_type == OPT_GLOBAL)
3641
tmp1= thd->initial_status_var;
3643
else if (schema_table_idx == SCH_GLOBAL_STATUS)
3645
option_type= OPT_GLOBAL;
3650
option_type= OPT_SESSION;
3651
tmp1= &thd->status_var;
3654
pthread_mutex_lock(&LOCK_status);
3655
if (option_type == OPT_GLOBAL)
3656
calc_sum_of_all_status(&tmp);
3657
res= show_status_array(thd, wild,
3658
(SHOW_VAR *)all_status_vars.buffer,
3659
option_type, tmp1, "", tables->table,
3661
pthread_mutex_unlock(&LOCK_status);
3667
Fill and store records into I_S.referential_constraints table
3670
get_referential_constraints_record()
3672
tables table list struct(processed table)
3674
res 1 means the error during opening of the processed table
3675
0 means processed table is opened without error
3677
file_name table name
3685
get_referential_constraints_record(THD *thd, TableList *tables,
3686
Table *table, bool res,
3687
LEX_STRING *db_name, LEX_STRING *table_name)
3689
const CHARSET_INFO * const cs= system_charset_info;
3693
if (thd->is_error())
3694
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3695
thd->main_da.sql_errno(), thd->main_da.message());
3701
List<FOREIGN_KEY_INFO> f_key_list;
3702
Table *show_table= tables->table;
3703
show_table->file->info(HA_STATUS_VARIABLE |
3707
show_table->file->get_foreign_key_list(thd, &f_key_list);
3708
FOREIGN_KEY_INFO *f_key_info;
3709
List_iterator_fast<FOREIGN_KEY_INFO> it(f_key_list);
3710
while ((f_key_info= it++))
3712
restore_record(table, s->default_values);
3713
table->field[1]->store(db_name->str, db_name->length, cs);
3714
table->field[9]->store(table_name->str, table_name->length, cs);
3715
table->field[2]->store(f_key_info->forein_id->str,
3716
f_key_info->forein_id->length, cs);
3717
table->field[4]->store(f_key_info->referenced_db->str,
3718
f_key_info->referenced_db->length, cs);
3719
table->field[10]->store(f_key_info->referenced_table->str,
3720
f_key_info->referenced_table->length, cs);
3721
if (f_key_info->referenced_key_name)
3723
table->field[5]->store(f_key_info->referenced_key_name->str,
3724
f_key_info->referenced_key_name->length, cs);
3725
table->field[5]->set_notnull();
3728
table->field[5]->set_null();
3729
table->field[6]->store(STRING_WITH_LEN("NONE"), cs);
3730
table->field[7]->store(f_key_info->update_method->str,
3731
f_key_info->update_method->length, cs);
3732
table->field[8]->store(f_key_info->delete_method->str,
3733
f_key_info->delete_method->length, cs);
3734
if (schema_table_store_record(thd, table))
3742
struct schema_table_ref
3744
const char *table_name;
3745
ST_SCHEMA_TABLE *schema_table;
3750
Find schema_tables elment by name
3753
find_schema_table_in_plugin()
3756
table_name table name
3760
1 found the schema table
3762
static bool find_schema_table_in_plugin(THD *thd __attribute__((unused)),
3766
schema_table_ref *p_schema_table= (schema_table_ref *)p_table;
3767
const char* table_name= p_schema_table->table_name;
3768
ST_SCHEMA_TABLE *schema_table= plugin_data(plugin, ST_SCHEMA_TABLE *);
3770
if (!my_strcasecmp(system_charset_info,
3771
schema_table->table_name,
3773
p_schema_table->schema_table= schema_table;
3782
Find schema_tables elment by name
3787
table_name table name
3791
# pointer to 'schema_tables' element
3794
ST_SCHEMA_TABLE *find_schema_table(THD *thd, const char* table_name)
3796
schema_table_ref schema_table_a;
3797
ST_SCHEMA_TABLE *schema_table= schema_tables;
3799
for (; schema_table->table_name; schema_table++)
3801
if (!my_strcasecmp(system_charset_info,
3802
schema_table->table_name,
3804
return(schema_table);
3807
schema_table_a.table_name= table_name;
3808
if (plugin_foreach(thd, find_schema_table_in_plugin,
3809
DRIZZLE_INFORMATION_SCHEMA_PLUGIN, &schema_table_a))
3810
return(schema_table_a.schema_table);
3816
ST_SCHEMA_TABLE *get_schema_table(enum enum_schema_tables schema_table_idx)
3818
return &schema_tables[schema_table_idx];
3823
Create information_schema table using schema_table data.
3830
@param table_list Used to pass I_S table information(fields info, tables
3831
parameters etc) and table name.
3833
@retval \# Pointer to created table
3834
@retval NULL Can't create table
3837
Table *create_schema_table(THD *thd, TableList *table_list)
3842
List<Item> field_list;
3843
ST_SCHEMA_TABLE *schema_table= table_list->schema_table;
3844
ST_FIELD_INFO *fields_info= schema_table->fields_info;
3845
const CHARSET_INFO * const cs= system_charset_info;
3847
for (; fields_info->field_name; fields_info++)
3849
switch (fields_info->field_type) {
3850
case DRIZZLE_TYPE_TINY:
3851
case DRIZZLE_TYPE_LONG:
3852
case DRIZZLE_TYPE_LONGLONG:
3853
if (!(item= new Item_return_int(fields_info->field_name,
3854
fields_info->field_length,
3855
fields_info->field_type,
3856
fields_info->value)))
3860
item->unsigned_flag= (fields_info->field_flags & MY_I_S_UNSIGNED);
3862
case DRIZZLE_TYPE_NEWDATE:
3863
case DRIZZLE_TYPE_TIME:
3864
case DRIZZLE_TYPE_TIMESTAMP:
3865
case DRIZZLE_TYPE_DATETIME:
3866
if (!(item=new Item_return_date_time(fields_info->field_name,
3867
fields_info->field_type)))
3872
case DRIZZLE_TYPE_DOUBLE:
3873
if ((item= new Item_float(fields_info->field_name, 0.0, NOT_FIXED_DEC,
3874
fields_info->field_length)) == NULL)
3877
case DRIZZLE_TYPE_NEWDECIMAL:
3878
if (!(item= new Item_decimal((int64_t) fields_info->value, false)))
3882
item->unsigned_flag= (fields_info->field_flags & MY_I_S_UNSIGNED);
3883
item->decimals= fields_info->field_length%10;
3884
item->max_length= (fields_info->field_length/100)%100;
3885
if (item->unsigned_flag == 0)
3886
item->max_length+= 1;
3887
if (item->decimals > 0)
3888
item->max_length+= 1;
3889
item->set_name(fields_info->field_name,
3890
strlen(fields_info->field_name), cs);
3892
case DRIZZLE_TYPE_BLOB:
3893
if (!(item= new Item_blob(fields_info->field_name,
3894
fields_info->field_length)))
3900
if (!(item= new Item_empty_string("", fields_info->field_length, cs)))
3904
item->set_name(fields_info->field_name,
3905
strlen(fields_info->field_name), cs);
3908
field_list.push_back(item);
3909
item->maybe_null= (fields_info->field_flags & MY_I_S_MAYBE_NULL);
3912
TMP_TABLE_PARAM *tmp_table_param =
3913
(TMP_TABLE_PARAM*) (thd->alloc(sizeof(TMP_TABLE_PARAM)));
3914
tmp_table_param->init();
3915
tmp_table_param->table_charset= cs;
3916
tmp_table_param->field_count= field_count;
3917
tmp_table_param->schema_table= 1;
3918
SELECT_LEX *select_lex= thd->lex->current_select;
3919
if (!(table= create_tmp_table(thd, tmp_table_param,
3920
field_list, (order_st*) 0, 0, 0,
3921
(select_lex->options | thd->options |
3922
TMP_TABLE_ALL_COLUMNS),
3923
HA_POS_ERROR, table_list->alias)))
3925
my_bitmap_map* bitmaps=
3926
(my_bitmap_map*) thd->alloc(bitmap_buffer_size(field_count));
3927
bitmap_init(&table->def_read_set, (my_bitmap_map*) bitmaps, field_count,
3929
table->read_set= &table->def_read_set;
3930
bitmap_clear_all(table->read_set);
3931
table_list->schema_table_param= tmp_table_param;
3937
For old SHOW compatibility. It is used when
3938
old SHOW doesn't have generated column names
3939
Make list of fields for SHOW
3944
schema_table pointer to 'schema_tables' element
3951
int make_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
3953
ST_FIELD_INFO *field_info= schema_table->fields_info;
3954
Name_resolution_context *context= &thd->lex->select_lex.context;
3955
for (; field_info->field_name; field_info++)
3957
if (field_info->old_name)
3959
Item_field *field= new Item_field(context,
3960
NULL, NULL, field_info->field_name);
3963
field->set_name(field_info->old_name,
3964
strlen(field_info->old_name),
3965
system_charset_info);
3966
if (add_item_to_list(thd, field))
3975
int make_schemata_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
3979
SELECT_LEX *sel= lex->current_select;
3980
Name_resolution_context *context= &sel->context;
3982
if (!sel->item_list.elements)
3984
ST_FIELD_INFO *field_info= &schema_table->fields_info[1];
3985
String buffer(tmp,sizeof(tmp), system_charset_info);
3986
Item_field *field= new Item_field(context,
3987
NULL, NULL, field_info->field_name);
3988
if (!field || add_item_to_list(thd, field))
3991
buffer.append(field_info->old_name);
3992
if (lex->wild && lex->wild->ptr())
3994
buffer.append(STRING_WITH_LEN(" ("));
3995
buffer.append(lex->wild->ptr());
3998
field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
4004
int make_table_names_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
4007
String buffer(tmp,sizeof(tmp), thd->charset());
4009
Name_resolution_context *context= &lex->select_lex.context;
4011
ST_FIELD_INFO *field_info= &schema_table->fields_info[2];
4013
buffer.append(field_info->old_name);
4014
buffer.append(lex->select_lex.db);
4015
if (lex->wild && lex->wild->ptr())
4017
buffer.append(STRING_WITH_LEN(" ("));
4018
buffer.append(lex->wild->ptr());
4021
Item_field *field= new Item_field(context,
4022
NULL, NULL, field_info->field_name);
4023
if (add_item_to_list(thd, field))
4025
field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
4026
if (thd->lex->verbose)
4028
field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
4029
field_info= &schema_table->fields_info[3];
4030
field= new Item_field(context, NULL, NULL, field_info->field_name);
4031
if (add_item_to_list(thd, field))
4033
field->set_name(field_info->old_name, strlen(field_info->old_name),
4034
system_charset_info);
4040
int make_columns_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
4042
int fields_arr[]= {3, 14, 13, 6, 15, 5, 16, 17, 18, -1};
4043
int *field_num= fields_arr;
4044
ST_FIELD_INFO *field_info;
4045
Name_resolution_context *context= &thd->lex->select_lex.context;
4047
for (; *field_num >= 0; field_num++)
4049
field_info= &schema_table->fields_info[*field_num];
4050
if (!thd->lex->verbose && (*field_num == 13 ||
4054
Item_field *field= new Item_field(context,
4055
NULL, NULL, field_info->field_name);
4058
field->set_name(field_info->old_name,
4059
strlen(field_info->old_name),
4060
system_charset_info);
4061
if (add_item_to_list(thd, field))
4069
int make_character_sets_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
4071
int fields_arr[]= {0, 2, 1, 3, -1};
4072
int *field_num= fields_arr;
4073
ST_FIELD_INFO *field_info;
4074
Name_resolution_context *context= &thd->lex->select_lex.context;
4076
for (; *field_num >= 0; field_num++)
4078
field_info= &schema_table->fields_info[*field_num];
4079
Item_field *field= new Item_field(context,
4080
NULL, NULL, field_info->field_name);
4083
field->set_name(field_info->old_name,
4084
strlen(field_info->old_name),
4085
system_charset_info);
4086
if (add_item_to_list(thd, field))
4095
Create information_schema table
4098
mysql_schema_table()
4101
table_list pointer to table_list
4108
int mysql_schema_table(THD *thd, LEX *lex, TableList *table_list)
4111
if (!(table= table_list->schema_table->create_table(thd, table_list)))
4113
table->s->tmp_table= SYSTEM_TMP_TABLE;
4115
This test is necessary to make
4116
case insensitive file systems +
4117
upper case table names(information schema tables) +
4121
if (table_list->schema_table_name)
4122
table->alias_name_used= my_strcasecmp(table_alias_charset,
4123
table_list->schema_table_name,
4125
table_list->table_name= table->s->table_name.str;
4126
table_list->table_name_length= table->s->table_name.length;
4127
table_list->table= table;
4128
table->next= thd->derived_tables;
4129
thd->derived_tables= table;
4130
table_list->select_lex->options |= OPTION_SCHEMA_TABLE;
4132
if (table_list->schema_table_reformed) // show command
4134
SELECT_LEX *sel= lex->current_select;
4136
Field_translator *transl, *org_transl;
4138
if (table_list->field_translation)
4140
Field_translator *end= table_list->field_translation_end;
4141
for (transl= table_list->field_translation; transl < end; transl++)
4143
if (!transl->item->fixed &&
4144
transl->item->fix_fields(thd, &transl->item))
4149
List_iterator_fast<Item> it(sel->item_list);
4151
(Field_translator*)(thd->alloc(sel->item_list.elements *
4152
sizeof(Field_translator)))))
4156
for (org_transl= transl; (item= it++); transl++)
4159
transl->name= item->name;
4160
if (!item->fixed && item->fix_fields(thd, &transl->item))
4165
table_list->field_translation= org_transl;
4166
table_list->field_translation_end= transl;
4174
Generate select from information_schema table
4177
make_schema_select()
4179
sel pointer to SELECT_LEX
4180
schema_table_idx index of 'schema_tables' element
4187
int make_schema_select(THD *thd, SELECT_LEX *sel,
4188
enum enum_schema_tables schema_table_idx)
4190
ST_SCHEMA_TABLE *schema_table= get_schema_table(schema_table_idx);
4191
LEX_STRING db, table;
4193
We have to make non const db_name & table_name
4194
because of lower_case_table_names
4196
thd->make_lex_string(&db, INFORMATION_SCHEMA_NAME.str,
4197
INFORMATION_SCHEMA_NAME.length, 0);
4198
thd->make_lex_string(&table, schema_table->table_name,
4199
strlen(schema_table->table_name), 0);
4200
if (schema_table->old_format(thd, schema_table) || /* Handle old syntax */
4201
!sel->add_table_to_list(thd, new Table_ident(thd, db, table, 0),
4211
Fill temporary schema tables before SELECT
4214
get_schema_tables_result()
4215
join join which use schema tables
4216
executed_place place where I_S table processed
4223
bool get_schema_tables_result(JOIN *join,
4224
enum enum_schema_table_state executed_place)
4226
JOIN_TAB *tmp_join_tab= join->join_tab+join->tables;
4227
THD *thd= join->thd;
4231
thd->no_warnings_for_error= 1;
4232
for (JOIN_TAB *tab= join->join_tab; tab < tmp_join_tab; tab++)
4234
if (!tab->table || !tab->table->pos_in_table_list)
4237
TableList *table_list= tab->table->pos_in_table_list;
4238
if (table_list->schema_table)
4240
bool is_subselect= (&lex->unit != lex->current_select->master_unit() &&
4241
lex->current_select->master_unit()->item);
4244
/* skip I_S optimizations specific to get_all_tables */
4245
if (thd->lex->describe &&
4246
(table_list->schema_table->fill_table != get_all_tables))
4250
If schema table is already processed and
4251
the statement is not a subselect then
4252
we don't need to fill this table again.
4253
If schema table is already processed and
4254
schema_table_state != executed_place then
4255
table is already processed and
4256
we should skip second data processing.
4258
if (table_list->schema_table_state &&
4259
(!is_subselect || table_list->schema_table_state != executed_place))
4263
if table is used in a subselect and
4264
table has been processed earlier with the same
4265
'executed_place' value then we should refresh the table.
4267
if (table_list->schema_table_state && is_subselect)
4269
table_list->table->file->extra(HA_EXTRA_NO_CACHE);
4270
table_list->table->file->extra(HA_EXTRA_RESET_STATE);
4271
table_list->table->file->ha_delete_all_rows();
4272
free_io_cache(table_list->table);
4273
filesort_free_buffers(table_list->table,1);
4274
table_list->table->null_row= 0;
4277
table_list->table->file->stats.records= 0;
4279
if (table_list->schema_table->fill_table(thd, table_list,
4284
tab->read_record.file= table_list->table->file;
4285
table_list->schema_table_state= executed_place;
4288
tab->read_record.file= table_list->table->file;
4289
table_list->schema_table_state= executed_place;
4292
thd->no_warnings_for_error= 0;
4296
ST_FIELD_INFO schema_fields_info[]=
4298
{"CATALOG_NAME", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, SKIP_OPEN_TABLE},
4299
{"SCHEMA_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Database",
4301
{"DEFAULT_CHARACTER_SET_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4303
{"DEFAULT_COLLATION_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE},
4304
{"SQL_PATH", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, SKIP_OPEN_TABLE},
4305
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4309
ST_FIELD_INFO tables_fields_info[]=
4311
{"TABLE_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, SKIP_OPEN_TABLE},
4312
{"TABLE_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE},
4313
{"TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Name",
4315
{"TABLE_TYPE", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FRM_ONLY},
4316
{"ENGINE", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 1, "Engine", OPEN_FRM_ONLY},
4317
{"VERSION", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4318
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Version", OPEN_FRM_ONLY},
4319
{"ROW_FORMAT", 10, DRIZZLE_TYPE_VARCHAR, 0, 1, "Row_format", OPEN_FULL_TABLE},
4320
{"TABLE_ROWS", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4321
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Rows", OPEN_FULL_TABLE},
4322
{"AVG_ROW_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4323
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Avg_row_length", OPEN_FULL_TABLE},
4324
{"DATA_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4325
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Data_length", OPEN_FULL_TABLE},
4326
{"MAX_DATA_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4327
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Max_data_length", OPEN_FULL_TABLE},
4328
{"INDEX_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4329
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Index_length", OPEN_FULL_TABLE},
4330
{"DATA_FREE", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4331
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Data_free", OPEN_FULL_TABLE},
4332
{"AUTO_INCREMENT", MY_INT64_NUM_DECIMAL_DIGITS , DRIZZLE_TYPE_LONGLONG, 0,
4333
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Auto_increment", OPEN_FULL_TABLE},
4334
{"CREATE_TIME", 0, DRIZZLE_TYPE_DATETIME, 0, 1, "Create_time", OPEN_FULL_TABLE},
4335
{"UPDATE_TIME", 0, DRIZZLE_TYPE_DATETIME, 0, 1, "Update_time", OPEN_FULL_TABLE},
4336
{"CHECK_TIME", 0, DRIZZLE_TYPE_DATETIME, 0, 1, "Check_time", OPEN_FULL_TABLE},
4337
{"TABLE_COLLATION", 64, DRIZZLE_TYPE_VARCHAR, 0, 1, "Collation", OPEN_FRM_ONLY},
4338
{"CHECKSUM", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4339
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Checksum", OPEN_FULL_TABLE},
4340
{"CREATE_OPTIONS", 255, DRIZZLE_TYPE_VARCHAR, 0, 1, "Create_options",
4342
{"TABLE_COMMENT", TABLE_COMMENT_MAXLEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Comment", OPEN_FRM_ONLY},
4343
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4347
ST_FIELD_INFO columns_fields_info[]=
4349
{"TABLE_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, OPEN_FRM_ONLY},
4350
{"TABLE_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FRM_ONLY},
4351
{"TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FRM_ONLY},
4352
{"COLUMN_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Field",
4354
{"ORDINAL_POSITION", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4355
MY_I_S_UNSIGNED, 0, OPEN_FRM_ONLY},
4356
{"COLUMN_DEFAULT", MAX_FIELD_VARCHARLENGTH, DRIZZLE_TYPE_VARCHAR, 0,
4357
1, "Default", OPEN_FRM_ONLY},
4358
{"IS_NULLABLE", 3, DRIZZLE_TYPE_VARCHAR, 0, 0, "Null", OPEN_FRM_ONLY},
4359
{"DATA_TYPE", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FRM_ONLY},
4360
{"CHARACTER_MAXIMUM_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG,
4361
0, (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), 0, OPEN_FRM_ONLY},
4362
{"CHARACTER_OCTET_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS , DRIZZLE_TYPE_LONGLONG,
4363
0, (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), 0, OPEN_FRM_ONLY},
4364
{"NUMERIC_PRECISION", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG,
4365
0, (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), 0, OPEN_FRM_ONLY},
4366
{"NUMERIC_SCALE", MY_INT64_NUM_DECIMAL_DIGITS , DRIZZLE_TYPE_LONGLONG,
4367
0, (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), 0, OPEN_FRM_ONLY},
4368
{"CHARACTER_SET_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, OPEN_FRM_ONLY},
4369
{"COLLATION_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 1, "Collation", OPEN_FRM_ONLY},
4370
{"COLUMN_TYPE", 65535, DRIZZLE_TYPE_VARCHAR, 0, 0, "Type", OPEN_FRM_ONLY},
4371
{"COLUMN_KEY", 3, DRIZZLE_TYPE_VARCHAR, 0, 0, "Key", OPEN_FRM_ONLY},
4372
{"EXTRA", 27, DRIZZLE_TYPE_VARCHAR, 0, 0, "Extra", OPEN_FRM_ONLY},
4373
{"PRIVILEGES", 80, DRIZZLE_TYPE_VARCHAR, 0, 0, "Privileges", OPEN_FRM_ONLY},
4374
{"COLUMN_COMMENT", COLUMN_COMMENT_MAXLEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Comment", OPEN_FRM_ONLY},
4375
{"STORAGE", 8, DRIZZLE_TYPE_VARCHAR, 0, 0, "Storage", OPEN_FRM_ONLY},
4376
{"FORMAT", 8, DRIZZLE_TYPE_VARCHAR, 0, 0, "Format", OPEN_FRM_ONLY},
4377
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4381
ST_FIELD_INFO charsets_fields_info[]=
4383
{"CHARACTER_SET_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, "Charset",
4385
{"DEFAULT_COLLATE_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, "Default collation",
4387
{"DESCRIPTION", 60, DRIZZLE_TYPE_VARCHAR, 0, 0, "Description",
4389
{"MAXLEN", 3, DRIZZLE_TYPE_LONGLONG, 0, 0, "Maxlen", SKIP_OPEN_TABLE},
4390
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4394
ST_FIELD_INFO collation_fields_info[]=
4396
{"COLLATION_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, "Collation", SKIP_OPEN_TABLE},
4397
{"CHARACTER_SET_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, "Charset",
4399
{"ID", MY_INT32_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0, 0, "Id",
4401
{"IS_DEFAULT", 3, DRIZZLE_TYPE_VARCHAR, 0, 0, "Default", SKIP_OPEN_TABLE},
4402
{"IS_COMPILED", 3, DRIZZLE_TYPE_VARCHAR, 0, 0, "Compiled", SKIP_OPEN_TABLE},
4403
{"SORTLEN", 3, DRIZZLE_TYPE_LONGLONG, 0, 0, "Sortlen", SKIP_OPEN_TABLE},
4404
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4409
ST_FIELD_INFO coll_charset_app_fields_info[]=
4411
{"COLLATION_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE},
4412
{"CHARACTER_SET_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE},
4413
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4417
ST_FIELD_INFO stat_fields_info[]=
4419
{"TABLE_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, OPEN_FRM_ONLY},
4420
{"TABLE_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FRM_ONLY},
4421
{"TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Table", OPEN_FRM_ONLY},
4422
{"NON_UNIQUE", 1, DRIZZLE_TYPE_LONGLONG, 0, 0, "Non_unique", OPEN_FRM_ONLY},
4423
{"INDEX_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FRM_ONLY},
4424
{"INDEX_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Key_name",
4426
{"SEQ_IN_INDEX", 2, DRIZZLE_TYPE_LONGLONG, 0, 0, "Seq_in_index", OPEN_FRM_ONLY},
4427
{"COLUMN_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Column_name",
4429
{"COLLATION", 1, DRIZZLE_TYPE_VARCHAR, 0, 1, "Collation", OPEN_FRM_ONLY},
4430
{"CARDINALITY", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0, 1,
4431
"Cardinality", OPEN_FULL_TABLE},
4432
{"SUB_PART", 3, DRIZZLE_TYPE_LONGLONG, 0, 1, "Sub_part", OPEN_FRM_ONLY},
4433
{"PACKED", 10, DRIZZLE_TYPE_VARCHAR, 0, 1, "Packed", OPEN_FRM_ONLY},
4434
{"NULLABLE", 3, DRIZZLE_TYPE_VARCHAR, 0, 0, "Null", OPEN_FRM_ONLY},
4435
{"INDEX_TYPE", 16, DRIZZLE_TYPE_VARCHAR, 0, 0, "Index_type", OPEN_FULL_TABLE},
4436
{"COMMENT", 16, DRIZZLE_TYPE_VARCHAR, 0, 1, "Comment", OPEN_FRM_ONLY},
4437
{"INDEX_COMMENT", INDEX_COMMENT_MAXLEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Index_Comment", OPEN_FRM_ONLY},
4438
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4442
ST_FIELD_INFO table_constraints_fields_info[]=
4444
{"CONSTRAINT_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, OPEN_FULL_TABLE},
4445
{"CONSTRAINT_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4447
{"CONSTRAINT_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4449
{"TABLE_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4450
{"TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4451
{"CONSTRAINT_TYPE", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4453
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4457
ST_FIELD_INFO key_column_usage_fields_info[]=
4459
{"CONSTRAINT_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, OPEN_FULL_TABLE},
4460
{"CONSTRAINT_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4462
{"CONSTRAINT_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4464
{"TABLE_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, OPEN_FULL_TABLE},
4465
{"TABLE_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4466
{"TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4467
{"COLUMN_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4468
{"ORDINAL_POSITION", 10 ,DRIZZLE_TYPE_LONGLONG, 0, 0, 0, OPEN_FULL_TABLE},
4469
{"POSITION_IN_UNIQUE_CONSTRAINT", 10 ,DRIZZLE_TYPE_LONGLONG, 0, 1, 0,
4471
{"REFERENCED_TABLE_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0,
4473
{"REFERENCED_TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0,
4475
{"REFERENCED_COLUMN_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0,
4477
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4481
ST_FIELD_INFO table_names_fields_info[]=
4483
{"TABLE_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, SKIP_OPEN_TABLE},
4484
{"TABLE_SCHEMA",NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE},
4485
{"TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Tables_in_",
4487
{"TABLE_TYPE", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Table_type",
4489
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4493
ST_FIELD_INFO open_tables_fields_info[]=
4495
{"Database", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Database",
4497
{"Table",NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Table", SKIP_OPEN_TABLE},
4498
{"In_use", 1, DRIZZLE_TYPE_LONGLONG, 0, 0, "In_use", SKIP_OPEN_TABLE},
4499
{"Name_locked", 4, DRIZZLE_TYPE_LONGLONG, 0, 0, "Name_locked", SKIP_OPEN_TABLE},
4500
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4504
ST_FIELD_INFO variables_fields_info[]=
4506
{"VARIABLE_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, "Variable_name",
4508
{"VARIABLE_VALUE", 16300, DRIZZLE_TYPE_VARCHAR, 0, 1, "Value", SKIP_OPEN_TABLE},
4509
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4513
ST_FIELD_INFO processlist_fields_info[]=
4515
{"ID", 4, DRIZZLE_TYPE_LONGLONG, 0, 0, "Id", SKIP_OPEN_TABLE},
4516
{"USER", 16, DRIZZLE_TYPE_VARCHAR, 0, 0, "User", SKIP_OPEN_TABLE},
4517
{"HOST", LIST_PROCESS_HOST_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Host",
4519
{"DB", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 1, "Db", SKIP_OPEN_TABLE},
4520
{"COMMAND", 16, DRIZZLE_TYPE_VARCHAR, 0, 0, "Command", SKIP_OPEN_TABLE},
4521
{"TIME", 7, DRIZZLE_TYPE_LONGLONG, 0, 0, "Time", SKIP_OPEN_TABLE},
4522
{"STATE", 64, DRIZZLE_TYPE_VARCHAR, 0, 1, "State", SKIP_OPEN_TABLE},
4523
{"INFO", PROCESS_LIST_INFO_WIDTH, DRIZZLE_TYPE_VARCHAR, 0, 1, "Info",
4525
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4529
ST_FIELD_INFO plugin_fields_info[]=
4531
{"PLUGIN_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Name",
4533
{"PLUGIN_VERSION", 20, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE},
4534
{"PLUGIN_STATUS", 10, DRIZZLE_TYPE_VARCHAR, 0, 0, "Status", SKIP_OPEN_TABLE},
4535
{"PLUGIN_TYPE", 80, DRIZZLE_TYPE_VARCHAR, 0, 0, "Type", SKIP_OPEN_TABLE},
4536
{"PLUGIN_LIBRARY", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 1, "Library",
4538
{"PLUGIN_AUTHOR", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, SKIP_OPEN_TABLE},
4539
{"PLUGIN_DESCRIPTION", 65535, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, SKIP_OPEN_TABLE},
4540
{"PLUGIN_LICENSE", 80, DRIZZLE_TYPE_VARCHAR, 0, 1, "License", SKIP_OPEN_TABLE},
4541
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4544
ST_FIELD_INFO referential_constraints_fields_info[]=
4546
{"CONSTRAINT_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, OPEN_FULL_TABLE},
4547
{"CONSTRAINT_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4549
{"CONSTRAINT_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4551
{"UNIQUE_CONSTRAINT_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0,
4553
{"UNIQUE_CONSTRAINT_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4555
{"UNIQUE_CONSTRAINT_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0,
4556
MY_I_S_MAYBE_NULL, 0, OPEN_FULL_TABLE},
4557
{"MATCH_OPTION", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4558
{"UPDATE_RULE", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4559
{"DELETE_RULE", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4560
{"TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4561
{"REFERENCED_TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4563
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4568
Description of ST_FIELD_INFO in table.h
4570
Make sure that the order of schema_tables and enum_schema_tables are the same.
4574
ST_SCHEMA_TABLE schema_tables[]=
4576
{"CHARACTER_SETS", charsets_fields_info, create_schema_table,
4577
fill_schema_charsets, make_character_sets_old_format, 0, -1, -1, 0, 0},
4578
{"COLLATIONS", collation_fields_info, create_schema_table,
4579
fill_schema_collation, make_old_format, 0, -1, -1, 0, 0},
4580
{"COLLATION_CHARACTER_SET_APPLICABILITY", coll_charset_app_fields_info,
4581
create_schema_table, fill_schema_coll_charset_app, 0, 0, -1, -1, 0, 0},
4582
{"COLUMNS", columns_fields_info, create_schema_table,
4583
get_all_tables, make_columns_old_format, get_schema_column_record, 1, 2, 0,
4584
OPTIMIZE_I_S_TABLE},
4585
{"GLOBAL_STATUS", variables_fields_info, create_schema_table,
4586
fill_status, make_old_format, 0, -1, -1, 0, 0},
4587
{"GLOBAL_VARIABLES", variables_fields_info, create_schema_table,
4588
fill_variables, make_old_format, 0, -1, -1, 0, 0},
4589
{"KEY_COLUMN_USAGE", key_column_usage_fields_info, create_schema_table,
4590
get_all_tables, 0, get_schema_key_column_usage_record, 4, 5, 0,
4592
{"OPEN_TABLES", open_tables_fields_info, create_schema_table,
4593
fill_open_tables, make_old_format, 0, -1, -1, 1, 0},
4594
{"PLUGINS", plugin_fields_info, create_schema_table,
4595
fill_plugins, make_old_format, 0, -1, -1, 0, 0},
4596
{"PROCESSLIST", processlist_fields_info, create_schema_table,
4597
fill_schema_processlist, make_old_format, 0, -1, -1, 0, 0},
4598
{"REFERENTIAL_CONSTRAINTS", referential_constraints_fields_info,
4599
create_schema_table, get_all_tables, 0, get_referential_constraints_record,
4600
1, 9, 0, OPEN_TABLE_ONLY},
4601
{"SCHEMATA", schema_fields_info, create_schema_table,
4602
fill_schema_schemata, make_schemata_old_format, 0, 1, -1, 0, 0},
4603
{"SESSION_STATUS", variables_fields_info, create_schema_table,
4604
fill_status, make_old_format, 0, -1, -1, 0, 0},
4605
{"SESSION_VARIABLES", variables_fields_info, create_schema_table,
4606
fill_variables, make_old_format, 0, -1, -1, 0, 0},
4607
{"STATISTICS", stat_fields_info, create_schema_table,
4608
get_all_tables, make_old_format, get_schema_stat_record, 1, 2, 0,
4609
OPEN_TABLE_ONLY|OPTIMIZE_I_S_TABLE},
4610
{"STATUS", variables_fields_info, create_schema_table, fill_status,
4611
make_old_format, 0, -1, -1, 1, 0},
4612
{"TABLES", tables_fields_info, create_schema_table,
4613
get_all_tables, make_old_format, get_schema_tables_record, 1, 2, 0,
4614
OPTIMIZE_I_S_TABLE},
4615
{"TABLE_CONSTRAINTS", table_constraints_fields_info, create_schema_table,
4616
get_all_tables, 0, get_schema_constraints_record, 3, 4, 0, OPEN_TABLE_ONLY},
4617
{"TABLE_NAMES", table_names_fields_info, create_schema_table,
4618
get_all_tables, make_table_names_old_format, 0, 1, 2, 1, 0},
4619
{"VARIABLES", variables_fields_info, create_schema_table, fill_variables,
4620
make_old_format, 0, -1, -1, 1, 0},
4621
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
4625
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
4626
template class List_iterator_fast<char>;
4627
template class List<char>;
4630
int initialize_schema_table(st_plugin_int *plugin)
4632
ST_SCHEMA_TABLE *schema_table;
4634
if (!(schema_table= (ST_SCHEMA_TABLE *)my_malloc(sizeof(ST_SCHEMA_TABLE),
4635
MYF(MY_WME | MY_ZEROFILL))))
4637
/* Historical Requirement */
4638
plugin->data= schema_table; // shortcut for the future
4639
if (plugin->plugin->init)
4641
schema_table->create_table= create_schema_table;
4642
schema_table->old_format= make_old_format;
4643
schema_table->idx_field1= -1,
4644
schema_table->idx_field2= -1;
4646
/* Make the name available to the init() function. */
4647
schema_table->table_name= plugin->name.str;
4649
if (plugin->plugin->init(schema_table))
4651
sql_print_error(_("Plugin '%s' init function returned error."),
4656
/* Make sure the plugin name is not set inside the init() function. */
4657
schema_table->table_name= plugin->name.str;
4666
int finalize_schema_table(st_plugin_int *plugin)
4668
ST_SCHEMA_TABLE *schema_table= (ST_SCHEMA_TABLE *)plugin->data;
4670
if (schema_table && plugin->plugin->deinit)