1477
shrink_var_array(&all_status_vars);
1481
inline void make_upper(char *buf)
1484
*buf= my_toupper(system_charset_info, *buf);
1487
static bool show_status_array(THD *thd, const char *wild,
1488
SHOW_VAR *variables,
1489
enum enum_var_type value_type,
1490
struct system_status_var *status_var,
1491
const char *prefix, TABLE *table,
1494
MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, long);
1495
char * const buff= (char *) &buff_data;
1497
/* the variable name should not be longer than 64 characters */
1498
char name_buffer[64];
1500
LEX_STRING null_lex_str;
1503
null_lex_str.str= 0; // For sys_var->value_ptr()
1504
null_lex_str.length= 0;
1506
prefix_end=stpncpy(name_buffer, prefix, sizeof(name_buffer)-1);
1509
len=name_buffer + sizeof(name_buffer) - prefix_end;
1511
for (; variables->name; variables++)
1513
stpncpy(prefix_end, variables->name, len);
1514
name_buffer[sizeof(name_buffer)-1]=0; /* Safety */
1516
make_upper(name_buffer);
1519
if var->type is SHOW_FUNC, call the function.
1520
Repeat as necessary, if new var is again SHOW_FUNC
1522
for (var=variables; var->type == SHOW_FUNC; var= &tmp)
1523
((mysql_show_var_func)((st_show_var_func_container *)var->value)->func)(thd, &tmp, buff);
1525
SHOW_TYPE show_type=var->type;
1526
if (show_type == SHOW_ARRAY)
1528
show_status_array(thd, wild, (SHOW_VAR *) var->value, value_type,
1529
status_var, name_buffer, table, ucase_names);
1533
if (!(wild && wild[0] && wild_case_compare(system_charset_info,
1534
name_buffer, wild)))
1536
char *value=var->value;
1537
const char *pos, *end; // We assign a lot of const's
1539
pthread_mutex_lock(&LOCK_global_system_variables);
1541
if (show_type == SHOW_SYS)
1543
show_type= ((sys_var*) value)->show_type();
1544
value= (char*) ((sys_var*) value)->value_ptr(thd, value_type,
1550
note that value may be == buff. All SHOW_xxx code below
1551
should still work in this case
1553
switch (show_type) {
1554
case SHOW_DOUBLE_STATUS:
1555
value= ((char *) status_var + (ulong) value);
1558
/* 6 is the default precision for '%f' in sprintf() */
1559
end= buff + my_fcvt(*(double *) value, 6, buff, NULL);
1561
case SHOW_LONG_STATUS:
1562
value= ((char *) status_var + (ulong) value);
1565
case SHOW_LONG_NOFLUSH: // the difference lies in refresh_status()
1566
end= int10_to_str(*(long*) value, buff, 10);
1568
case SHOW_LONGLONG_STATUS:
1569
value= ((char *) status_var + (uint64_t) value);
1572
end= int64_t10_to_str(*(int64_t*) value, buff, 10);
1575
end= int64_t10_to_str((int64_t) *(ha_rows*) value, buff, 10);
1578
end= stpcpy(buff, *(bool*) value ? "ON" : "OFF");
1581
end= stpcpy(buff, *(bool*) value ? "ON" : "OFF");
1584
end= int10_to_str((long) *(uint32_t*) value, buff, 10);
1588
SHOW_COMP_OPTION tmp= *(SHOW_COMP_OPTION*) value;
1589
pos= show_comp_option_name[(int) tmp];
1602
if (!(pos= *(char**) value))
1607
case SHOW_KEY_CACHE_LONG:
1608
value= (char*) dflt_key_cache + (ulong)value;
1609
end= int10_to_str(*(long*) value, buff, 10);
1611
case SHOW_KEY_CACHE_LONGLONG:
1612
value= (char*) dflt_key_cache + (ulong)value;
1613
end= int64_t10_to_str(*(int64_t*) value, buff, 10);
1616
break; // Return empty string
1617
case SHOW_SYS: // Cannot happen
1622
restore_record(table, s->default_values);
1623
table->field[0]->store(name_buffer, strlen(name_buffer),
1624
system_charset_info);
1625
table->field[1]->store(pos, (uint32_t) (end - pos), system_charset_info);
1626
table->field[1]->set_notnull();
1628
pthread_mutex_unlock(&LOCK_global_system_variables);
1630
if (schema_table_store_record(thd, table))
810
/* removes all the SHOW_UNDEF elements from the vector */
811
all_status_vars.erase(std::remove_if(all_status_vars.begin(),
812
all_status_vars.end(),show_var_remove_if()),
813
all_status_vars.end());
1640
817
/* collect status for all running threads */
1642
void calc_sum_of_all_status(STATUS_VAR *to)
819
void calc_sum_of_all_status(system_status_var *to)
1645
821
/* Ensure that thread id not killed during loop */
1646
VOID(pthread_mutex_lock(&LOCK_thread_count)); // For unlink from list
822
pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
1648
I_List_iterator<THD> it(threads);
1651
824
/* Get global values as base */
1652
825
*to= global_status_var;
1654
827
/* Add to this status from existing threads */
1656
add_to_status(to, &tmp->status_var);
1658
VOID(pthread_mutex_unlock(&LOCK_thread_count));
828
for(SessionList::iterator it= getSessionList().begin(); it != getSessionList().end(); ++it )
830
add_to_status(to, &((*it)->status_var));
833
pthread_mutex_unlock(&LOCK_thread_count);
1663
/* This is only used internally, but we need it here as a forward reference */
1664
extern ST_SCHEMA_TABLE schema_tables[];
1666
typedef struct st_lookup_field_values
1668
LEX_STRING db_value, table_value;
1669
bool wild_db_value, wild_table_value;
1670
} LOOKUP_FIELD_VALUES;
1674
Store record to I_S table, convert HEAP table
1675
to MyISAM if necessary
1678
schema_table_store_record()
1680
table Information schema table to be updated
1687
bool schema_table_store_record(THD *thd, TABLE *table)
1690
if ((error= table->file->ha_write_row(table->record[0])))
1692
TMP_TABLE_PARAM *param= table->pos_in_table_list->schema_table_param;
1694
if (create_myisam_from_heap(thd, table, param->start_recinfo,
1695
¶m->recinfo, error, 0))
1702
int make_table_list(THD *thd, SELECT_LEX *sel,
1703
LEX_STRING *db_name, LEX_STRING *table_name)
1705
Table_ident *table_ident;
1706
table_ident= new Table_ident(thd, *db_name, *table_name, 1);
1708
if (!sel->add_table_to_list(thd, table_ident, 0, 0, TL_READ))
1715
@brief Get lookup value from the part of 'WHERE' condition
1717
@details This function gets lookup value from
1718
the part of 'WHERE' condition if it's possible and
1719
fill appropriate lookup_field_vals struct field
1722
@param[in] thd thread handler
1723
@param[in] item_func part of WHERE condition
1724
@param[in] table I_S table
1725
@param[in, out] lookup_field_vals Struct which holds lookup values
1729
1 error, there can be no matching records for the condition
1732
bool get_lookup_value(THD *thd, Item_func *item_func,
1734
LOOKUP_FIELD_VALUES *lookup_field_vals)
1736
ST_SCHEMA_TABLE *schema_table= table->schema_table;
1737
ST_FIELD_INFO *field_info= schema_table->fields_info;
1738
const char *field_name1= schema_table->idx_field1 >= 0 ?
1739
field_info[schema_table->idx_field1].field_name : "";
1740
const char *field_name2= schema_table->idx_field2 >= 0 ?
1741
field_info[schema_table->idx_field2].field_name : "";
1743
if (item_func->functype() == Item_func::EQ_FUNC ||
1744
item_func->functype() == Item_func::EQUAL_FUNC)
1746
int idx_field, idx_val;
1747
char tmp[MAX_FIELD_WIDTH];
1748
String *tmp_str, str_buff(tmp, sizeof(tmp), system_charset_info);
1749
Item_field *item_field;
1750
const CHARSET_INFO * const cs= system_charset_info;
1752
if (item_func->arguments()[0]->type() == Item::FIELD_ITEM &&
1753
item_func->arguments()[1]->const_item())
1758
else if (item_func->arguments()[1]->type() == Item::FIELD_ITEM &&
1759
item_func->arguments()[0]->const_item())
1767
item_field= (Item_field*) item_func->arguments()[idx_field];
1768
if (table->table != item_field->field->table)
1770
tmp_str= item_func->arguments()[idx_val]->val_str(&str_buff);
1772
/* impossible value */
1776
/* Lookup value is database name */
1777
if (!cs->coll->strnncollsp(cs, (uchar *) field_name1, strlen(field_name1),
1778
(uchar *) item_field->field_name,
1779
strlen(item_field->field_name), 0))
1781
thd->make_lex_string(&lookup_field_vals->db_value, tmp_str->ptr(),
1782
tmp_str->length(), false);
1784
/* Lookup value is table name */
1785
else if (!cs->coll->strnncollsp(cs, (uchar *) field_name2,
1786
strlen(field_name2),
1787
(uchar *) item_field->field_name,
1788
strlen(item_field->field_name), 0))
1790
thd->make_lex_string(&lookup_field_vals->table_value, tmp_str->ptr(),
1791
tmp_str->length(), false);
1799
@brief Calculates lookup values from 'WHERE' condition
1801
@details This function calculates lookup value(database name, table name)
1802
from 'WHERE' condition if it's possible and
1803
fill lookup_field_vals struct fields with these values.
1805
@param[in] thd thread handler
1806
@param[in] cond WHERE condition
1807
@param[in] table I_S table
1808
@param[in, out] lookup_field_vals Struct which holds lookup values
1812
1 error, there can be no matching records for the condition
1815
bool calc_lookup_values_from_cond(THD *thd, COND *cond, TABLE_LIST *table,
1816
LOOKUP_FIELD_VALUES *lookup_field_vals)
1821
if (cond->type() == Item::COND_ITEM)
1823
if (((Item_cond*) cond)->functype() == Item_func::COND_AND_FUNC)
1825
List_iterator<Item> li(*((Item_cond*) cond)->argument_list());
1827
while ((item= li++))
1829
if (item->type() == Item::FUNC_ITEM)
1831
if (get_lookup_value(thd, (Item_func*)item, table, lookup_field_vals))
1836
if (calc_lookup_values_from_cond(thd, item, table, lookup_field_vals))
1843
else if (cond->type() == Item::FUNC_ITEM &&
1844
get_lookup_value(thd, (Item_func*) cond, table, lookup_field_vals))
1850
bool uses_only_table_name_fields(Item *item, TABLE_LIST *table)
1852
if (item->type() == Item::FUNC_ITEM)
1854
Item_func *item_func= (Item_func*)item;
1855
for (uint i=0; i<item_func->argument_count(); i++)
1857
if (!uses_only_table_name_fields(item_func->arguments()[i], table))
1861
else if (item->type() == Item::FIELD_ITEM)
1863
Item_field *item_field= (Item_field*)item;
1864
const CHARSET_INFO * const cs= system_charset_info;
1865
ST_SCHEMA_TABLE *schema_table= table->schema_table;
1866
ST_FIELD_INFO *field_info= schema_table->fields_info;
1867
const char *field_name1= schema_table->idx_field1 >= 0 ?
1868
field_info[schema_table->idx_field1].field_name : "";
1869
const char *field_name2= schema_table->idx_field2 >= 0 ?
1870
field_info[schema_table->idx_field2].field_name : "";
1871
if (table->table != item_field->field->table ||
1872
(cs->coll->strnncollsp(cs, (uchar *) field_name1, strlen(field_name1),
1873
(uchar *) item_field->field_name,
1874
strlen(item_field->field_name), 0) &&
1875
cs->coll->strnncollsp(cs, (uchar *) field_name2, strlen(field_name2),
1876
(uchar *) item_field->field_name,
1877
strlen(item_field->field_name), 0)))
1880
else if (item->type() == Item::REF_ITEM)
1881
return uses_only_table_name_fields(item->real_item(), table);
1883
if (item->type() == Item::SUBSELECT_ITEM && !item->const_item())
1890
static COND * make_cond_for_info_schema(COND *cond, TABLE_LIST *table)
1894
if (cond->type() == Item::COND_ITEM)
1896
if (((Item_cond*) cond)->functype() == Item_func::COND_AND_FUNC)
1898
/* Create new top level AND item */
1899
Item_cond_and *new_cond=new Item_cond_and;
1902
List_iterator<Item> li(*((Item_cond*) cond)->argument_list());
1906
Item *fix= make_cond_for_info_schema(item, table);
1908
new_cond->argument_list()->push_back(fix);
1910
switch (new_cond->argument_list()->elements) {
1914
return new_cond->argument_list()->head();
1916
new_cond->quick_fix_field();
1922
Item_cond_or *new_cond=new Item_cond_or;
1925
List_iterator<Item> li(*((Item_cond*) cond)->argument_list());
1929
Item *fix=make_cond_for_info_schema(item, table);
1932
new_cond->argument_list()->push_back(fix);
1934
new_cond->quick_fix_field();
1935
new_cond->top_level_item();
1940
if (!uses_only_table_name_fields(cond, table))
1947
@brief Calculate lookup values(database name, table name)
1949
@details This function calculates lookup values(database name, table name)
1950
from 'WHERE' condition or wild values (for 'SHOW' commands only)
1951
from LEX struct and fill lookup_field_vals struct field
1954
@param[in] thd thread handler
1955
@param[in] cond WHERE condition
1956
@param[in] tables I_S table
1957
@param[in, out] lookup_field_values Struct which holds lookup values
1961
1 error, there can be no matching records for the condition
1964
bool get_lookup_field_values(THD *thd, COND *cond, TABLE_LIST *tables,
1965
LOOKUP_FIELD_VALUES *lookup_field_values)
1968
const char *wild= lex->wild ? lex->wild->ptr() : NullS;
1969
memset(lookup_field_values, 0, sizeof(LOOKUP_FIELD_VALUES));
1970
switch (lex->sql_command) {
1971
case SQLCOM_SHOW_DATABASES:
1974
lookup_field_values->db_value.str= (char*) wild;
1975
lookup_field_values->db_value.length= strlen(wild);
1976
lookup_field_values->wild_db_value= 1;
1979
case SQLCOM_SHOW_TABLES:
1980
case SQLCOM_SHOW_TABLE_STATUS:
1981
lookup_field_values->db_value.str= lex->select_lex.db;
1982
lookup_field_values->db_value.length=strlen(lex->select_lex.db);
1985
lookup_field_values->table_value.str= (char*)wild;
1986
lookup_field_values->table_value.length= strlen(wild);
1987
lookup_field_values->wild_table_value= 1;
1992
The "default" is for queries over I_S.
1993
All previous cases handle SHOW commands.
1995
return calc_lookup_values_from_cond(thd, cond, tables, lookup_field_values);
2000
enum enum_schema_tables get_schema_table_idx(ST_SCHEMA_TABLE *schema_table)
2002
return (enum enum_schema_tables) (schema_table - &schema_tables[0]);
2007
Create db names list. Information schema name always is first in list
2012
files list of db names
2014
idx_field_vals idx_field_vals->db_name contains db name or
2016
with_i_schema returns 1 if we added 'IS' name to list
2024
int make_db_list(THD *thd, List<LEX_STRING> *files,
2025
LOOKUP_FIELD_VALUES *lookup_field_vals,
2026
bool *with_i_schema)
2028
LEX_STRING *i_s_name_copy= 0;
2029
i_s_name_copy= thd->make_lex_string(i_s_name_copy,
2030
INFORMATION_SCHEMA_NAME.str,
2031
INFORMATION_SCHEMA_NAME.length, true);
2033
if (lookup_field_vals->wild_db_value)
2036
This part of code is only for SHOW DATABASES command.
2037
idx_field_vals->db_value can be 0 when we don't use
2038
LIKE clause (see also get_index_field_values() function)
2040
if (!lookup_field_vals->db_value.str ||
2041
!wild_case_compare(system_charset_info,
2042
INFORMATION_SCHEMA_NAME.str,
2043
lookup_field_vals->db_value.str))
2046
if (files->push_back(i_s_name_copy))
2049
return (find_files(thd, files, NullS, mysql_data_home,
2050
lookup_field_vals->db_value.str, 1) != FIND_FILES_OK);
2055
If we have db lookup vaule we just add it to list and
2056
exit from the function
2058
if (lookup_field_vals->db_value.str)
2060
if (!my_strcasecmp(system_charset_info, INFORMATION_SCHEMA_NAME.str,
2061
lookup_field_vals->db_value.str))
2064
if (files->push_back(i_s_name_copy))
2068
if (files->push_back(&lookup_field_vals->db_value))
2074
Create list of existing databases. It is used in case
2075
of select from information schema table
2077
if (files->push_back(i_s_name_copy))
2080
return (find_files(thd, files, NullS,
2081
mysql_data_home, NullS, 1) != FIND_FILES_OK);
2085
struct st_add_schema_table
2087
List<LEX_STRING> *files;
2092
static bool add_schema_table(THD *thd, plugin_ref plugin,
2095
LEX_STRING *file_name= 0;
2096
st_add_schema_table *data= (st_add_schema_table *)p_data;
2097
List<LEX_STRING> *file_list= data->files;
2098
const char *wild= data->wild;
2099
ST_SCHEMA_TABLE *schema_table= plugin_data(plugin, ST_SCHEMA_TABLE *);
2101
if (schema_table->hidden)
2105
if (lower_case_table_names)
2107
if (wild_case_compare(files_charset_info,
2108
schema_table->table_name,
2112
else if (wild_compare(schema_table->table_name, wild, 0))
2116
if ((file_name= thd->make_lex_string(file_name, schema_table->table_name,
2117
strlen(schema_table->table_name),
2119
!file_list->push_back(file_name))
2125
int schema_tables_add(THD *thd, List<LEX_STRING> *files, const char *wild)
2127
LEX_STRING *file_name= 0;
2128
ST_SCHEMA_TABLE *tmp_schema_table= schema_tables;
2129
st_add_schema_table add_data;
2131
for (; tmp_schema_table->table_name; tmp_schema_table++)
2133
if (tmp_schema_table->hidden)
2137
if (lower_case_table_names)
2139
if (wild_case_compare(files_charset_info,
2140
tmp_schema_table->table_name,
2144
else if (wild_compare(tmp_schema_table->table_name, wild, 0))
2148
thd->make_lex_string(file_name, tmp_schema_table->table_name,
2149
strlen(tmp_schema_table->table_name), true)) &&
2150
!files->push_back(file_name))
2155
add_data.files= files;
2156
add_data.wild= wild;
2157
if (plugin_foreach(thd, add_schema_table,
2158
DRIZZLE_INFORMATION_SCHEMA_PLUGIN, &add_data))
2166
@brief Create table names list
2168
@details The function creates the list of table names in
2171
@param[in] thd thread handler
2172
@param[in] table_names List of table names in database
2173
@param[in] lex pointer to LEX struct
2174
@param[in] lookup_field_vals pointer to LOOKUP_FIELD_VALUE struct
2175
@param[in] with_i_schema true means that we add I_S tables to list
2176
@param[in] db_name database name
2178
@return Operation status
2180
@retval 1 fatal error
2181
@retval 2 Not fatal error; Safe to ignore this file list
2185
make_table_name_list(THD *thd, List<LEX_STRING> *table_names, LEX *lex,
2186
LOOKUP_FIELD_VALUES *lookup_field_vals,
2187
bool with_i_schema, LEX_STRING *db_name)
2189
char path[FN_REFLEN];
2190
build_table_filename(path, sizeof(path), db_name->str, "", "", 0);
2191
if (!lookup_field_vals->wild_table_value &&
2192
lookup_field_vals->table_value.str)
2196
if (find_schema_table(thd, lookup_field_vals->table_value.str))
2198
if (table_names->push_back(&lookup_field_vals->table_value))
2204
if (table_names->push_back(&lookup_field_vals->table_value))
2211
This call will add all matching the wildcards (if specified) IS tables
2215
return (schema_tables_add(thd, table_names,
2216
lookup_field_vals->table_value.str));
2218
find_files_result res= find_files(thd, table_names, db_name->str, path,
2219
lookup_field_vals->table_value.str, 0);
2220
if (res != FIND_FILES_OK)
2223
Downgrade errors about problems with database directory to
2224
warnings if this is not a 'SHOW' command. Another thread
2225
may have dropped database, and we may still have a name
2228
if (res == FIND_FILES_DIR)
2230
if (lex->sql_command != SQLCOM_SELECT)
2242
@brief Fill I_S table for SHOW COLUMNS|INDEX commands
2244
@param[in] thd thread handler
2245
@param[in] tables TABLE_LIST for I_S table
2246
@param[in] schema_table pointer to I_S structure
2247
@param[in] open_tables_state_backup pointer to Open_tables_state object
2248
which is used to save|restore original
2249
status of variables related to
2252
@return Operation status
2258
fill_schema_show_cols_or_idxs(THD *thd, TABLE_LIST *tables,
2259
ST_SCHEMA_TABLE *schema_table,
2260
Open_tables_state *open_tables_state_backup)
2264
LEX_STRING tmp_lex_string, tmp_lex_string1, *db_name, *table_name;
2265
enum_sql_command save_sql_command= lex->sql_command;
2266
TABLE_LIST *show_table_list= (TABLE_LIST*) tables->schema_select_lex->
2268
TABLE *table= tables->table;
2271
lex->all_selects_list= tables->schema_select_lex;
2273
Restore thd->temporary_tables to be able to process
2274
temporary tables(only for 'show index' & 'show columns').
2275
This should be changed when processing of temporary tables for
2276
I_S tables will be done.
2278
thd->temporary_tables= open_tables_state_backup->temporary_tables;
2280
Let us set fake sql_command so views won't try to merge
2281
themselves into main statement. If we don't do this,
2282
SELECT * from information_schema.xxxx will cause problems.
2283
SQLCOM_SHOW_FIELDS is used because it satisfies 'only_view_structure()'
2285
lex->sql_command= SQLCOM_SHOW_FIELDS;
2286
res= open_normal_and_derived_tables(thd, show_table_list,
2287
DRIZZLE_LOCK_IGNORE_FLUSH);
2288
lex->sql_command= save_sql_command;
2290
get_all_tables() returns 1 on failure and 0 on success thus
2291
return only these and not the result code of ::process_table()
2293
We should use show_table_list->alias instead of
2294
show_table_list->table_name because table_name
2295
could be changed during opening of I_S tables. It's safe
2296
to use alias because alias contains original table name
2297
in this case(this part of code is used only for
2298
'show columns' & 'show statistics' commands).
2300
table_name= thd->make_lex_string(&tmp_lex_string1, show_table_list->alias,
2301
strlen(show_table_list->alias), false);
2302
db_name= thd->make_lex_string(&tmp_lex_string, show_table_list->db,
2303
show_table_list->db_length, false);
2306
error= test(schema_table->process_table(thd, show_table_list,
2307
table, res, db_name,
2309
thd->temporary_tables= 0;
2310
close_tables_for_reopen(thd, &show_table_list);
2316
@brief Fill I_S table for SHOW TABLE NAMES commands
2318
@param[in] thd thread handler
2319
@param[in] table TABLE struct for I_S table
2320
@param[in] db_name database name
2321
@param[in] table_name table name
2322
@param[in] with_i_schema I_S table if true
2324
@return Operation status
2329
static int fill_schema_table_names(THD *thd, TABLE *table,
2330
LEX_STRING *db_name, LEX_STRING *table_name,
2335
table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"),
2336
system_charset_info);
2340
enum legacy_db_type not_used;
2341
char path[FN_REFLEN];
2342
(void) build_table_filename(path, sizeof(path), db_name->str,
2343
table_name->str, reg_ext, 0);
2344
switch (mysql_frm_type(thd, path, ¬_used)) {
2346
table->field[3]->store(STRING_WITH_LEN("ERROR"),
2347
system_charset_info);
2350
table->field[3]->store(STRING_WITH_LEN("BASE TABLE"),
2351
system_charset_info);
2356
if (thd->is_error() && thd->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2362
if (schema_table_store_record(thd, table))
2369
@brief Get open table method
2371
@details The function calculates the method which will be used
2373
SKIP_OPEN_TABLE - do not open table
2374
OPEN_FRM_ONLY - open FRM file only
2375
OPEN_FULL_TABLE - open FRM, data, index files
2376
@param[in] tables I_S table table_list
2377
@param[in] schema_table I_S table struct
2378
@param[in] schema_table_idx I_S table index
2380
@return return a set of flags
2381
@retval SKIP_OPEN_TABLE | OPEN_FRM_ONLY | OPEN_FULL_TABLE
2384
static uint get_table_open_method(TABLE_LIST *tables,
2385
ST_SCHEMA_TABLE *schema_table,
2386
enum enum_schema_tables schema_table_idx __attribute__((unused)))
2389
determine which method will be used for table opening
2391
if (schema_table->i_s_requested_object & OPTIMIZE_I_S_TABLE)
2393
Field **ptr, *field;
2394
int table_open_method= 0, field_indx= 0;
2395
for (ptr=tables->table->field; (field= *ptr) ; ptr++)
2397
if (bitmap_is_set(tables->table->read_set, field->field_index))
2398
table_open_method|= schema_table->fields_info[field_indx].open_method;
2401
return table_open_method;
2403
/* I_S tables which use get_all_tables but can not be optimized */
2404
return (uint) OPEN_FULL_TABLE;
2409
@brief Fill I_S table with data from FRM file only
2411
@param[in] thd thread handler
2412
@param[in] table TABLE struct for I_S table
2413
@param[in] schema_table I_S table struct
2414
@param[in] db_name database name
2415
@param[in] table_name table name
2416
@param[in] schema_table_idx I_S table index
2418
@return Operation status
2419
@retval 0 Table is processed and we can continue
2421
@retval 1 It's view and we have to use
2422
open_tables function for this table
2425
static int fill_schema_table_from_frm(THD *thd,TABLE_LIST *tables,
2426
ST_SCHEMA_TABLE *schema_table,
2427
LEX_STRING *db_name,
2428
LEX_STRING *table_name,
2429
enum enum_schema_tables schema_table_idx __attribute__((unused)))
2431
TABLE *table= tables->table;
2434
TABLE_LIST table_list;
2437
char key[MAX_DBKEY_LENGTH];
2440
memset(&table_list, 0, sizeof(TABLE_LIST));
2441
memset(&tbl, 0, sizeof(TABLE));
2443
table_list.table_name= table_name->str;
2444
table_list.db= db_name->str;
2446
key_length= create_table_def_key(thd, key, &table_list, 0);
2447
pthread_mutex_lock(&LOCK_open);
2448
share= get_table_share(thd, &table_list, key,
2449
key_length, OPEN_VIEW, &error);
2458
table_list.table= &tbl;
2459
res= schema_table->process_table(thd, &table_list, table,
2460
res, db_name, table_name);
2463
release_table_share(share, RELEASE_NORMAL);
2466
pthread_mutex_unlock(&LOCK_open);
2474
@brief Fill I_S tables whose data are retrieved
2475
from frm files and storage engine
2477
@details The information schema tables are internally represented as
2478
temporary tables that are filled at query execution time.
2479
Those I_S tables whose data are retrieved
2480
from frm files and storage engine are filled by the function
2483
@param[in] thd thread handler
2484
@param[in] tables I_S table
2485
@param[in] cond 'WHERE' condition
2487
@return Operation status
2492
int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
2495
TABLE *table= tables->table;
2496
SELECT_LEX *old_all_select_lex= lex->all_selects_list;
2497
enum_sql_command save_sql_command= lex->sql_command;
2498
SELECT_LEX *lsel= tables->schema_select_lex;
2499
ST_SCHEMA_TABLE *schema_table= tables->schema_table;
2501
LOOKUP_FIELD_VALUES lookup_field_vals;
2502
LEX_STRING *db_name, *table_name;
2504
enum enum_schema_tables schema_table_idx;
2505
List<LEX_STRING> db_names;
2506
List_iterator_fast<LEX_STRING> it(db_names);
2507
COND *partial_cond= 0;
2508
uint derived_tables= lex->derived_tables;
2510
Open_tables_state open_tables_state_backup;
2511
Query_tables_list query_tables_list_backup;
2512
uint table_open_method;
2513
bool old_value= thd->no_warnings_for_error;
2515
lex->reset_n_backup_query_tables_list(&query_tables_list_backup);
2518
We should not introduce deadlocks even if we already have some
2519
tables open and locked, since we won't lock tables which we will
2520
open and will ignore possible name-locks for these tables.
2522
thd->reset_n_backup_open_tables_state(&open_tables_state_backup);
2524
schema_table_idx= get_schema_table_idx(schema_table);
2525
tables->table_open_method= table_open_method=
2526
get_table_open_method(tables, schema_table, schema_table_idx);
2528
this branch processes SHOW FIELDS, SHOW INDEXES commands.
2529
see sql_parse.cc, prepare_schema_table() function where
2530
this values are initialized
2532
if (lsel && lsel->table_list.first)
2534
error= fill_schema_show_cols_or_idxs(thd, tables, schema_table,
2535
&open_tables_state_backup);
2539
if (get_lookup_field_values(thd, cond, tables, &lookup_field_vals))
2545
if (!lookup_field_vals.wild_db_value && !lookup_field_vals.wild_table_value)
2548
if lookup value is empty string then
2549
it's impossible table name or db name
2551
if ((lookup_field_vals.db_value.str && !lookup_field_vals.db_value.str[0]) ||
2552
(lookup_field_vals.table_value.str && !lookup_field_vals.table_value.str[0]))
2559
if (lookup_field_vals.db_value.length &&
2560
!lookup_field_vals.wild_db_value)
2561
tables->has_db_lookup_value= true;
2562
if (lookup_field_vals.table_value.length &&
2563
!lookup_field_vals.wild_table_value)
2564
tables->has_table_lookup_value= true;
2566
if (tables->has_db_lookup_value && tables->has_table_lookup_value)
2569
partial_cond= make_cond_for_info_schema(cond, tables);
2573
/* EXPLAIN SELECT */
2578
if (make_db_list(thd, &db_names, &lookup_field_vals, &with_i_schema))
2580
it.rewind(); /* To get access to new elements in basis list */
2581
while ((db_name= it++))
2584
thd->no_warnings_for_error= 1;
2585
List<LEX_STRING> table_names;
2586
int res= make_table_name_list(thd, &table_names, lex,
2588
with_i_schema, db_name);
2589
if (res == 2) /* Not fatal error, continue */
2594
List_iterator_fast<LEX_STRING> it_files(table_names);
2595
while ((table_name= it_files++))
2597
restore_record(table, s->default_values);
2598
table->field[schema_table->idx_field1]->
2599
store(db_name->str, db_name->length, system_charset_info);
2600
table->field[schema_table->idx_field2]->
2601
store(table_name->str, table_name->length, system_charset_info);
2603
if (!partial_cond || partial_cond->val_int())
2606
If table is I_S.tables and open_table_method is 0 (eg SKIP_OPEN)
2607
we can skip table opening and we don't have lookup value for
2608
table name or lookup value is wild string(table name list is
2609
already created by make_table_name_list() function).
2611
if (!table_open_method && schema_table_idx == SCH_TABLES &&
2612
(!lookup_field_vals.table_value.length ||
2613
lookup_field_vals.wild_table_value))
2615
if (schema_table_store_record(thd, table))
2616
goto err; /* Out of space in temporary table */
2620
/* SHOW TABLE NAMES command */
2621
if (schema_table_idx == SCH_TABLE_NAMES)
2623
if (fill_schema_table_names(thd, tables->table, db_name,
2624
table_name, with_i_schema))
2629
if (!(table_open_method & ~OPEN_FRM_ONLY) &&
2632
if (!fill_schema_table_from_frm(thd, tables, schema_table, db_name,
2633
table_name, schema_table_idx))
2638
LEX_STRING tmp_lex_string, orig_db_name;
2640
Set the parent lex of 'sel' because it is needed by
2641
sel.init_query() which is called inside make_table_list.
2643
thd->no_warnings_for_error= 1;
2644
sel.parent_lex= lex;
2645
/* db_name can be changed in make_table_list() func */
2646
if (!thd->make_lex_string(&orig_db_name, db_name->str,
2647
db_name->length, false))
2649
if (make_table_list(thd, &sel, db_name, table_name))
2651
TABLE_LIST *show_table_list= (TABLE_LIST*) sel.table_list.first;
2652
lex->all_selects_list= &sel;
2653
lex->derived_tables= 0;
2654
lex->sql_command= SQLCOM_SHOW_FIELDS;
2655
show_table_list->i_s_requested_object=
2656
schema_table->i_s_requested_object;
2657
res= open_normal_and_derived_tables(thd, show_table_list,
2658
DRIZZLE_LOCK_IGNORE_FLUSH);
2659
lex->sql_command= save_sql_command;
2661
XXX: show_table_list has a flag i_is_requested,
2662
and when it's set, open_normal_and_derived_tables()
2663
can return an error without setting an error message
2664
in THD, which is a hack. This is why we have to
2665
check for res, then for thd->is_error() only then
2666
for thd->main_da.sql_errno().
2668
if (res && thd->is_error() &&
2669
thd->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2672
Hide error for not existing table.
2673
This error can occur for example when we use
2674
where condition with db name and table name and this
2675
table does not exist.
2683
We should use show_table_list->alias instead of
2684
show_table_list->table_name because table_name
2685
could be changed during opening of I_S tables. It's safe
2686
to use alias because alias contains original table name
2689
thd->make_lex_string(&tmp_lex_string, show_table_list->alias,
2690
strlen(show_table_list->alias), false);
2691
res= schema_table->process_table(thd, show_table_list, table,
2694
close_tables_for_reopen(thd, &show_table_list);
2696
assert(!lex->query_tables_own_last);
2703
If we have information schema its always the first table and only
2704
the first table. Reset for other tables.
2712
thd->restore_backup_open_tables_state(&open_tables_state_backup);
2713
lex->restore_backup_query_tables_list(&query_tables_list_backup);
2714
lex->derived_tables= derived_tables;
2715
lex->all_selects_list= old_all_select_lex;
2716
lex->sql_command= save_sql_command;
2717
thd->no_warnings_for_error= old_value;
2722
bool store_schema_shemata(THD* thd, TABLE *table, LEX_STRING *db_name,
2723
const CHARSET_INFO * const cs)
2725
restore_record(table, s->default_values);
2726
table->field[1]->store(db_name->str, db_name->length, system_charset_info);
2727
table->field[2]->store(cs->csname, strlen(cs->csname), system_charset_info);
2728
table->field[3]->store(cs->name, strlen(cs->name), system_charset_info);
2729
return schema_table_store_record(thd, table);
2733
int fill_schema_schemata(THD *thd, TABLE_LIST *tables, COND *cond)
2736
TODO: fill_schema_shemata() is called when new client is connected.
2737
Returning error status in this case leads to client hangup.
2740
LOOKUP_FIELD_VALUES lookup_field_vals;
2741
List<LEX_STRING> db_names;
2742
LEX_STRING *db_name;
2744
HA_CREATE_INFO create;
2745
TABLE *table= tables->table;
2747
if (get_lookup_field_values(thd, cond, tables, &lookup_field_vals))
2749
if (make_db_list(thd, &db_names, &lookup_field_vals,
2754
If we have lookup db value we should check that the database exists
2756
if(lookup_field_vals.db_value.str && !lookup_field_vals.wild_db_value &&
2759
char path[FN_REFLEN+16];
2761
struct stat stat_info;
2762
if (!lookup_field_vals.db_value.str[0])
2764
path_len= build_table_filename(path, sizeof(path),
2765
lookup_field_vals.db_value.str, "", "", 0);
2766
path[path_len-1]= 0;
2767
if (stat(path,&stat_info))
2771
List_iterator_fast<LEX_STRING> it(db_names);
2772
while ((db_name=it++))
2774
if (with_i_schema) // information schema name is always first in list
2776
if (store_schema_shemata(thd, table, db_name,
2777
system_charset_info))
2783
load_db_opt_by_name(thd, db_name->str, &create);
2784
if (store_schema_shemata(thd, table, db_name,
2785
create.default_table_charset))
2793
static int get_schema_tables_record(THD *thd, TABLE_LIST *tables,
2794
TABLE *table, bool res,
2795
LEX_STRING *db_name,
2796
LEX_STRING *table_name)
2798
const char *tmp_buff;
2800
const CHARSET_INFO * const cs= system_charset_info;
2802
restore_record(table, s->default_values);
2803
table->field[1]->store(db_name->str, db_name->length, cs);
2804
table->field[2]->store(table_name->str, table_name->length, cs);
2808
there was errors during opening tables
2810
const char *error= thd->is_error() ? thd->main_da.message() : "";
2811
if (tables->schema_table)
2812
table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"), cs);
2814
table->field[3]->store(STRING_WITH_LEN("BASE TABLE"), cs);
2815
table->field[20]->store(error, strlen(error), cs);
2820
char option_buff[400],*ptr;
2821
TABLE *show_table= tables->table;
2822
TABLE_SHARE *share= show_table->s;
2823
handler *file= show_table->file;
2824
handlerton *tmp_db_type= share->db_type();
2825
if (share->tmp_table == SYSTEM_TMP_TABLE)
2826
table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"), cs);
2827
else if (share->tmp_table)
2828
table->field[3]->store(STRING_WITH_LEN("LOCAL TEMPORARY"), cs);
2830
table->field[3]->store(STRING_WITH_LEN("BASE TABLE"), cs);
2832
for (int i= 4; i < 20; i++)
2834
if (i == 7 || (i > 12 && i < 17) || i == 18)
2836
table->field[i]->set_notnull();
2838
tmp_buff= (char *) ha_resolve_storage_engine_name(tmp_db_type);
2839
table->field[4]->store(tmp_buff, strlen(tmp_buff), cs);
2840
table->field[5]->store((int64_t) share->frm_version, true);
2843
if (share->min_rows)
2845
ptr=stpcpy(ptr," min_rows=");
2846
ptr=int64_t10_to_str(share->min_rows,ptr,10);
2848
if (share->max_rows)
2850
ptr=stpcpy(ptr," max_rows=");
2851
ptr=int64_t10_to_str(share->max_rows,ptr,10);
2853
if (share->avg_row_length)
2855
ptr=stpcpy(ptr," avg_row_length=");
2856
ptr=int64_t10_to_str(share->avg_row_length,ptr,10);
2858
if (share->db_create_options & HA_OPTION_PACK_KEYS)
2859
ptr=stpcpy(ptr," pack_keys=1");
2860
if (share->db_create_options & HA_OPTION_NO_PACK_KEYS)
2861
ptr=stpcpy(ptr," pack_keys=0");
2862
/* We use CHECKSUM, instead of TABLE_CHECKSUM, for backward compability */
2863
if (share->db_create_options & HA_OPTION_CHECKSUM)
2864
ptr=stpcpy(ptr," checksum=1");
2865
if (share->page_checksum != HA_CHOICE_UNDEF)
2866
ptr= strxmov(ptr, " page_checksum=",
2867
ha_choice_values[(uint) share->page_checksum], NullS);
2868
if (share->db_create_options & HA_OPTION_DELAY_KEY_WRITE)
2869
ptr=stpcpy(ptr," delay_key_write=1");
2870
if (share->row_type != ROW_TYPE_DEFAULT)
2871
ptr=strxmov(ptr, " row_format=",
2872
ha_row_type[(uint) share->row_type],
2874
if (share->block_size)
2876
ptr= stpcpy(ptr, " block_size=");
2877
ptr= int64_t10_to_str(share->block_size, ptr, 10);
2880
if (share->transactional != HA_CHOICE_UNDEF)
2882
ptr= strxmov(ptr, " TRANSACTIONAL=",
2883
(share->transactional == HA_CHOICE_YES ? "1" : "0"),
2886
if (share->transactional != HA_CHOICE_UNDEF)
2887
ptr= strxmov(ptr, " transactional=",
2888
ha_choice_values[(uint) share->transactional], NullS);
2889
table->field[19]->store(option_buff+1,
2890
(ptr == option_buff ? 0 :
2891
(uint) (ptr-option_buff)-1), cs);
2893
tmp_buff= (share->table_charset ?
2894
share->table_charset->name : "default");
2895
table->field[17]->store(tmp_buff, strlen(tmp_buff), cs);
2897
if (share->comment.str)
2898
table->field[20]->store(share->comment.str, share->comment.length, cs);
2902
file->info(HA_STATUS_VARIABLE | HA_STATUS_TIME | HA_STATUS_AUTO |
2904
enum row_type row_type = file->get_row_type();
2906
case ROW_TYPE_NOT_USED:
2907
case ROW_TYPE_DEFAULT:
2908
tmp_buff= ((share->db_options_in_use &
2909
HA_OPTION_COMPRESS_RECORD) ? "Compressed" :
2910
(share->db_options_in_use & HA_OPTION_PACK_RECORD) ?
2911
"Dynamic" : "Fixed");
2913
case ROW_TYPE_FIXED:
2916
case ROW_TYPE_DYNAMIC:
2917
tmp_buff= "Dynamic";
2919
case ROW_TYPE_COMPRESSED:
2920
tmp_buff= "Compressed";
2922
case ROW_TYPE_REDUNDANT:
2923
tmp_buff= "Redundant";
2925
case ROW_TYPE_COMPACT:
2926
tmp_buff= "Compact";
2932
table->field[6]->store(tmp_buff, strlen(tmp_buff), cs);
2933
if (!tables->schema_table)
2935
table->field[7]->store((int64_t) file->stats.records, true);
2936
table->field[7]->set_notnull();
2938
table->field[8]->store((int64_t) file->stats.mean_rec_length, true);
2939
table->field[9]->store((int64_t) file->stats.data_file_length, true);
2940
if (file->stats.max_data_file_length)
2942
table->field[10]->store((int64_t) file->stats.max_data_file_length,
2945
table->field[11]->store((int64_t) file->stats.index_file_length, true);
2946
table->field[12]->store((int64_t) file->stats.delete_length, true);
2947
if (show_table->found_next_number_field)
2949
table->field[13]->store((int64_t) file->stats.auto_increment_value,
2951
table->field[13]->set_notnull();
2953
if (file->stats.create_time)
2955
thd->variables.time_zone->gmt_sec_to_TIME(&time,
2956
(my_time_t) file->stats.create_time);
2957
table->field[14]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2958
table->field[14]->set_notnull();
2960
if (file->stats.update_time)
2962
thd->variables.time_zone->gmt_sec_to_TIME(&time,
2963
(my_time_t) file->stats.update_time);
2964
table->field[15]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2965
table->field[15]->set_notnull();
2967
if (file->stats.check_time)
2969
thd->variables.time_zone->gmt_sec_to_TIME(&time,
2970
(my_time_t) file->stats.check_time);
2971
table->field[16]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2972
table->field[16]->set_notnull();
2974
if (file->ha_table_flags() & (ulong) HA_HAS_CHECKSUM)
2976
table->field[18]->store((int64_t) file->checksum(), true);
2977
table->field[18]->set_notnull();
2981
return(schema_table_store_record(thd, table));
2986
@brief Store field characteristics into appropriate I_S table columns
2988
@param[in] table I_S table
2989
@param[in] field processed field
2990
@param[in] cs I_S table charset
2991
@param[in] offset offset from beginning of table
2992
to DATE_TYPE column in I_S table
2997
void store_column_type(TABLE *table, Field *field, const CHARSET_INFO * const cs,
3001
int decimals, field_length;
3002
const char *tmp_buff;
3003
char column_type_buff[MAX_FIELD_WIDTH];
3004
String column_type(column_type_buff, sizeof(column_type_buff), cs);
3006
field->sql_type(column_type);
3007
/* DTD_IDENTIFIER column */
3008
table->field[offset + 7]->store(column_type.ptr(), column_type.length(), cs);
3009
table->field[offset + 7]->set_notnull();
3010
tmp_buff= strchr(column_type.ptr(), '(');
3011
/* DATA_TYPE column */
3012
table->field[offset]->store(column_type.ptr(),
3013
(tmp_buff ? tmp_buff - column_type.ptr() :
3014
column_type.length()), cs);
3015
is_blob= (field->type() == DRIZZLE_TYPE_BLOB);
3016
if (field->has_charset() || is_blob ||
3017
field->real_type() == DRIZZLE_TYPE_VARCHAR) // For varbinary type
3019
uint32_t octet_max_length= field->max_display_length();
3020
if (is_blob && octet_max_length != (uint32_t) 4294967295U)
3021
octet_max_length /= field->charset()->mbmaxlen;
3022
int64_t char_max_len= is_blob ?
3023
(int64_t) octet_max_length / field->charset()->mbminlen :
3024
(int64_t) octet_max_length / field->charset()->mbmaxlen;
3025
/* CHARACTER_MAXIMUM_LENGTH column*/
3026
table->field[offset + 1]->store(char_max_len, true);
3027
table->field[offset + 1]->set_notnull();
3028
/* CHARACTER_OCTET_LENGTH column */
3029
table->field[offset + 2]->store((int64_t) octet_max_length, true);
3030
table->field[offset + 2]->set_notnull();
3034
Calculate field_length and decimals.
3035
They are set to -1 if they should not be set (we should return NULL)
3038
decimals= field->decimals();
3039
switch (field->type()) {
3040
case DRIZZLE_TYPE_NEWDECIMAL:
3041
field_length= ((Field_new_decimal*) field)->precision;
3043
case DRIZZLE_TYPE_TINY:
3044
case DRIZZLE_TYPE_SHORT:
3045
case DRIZZLE_TYPE_LONG:
3046
case DRIZZLE_TYPE_LONGLONG:
3047
field_length= field->max_display_length() - 1;
3049
case DRIZZLE_TYPE_DOUBLE:
3050
field_length= field->field_length;
3051
if (decimals == NOT_FIXED_DEC)
3052
decimals= -1; // return NULL
3055
field_length= decimals= -1;
3059
/* NUMERIC_PRECISION column */
3060
if (field_length >= 0)
3062
table->field[offset + 3]->store((int64_t) field_length, true);
3063
table->field[offset + 3]->set_notnull();
3065
/* NUMERIC_SCALE column */
3068
table->field[offset + 4]->store((int64_t) decimals, true);
3069
table->field[offset + 4]->set_notnull();
3071
if (field->has_charset())
3073
/* CHARACTER_SET_NAME column*/
3074
tmp_buff= field->charset()->csname;
3075
table->field[offset + 5]->store(tmp_buff, strlen(tmp_buff), cs);
3076
table->field[offset + 5]->set_notnull();
3077
/* COLLATION_NAME column */
3078
tmp_buff= field->charset()->name;
3079
table->field[offset + 6]->store(tmp_buff, strlen(tmp_buff), cs);
3080
table->field[offset + 6]->set_notnull();
3085
static int get_schema_column_record(THD *thd, TABLE_LIST *tables,
3086
TABLE *table, bool res,
3087
LEX_STRING *db_name,
3088
LEX_STRING *table_name)
3091
const char *wild= lex->wild ? lex->wild->ptr() : NullS;
3092
const CHARSET_INFO * const cs= system_charset_info;
3094
TABLE_SHARE *show_table_share;
3095
Field **ptr, *field, *timestamp_field;
3100
if (lex->sql_command != SQLCOM_SHOW_FIELDS)
3103
I.e. we are in SELECT FROM INFORMATION_SCHEMA.COLUMS
3104
rather than in SHOW COLUMNS
3106
if (thd->is_error())
3107
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3108
thd->main_da.sql_errno(), thd->main_da.message());
3115
show_table= tables->table;
3116
show_table_share= show_table->s;
3119
if (tables->schema_table)
3121
ptr= show_table->field;
3122
timestamp_field= show_table->timestamp_field;
3123
show_table->use_all_columns(); // Required for default
3127
ptr= show_table_share->field;
3128
timestamp_field= show_table_share->timestamp_field;
3130
read_set may be inited in case of
3133
if (!show_table->read_set)
3135
/* to satisfy 'field->val_str' ASSERTs */
3137
uint bitmap_size= show_table_share->column_bitmap_size;
3138
if (!(bitmaps= (uchar*) alloc_root(thd->mem_root, bitmap_size)))
3140
bitmap_init(&show_table->def_read_set,
3141
(my_bitmap_map*) bitmaps, show_table_share->fields, false);
3142
bitmap_set_all(&show_table->def_read_set);
3143
show_table->read_set= &show_table->def_read_set;
3145
bitmap_set_all(show_table->read_set);
3148
for (; (field= *ptr) ; ptr++)
3151
char tmp[MAX_FIELD_WIDTH];
3152
String type(tmp,sizeof(tmp), system_charset_info);
3155
/* to satisfy 'field->val_str' ASSERTs */
3156
field->table= show_table;
3157
show_table->in_use= thd;
3159
if (wild && wild[0] &&
3160
wild_case_compare(system_charset_info, field->field_name,wild))
3164
/* Get default row, with all NULL fields set to NULL */
3165
restore_record(table, s->default_values);
3167
table->field[1]->store(db_name->str, db_name->length, cs);
3168
table->field[2]->store(table_name->str, table_name->length, cs);
3169
table->field[3]->store(field->field_name, strlen(field->field_name),
3171
table->field[4]->store((int64_t) count, true);
3173
if (get_field_default_value(thd, timestamp_field, field, &type, 0))
3175
table->field[5]->store(type.ptr(), type.length(), cs);
3176
table->field[5]->set_notnull();
3178
pos=(uchar*) ((field->flags & NOT_NULL_FLAG) ? "NO" : "YES");
3179
table->field[6]->store((const char*) pos,
3180
strlen((const char*) pos), cs);
3181
store_column_type(table, field, cs, 7);
3183
pos=(uchar*) ((field->flags & PRI_KEY_FLAG) ? "PRI" :
3184
(field->flags & UNIQUE_KEY_FLAG) ? "UNI" :
3185
(field->flags & MULTIPLE_KEY_FLAG) ? "MUL":"");
3186
table->field[15]->store((const char*) pos,
3187
strlen((const char*) pos), cs);
3190
if (field->unireg_check == Field::NEXT_NUMBER)
3191
table->field[16]->store(STRING_WITH_LEN("auto_increment"), cs);
3192
if (timestamp_field == field &&
3193
field->unireg_check != Field::TIMESTAMP_DN_FIELD)
3194
table->field[16]->store(STRING_WITH_LEN("on update CURRENT_TIMESTAMP"),
3197
table->field[18]->store(field->comment.str, field->comment.length, cs);
3199
enum column_format_type column_format= (enum column_format_type)
3200
((field->flags >> COLUMN_FORMAT_FLAGS) & COLUMN_FORMAT_MASK);
3201
pos=(uchar*)"Default";
3202
table->field[19]->store((const char*) pos,
3203
strlen((const char*) pos), cs);
3204
pos=(uchar*)(column_format == COLUMN_FORMAT_TYPE_DEFAULT ? "Default" :
3205
column_format == COLUMN_FORMAT_TYPE_FIXED ? "Fixed" :
3207
table->field[20]->store((const char*) pos,
3208
strlen((const char*) pos), cs);
3210
if (schema_table_store_record(thd, table))
3218
int fill_schema_charsets(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
3221
const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
3222
TABLE *table= tables->table;
3223
const CHARSET_INFO * const scs= system_charset_info;
3225
for (cs= all_charsets ; cs < all_charsets+255 ; cs++)
3227
const CHARSET_INFO * const tmp_cs= cs[0];
3228
if (tmp_cs && (tmp_cs->state & MY_CS_PRIMARY) &&
3229
(tmp_cs->state & MY_CS_AVAILABLE) &&
3230
!(tmp_cs->state & MY_CS_HIDDEN) &&
3231
!(wild && wild[0] &&
3232
wild_case_compare(scs, tmp_cs->csname,wild)))
3234
const char *comment;
3235
restore_record(table, s->default_values);
3236
table->field[0]->store(tmp_cs->csname, strlen(tmp_cs->csname), scs);
3237
table->field[1]->store(tmp_cs->name, strlen(tmp_cs->name), scs);
3238
comment= tmp_cs->comment ? tmp_cs->comment : "";
3239
table->field[2]->store(comment, strlen(comment), scs);
3240
table->field[3]->store((int64_t) tmp_cs->mbmaxlen, true);
3241
if (schema_table_store_record(thd, table))
3249
int fill_schema_collation(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
3252
const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
3253
TABLE *table= tables->table;
3254
const CHARSET_INFO * const scs= system_charset_info;
3255
for (cs= all_charsets ; cs < all_charsets+255 ; cs++ )
3258
const CHARSET_INFO *tmp_cs= cs[0];
3259
if (!tmp_cs || !(tmp_cs->state & MY_CS_AVAILABLE) ||
3260
(tmp_cs->state & MY_CS_HIDDEN) ||
3261
!(tmp_cs->state & MY_CS_PRIMARY))
3263
for (cl= all_charsets; cl < all_charsets+255 ;cl ++)
3265
const CHARSET_INFO *tmp_cl= cl[0];
3266
if (!tmp_cl || !(tmp_cl->state & MY_CS_AVAILABLE) ||
3267
!my_charset_same(tmp_cs, tmp_cl))
3269
if (!(wild && wild[0] &&
3270
wild_case_compare(scs, tmp_cl->name,wild)))
3272
const char *tmp_buff;
3273
restore_record(table, s->default_values);
3274
table->field[0]->store(tmp_cl->name, strlen(tmp_cl->name), scs);
3275
table->field[1]->store(tmp_cl->csname , strlen(tmp_cl->csname), scs);
3276
table->field[2]->store((int64_t) tmp_cl->number, true);
3277
tmp_buff= (tmp_cl->state & MY_CS_PRIMARY) ? "Yes" : "";
3278
table->field[3]->store(tmp_buff, strlen(tmp_buff), scs);
3279
tmp_buff= (tmp_cl->state & MY_CS_COMPILED)? "Yes" : "";
3280
table->field[4]->store(tmp_buff, strlen(tmp_buff), scs);
3281
table->field[5]->store((int64_t) tmp_cl->strxfrm_multiply, true);
3282
if (schema_table_store_record(thd, table))
3291
int fill_schema_coll_charset_app(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
3294
TABLE *table= tables->table;
3295
const CHARSET_INFO * const scs= system_charset_info;
3296
for (cs= all_charsets ; cs < all_charsets+255 ; cs++ )
3299
const CHARSET_INFO *tmp_cs= cs[0];
3300
if (!tmp_cs || !(tmp_cs->state & MY_CS_AVAILABLE) ||
3301
!(tmp_cs->state & MY_CS_PRIMARY))
3303
for (cl= all_charsets; cl < all_charsets+255 ;cl ++)
3305
const CHARSET_INFO *tmp_cl= cl[0];
3306
if (!tmp_cl || !(tmp_cl->state & MY_CS_AVAILABLE) ||
3307
!my_charset_same(tmp_cs,tmp_cl))
3309
restore_record(table, s->default_values);
3310
table->field[0]->store(tmp_cl->name, strlen(tmp_cl->name), scs);
3311
table->field[1]->store(tmp_cl->csname , strlen(tmp_cl->csname), scs);
3312
if (schema_table_store_record(thd, table))
3320
static int get_schema_stat_record(THD *thd, TABLE_LIST *tables,
3321
TABLE *table, bool res,
3322
LEX_STRING *db_name,
3323
LEX_STRING *table_name)
3325
const CHARSET_INFO * const cs= system_charset_info;
3328
if (thd->lex->sql_command != SQLCOM_SHOW_KEYS)
3331
I.e. we are in SELECT FROM INFORMATION_SCHEMA.STATISTICS
3332
rather than in SHOW KEYS
3334
if (thd->is_error())
3335
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3336
thd->main_da.sql_errno(), thd->main_da.message());
3344
TABLE *show_table= tables->table;
3345
KEY *key_info=show_table->s->key_info;
3346
if (show_table->file)
3347
show_table->file->info(HA_STATUS_VARIABLE |
3350
for (uint i=0 ; i < show_table->s->keys ; i++,key_info++)
3352
KEY_PART_INFO *key_part= key_info->key_part;
3354
for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
3356
restore_record(table, s->default_values);
3357
table->field[1]->store(db_name->str, db_name->length, cs);
3358
table->field[2]->store(table_name->str, table_name->length, cs);
3359
table->field[3]->store((int64_t) ((key_info->flags &
3360
HA_NOSAME) ? 0 : 1), true);
3361
table->field[4]->store(db_name->str, db_name->length, cs);
3362
table->field[5]->store(key_info->name, strlen(key_info->name), cs);
3363
table->field[6]->store((int64_t) (j+1), true);
3364
str=(key_part->field ? key_part->field->field_name :
3366
table->field[7]->store(str, strlen(str), cs);
3367
if (show_table->file)
3369
if (show_table->file->index_flags(i, j, 0) & HA_READ_ORDER)
3371
table->field[8]->store(((key_part->key_part_flag &
3374
table->field[8]->set_notnull();
3376
KEY *key=show_table->key_info+i;
3377
if (key->rec_per_key[j])
3379
ha_rows records=(show_table->file->stats.records /
3380
key->rec_per_key[j]);
3381
table->field[9]->store((int64_t) records, true);
3382
table->field[9]->set_notnull();
3384
str= show_table->file->index_type(i);
3385
table->field[13]->store(str, strlen(str), cs);
3387
if ((key_part->field &&
3389
show_table->s->field[key_part->fieldnr-1]->key_length()))
3391
table->field[10]->store((int64_t) key_part->length /
3392
key_part->field->charset()->mbmaxlen, true);
3393
table->field[10]->set_notnull();
3395
uint flags= key_part->field ? key_part->field->flags : 0;
3396
const char *pos=(char*) ((flags & NOT_NULL_FLAG) ? "" : "YES");
3397
table->field[12]->store(pos, strlen(pos), cs);
3398
if (!show_table->s->keys_in_use.is_set(i))
3399
table->field[14]->store(STRING_WITH_LEN("disabled"), cs);
3401
table->field[14]->store("", 0, cs);
3402
table->field[14]->set_notnull();
3403
assert(test(key_info->flags & HA_USES_COMMENT) ==
3404
(key_info->comment.length > 0));
3405
if (key_info->flags & HA_USES_COMMENT)
3406
table->field[15]->store(key_info->comment.str,
3407
key_info->comment.length, cs);
3408
if (schema_table_store_record(thd, table))
3417
bool store_constraints(THD *thd, TABLE *table, LEX_STRING *db_name,
3418
LEX_STRING *table_name, const char *key_name,
3419
uint key_len, const char *con_type, uint con_len)
3421
const CHARSET_INFO * const cs= system_charset_info;
3422
restore_record(table, s->default_values);
3423
table->field[1]->store(db_name->str, db_name->length, cs);
3424
table->field[2]->store(key_name, key_len, cs);
3425
table->field[3]->store(db_name->str, db_name->length, cs);
3426
table->field[4]->store(table_name->str, table_name->length, cs);
3427
table->field[5]->store(con_type, con_len, cs);
3428
return schema_table_store_record(thd, table);
3432
static int get_schema_constraints_record(THD *thd, TABLE_LIST *tables,
3433
TABLE *table, bool res,
3434
LEX_STRING *db_name,
3435
LEX_STRING *table_name)
3439
if (thd->is_error())
3440
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3441
thd->main_da.sql_errno(), thd->main_da.message());
3447
List<FOREIGN_KEY_INFO> f_key_list;
3448
TABLE *show_table= tables->table;
3449
KEY *key_info=show_table->key_info;
3450
uint primary_key= show_table->s->primary_key;
3451
show_table->file->info(HA_STATUS_VARIABLE |
3454
for (uint i=0 ; i < show_table->s->keys ; i++, key_info++)
3456
if (i != primary_key && !(key_info->flags & HA_NOSAME))
3459
if (i == primary_key && !strcmp(key_info->name, primary_key_name))
3461
if (store_constraints(thd, table, db_name, table_name, key_info->name,
3462
strlen(key_info->name),
3463
STRING_WITH_LEN("PRIMARY KEY")))
3466
else if (key_info->flags & HA_NOSAME)
3468
if (store_constraints(thd, table, db_name, table_name, key_info->name,
3469
strlen(key_info->name),
3470
STRING_WITH_LEN("UNIQUE")))
3475
show_table->file->get_foreign_key_list(thd, &f_key_list);
3476
FOREIGN_KEY_INFO *f_key_info;
3477
List_iterator_fast<FOREIGN_KEY_INFO> it(f_key_list);
3478
while ((f_key_info=it++))
3480
if (store_constraints(thd, table, db_name, table_name,
3481
f_key_info->forein_id->str,
3482
strlen(f_key_info->forein_id->str),
3491
void store_key_column_usage(TABLE *table, LEX_STRING *db_name,
3492
LEX_STRING *table_name, const char *key_name,
3493
uint key_len, const char *con_type, uint con_len,
3496
const CHARSET_INFO * const cs= system_charset_info;
3497
table->field[1]->store(db_name->str, db_name->length, cs);
3498
table->field[2]->store(key_name, key_len, cs);
3499
table->field[4]->store(db_name->str, db_name->length, cs);
3500
table->field[5]->store(table_name->str, table_name->length, cs);
3501
table->field[6]->store(con_type, con_len, cs);
3502
table->field[7]->store((int64_t) idx, true);
3506
static int get_schema_key_column_usage_record(THD *thd,
3508
TABLE *table, bool res,
3509
LEX_STRING *db_name,
3510
LEX_STRING *table_name)
3514
if (thd->is_error())
3515
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3516
thd->main_da.sql_errno(), thd->main_da.message());
3522
List<FOREIGN_KEY_INFO> f_key_list;
3523
TABLE *show_table= tables->table;
3524
KEY *key_info=show_table->key_info;
3525
uint primary_key= show_table->s->primary_key;
3526
show_table->file->info(HA_STATUS_VARIABLE |
3529
for (uint i=0 ; i < show_table->s->keys ; i++, key_info++)
3531
if (i != primary_key && !(key_info->flags & HA_NOSAME))
3534
KEY_PART_INFO *key_part= key_info->key_part;
3535
for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
3537
if (key_part->field)
3540
restore_record(table, s->default_values);
3541
store_key_column_usage(table, db_name, table_name,
3543
strlen(key_info->name),
3544
key_part->field->field_name,
3545
strlen(key_part->field->field_name),
3547
if (schema_table_store_record(thd, table))
3553
show_table->file->get_foreign_key_list(thd, &f_key_list);
3554
FOREIGN_KEY_INFO *f_key_info;
3555
List_iterator_fast<FOREIGN_KEY_INFO> fkey_it(f_key_list);
3556
while ((f_key_info= fkey_it++))
3560
List_iterator_fast<LEX_STRING> it(f_key_info->foreign_fields),
3561
it1(f_key_info->referenced_fields);
3563
while ((f_info= it++))
3567
restore_record(table, s->default_values);
3568
store_key_column_usage(table, db_name, table_name,
3569
f_key_info->forein_id->str,
3570
f_key_info->forein_id->length,
3571
f_info->str, f_info->length,
3573
table->field[8]->store((int64_t) f_idx, true);
3574
table->field[8]->set_notnull();
3575
table->field[9]->store(f_key_info->referenced_db->str,
3576
f_key_info->referenced_db->length,
3577
system_charset_info);
3578
table->field[9]->set_notnull();
3579
table->field[10]->store(f_key_info->referenced_table->str,
3580
f_key_info->referenced_table->length,
3581
system_charset_info);
3582
table->field[10]->set_notnull();
3583
table->field[11]->store(r_info->str, r_info->length,
3584
system_charset_info);
3585
table->field[11]->set_notnull();
3586
if (schema_table_store_record(thd, table))
3595
int fill_open_tables(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
3597
const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
3598
TABLE *table= tables->table;
3599
const CHARSET_INFO * const cs= system_charset_info;
3600
OPEN_TABLE_LIST *open_list;
3601
if (!(open_list=list_open_tables(thd,thd->lex->select_lex.db, wild))
3602
&& thd->is_fatal_error)
3605
for (; open_list ; open_list=open_list->next)
3607
restore_record(table, s->default_values);
3608
table->field[0]->store(open_list->db, strlen(open_list->db), cs);
3609
table->field[1]->store(open_list->table, strlen(open_list->table), cs);
3610
table->field[2]->store((int64_t) open_list->in_use, true);
3611
table->field[3]->store((int64_t) open_list->locked, true);
3612
if (schema_table_store_record(thd, table))
3619
int fill_variables(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
3623
const char *wild= lex->wild ? lex->wild->ptr() : NullS;
3624
enum enum_schema_tables schema_table_idx=
3625
get_schema_table_idx(tables->schema_table);
3626
enum enum_var_type option_type= OPT_SESSION;
3627
bool upper_case_names= (schema_table_idx != SCH_VARIABLES);
3628
bool sorted_vars= (schema_table_idx == SCH_VARIABLES);
3630
if (lex->option_type == OPT_GLOBAL ||
3631
schema_table_idx == SCH_GLOBAL_VARIABLES)
3632
option_type= OPT_GLOBAL;
3634
rw_rdlock(&LOCK_system_variables_hash);
3635
res= show_status_array(thd, wild, enumerate_sys_vars(thd, sorted_vars),
3636
option_type, NULL, "", tables->table, upper_case_names);
3637
rw_unlock(&LOCK_system_variables_hash);
3642
int fill_status(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
3645
const char *wild= lex->wild ? lex->wild->ptr() : NullS;
3647
STATUS_VAR *tmp1, tmp;
3648
enum enum_schema_tables schema_table_idx=
3649
get_schema_table_idx(tables->schema_table);
3650
enum enum_var_type option_type;
3651
bool upper_case_names= (schema_table_idx != SCH_STATUS);
3653
if (schema_table_idx == SCH_STATUS)
3655
option_type= lex->option_type;
3656
if (option_type == OPT_GLOBAL)
3659
tmp1= thd->initial_status_var;
3661
else if (schema_table_idx == SCH_GLOBAL_STATUS)
3663
option_type= OPT_GLOBAL;
3668
option_type= OPT_SESSION;
3669
tmp1= &thd->status_var;
3672
pthread_mutex_lock(&LOCK_status);
3673
if (option_type == OPT_GLOBAL)
3674
calc_sum_of_all_status(&tmp);
3675
res= show_status_array(thd, wild,
3676
(SHOW_VAR *)all_status_vars.buffer,
3677
option_type, tmp1, "", tables->table,
3679
pthread_mutex_unlock(&LOCK_status);
3685
Fill and store records into I_S.referential_constraints table
3688
get_referential_constraints_record()
3690
tables table list struct(processed table)
3692
res 1 means the error during opening of the processed table
3693
0 means processed table is opened without error
3695
file_name table name
3703
get_referential_constraints_record(THD *thd, TABLE_LIST *tables,
3704
TABLE *table, bool res,
3705
LEX_STRING *db_name, LEX_STRING *table_name)
3707
const CHARSET_INFO * const cs= system_charset_info;
3711
if (thd->is_error())
3712
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3713
thd->main_da.sql_errno(), thd->main_da.message());
3719
List<FOREIGN_KEY_INFO> f_key_list;
3720
TABLE *show_table= tables->table;
3721
show_table->file->info(HA_STATUS_VARIABLE |
3725
show_table->file->get_foreign_key_list(thd, &f_key_list);
3726
FOREIGN_KEY_INFO *f_key_info;
3727
List_iterator_fast<FOREIGN_KEY_INFO> it(f_key_list);
3728
while ((f_key_info= it++))
3730
restore_record(table, s->default_values);
3731
table->field[1]->store(db_name->str, db_name->length, cs);
3732
table->field[9]->store(table_name->str, table_name->length, cs);
3733
table->field[2]->store(f_key_info->forein_id->str,
3734
f_key_info->forein_id->length, cs);
3735
table->field[4]->store(f_key_info->referenced_db->str,
3736
f_key_info->referenced_db->length, cs);
3737
table->field[10]->store(f_key_info->referenced_table->str,
3738
f_key_info->referenced_table->length, cs);
3739
if (f_key_info->referenced_key_name)
3741
table->field[5]->store(f_key_info->referenced_key_name->str,
3742
f_key_info->referenced_key_name->length, cs);
3743
table->field[5]->set_notnull();
3746
table->field[5]->set_null();
3747
table->field[6]->store(STRING_WITH_LEN("NONE"), cs);
3748
table->field[7]->store(f_key_info->update_method->str,
3749
f_key_info->update_method->length, cs);
3750
table->field[8]->store(f_key_info->delete_method->str,
3751
f_key_info->delete_method->length, cs);
3752
if (schema_table_store_record(thd, table))
3760
struct schema_table_ref
3762
const char *table_name;
3763
ST_SCHEMA_TABLE *schema_table;
3768
Find schema_tables elment by name
3771
find_schema_table_in_plugin()
3774
table_name table name
3778
1 found the schema table
3780
static bool find_schema_table_in_plugin(THD *thd __attribute__((unused)),
3784
schema_table_ref *p_schema_table= (schema_table_ref *)p_table;
3785
const char* table_name= p_schema_table->table_name;
3786
ST_SCHEMA_TABLE *schema_table= plugin_data(plugin, ST_SCHEMA_TABLE *);
3788
if (!my_strcasecmp(system_charset_info,
3789
schema_table->table_name,
3791
p_schema_table->schema_table= schema_table;
3800
Find schema_tables elment by name
3805
table_name table name
3809
# pointer to 'schema_tables' element
3812
ST_SCHEMA_TABLE *find_schema_table(THD *thd, const char* table_name)
3814
schema_table_ref schema_table_a;
3815
ST_SCHEMA_TABLE *schema_table= schema_tables;
3817
for (; schema_table->table_name; schema_table++)
3819
if (!my_strcasecmp(system_charset_info,
3820
schema_table->table_name,
3822
return(schema_table);
3825
schema_table_a.table_name= table_name;
3826
if (plugin_foreach(thd, find_schema_table_in_plugin,
3827
DRIZZLE_INFORMATION_SCHEMA_PLUGIN, &schema_table_a))
3828
return(schema_table_a.schema_table);
3834
ST_SCHEMA_TABLE *get_schema_table(enum enum_schema_tables schema_table_idx)
3836
return &schema_tables[schema_table_idx];
3841
Create information_schema table using schema_table data.
3848
@param table_list Used to pass I_S table information(fields info, tables
3849
parameters etc) and table name.
3851
@retval \# Pointer to created table
3852
@retval NULL Can't create table
3855
TABLE *create_schema_table(THD *thd, TABLE_LIST *table_list)
3860
List<Item> field_list;
3861
ST_SCHEMA_TABLE *schema_table= table_list->schema_table;
3862
ST_FIELD_INFO *fields_info= schema_table->fields_info;
3863
const CHARSET_INFO * const cs= system_charset_info;
3865
for (; fields_info->field_name; fields_info++)
3867
switch (fields_info->field_type) {
3868
case DRIZZLE_TYPE_TINY:
3869
case DRIZZLE_TYPE_LONG:
3870
case DRIZZLE_TYPE_SHORT:
3871
case DRIZZLE_TYPE_LONGLONG:
3872
if (!(item= new Item_return_int(fields_info->field_name,
3873
fields_info->field_length,
3874
fields_info->field_type,
3875
fields_info->value)))
3879
item->unsigned_flag= (fields_info->field_flags & MY_I_S_UNSIGNED);
3881
case DRIZZLE_TYPE_NEWDATE:
3882
case DRIZZLE_TYPE_TIME:
3883
case DRIZZLE_TYPE_TIMESTAMP:
3884
case DRIZZLE_TYPE_DATETIME:
3885
if (!(item=new Item_return_date_time(fields_info->field_name,
3886
fields_info->field_type)))
3891
case DRIZZLE_TYPE_DOUBLE:
3892
if ((item= new Item_float(fields_info->field_name, 0.0, NOT_FIXED_DEC,
3893
fields_info->field_length)) == NULL)
3896
case DRIZZLE_TYPE_NEWDECIMAL:
3897
if (!(item= new Item_decimal((int64_t) fields_info->value, false)))
3901
item->unsigned_flag= (fields_info->field_flags & MY_I_S_UNSIGNED);
3902
item->decimals= fields_info->field_length%10;
3903
item->max_length= (fields_info->field_length/100)%100;
3904
if (item->unsigned_flag == 0)
3905
item->max_length+= 1;
3906
if (item->decimals > 0)
3907
item->max_length+= 1;
3908
item->set_name(fields_info->field_name,
3909
strlen(fields_info->field_name), cs);
3911
case DRIZZLE_TYPE_BLOB:
3912
if (!(item= new Item_blob(fields_info->field_name,
3913
fields_info->field_length)))
3919
if (!(item= new Item_empty_string("", fields_info->field_length, cs)))
3923
item->set_name(fields_info->field_name,
3924
strlen(fields_info->field_name), cs);
3927
field_list.push_back(item);
3928
item->maybe_null= (fields_info->field_flags & MY_I_S_MAYBE_NULL);
3931
TMP_TABLE_PARAM *tmp_table_param =
3932
(TMP_TABLE_PARAM*) (thd->alloc(sizeof(TMP_TABLE_PARAM)));
3933
tmp_table_param->init();
3934
tmp_table_param->table_charset= cs;
3935
tmp_table_param->field_count= field_count;
3936
tmp_table_param->schema_table= 1;
3937
SELECT_LEX *select_lex= thd->lex->current_select;
3938
if (!(table= create_tmp_table(thd, tmp_table_param,
3939
field_list, (ORDER*) 0, 0, 0,
3940
(select_lex->options | thd->options |
3941
TMP_TABLE_ALL_COLUMNS),
3942
HA_POS_ERROR, table_list->alias)))
3944
my_bitmap_map* bitmaps=
3945
(my_bitmap_map*) thd->alloc(bitmap_buffer_size(field_count));
3946
bitmap_init(&table->def_read_set, (my_bitmap_map*) bitmaps, field_count,
3948
table->read_set= &table->def_read_set;
3949
bitmap_clear_all(table->read_set);
3950
table_list->schema_table_param= tmp_table_param;
3956
For old SHOW compatibility. It is used when
3957
old SHOW doesn't have generated column names
3958
Make list of fields for SHOW
3963
schema_table pointer to 'schema_tables' element
3970
int make_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
3972
ST_FIELD_INFO *field_info= schema_table->fields_info;
3973
Name_resolution_context *context= &thd->lex->select_lex.context;
3974
for (; field_info->field_name; field_info++)
3976
if (field_info->old_name)
3978
Item_field *field= new Item_field(context,
3979
NullS, NullS, field_info->field_name);
3982
field->set_name(field_info->old_name,
3983
strlen(field_info->old_name),
3984
system_charset_info);
3985
if (add_item_to_list(thd, field))
3994
int make_schemata_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
3998
SELECT_LEX *sel= lex->current_select;
3999
Name_resolution_context *context= &sel->context;
4001
if (!sel->item_list.elements)
4003
ST_FIELD_INFO *field_info= &schema_table->fields_info[1];
4004
String buffer(tmp,sizeof(tmp), system_charset_info);
4005
Item_field *field= new Item_field(context,
4006
NullS, NullS, field_info->field_name);
4007
if (!field || add_item_to_list(thd, field))
4010
buffer.append(field_info->old_name);
4011
if (lex->wild && lex->wild->ptr())
4013
buffer.append(STRING_WITH_LEN(" ("));
4014
buffer.append(lex->wild->ptr());
4017
field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
4023
int make_table_names_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
4026
String buffer(tmp,sizeof(tmp), thd->charset());
4028
Name_resolution_context *context= &lex->select_lex.context;
4030
ST_FIELD_INFO *field_info= &schema_table->fields_info[2];
4032
buffer.append(field_info->old_name);
4033
buffer.append(lex->select_lex.db);
4034
if (lex->wild && lex->wild->ptr())
4036
buffer.append(STRING_WITH_LEN(" ("));
4037
buffer.append(lex->wild->ptr());
4040
Item_field *field= new Item_field(context,
4041
NullS, NullS, field_info->field_name);
4042
if (add_item_to_list(thd, field))
4044
field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
4045
if (thd->lex->verbose)
4047
field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
4048
field_info= &schema_table->fields_info[3];
4049
field= new Item_field(context, NullS, NullS, field_info->field_name);
4050
if (add_item_to_list(thd, field))
4052
field->set_name(field_info->old_name, strlen(field_info->old_name),
4053
system_charset_info);
4059
int make_columns_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
4061
int fields_arr[]= {3, 14, 13, 6, 15, 5, 16, 17, 18, -1};
4062
int *field_num= fields_arr;
4063
ST_FIELD_INFO *field_info;
4064
Name_resolution_context *context= &thd->lex->select_lex.context;
4066
for (; *field_num >= 0; field_num++)
4068
field_info= &schema_table->fields_info[*field_num];
4069
if (!thd->lex->verbose && (*field_num == 13 ||
4073
Item_field *field= new Item_field(context,
4074
NullS, NullS, field_info->field_name);
4077
field->set_name(field_info->old_name,
4078
strlen(field_info->old_name),
4079
system_charset_info);
4080
if (add_item_to_list(thd, field))
4088
int make_character_sets_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
4090
int fields_arr[]= {0, 2, 1, 3, -1};
4091
int *field_num= fields_arr;
4092
ST_FIELD_INFO *field_info;
4093
Name_resolution_context *context= &thd->lex->select_lex.context;
4095
for (; *field_num >= 0; field_num++)
4097
field_info= &schema_table->fields_info[*field_num];
4098
Item_field *field= new Item_field(context,
4099
NullS, NullS, field_info->field_name);
4102
field->set_name(field_info->old_name,
4103
strlen(field_info->old_name),
4104
system_charset_info);
4105
if (add_item_to_list(thd, field))
4114
Create information_schema table
4117
mysql_schema_table()
4120
table_list pointer to table_list
4127
int mysql_schema_table(THD *thd, LEX *lex, TABLE_LIST *table_list)
4130
if (!(table= table_list->schema_table->create_table(thd, table_list)))
4132
table->s->tmp_table= SYSTEM_TMP_TABLE;
4134
This test is necessary to make
4135
case insensitive file systems +
4136
upper case table names(information schema tables) +
4140
if (table_list->schema_table_name)
4141
table->alias_name_used= my_strcasecmp(table_alias_charset,
4142
table_list->schema_table_name,
4144
table_list->table_name= table->s->table_name.str;
4145
table_list->table_name_length= table->s->table_name.length;
4146
table_list->table= table;
4147
table->next= thd->derived_tables;
4148
thd->derived_tables= table;
4149
table_list->select_lex->options |= OPTION_SCHEMA_TABLE;
4151
if (table_list->schema_table_reformed) // show command
4153
SELECT_LEX *sel= lex->current_select;
4155
Field_translator *transl, *org_transl;
4157
if (table_list->field_translation)
4159
Field_translator *end= table_list->field_translation_end;
4160
for (transl= table_list->field_translation; transl < end; transl++)
4162
if (!transl->item->fixed &&
4163
transl->item->fix_fields(thd, &transl->item))
4168
List_iterator_fast<Item> it(sel->item_list);
4170
(Field_translator*)(thd->stmt_arena->
4171
alloc(sel->item_list.elements *
4172
sizeof(Field_translator)))))
4176
for (org_transl= transl; (item= it++); transl++)
4179
transl->name= item->name;
4180
if (!item->fixed && item->fix_fields(thd, &transl->item))
4185
table_list->field_translation= org_transl;
4186
table_list->field_translation_end= transl;
4194
Generate select from information_schema table
4197
make_schema_select()
4199
sel pointer to SELECT_LEX
4200
schema_table_idx index of 'schema_tables' element
4207
int make_schema_select(THD *thd, SELECT_LEX *sel,
4208
enum enum_schema_tables schema_table_idx)
4210
ST_SCHEMA_TABLE *schema_table= get_schema_table(schema_table_idx);
4211
LEX_STRING db, table;
4213
We have to make non const db_name & table_name
4214
because of lower_case_table_names
4216
thd->make_lex_string(&db, INFORMATION_SCHEMA_NAME.str,
4217
INFORMATION_SCHEMA_NAME.length, 0);
4218
thd->make_lex_string(&table, schema_table->table_name,
4219
strlen(schema_table->table_name), 0);
4220
if (schema_table->old_format(thd, schema_table) || /* Handle old syntax */
4221
!sel->add_table_to_list(thd, new Table_ident(thd, db, table, 0),
4231
Fill temporary schema tables before SELECT
4234
get_schema_tables_result()
4235
join join which use schema tables
4236
executed_place place where I_S table processed
4243
bool get_schema_tables_result(JOIN *join,
4244
enum enum_schema_table_state executed_place)
4246
JOIN_TAB *tmp_join_tab= join->join_tab+join->tables;
4247
THD *thd= join->thd;
4251
thd->no_warnings_for_error= 1;
4252
for (JOIN_TAB *tab= join->join_tab; tab < tmp_join_tab; tab++)
4254
if (!tab->table || !tab->table->pos_in_table_list)
4257
TABLE_LIST *table_list= tab->table->pos_in_table_list;
4258
if (table_list->schema_table)
4260
bool is_subselect= (&lex->unit != lex->current_select->master_unit() &&
4261
lex->current_select->master_unit()->item);
4264
/* skip I_S optimizations specific to get_all_tables */
4265
if (thd->lex->describe &&
4266
(table_list->schema_table->fill_table != get_all_tables))
4270
If schema table is already processed and
4271
the statement is not a subselect then
4272
we don't need to fill this table again.
4273
If schema table is already processed and
4274
schema_table_state != executed_place then
4275
table is already processed and
4276
we should skip second data processing.
4278
if (table_list->schema_table_state &&
4279
(!is_subselect || table_list->schema_table_state != executed_place))
4283
if table is used in a subselect and
4284
table has been processed earlier with the same
4285
'executed_place' value then we should refresh the table.
4287
if (table_list->schema_table_state && is_subselect)
4289
table_list->table->file->extra(HA_EXTRA_NO_CACHE);
4290
table_list->table->file->extra(HA_EXTRA_RESET_STATE);
4291
table_list->table->file->ha_delete_all_rows();
4292
free_io_cache(table_list->table);
4293
filesort_free_buffers(table_list->table,1);
4294
table_list->table->null_row= 0;
4297
table_list->table->file->stats.records= 0;
4299
if (table_list->schema_table->fill_table(thd, table_list,
4304
tab->read_record.file= table_list->table->file;
4305
table_list->schema_table_state= executed_place;
4308
tab->read_record.file= table_list->table->file;
4309
table_list->schema_table_state= executed_place;
4312
thd->no_warnings_for_error= 0;
4316
ST_FIELD_INFO schema_fields_info[]=
4318
{"CATALOG_NAME", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, SKIP_OPEN_TABLE},
4319
{"SCHEMA_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Database",
4321
{"DEFAULT_CHARACTER_SET_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4323
{"DEFAULT_COLLATION_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE},
4324
{"SQL_PATH", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, SKIP_OPEN_TABLE},
4325
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4329
ST_FIELD_INFO tables_fields_info[]=
4331
{"TABLE_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, SKIP_OPEN_TABLE},
4332
{"TABLE_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE},
4333
{"TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Name",
4335
{"TABLE_TYPE", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FRM_ONLY},
4336
{"ENGINE", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 1, "Engine", OPEN_FRM_ONLY},
4337
{"VERSION", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4338
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Version", OPEN_FRM_ONLY},
4339
{"ROW_FORMAT", 10, DRIZZLE_TYPE_VARCHAR, 0, 1, "Row_format", OPEN_FULL_TABLE},
4340
{"TABLE_ROWS", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4341
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Rows", OPEN_FULL_TABLE},
4342
{"AVG_ROW_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4343
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Avg_row_length", OPEN_FULL_TABLE},
4344
{"DATA_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4345
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Data_length", OPEN_FULL_TABLE},
4346
{"MAX_DATA_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4347
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Max_data_length", OPEN_FULL_TABLE},
4348
{"INDEX_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4349
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Index_length", OPEN_FULL_TABLE},
4350
{"DATA_FREE", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4351
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Data_free", OPEN_FULL_TABLE},
4352
{"AUTO_INCREMENT", MY_INT64_NUM_DECIMAL_DIGITS , DRIZZLE_TYPE_LONGLONG, 0,
4353
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Auto_increment", OPEN_FULL_TABLE},
4354
{"CREATE_TIME", 0, DRIZZLE_TYPE_DATETIME, 0, 1, "Create_time", OPEN_FULL_TABLE},
4355
{"UPDATE_TIME", 0, DRIZZLE_TYPE_DATETIME, 0, 1, "Update_time", OPEN_FULL_TABLE},
4356
{"CHECK_TIME", 0, DRIZZLE_TYPE_DATETIME, 0, 1, "Check_time", OPEN_FULL_TABLE},
4357
{"TABLE_COLLATION", 64, DRIZZLE_TYPE_VARCHAR, 0, 1, "Collation", OPEN_FRM_ONLY},
4358
{"CHECKSUM", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4359
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Checksum", OPEN_FULL_TABLE},
4360
{"CREATE_OPTIONS", 255, DRIZZLE_TYPE_VARCHAR, 0, 1, "Create_options",
4362
{"TABLE_COMMENT", TABLE_COMMENT_MAXLEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Comment", OPEN_FRM_ONLY},
4363
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4367
ST_FIELD_INFO columns_fields_info[]=
4369
{"TABLE_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, OPEN_FRM_ONLY},
4370
{"TABLE_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FRM_ONLY},
4371
{"TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FRM_ONLY},
4372
{"COLUMN_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Field",
4374
{"ORDINAL_POSITION", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4375
MY_I_S_UNSIGNED, 0, OPEN_FRM_ONLY},
4376
{"COLUMN_DEFAULT", MAX_FIELD_VARCHARLENGTH, DRIZZLE_TYPE_VARCHAR, 0,
4377
1, "Default", OPEN_FRM_ONLY},
4378
{"IS_NULLABLE", 3, DRIZZLE_TYPE_VARCHAR, 0, 0, "Null", OPEN_FRM_ONLY},
4379
{"DATA_TYPE", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FRM_ONLY},
4380
{"CHARACTER_MAXIMUM_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG,
4381
0, (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), 0, OPEN_FRM_ONLY},
4382
{"CHARACTER_OCTET_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS , DRIZZLE_TYPE_LONGLONG,
4383
0, (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), 0, OPEN_FRM_ONLY},
4384
{"NUMERIC_PRECISION", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG,
4385
0, (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), 0, OPEN_FRM_ONLY},
4386
{"NUMERIC_SCALE", MY_INT64_NUM_DECIMAL_DIGITS , DRIZZLE_TYPE_LONGLONG,
4387
0, (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), 0, OPEN_FRM_ONLY},
4388
{"CHARACTER_SET_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, OPEN_FRM_ONLY},
4389
{"COLLATION_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 1, "Collation", OPEN_FRM_ONLY},
4390
{"COLUMN_TYPE", 65535, DRIZZLE_TYPE_VARCHAR, 0, 0, "Type", OPEN_FRM_ONLY},
4391
{"COLUMN_KEY", 3, DRIZZLE_TYPE_VARCHAR, 0, 0, "Key", OPEN_FRM_ONLY},
4392
{"EXTRA", 27, DRIZZLE_TYPE_VARCHAR, 0, 0, "Extra", OPEN_FRM_ONLY},
4393
{"PRIVILEGES", 80, DRIZZLE_TYPE_VARCHAR, 0, 0, "Privileges", OPEN_FRM_ONLY},
4394
{"COLUMN_COMMENT", COLUMN_COMMENT_MAXLEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Comment", OPEN_FRM_ONLY},
4395
{"STORAGE", 8, DRIZZLE_TYPE_VARCHAR, 0, 0, "Storage", OPEN_FRM_ONLY},
4396
{"FORMAT", 8, DRIZZLE_TYPE_VARCHAR, 0, 0, "Format", OPEN_FRM_ONLY},
4397
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4401
ST_FIELD_INFO charsets_fields_info[]=
4403
{"CHARACTER_SET_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, "Charset",
4405
{"DEFAULT_COLLATE_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, "Default collation",
4407
{"DESCRIPTION", 60, DRIZZLE_TYPE_VARCHAR, 0, 0, "Description",
4409
{"MAXLEN", 3, DRIZZLE_TYPE_LONGLONG, 0, 0, "Maxlen", SKIP_OPEN_TABLE},
4410
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4414
ST_FIELD_INFO collation_fields_info[]=
4416
{"COLLATION_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, "Collation", SKIP_OPEN_TABLE},
4417
{"CHARACTER_SET_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, "Charset",
4419
{"ID", MY_INT32_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0, 0, "Id",
4421
{"IS_DEFAULT", 3, DRIZZLE_TYPE_VARCHAR, 0, 0, "Default", SKIP_OPEN_TABLE},
4422
{"IS_COMPILED", 3, DRIZZLE_TYPE_VARCHAR, 0, 0, "Compiled", SKIP_OPEN_TABLE},
4423
{"SORTLEN", 3, DRIZZLE_TYPE_LONGLONG, 0, 0, "Sortlen", SKIP_OPEN_TABLE},
4424
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4429
ST_FIELD_INFO coll_charset_app_fields_info[]=
4431
{"COLLATION_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE},
4432
{"CHARACTER_SET_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE},
4433
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4437
ST_FIELD_INFO stat_fields_info[]=
4439
{"TABLE_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, OPEN_FRM_ONLY},
4440
{"TABLE_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FRM_ONLY},
4441
{"TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Table", OPEN_FRM_ONLY},
4442
{"NON_UNIQUE", 1, DRIZZLE_TYPE_LONGLONG, 0, 0, "Non_unique", OPEN_FRM_ONLY},
4443
{"INDEX_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FRM_ONLY},
4444
{"INDEX_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Key_name",
4446
{"SEQ_IN_INDEX", 2, DRIZZLE_TYPE_LONGLONG, 0, 0, "Seq_in_index", OPEN_FRM_ONLY},
4447
{"COLUMN_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Column_name",
4449
{"COLLATION", 1, DRIZZLE_TYPE_VARCHAR, 0, 1, "Collation", OPEN_FRM_ONLY},
4450
{"CARDINALITY", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0, 1,
4451
"Cardinality", OPEN_FULL_TABLE},
4452
{"SUB_PART", 3, DRIZZLE_TYPE_LONGLONG, 0, 1, "Sub_part", OPEN_FRM_ONLY},
4453
{"PACKED", 10, DRIZZLE_TYPE_VARCHAR, 0, 1, "Packed", OPEN_FRM_ONLY},
4454
{"NULLABLE", 3, DRIZZLE_TYPE_VARCHAR, 0, 0, "Null", OPEN_FRM_ONLY},
4455
{"INDEX_TYPE", 16, DRIZZLE_TYPE_VARCHAR, 0, 0, "Index_type", OPEN_FULL_TABLE},
4456
{"COMMENT", 16, DRIZZLE_TYPE_VARCHAR, 0, 1, "Comment", OPEN_FRM_ONLY},
4457
{"INDEX_COMMENT", INDEX_COMMENT_MAXLEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Index_Comment", OPEN_FRM_ONLY},
4458
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4462
ST_FIELD_INFO table_constraints_fields_info[]=
4464
{"CONSTRAINT_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, OPEN_FULL_TABLE},
4465
{"CONSTRAINT_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4467
{"CONSTRAINT_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4469
{"TABLE_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4470
{"TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4471
{"CONSTRAINT_TYPE", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4473
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4477
ST_FIELD_INFO key_column_usage_fields_info[]=
4479
{"CONSTRAINT_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, OPEN_FULL_TABLE},
4480
{"CONSTRAINT_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4482
{"CONSTRAINT_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4484
{"TABLE_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, OPEN_FULL_TABLE},
4485
{"TABLE_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4486
{"TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4487
{"COLUMN_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4488
{"ORDINAL_POSITION", 10 ,DRIZZLE_TYPE_LONGLONG, 0, 0, 0, OPEN_FULL_TABLE},
4489
{"POSITION_IN_UNIQUE_CONSTRAINT", 10 ,DRIZZLE_TYPE_LONGLONG, 0, 1, 0,
4491
{"REFERENCED_TABLE_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0,
4493
{"REFERENCED_TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0,
4495
{"REFERENCED_COLUMN_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0,
4497
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4501
ST_FIELD_INFO table_names_fields_info[]=
4503
{"TABLE_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, SKIP_OPEN_TABLE},
4504
{"TABLE_SCHEMA",NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE},
4505
{"TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Tables_in_",
4507
{"TABLE_TYPE", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Table_type",
4509
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4513
ST_FIELD_INFO open_tables_fields_info[]=
4515
{"Database", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Database",
4517
{"Table",NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Table", SKIP_OPEN_TABLE},
4518
{"In_use", 1, DRIZZLE_TYPE_LONGLONG, 0, 0, "In_use", SKIP_OPEN_TABLE},
4519
{"Name_locked", 4, DRIZZLE_TYPE_LONGLONG, 0, 0, "Name_locked", SKIP_OPEN_TABLE},
4520
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4524
ST_FIELD_INFO variables_fields_info[]=
4526
{"VARIABLE_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, "Variable_name",
4528
{"VARIABLE_VALUE", 16300, DRIZZLE_TYPE_VARCHAR, 0, 1, "Value", SKIP_OPEN_TABLE},
4529
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4533
ST_FIELD_INFO processlist_fields_info[]=
4535
{"ID", 4, DRIZZLE_TYPE_LONGLONG, 0, 0, "Id", SKIP_OPEN_TABLE},
4536
{"USER", 16, DRIZZLE_TYPE_VARCHAR, 0, 0, "User", SKIP_OPEN_TABLE},
4537
{"HOST", LIST_PROCESS_HOST_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Host",
4539
{"DB", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 1, "Db", SKIP_OPEN_TABLE},
4540
{"COMMAND", 16, DRIZZLE_TYPE_VARCHAR, 0, 0, "Command", SKIP_OPEN_TABLE},
4541
{"TIME", 7, DRIZZLE_TYPE_LONGLONG, 0, 0, "Time", SKIP_OPEN_TABLE},
4542
{"STATE", 64, DRIZZLE_TYPE_VARCHAR, 0, 1, "State", SKIP_OPEN_TABLE},
4543
{"INFO", PROCESS_LIST_INFO_WIDTH, DRIZZLE_TYPE_VARCHAR, 0, 1, "Info",
4545
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4549
ST_FIELD_INFO plugin_fields_info[]=
4551
{"PLUGIN_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Name",
4553
{"PLUGIN_VERSION", 20, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE},
4554
{"PLUGIN_STATUS", 10, DRIZZLE_TYPE_VARCHAR, 0, 0, "Status", SKIP_OPEN_TABLE},
4555
{"PLUGIN_TYPE", 80, DRIZZLE_TYPE_VARCHAR, 0, 0, "Type", SKIP_OPEN_TABLE},
4556
{"PLUGIN_LIBRARY", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 1, "Library",
4558
{"PLUGIN_AUTHOR", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, SKIP_OPEN_TABLE},
4559
{"PLUGIN_DESCRIPTION", 65535, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, SKIP_OPEN_TABLE},
4560
{"PLUGIN_LICENSE", 80, DRIZZLE_TYPE_VARCHAR, 0, 1, "License", SKIP_OPEN_TABLE},
4561
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4564
ST_FIELD_INFO referential_constraints_fields_info[]=
4566
{"CONSTRAINT_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, OPEN_FULL_TABLE},
4567
{"CONSTRAINT_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4569
{"CONSTRAINT_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4571
{"UNIQUE_CONSTRAINT_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0,
4573
{"UNIQUE_CONSTRAINT_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4575
{"UNIQUE_CONSTRAINT_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0,
4576
MY_I_S_MAYBE_NULL, 0, OPEN_FULL_TABLE},
4577
{"MATCH_OPTION", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4578
{"UPDATE_RULE", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4579
{"DELETE_RULE", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4580
{"TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4581
{"REFERENCED_TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4583
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4588
Description of ST_FIELD_INFO in table.h
4590
Make sure that the order of schema_tables and enum_schema_tables are the same.
4594
ST_SCHEMA_TABLE schema_tables[]=
4596
{"CHARACTER_SETS", charsets_fields_info, create_schema_table,
4597
fill_schema_charsets, make_character_sets_old_format, 0, -1, -1, 0, 0},
4598
{"COLLATIONS", collation_fields_info, create_schema_table,
4599
fill_schema_collation, make_old_format, 0, -1, -1, 0, 0},
4600
{"COLLATION_CHARACTER_SET_APPLICABILITY", coll_charset_app_fields_info,
4601
create_schema_table, fill_schema_coll_charset_app, 0, 0, -1, -1, 0, 0},
4602
{"COLUMNS", columns_fields_info, create_schema_table,
4603
get_all_tables, make_columns_old_format, get_schema_column_record, 1, 2, 0,
4604
OPTIMIZE_I_S_TABLE|OPEN_VIEW_FULL},
4605
{"GLOBAL_STATUS", variables_fields_info, create_schema_table,
4606
fill_status, make_old_format, 0, -1, -1, 0, 0},
4607
{"GLOBAL_VARIABLES", variables_fields_info, create_schema_table,
4608
fill_variables, make_old_format, 0, -1, -1, 0, 0},
4609
{"KEY_COLUMN_USAGE", key_column_usage_fields_info, create_schema_table,
4610
get_all_tables, 0, get_schema_key_column_usage_record, 4, 5, 0,
4612
{"OPEN_TABLES", open_tables_fields_info, create_schema_table,
4613
fill_open_tables, make_old_format, 0, -1, -1, 1, 0},
4614
{"PLUGINS", plugin_fields_info, create_schema_table,
4615
fill_plugins, make_old_format, 0, -1, -1, 0, 0},
4616
{"PROCESSLIST", processlist_fields_info, create_schema_table,
4617
fill_schema_processlist, make_old_format, 0, -1, -1, 0, 0},
4618
{"REFERENTIAL_CONSTRAINTS", referential_constraints_fields_info,
4619
create_schema_table, get_all_tables, 0, get_referential_constraints_record,
4620
1, 9, 0, OPEN_TABLE_ONLY},
4621
{"SCHEMATA", schema_fields_info, create_schema_table,
4622
fill_schema_schemata, make_schemata_old_format, 0, 1, -1, 0, 0},
4623
{"SESSION_STATUS", variables_fields_info, create_schema_table,
4624
fill_status, make_old_format, 0, -1, -1, 0, 0},
4625
{"SESSION_VARIABLES", variables_fields_info, create_schema_table,
4626
fill_variables, make_old_format, 0, -1, -1, 0, 0},
4627
{"STATISTICS", stat_fields_info, create_schema_table,
4628
get_all_tables, make_old_format, get_schema_stat_record, 1, 2, 0,
4629
OPEN_TABLE_ONLY|OPTIMIZE_I_S_TABLE},
4630
{"STATUS", variables_fields_info, create_schema_table, fill_status,
4631
make_old_format, 0, -1, -1, 1, 0},
4632
{"TABLES", tables_fields_info, create_schema_table,
4633
get_all_tables, make_old_format, get_schema_tables_record, 1, 2, 0,
4634
OPTIMIZE_I_S_TABLE},
4635
{"TABLE_CONSTRAINTS", table_constraints_fields_info, create_schema_table,
4636
get_all_tables, 0, get_schema_constraints_record, 3, 4, 0, OPEN_TABLE_ONLY},
4637
{"TABLE_NAMES", table_names_fields_info, create_schema_table,
4638
get_all_tables, make_table_names_old_format, 0, 1, 2, 1, 0},
4639
{"VARIABLES", variables_fields_info, create_schema_table, fill_variables,
4640
make_old_format, 0, -1, -1, 1, 0},
4641
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
4645
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
4646
template class List_iterator_fast<char>;
4647
template class List<char>;
4650
int initialize_schema_table(st_plugin_int *plugin)
4652
ST_SCHEMA_TABLE *schema_table;
4654
if (!(schema_table= (ST_SCHEMA_TABLE *)my_malloc(sizeof(ST_SCHEMA_TABLE),
4655
MYF(MY_WME | MY_ZEROFILL))))
4657
/* Historical Requirement */
4658
plugin->data= schema_table; // shortcut for the future
4659
if (plugin->plugin->init)
4661
schema_table->create_table= create_schema_table;
4662
schema_table->old_format= make_old_format;
4663
schema_table->idx_field1= -1,
4664
schema_table->idx_field2= -1;
4666
/* Make the name available to the init() function. */
4667
schema_table->table_name= plugin->name.str;
4669
if (plugin->plugin->init(schema_table))
4671
sql_print_error("Plugin '%s' init function returned error.",
4676
/* Make sure the plugin name is not set inside the init() function. */
4677
schema_table->table_name= plugin->name.str;
4682
my_free(schema_table, MYF(0));
4686
int finalize_schema_table(st_plugin_int *plugin)
4688
ST_SCHEMA_TABLE *schema_table= (ST_SCHEMA_TABLE *)plugin->data;
4690
if (schema_table && plugin->plugin->deinit)
4691
my_free(schema_table, MYF(0));
837
} /* namespace drizzled */