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());
1391
shrink_var_array(&all_status_vars);
1395
inline void make_upper(char *buf)
1398
*buf= my_toupper(system_charset_info, *buf);
1401
static bool show_status_array(Session *session, const char *wild,
1402
SHOW_VAR *variables,
1403
enum enum_var_type value_type,
1404
struct system_status_var *status_var,
1405
const char *prefix, Table *table,
1408
MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, int64_t);
1409
char * const buff= (char *) &buff_data;
1411
/* the variable name should not be longer than 64 characters */
1412
char name_buffer[64];
1414
LEX_STRING null_lex_str;
1417
null_lex_str.str= 0; // For sys_var->value_ptr()
1418
null_lex_str.length= 0;
1420
prefix_end= strncpy(name_buffer, prefix, sizeof(name_buffer)-1);
1421
prefix_end+= strlen(prefix);
1425
len=name_buffer + sizeof(name_buffer) - prefix_end;
1427
for (; variables->name; variables++)
1429
strncpy(prefix_end, variables->name, len);
1430
name_buffer[sizeof(name_buffer)-1]=0; /* Safety */
1432
make_upper(name_buffer);
1435
if var->type is SHOW_FUNC, call the function.
1436
Repeat as necessary, if new var is again SHOW_FUNC
1438
for (var=variables; var->type == SHOW_FUNC; var= &tmp)
1439
((mysql_show_var_func)((st_show_var_func_container *)var->value)->func)(session, &tmp, buff);
1441
SHOW_TYPE show_type=var->type;
1442
if (show_type == SHOW_ARRAY)
1444
show_status_array(session, wild, (SHOW_VAR *) var->value, value_type,
1445
status_var, name_buffer, table, ucase_names);
1449
if (!(wild && wild[0] && wild_case_compare(system_charset_info,
1450
name_buffer, wild)))
1452
char *value=var->value;
1453
const char *pos, *end; // We assign a lot of const's
1454
pthread_mutex_lock(&LOCK_global_system_variables);
1456
if (show_type == SHOW_SYS)
1458
show_type= ((sys_var*) value)->show_type();
1459
value= (char*) ((sys_var*) value)->value_ptr(session, value_type,
1465
note that value may be == buff. All SHOW_xxx code below
1466
should still work in this case
1468
switch (show_type) {
1469
case SHOW_DOUBLE_STATUS:
1470
value= ((char *) status_var + (ulong) value);
1473
/* 6 is the default precision for '%f' in sprintf() */
1474
end= buff + my_fcvt(*(double *) value, 6, buff, NULL);
1476
case SHOW_LONG_STATUS:
1477
value= ((char *) status_var + (ulong) value);
1480
case SHOW_LONG_NOFLUSH: // the difference lies in refresh_status()
1481
end= int10_to_str(*(long*) value, buff, 10);
1483
case SHOW_LONGLONG_STATUS:
1484
value= ((char *) status_var + (uint64_t) value);
1487
end= int64_t10_to_str(*(int64_t*) value, buff, 10);
1491
stringstream ss (stringstream::in);
1492
ss << *(size_t*) value;
1494
string str= ss.str();
1495
strncpy(buff, str.c_str(), str.length());
1496
end= buff+ str.length();
1500
end= int64_t10_to_str((int64_t) *(ha_rows*) value, buff, 10);
1503
end+= sprintf(buff,"%s", *(bool*) value ? "ON" : "OFF");
1506
end+= sprintf(buff,"%s", *(bool*) value ? "ON" : "OFF");
1509
end= int10_to_str((long) *(uint32_t*) value, buff, 10);
1513
SHOW_COMP_OPTION tmp= *(SHOW_COMP_OPTION*) value;
1514
pos= show_comp_option_name[(int) tmp];
1515
end= strchr(pos, '\0');
1522
end= strchr(pos, '\0');
1527
if (!(pos= *(char**) value))
1529
end= strchr(pos, '\0');
1532
case SHOW_KEY_CACHE_LONG:
1533
value= (char*) dflt_key_cache + (ulong)value;
1534
end= int10_to_str(*(long*) value, buff, 10);
1536
case SHOW_KEY_CACHE_LONGLONG:
1537
value= (char*) dflt_key_cache + (ulong)value;
1538
end= int64_t10_to_str(*(int64_t*) value, buff, 10);
1541
break; // Return empty string
1542
case SHOW_SYS: // Cannot happen
1547
restore_record(table, s->default_values);
1548
table->field[0]->store(name_buffer, strlen(name_buffer),
1549
system_charset_info);
1550
table->field[1]->store(pos, (uint32_t) (end - pos), system_charset_info);
1551
table->field[1]->set_notnull();
1553
pthread_mutex_unlock(&LOCK_global_system_variables);
1555
if (schema_table_store_record(session, table))
860
1565
/* collect status for all running threads */
862
void calc_sum_of_all_status(system_status_var *to)
1567
void calc_sum_of_all_status(STATUS_VAR *to)
864
1570
/* Ensure that thread id not killed during loop */
865
1571
pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
1573
I_List_iterator<Session> it(threads);
867
1576
/* Get global values as base */
868
1577
*to= global_status_var;
870
1579
/* 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));
1581
add_to_status(to, &tmp->status_var);
876
1583
pthread_mutex_unlock(&LOCK_thread_count);
880
} /* namespace drizzled */
1588
/* This is only used internally, but we need it here as a forward reference */
1589
extern ST_SCHEMA_TABLE schema_tables[];
1591
typedef struct st_lookup_field_values
1593
LEX_STRING db_value, table_value;
1594
bool wild_db_value, wild_table_value;
1595
} LOOKUP_FIELD_VALUES;
1599
Store record to I_S table, convert HEAP table
1600
to MyISAM if necessary
1603
schema_table_store_record()
1604
session thread handler
1605
table Information schema table to be updated
1612
bool schema_table_store_record(Session *session, Table *table)
1615
if ((error= table->file->ha_write_row(table->record[0])))
1617
TMP_TABLE_PARAM *param= table->pos_in_table_list->schema_table_param;
1619
if (create_myisam_from_heap(session, table, param->start_recinfo,
1620
¶m->recinfo, error, 0))
1627
int make_table_list(Session *session, SELECT_LEX *sel,
1628
LEX_STRING *db_name, LEX_STRING *table_name)
1630
Table_ident *table_ident;
1631
table_ident= new Table_ident(session, *db_name, *table_name, 1);
1633
if (!sel->add_table_to_list(session, table_ident, 0, 0, TL_READ))
1640
@brief Get lookup value from the part of 'WHERE' condition
1642
@details This function gets lookup value from
1643
the part of 'WHERE' condition if it's possible and
1644
fill appropriate lookup_field_vals struct field
1647
@param[in] session thread handler
1648
@param[in] item_func part of WHERE condition
1649
@param[in] table I_S table
1650
@param[in, out] lookup_field_vals Struct which holds lookup values
1654
1 error, there can be no matching records for the condition
1657
bool get_lookup_value(Session *session, Item_func *item_func,
1659
LOOKUP_FIELD_VALUES *lookup_field_vals)
1661
ST_SCHEMA_TABLE *schema_table= table->schema_table;
1662
ST_FIELD_INFO *field_info= schema_table->fields_info;
1663
const char *field_name1= schema_table->idx_field1 >= 0 ?
1664
field_info[schema_table->idx_field1].field_name : "";
1665
const char *field_name2= schema_table->idx_field2 >= 0 ?
1666
field_info[schema_table->idx_field2].field_name : "";
1668
if (item_func->functype() == Item_func::EQ_FUNC ||
1669
item_func->functype() == Item_func::EQUAL_FUNC)
1671
int idx_field, idx_val;
1672
char tmp[MAX_FIELD_WIDTH];
1673
String *tmp_str, str_buff(tmp, sizeof(tmp), system_charset_info);
1674
Item_field *item_field;
1675
const CHARSET_INFO * const cs= system_charset_info;
1677
if (item_func->arguments()[0]->type() == Item::FIELD_ITEM &&
1678
item_func->arguments()[1]->const_item())
1683
else if (item_func->arguments()[1]->type() == Item::FIELD_ITEM &&
1684
item_func->arguments()[0]->const_item())
1692
item_field= (Item_field*) item_func->arguments()[idx_field];
1693
if (table->table != item_field->field->table)
1695
tmp_str= item_func->arguments()[idx_val]->val_str(&str_buff);
1697
/* impossible value */
1701
/* Lookup value is database name */
1702
if (!cs->coll->strnncollsp(cs, (unsigned char *) field_name1, strlen(field_name1),
1703
(unsigned char *) item_field->field_name,
1704
strlen(item_field->field_name), 0))
1706
session->make_lex_string(&lookup_field_vals->db_value, tmp_str->ptr(),
1707
tmp_str->length(), false);
1709
/* Lookup value is table name */
1710
else if (!cs->coll->strnncollsp(cs, (unsigned char *) field_name2,
1711
strlen(field_name2),
1712
(unsigned char *) item_field->field_name,
1713
strlen(item_field->field_name), 0))
1715
session->make_lex_string(&lookup_field_vals->table_value, tmp_str->ptr(),
1716
tmp_str->length(), false);
1724
@brief Calculates lookup values from 'WHERE' condition
1726
@details This function calculates lookup value(database name, table name)
1727
from 'WHERE' condition if it's possible and
1728
fill lookup_field_vals struct fields with these values.
1730
@param[in] session thread handler
1731
@param[in] cond WHERE condition
1732
@param[in] table I_S table
1733
@param[in, out] lookup_field_vals Struct which holds lookup values
1737
1 error, there can be no matching records for the condition
1740
bool calc_lookup_values_from_cond(Session *session, COND *cond, TableList *table,
1741
LOOKUP_FIELD_VALUES *lookup_field_vals)
1746
if (cond->type() == Item::COND_ITEM)
1748
if (((Item_cond*) cond)->functype() == Item_func::COND_AND_FUNC)
1750
List_iterator<Item> li(*((Item_cond*) cond)->argument_list());
1752
while ((item= li++))
1754
if (item->type() == Item::FUNC_ITEM)
1756
if (get_lookup_value(session, (Item_func*)item, table, lookup_field_vals))
1761
if (calc_lookup_values_from_cond(session, item, table, lookup_field_vals))
1768
else if (cond->type() == Item::FUNC_ITEM &&
1769
get_lookup_value(session, (Item_func*) cond, table, lookup_field_vals))
1775
bool uses_only_table_name_fields(Item *item, TableList *table)
1777
if (item->type() == Item::FUNC_ITEM)
1779
Item_func *item_func= (Item_func*)item;
1780
for (uint32_t i=0; i<item_func->argument_count(); i++)
1782
if (!uses_only_table_name_fields(item_func->arguments()[i], table))
1786
else if (item->type() == Item::FIELD_ITEM)
1788
Item_field *item_field= (Item_field*)item;
1789
const CHARSET_INFO * const cs= system_charset_info;
1790
ST_SCHEMA_TABLE *schema_table= table->schema_table;
1791
ST_FIELD_INFO *field_info= schema_table->fields_info;
1792
const char *field_name1= schema_table->idx_field1 >= 0 ?
1793
field_info[schema_table->idx_field1].field_name : "";
1794
const char *field_name2= schema_table->idx_field2 >= 0 ?
1795
field_info[schema_table->idx_field2].field_name : "";
1796
if (table->table != item_field->field->table ||
1797
(cs->coll->strnncollsp(cs, (unsigned char *) field_name1, strlen(field_name1),
1798
(unsigned char *) item_field->field_name,
1799
strlen(item_field->field_name), 0) &&
1800
cs->coll->strnncollsp(cs, (unsigned char *) field_name2, strlen(field_name2),
1801
(unsigned char *) item_field->field_name,
1802
strlen(item_field->field_name), 0)))
1805
else if (item->type() == Item::REF_ITEM)
1806
return uses_only_table_name_fields(item->real_item(), table);
1808
if (item->type() == Item::SUBSELECT_ITEM && !item->const_item())
1815
static COND * make_cond_for_info_schema(COND *cond, TableList *table)
1819
if (cond->type() == Item::COND_ITEM)
1821
if (((Item_cond*) cond)->functype() == Item_func::COND_AND_FUNC)
1823
/* Create new top level AND item */
1824
Item_cond_and *new_cond=new Item_cond_and;
1827
List_iterator<Item> li(*((Item_cond*) cond)->argument_list());
1831
Item *fix= make_cond_for_info_schema(item, table);
1833
new_cond->argument_list()->push_back(fix);
1835
switch (new_cond->argument_list()->elements) {
1839
return new_cond->argument_list()->head();
1841
new_cond->quick_fix_field();
1847
Item_cond_or *new_cond=new Item_cond_or;
1850
List_iterator<Item> li(*((Item_cond*) cond)->argument_list());
1854
Item *fix=make_cond_for_info_schema(item, table);
1857
new_cond->argument_list()->push_back(fix);
1859
new_cond->quick_fix_field();
1860
new_cond->top_level_item();
1865
if (!uses_only_table_name_fields(cond, table))
1872
@brief Calculate lookup values(database name, table name)
1874
@details This function calculates lookup values(database name, table name)
1875
from 'WHERE' condition or wild values (for 'SHOW' commands only)
1876
from LEX struct and fill lookup_field_vals struct field
1879
@param[in] session thread handler
1880
@param[in] cond WHERE condition
1881
@param[in] tables I_S table
1882
@param[in, out] lookup_field_values Struct which holds lookup values
1886
1 error, there can be no matching records for the condition
1889
bool get_lookup_field_values(Session *session, COND *cond, TableList *tables,
1890
LOOKUP_FIELD_VALUES *lookup_field_values)
1892
LEX *lex= session->lex;
1893
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
1894
memset(lookup_field_values, 0, sizeof(LOOKUP_FIELD_VALUES));
1895
switch (lex->sql_command) {
1896
case SQLCOM_SHOW_DATABASES:
1899
lookup_field_values->db_value.str= (char*) wild;
1900
lookup_field_values->db_value.length= strlen(wild);
1901
lookup_field_values->wild_db_value= 1;
1904
case SQLCOM_SHOW_TABLES:
1905
case SQLCOM_SHOW_TABLE_STATUS:
1906
lookup_field_values->db_value.str= lex->select_lex.db;
1907
lookup_field_values->db_value.length=strlen(lex->select_lex.db);
1910
lookup_field_values->table_value.str= (char*)wild;
1911
lookup_field_values->table_value.length= strlen(wild);
1912
lookup_field_values->wild_table_value= 1;
1917
The "default" is for queries over I_S.
1918
All previous cases handle SHOW commands.
1920
return calc_lookup_values_from_cond(session, cond, tables, lookup_field_values);
1925
enum enum_schema_tables get_schema_table_idx(ST_SCHEMA_TABLE *schema_table)
1927
return (enum enum_schema_tables) (schema_table - &schema_tables[0]);
1932
Create db names list. Information schema name always is first in list
1936
session thread handler
1937
files list of db names
1939
idx_field_vals idx_field_vals->db_name contains db name or
1941
with_i_schema returns 1 if we added 'IS' name to list
1949
int make_db_list(Session *session, List<LEX_STRING> *files,
1950
LOOKUP_FIELD_VALUES *lookup_field_vals,
1951
bool *with_i_schema)
1953
LEX_STRING *i_s_name_copy= 0;
1954
i_s_name_copy= session->make_lex_string(i_s_name_copy,
1955
INFORMATION_SCHEMA_NAME.c_str(),
1956
INFORMATION_SCHEMA_NAME.length(), true);
1958
if (lookup_field_vals->wild_db_value)
1961
This part of code is only for SHOW DATABASES command.
1962
idx_field_vals->db_value can be 0 when we don't use
1963
LIKE clause (see also get_index_field_values() function)
1965
if (!lookup_field_vals->db_value.str ||
1966
!wild_case_compare(system_charset_info,
1967
INFORMATION_SCHEMA_NAME.c_str(),
1968
lookup_field_vals->db_value.str))
1971
if (files->push_back(i_s_name_copy))
1974
return (find_files(session, files, NULL, drizzle_data_home,
1975
lookup_field_vals->db_value.str, 1) != FIND_FILES_OK);
1980
If we have db lookup vaule we just add it to list and
1981
exit from the function
1983
if (lookup_field_vals->db_value.str)
1985
if (!my_strcasecmp(system_charset_info, INFORMATION_SCHEMA_NAME.c_str(),
1986
lookup_field_vals->db_value.str))
1989
if (files->push_back(i_s_name_copy))
1993
if (files->push_back(&lookup_field_vals->db_value))
1999
Create list of existing databases. It is used in case
2000
of select from information schema table
2002
if (files->push_back(i_s_name_copy))
2005
return (find_files(session, files, NULL,
2006
drizzle_data_home, NULL, 1) != FIND_FILES_OK);
2010
struct st_add_schema_table
2012
List<LEX_STRING> *files;
2017
static bool add_schema_table(Session *session, plugin_ref plugin,
2020
LEX_STRING *file_name= 0;
2021
st_add_schema_table *data= (st_add_schema_table *)p_data;
2022
List<LEX_STRING> *file_list= data->files;
2023
const char *wild= data->wild;
2024
ST_SCHEMA_TABLE *schema_table= plugin_data(plugin, ST_SCHEMA_TABLE *);
2026
if (schema_table->hidden)
2030
if (lower_case_table_names)
2032
if (wild_case_compare(files_charset_info,
2033
schema_table->table_name,
2037
else if (wild_compare(schema_table->table_name, wild, 0))
2041
if ((file_name= session->make_lex_string(file_name, schema_table->table_name,
2042
strlen(schema_table->table_name),
2044
!file_list->push_back(file_name))
2050
int schema_tables_add(Session *session, List<LEX_STRING> *files, const char *wild)
2052
LEX_STRING *file_name= 0;
2053
ST_SCHEMA_TABLE *tmp_schema_table= schema_tables;
2054
st_add_schema_table add_data;
2056
for (; tmp_schema_table->table_name; tmp_schema_table++)
2058
if (tmp_schema_table->hidden)
2062
if (lower_case_table_names)
2064
if (wild_case_compare(files_charset_info,
2065
tmp_schema_table->table_name,
2069
else if (wild_compare(tmp_schema_table->table_name, wild, 0))
2073
session->make_lex_string(file_name, tmp_schema_table->table_name,
2074
strlen(tmp_schema_table->table_name), true)) &&
2075
!files->push_back(file_name))
2080
add_data.files= files;
2081
add_data.wild= wild;
2082
if (plugin_foreach(session, add_schema_table,
2083
DRIZZLE_INFORMATION_SCHEMA_PLUGIN, &add_data))
2091
@brief Create table names list
2093
@details The function creates the list of table names in
2096
@param[in] session thread handler
2097
@param[in] table_names List of table names in database
2098
@param[in] lex pointer to LEX struct
2099
@param[in] lookup_field_vals pointer to LOOKUP_FIELD_VALUE struct
2100
@param[in] with_i_schema true means that we add I_S tables to list
2101
@param[in] db_name database name
2103
@return Operation status
2105
@retval 1 fatal error
2106
@retval 2 Not fatal error; Safe to ignore this file list
2110
make_table_name_list(Session *session, List<LEX_STRING> *table_names, LEX *lex,
2111
LOOKUP_FIELD_VALUES *lookup_field_vals,
2112
bool with_i_schema, LEX_STRING *db_name)
2114
char path[FN_REFLEN];
2115
build_table_filename(path, sizeof(path), db_name->str, "", "", 0);
2116
if (!lookup_field_vals->wild_table_value &&
2117
lookup_field_vals->table_value.str)
2121
if (find_schema_table(session, lookup_field_vals->table_value.str))
2123
if (table_names->push_back(&lookup_field_vals->table_value))
2129
if (table_names->push_back(&lookup_field_vals->table_value))
2136
This call will add all matching the wildcards (if specified) IS tables
2140
return (schema_tables_add(session, table_names,
2141
lookup_field_vals->table_value.str));
2143
find_files_result res= find_files(session, table_names, db_name->str, path,
2144
lookup_field_vals->table_value.str, 0);
2145
if (res != FIND_FILES_OK)
2148
Downgrade errors about problems with database directory to
2149
warnings if this is not a 'SHOW' command. Another thread
2150
may have dropped database, and we may still have a name
2153
if (res == FIND_FILES_DIR)
2155
if (lex->sql_command != SQLCOM_SELECT)
2157
session->clear_error();
2167
@brief Fill I_S table for SHOW COLUMNS|INDEX commands
2169
@param[in] session thread handler
2170
@param[in] tables TableList for I_S table
2171
@param[in] schema_table pointer to I_S structure
2172
@param[in] open_tables_state_backup pointer to Open_tables_state object
2173
which is used to save|restore original
2174
status of variables related to
2177
@return Operation status
2183
fill_schema_show_cols_or_idxs(Session *session, TableList *tables,
2184
ST_SCHEMA_TABLE *schema_table,
2185
Open_tables_state *open_tables_state_backup)
2187
LEX *lex= session->lex;
2189
LEX_STRING tmp_lex_string, tmp_lex_string1, *db_name, *table_name;
2190
enum_sql_command save_sql_command= lex->sql_command;
2191
TableList *show_table_list= (TableList*) tables->schema_select_lex->
2193
Table *table= tables->table;
2196
lex->all_selects_list= tables->schema_select_lex;
2198
Restore session->temporary_tables to be able to process
2199
temporary tables(only for 'show index' & 'show columns').
2200
This should be changed when processing of temporary tables for
2201
I_S tables will be done.
2203
session->temporary_tables= open_tables_state_backup->temporary_tables;
2205
Let us set fake sql_command so views won't try to merge
2206
themselves into main statement. If we don't do this,
2207
SELECT * from information_schema.xxxx will cause problems.
2208
SQLCOM_SHOW_FIELDS is used because it satisfies 'only_view_structure()'
2210
lex->sql_command= SQLCOM_SHOW_FIELDS;
2211
res= open_normal_and_derived_tables(session, show_table_list,
2212
DRIZZLE_LOCK_IGNORE_FLUSH);
2213
lex->sql_command= save_sql_command;
2215
get_all_tables() returns 1 on failure and 0 on success thus
2216
return only these and not the result code of ::process_table()
2218
We should use show_table_list->alias instead of
2219
show_table_list->table_name because table_name
2220
could be changed during opening of I_S tables. It's safe
2221
to use alias because alias contains original table name
2222
in this case(this part of code is used only for
2223
'show columns' & 'show statistics' commands).
2225
table_name= session->make_lex_string(&tmp_lex_string1, show_table_list->alias,
2226
strlen(show_table_list->alias), false);
2227
db_name= session->make_lex_string(&tmp_lex_string, show_table_list->db,
2228
show_table_list->db_length, false);
2231
error= test(schema_table->process_table(session, show_table_list,
2232
table, res, db_name,
2234
session->temporary_tables= 0;
2235
close_tables_for_reopen(session, &show_table_list);
2241
@brief Fill I_S table for SHOW Table NAMES commands
2243
@param[in] session thread handler
2244
@param[in] table Table struct for I_S table
2245
@param[in] db_name database name
2246
@param[in] table_name table name
2247
@param[in] with_i_schema I_S table if true
2249
@return Operation status
2254
static int fill_schema_table_names(Session *session, Table *table,
2255
LEX_STRING *db_name, LEX_STRING *table_name,
2260
table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"),
2261
system_charset_info);
2265
char path[FN_REFLEN];
2266
(void) build_table_filename(path, sizeof(path), db_name->str,
2267
table_name->str, reg_ext, 0);
2269
table->field[3]->store(STRING_WITH_LEN("BASE Table"),
2270
system_charset_info);
2272
if (session->is_error() && session->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2274
session->clear_error();
2278
if (schema_table_store_record(session, table))
2285
@brief Get open table method
2287
@details The function calculates the method which will be used
2289
SKIP_OPEN_TABLE - do not open table
2290
OPEN_FRM_ONLY - open FRM file only
2291
OPEN_FULL_TABLE - open FRM, data, index files
2292
@param[in] tables I_S table table_list
2293
@param[in] schema_table I_S table struct
2294
@param[in] schema_table_idx I_S table index
2296
@return return a set of flags
2297
@retval SKIP_OPEN_TABLE | OPEN_FRM_ONLY | OPEN_FULL_TABLE
2300
static uint32_t get_table_open_method(TableList *tables,
2301
ST_SCHEMA_TABLE *schema_table,
2302
enum enum_schema_tables)
2305
determine which method will be used for table opening
2307
if (schema_table->i_s_requested_object & OPTIMIZE_I_S_TABLE)
2309
Field **ptr, *field;
2310
int table_open_method= 0, field_indx= 0;
2311
for (ptr=tables->table->field; (field= *ptr) ; ptr++)
2313
if (bitmap_is_set(tables->table->read_set, field->field_index))
2314
table_open_method|= schema_table->fields_info[field_indx].open_method;
2317
return table_open_method;
2319
/* I_S tables which use get_all_tables but can not be optimized */
2320
return (uint) OPEN_FULL_TABLE;
2325
@brief Fill I_S table with data from FRM file only
2327
@param[in] session thread handler
2328
@param[in] table Table struct for I_S table
2329
@param[in] schema_table I_S table struct
2330
@param[in] db_name database name
2331
@param[in] table_name table name
2332
@param[in] schema_table_idx I_S table index
2334
@return Operation status
2335
@retval 0 Table is processed and we can continue
2337
@retval 1 It's view and we have to use
2338
open_tables function for this table
2341
static int fill_schema_table_from_frm(Session *session,TableList *tables,
2342
ST_SCHEMA_TABLE *schema_table,
2343
LEX_STRING *db_name,
2344
LEX_STRING *table_name,
2345
enum enum_schema_tables)
2347
Table *table= tables->table;
2350
TableList table_list;
2353
char key[MAX_DBKEY_LENGTH];
2354
uint32_t key_length;
2356
memset(&table_list, 0, sizeof(TableList));
2357
memset(&tbl, 0, sizeof(Table));
2359
table_list.table_name= table_name->str;
2360
table_list.db= db_name->str;
2362
key_length= create_table_def_key(session, key, &table_list, 0);
2363
pthread_mutex_lock(&LOCK_open);
2364
share= get_table_share(session, &table_list, key,
2365
key_length, 0, &error);
2374
table_list.table= &tbl;
2375
res= schema_table->process_table(session, &table_list, table,
2376
res, db_name, table_name);
2379
release_table_share(share, RELEASE_NORMAL);
2382
pthread_mutex_unlock(&LOCK_open);
2383
session->clear_error();
2390
@brief Fill I_S tables whose data are retrieved
2391
from frm files and storage engine
2393
@details The information schema tables are internally represented as
2394
temporary tables that are filled at query execution time.
2395
Those I_S tables whose data are retrieved
2396
from frm files and storage engine are filled by the function
2399
@param[in] session thread handler
2400
@param[in] tables I_S table
2401
@param[in] cond 'WHERE' condition
2403
@return Operation status
2408
int get_all_tables(Session *session, TableList *tables, COND *cond)
2410
LEX *lex= session->lex;
2411
Table *table= tables->table;
2412
SELECT_LEX *old_all_select_lex= lex->all_selects_list;
2413
enum_sql_command save_sql_command= lex->sql_command;
2414
SELECT_LEX *lsel= tables->schema_select_lex;
2415
ST_SCHEMA_TABLE *schema_table= tables->schema_table;
2417
LOOKUP_FIELD_VALUES lookup_field_vals;
2418
LEX_STRING *db_name, *table_name;
2420
enum enum_schema_tables schema_table_idx;
2421
List<LEX_STRING> db_names;
2422
List_iterator_fast<LEX_STRING> it(db_names);
2423
COND *partial_cond= 0;
2424
uint32_t derived_tables= lex->derived_tables;
2426
Open_tables_state open_tables_state_backup;
2427
Query_tables_list query_tables_list_backup;
2428
uint32_t table_open_method;
2429
bool old_value= session->no_warnings_for_error;
2432
We should not introduce deadlocks even if we already have some
2433
tables open and locked, since we won't lock tables which we will
2434
open and will ignore possible name-locks for these tables.
2436
session->reset_n_backup_open_tables_state(&open_tables_state_backup);
2438
schema_table_idx= get_schema_table_idx(schema_table);
2439
tables->table_open_method= table_open_method=
2440
get_table_open_method(tables, schema_table, schema_table_idx);
2442
this branch processes SHOW FIELDS, SHOW INDEXES commands.
2443
see sql_parse.cc, prepare_schema_table() function where
2444
this values are initialized
2446
if (lsel && lsel->table_list.first)
2448
error= fill_schema_show_cols_or_idxs(session, tables, schema_table,
2449
&open_tables_state_backup);
2453
if (get_lookup_field_values(session, cond, tables, &lookup_field_vals))
2459
if (!lookup_field_vals.wild_db_value && !lookup_field_vals.wild_table_value)
2462
if lookup value is empty string then
2463
it's impossible table name or db name
2465
if ((lookup_field_vals.db_value.str && !lookup_field_vals.db_value.str[0]) ||
2466
(lookup_field_vals.table_value.str && !lookup_field_vals.table_value.str[0]))
2473
if (lookup_field_vals.db_value.length &&
2474
!lookup_field_vals.wild_db_value)
2475
tables->has_db_lookup_value= true;
2476
if (lookup_field_vals.table_value.length &&
2477
!lookup_field_vals.wild_table_value)
2478
tables->has_table_lookup_value= true;
2480
if (tables->has_db_lookup_value && tables->has_table_lookup_value)
2483
partial_cond= make_cond_for_info_schema(cond, tables);
2487
/* EXPLAIN SELECT */
2492
if (make_db_list(session, &db_names, &lookup_field_vals, &with_i_schema))
2494
it.rewind(); /* To get access to new elements in basis list */
2495
while ((db_name= it++))
2498
session->no_warnings_for_error= 1;
2499
List<LEX_STRING> table_names;
2500
int res= make_table_name_list(session, &table_names, lex,
2502
with_i_schema, db_name);
2503
if (res == 2) /* Not fatal error, continue */
2508
List_iterator_fast<LEX_STRING> it_files(table_names);
2509
while ((table_name= it_files++))
2511
restore_record(table, s->default_values);
2512
table->field[schema_table->idx_field1]->
2513
store(db_name->str, db_name->length, system_charset_info);
2514
table->field[schema_table->idx_field2]->
2515
store(table_name->str, table_name->length, system_charset_info);
2517
if (!partial_cond || partial_cond->val_int())
2520
If table is I_S.tables and open_table_method is 0 (eg SKIP_OPEN)
2521
we can skip table opening and we don't have lookup value for
2522
table name or lookup value is wild string(table name list is
2523
already created by make_table_name_list() function).
2525
if (!table_open_method && schema_table_idx == SCH_TABLES &&
2526
(!lookup_field_vals.table_value.length ||
2527
lookup_field_vals.wild_table_value))
2529
if (schema_table_store_record(session, table))
2530
goto err; /* Out of space in temporary table */
2534
/* SHOW Table NAMES command */
2535
if (schema_table_idx == SCH_TABLE_NAMES)
2537
if (fill_schema_table_names(session, tables->table, db_name,
2538
table_name, with_i_schema))
2543
if (!(table_open_method & ~OPEN_FRM_ONLY) &&
2546
if (!fill_schema_table_from_frm(session, tables, schema_table, db_name,
2547
table_name, schema_table_idx))
2552
LEX_STRING tmp_lex_string, orig_db_name;
2554
Set the parent lex of 'sel' because it is needed by
2555
sel.init_query() which is called inside make_table_list.
2557
session->no_warnings_for_error= 1;
2558
sel.parent_lex= lex;
2559
/* db_name can be changed in make_table_list() func */
2560
if (!session->make_lex_string(&orig_db_name, db_name->str,
2561
db_name->length, false))
2563
if (make_table_list(session, &sel, db_name, table_name))
2565
TableList *show_table_list= (TableList*) sel.table_list.first;
2566
lex->all_selects_list= &sel;
2567
lex->derived_tables= 0;
2568
lex->sql_command= SQLCOM_SHOW_FIELDS;
2569
show_table_list->i_s_requested_object=
2570
schema_table->i_s_requested_object;
2571
res= open_normal_and_derived_tables(session, show_table_list,
2572
DRIZZLE_LOCK_IGNORE_FLUSH);
2573
lex->sql_command= save_sql_command;
2575
XXX: show_table_list has a flag i_is_requested,
2576
and when it's set, open_normal_and_derived_tables()
2577
can return an error without setting an error message
2578
in Session, which is a hack. This is why we have to
2579
check for res, then for session->is_error() only then
2580
for session->main_da.sql_errno().
2582
if (res && session->is_error() &&
2583
session->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2586
Hide error for not existing table.
2587
This error can occur for example when we use
2588
where condition with db name and table name and this
2589
table does not exist.
2592
session->clear_error();
2597
We should use show_table_list->alias instead of
2598
show_table_list->table_name because table_name
2599
could be changed during opening of I_S tables. It's safe
2600
to use alias because alias contains original table name
2603
session->make_lex_string(&tmp_lex_string, show_table_list->alias,
2604
strlen(show_table_list->alias), false);
2605
res= schema_table->process_table(session, show_table_list, table,
2608
close_tables_for_reopen(session, &show_table_list);
2610
assert(!lex->query_tables_own_last);
2617
If we have information schema its always the first table and only
2618
the first table. Reset for other tables.
2626
session->restore_backup_open_tables_state(&open_tables_state_backup);
2627
lex->derived_tables= derived_tables;
2628
lex->all_selects_list= old_all_select_lex;
2629
lex->sql_command= save_sql_command;
2630
session->no_warnings_for_error= old_value;
2635
bool store_schema_shemata(Session* session, Table *table, LEX_STRING *db_name,
2636
const CHARSET_INFO * const cs)
2638
restore_record(table, s->default_values);
2639
table->field[1]->store(db_name->str, db_name->length, system_charset_info);
2640
table->field[2]->store(cs->csname, strlen(cs->csname), system_charset_info);
2641
table->field[3]->store(cs->name, strlen(cs->name), system_charset_info);
2642
return schema_table_store_record(session, table);
2646
int fill_schema_schemata(Session *session, TableList *tables, COND *cond)
2649
TODO: fill_schema_shemata() is called when new client is connected.
2650
Returning error status in this case leads to client hangup.
2653
LOOKUP_FIELD_VALUES lookup_field_vals;
2654
List<LEX_STRING> db_names;
2655
LEX_STRING *db_name;
2657
HA_CREATE_INFO create;
2658
Table *table= tables->table;
2660
if (get_lookup_field_values(session, cond, tables, &lookup_field_vals))
2662
if (make_db_list(session, &db_names, &lookup_field_vals,
2667
If we have lookup db value we should check that the database exists
2669
if(lookup_field_vals.db_value.str && !lookup_field_vals.wild_db_value &&
2672
char path[FN_REFLEN+16];
2674
struct stat stat_info;
2675
if (!lookup_field_vals.db_value.str[0])
2677
path_len= build_table_filename(path, sizeof(path),
2678
lookup_field_vals.db_value.str, "", "", 0);
2679
path[path_len-1]= 0;
2680
if (stat(path,&stat_info))
2684
List_iterator_fast<LEX_STRING> it(db_names);
2685
while ((db_name=it++))
2687
if (with_i_schema) // information schema name is always first in list
2689
if (store_schema_shemata(session, table, db_name,
2690
system_charset_info))
2696
load_db_opt_by_name(session, db_name->str, &create);
2697
if (store_schema_shemata(session, table, db_name,
2698
create.default_table_charset))
2706
static int get_schema_tables_record(Session *session, TableList *tables,
2707
Table *table, bool res,
2708
LEX_STRING *db_name,
2709
LEX_STRING *table_name)
2711
const char *tmp_buff;
2713
const CHARSET_INFO * const cs= system_charset_info;
2715
restore_record(table, s->default_values);
2716
table->field[1]->store(db_name->str, db_name->length, cs);
2717
table->field[2]->store(table_name->str, table_name->length, cs);
2721
there was errors during opening tables
2723
const char *error= session->is_error() ? session->main_da.message() : "";
2724
if (tables->schema_table)
2725
table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"), cs);
2727
table->field[3]->store(STRING_WITH_LEN("BASE Table"), cs);
2728
table->field[20]->store(error, strlen(error), cs);
2729
session->clear_error();
2733
char option_buff[400],*ptr;
2734
Table *show_table= tables->table;
2735
TABLE_SHARE *share= show_table->s;
2736
handler *file= show_table->file;
2737
handlerton *tmp_db_type= share->db_type();
2738
if (share->tmp_table == SYSTEM_TMP_TABLE)
2739
table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"), cs);
2740
else if (share->tmp_table)
2741
table->field[3]->store(STRING_WITH_LEN("LOCAL TEMPORARY"), cs);
2743
table->field[3]->store(STRING_WITH_LEN("BASE Table"), cs);
2745
for (int i= 4; i < 20; i++)
2747
if (i == 7 || (i > 12 && i < 17) || i == 18)
2749
table->field[i]->set_notnull();
2751
tmp_buff= (char *) ha_resolve_storage_engine_name(tmp_db_type);
2752
table->field[4]->store(tmp_buff, strlen(tmp_buff), cs);
2753
table->field[5]->store((int64_t) 0, true);
2756
if (share->min_rows)
2758
ptr= strcpy(ptr," min_rows=")+10;
2759
ptr= int64_t10_to_str(share->min_rows,ptr,10);
2761
if (share->max_rows)
2763
ptr= strcpy(ptr," max_rows=")+10;
2764
ptr= int64_t10_to_str(share->max_rows,ptr,10);
2766
if (share->avg_row_length)
2768
ptr= strcpy(ptr," avg_row_length=")+16;
2769
ptr= int64_t10_to_str(share->avg_row_length,ptr,10);
2771
if (share->db_create_options & HA_OPTION_PACK_KEYS)
2772
ptr= strcpy(ptr," pack_keys=1")+12;
2773
if (share->db_create_options & HA_OPTION_NO_PACK_KEYS)
2774
ptr= strcpy(ptr," pack_keys=0")+12;
2775
/* We use CHECKSUM, instead of TABLE_CHECKSUM, for backward compability */
2776
if (share->db_create_options & HA_OPTION_CHECKSUM)
2777
ptr= strcpy(ptr," checksum=1")+11;
2778
if (share->page_checksum != HA_CHOICE_UNDEF)
2779
ptr+= sprintf(ptr, " page_checksum=%s",
2780
ha_choice_values[(uint) share->page_checksum]);
2781
if (share->db_create_options & HA_OPTION_DELAY_KEY_WRITE)
2782
ptr= strcpy(ptr," delay_key_write=1")+18;
2783
if (share->row_type != ROW_TYPE_DEFAULT)
2784
ptr+= sprintf(ptr, " row_format=%s", ha_row_type[(uint)share->row_type]);
2785
if (share->block_size)
2787
ptr= strcpy(ptr, " block_size=")+12;
2788
ptr= int64_t10_to_str(share->block_size, ptr, 10);
2791
if (share->transactional != HA_CHOICE_UNDEF)
2793
ptr+= sprintf(ptr, " TRANSACTIONAL=%s",
2794
(share->transactional == HA_CHOICE_YES ? "1" : "0"));
2796
if (share->transactional != HA_CHOICE_UNDEF)
2797
ptr+= sprintf(ptr, " transactional=%s",
2798
ha_choice_values[(uint) share->transactional]);
2799
table->field[19]->store(option_buff+1,
2800
(ptr == option_buff ? 0 :
2801
(uint) (ptr-option_buff)-1), cs);
2803
tmp_buff= (share->table_charset ?
2804
share->table_charset->name : "default");
2805
table->field[17]->store(tmp_buff, strlen(tmp_buff), cs);
2807
if (share->comment.str)
2808
table->field[20]->store(share->comment.str, share->comment.length, cs);
2812
file->info(HA_STATUS_VARIABLE | HA_STATUS_TIME | HA_STATUS_AUTO |
2814
enum row_type row_type = file->get_row_type();
2816
case ROW_TYPE_NOT_USED:
2817
case ROW_TYPE_DEFAULT:
2818
tmp_buff= ((share->db_options_in_use &
2819
HA_OPTION_COMPRESS_RECORD) ? "Compressed" :
2820
(share->db_options_in_use & HA_OPTION_PACK_RECORD) ?
2821
"Dynamic" : "Fixed");
2823
case ROW_TYPE_FIXED:
2826
case ROW_TYPE_DYNAMIC:
2827
tmp_buff= "Dynamic";
2829
case ROW_TYPE_COMPRESSED:
2830
tmp_buff= "Compressed";
2832
case ROW_TYPE_REDUNDANT:
2833
tmp_buff= "Redundant";
2835
case ROW_TYPE_COMPACT:
2836
tmp_buff= "Compact";
2842
table->field[6]->store(tmp_buff, strlen(tmp_buff), cs);
2843
if (!tables->schema_table)
2845
table->field[7]->store((int64_t) file->stats.records, true);
2846
table->field[7]->set_notnull();
2848
table->field[8]->store((int64_t) file->stats.mean_rec_length, true);
2849
table->field[9]->store((int64_t) file->stats.data_file_length, true);
2850
if (file->stats.max_data_file_length)
2852
table->field[10]->store((int64_t) file->stats.max_data_file_length,
2855
table->field[11]->store((int64_t) file->stats.index_file_length, true);
2856
table->field[12]->store((int64_t) file->stats.delete_length, true);
2857
if (show_table->found_next_number_field)
2859
table->field[13]->store((int64_t) file->stats.auto_increment_value,
2861
table->field[13]->set_notnull();
2863
if (file->stats.create_time)
2865
session->variables.time_zone->gmt_sec_to_TIME(&time,
2866
(time_t) file->stats.create_time);
2867
table->field[14]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2868
table->field[14]->set_notnull();
2870
if (file->stats.update_time)
2872
session->variables.time_zone->gmt_sec_to_TIME(&time,
2873
(time_t) file->stats.update_time);
2874
table->field[15]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2875
table->field[15]->set_notnull();
2877
if (file->stats.check_time)
2879
session->variables.time_zone->gmt_sec_to_TIME(&time,
2880
(time_t) file->stats.check_time);
2881
table->field[16]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2882
table->field[16]->set_notnull();
2884
if (file->ha_table_flags() & (ulong) HA_HAS_CHECKSUM)
2886
table->field[18]->store((int64_t) file->checksum(), true);
2887
table->field[18]->set_notnull();
2891
return(schema_table_store_record(session, table));
2896
@brief Store field characteristics into appropriate I_S table columns
2898
@param[in] table I_S table
2899
@param[in] field processed field
2900
@param[in] cs I_S table charset
2901
@param[in] offset offset from beginning of table
2902
to DATE_TYPE column in I_S table
2907
void store_column_type(Table *table, Field *field, const CHARSET_INFO * const cs,
2911
int decimals, field_length;
2912
const char *tmp_buff;
2913
char column_type_buff[MAX_FIELD_WIDTH];
2914
String column_type(column_type_buff, sizeof(column_type_buff), cs);
2916
field->sql_type(column_type);
2917
/* DTD_IDENTIFIER column */
2918
table->field[offset + 7]->store(column_type.ptr(), column_type.length(), cs);
2919
table->field[offset + 7]->set_notnull();
2920
tmp_buff= strchr(column_type.ptr(), '(');
2921
/* DATA_TYPE column */
2922
table->field[offset]->store(column_type.ptr(),
2923
(tmp_buff ? tmp_buff - column_type.ptr() :
2924
column_type.length()), cs);
2925
is_blob= (field->type() == DRIZZLE_TYPE_BLOB);
2926
if (field->has_charset() || is_blob ||
2927
field->real_type() == DRIZZLE_TYPE_VARCHAR) // For varbinary type
2929
uint32_t octet_max_length= field->max_display_length();
2930
if (is_blob && octet_max_length != (uint32_t) 4294967295U)
2931
octet_max_length /= field->charset()->mbmaxlen;
2932
int64_t char_max_len= is_blob ?
2933
(int64_t) octet_max_length / field->charset()->mbminlen :
2934
(int64_t) octet_max_length / field->charset()->mbmaxlen;
2935
/* CHARACTER_MAXIMUM_LENGTH column*/
2936
table->field[offset + 1]->store(char_max_len, true);
2937
table->field[offset + 1]->set_notnull();
2938
/* CHARACTER_OCTET_LENGTH column */
2939
table->field[offset + 2]->store((int64_t) octet_max_length, true);
2940
table->field[offset + 2]->set_notnull();
2944
Calculate field_length and decimals.
2945
They are set to -1 if they should not be set (we should return NULL)
2948
decimals= field->decimals();
2949
switch (field->type()) {
2950
case DRIZZLE_TYPE_NEWDECIMAL:
2951
field_length= ((Field_new_decimal*) field)->precision;
2953
case DRIZZLE_TYPE_LONG:
2954
case DRIZZLE_TYPE_LONGLONG:
2955
field_length= field->max_display_length() - 1;
2957
case DRIZZLE_TYPE_DOUBLE:
2958
field_length= field->field_length;
2959
if (decimals == NOT_FIXED_DEC)
2960
decimals= -1; // return NULL
2963
field_length= decimals= -1;
2967
/* NUMERIC_PRECISION column */
2968
if (field_length >= 0)
2970
table->field[offset + 3]->store((int64_t) field_length, true);
2971
table->field[offset + 3]->set_notnull();
2973
/* NUMERIC_SCALE column */
2976
table->field[offset + 4]->store((int64_t) decimals, true);
2977
table->field[offset + 4]->set_notnull();
2979
if (field->has_charset())
2981
/* CHARACTER_SET_NAME column*/
2982
tmp_buff= field->charset()->csname;
2983
table->field[offset + 5]->store(tmp_buff, strlen(tmp_buff), cs);
2984
table->field[offset + 5]->set_notnull();
2985
/* COLLATION_NAME column */
2986
tmp_buff= field->charset()->name;
2987
table->field[offset + 6]->store(tmp_buff, strlen(tmp_buff), cs);
2988
table->field[offset + 6]->set_notnull();
2993
static int get_schema_column_record(Session *session, TableList *tables,
2994
Table *table, bool res,
2995
LEX_STRING *db_name,
2996
LEX_STRING *table_name)
2998
LEX *lex= session->lex;
2999
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3000
const CHARSET_INFO * const cs= system_charset_info;
3002
TABLE_SHARE *show_table_share;
3003
Field **ptr, *field, *timestamp_field;
3008
if (lex->sql_command != SQLCOM_SHOW_FIELDS)
3011
I.e. we are in SELECT FROM INFORMATION_SCHEMA.COLUMS
3012
rather than in SHOW COLUMNS
3014
if (session->is_error())
3015
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3016
session->main_da.sql_errno(), session->main_da.message());
3017
session->clear_error();
3023
show_table= tables->table;
3024
show_table_share= show_table->s;
3027
if (tables->schema_table)
3029
ptr= show_table->field;
3030
timestamp_field= show_table->timestamp_field;
3031
show_table->use_all_columns(); // Required for default
3035
ptr= show_table_share->field;
3036
timestamp_field= show_table_share->timestamp_field;
3038
read_set may be inited in case of
3041
if (!show_table->read_set)
3043
/* to satisfy 'field->val_str' ASSERTs */
3044
unsigned char *bitmaps;
3045
uint32_t bitmap_size= show_table_share->column_bitmap_size;
3046
if (!(bitmaps= (unsigned char*) alloc_root(session->mem_root, bitmap_size)))
3048
bitmap_init(&show_table->def_read_set,
3049
(my_bitmap_map*) bitmaps, show_table_share->fields, false);
3050
bitmap_set_all(&show_table->def_read_set);
3051
show_table->read_set= &show_table->def_read_set;
3053
bitmap_set_all(show_table->read_set);
3056
for (; (field= *ptr) ; ptr++)
3059
char tmp[MAX_FIELD_WIDTH];
3060
String type(tmp,sizeof(tmp), system_charset_info);
3063
/* to satisfy 'field->val_str' ASSERTs */
3064
field->table= show_table;
3065
show_table->in_use= session;
3067
if (wild && wild[0] &&
3068
wild_case_compare(system_charset_info, field->field_name,wild))
3072
/* Get default row, with all NULL fields set to NULL */
3073
restore_record(table, s->default_values);
3075
table->field[1]->store(db_name->str, db_name->length, cs);
3076
table->field[2]->store(table_name->str, table_name->length, cs);
3077
table->field[3]->store(field->field_name, strlen(field->field_name),
3079
table->field[4]->store((int64_t) count, true);
3081
if (get_field_default_value(session, timestamp_field, field, &type, 0))
3083
table->field[5]->store(type.ptr(), type.length(), cs);
3084
table->field[5]->set_notnull();
3086
pos=(unsigned char*) ((field->flags & NOT_NULL_FLAG) ? "NO" : "YES");
3087
table->field[6]->store((const char*) pos,
3088
strlen((const char*) pos), cs);
3089
store_column_type(table, field, cs, 7);
3091
pos=(unsigned char*) ((field->flags & PRI_KEY_FLAG) ? "PRI" :
3092
(field->flags & UNIQUE_KEY_FLAG) ? "UNI" :
3093
(field->flags & MULTIPLE_KEY_FLAG) ? "MUL":"");
3094
table->field[15]->store((const char*) pos,
3095
strlen((const char*) pos), cs);
3098
if (field->unireg_check == Field::NEXT_NUMBER)
3099
table->field[16]->store(STRING_WITH_LEN("auto_increment"), cs);
3100
if (timestamp_field == field &&
3101
field->unireg_check != Field::TIMESTAMP_DN_FIELD)
3102
table->field[16]->store(STRING_WITH_LEN("on update CURRENT_TIMESTAMP"),
3104
if (field->vcol_info)
3105
table->field[16]->store(STRING_WITH_LEN("VIRTUAL"), cs);
3106
table->field[18]->store(field->comment.str, field->comment.length, cs);
3108
enum column_format_type column_format= (enum column_format_type)
3109
((field->flags >> COLUMN_FORMAT_FLAGS) & COLUMN_FORMAT_MASK);
3110
pos=(unsigned char*)"Default";
3111
table->field[19]->store((const char*) pos,
3112
strlen((const char*) pos), cs);
3113
pos=(unsigned char*)(column_format == COLUMN_FORMAT_TYPE_DEFAULT ? "Default" :
3114
column_format == COLUMN_FORMAT_TYPE_FIXED ? "Fixed" :
3116
table->field[20]->store((const char*) pos,
3117
strlen((const char*) pos), cs);
3119
if (schema_table_store_record(session, table))
3127
int fill_schema_charsets(Session *session, TableList *tables, COND *)
3130
const char *wild= session->lex->wild ? session->lex->wild->ptr() : NULL;
3131
Table *table= tables->table;
3132
const CHARSET_INFO * const scs= system_charset_info;
3134
for (cs= all_charsets ; cs < all_charsets+255 ; cs++)
3136
const CHARSET_INFO * const tmp_cs= cs[0];
3137
if (tmp_cs && (tmp_cs->state & MY_CS_PRIMARY) &&
3138
(tmp_cs->state & MY_CS_AVAILABLE) &&
3139
!(tmp_cs->state & MY_CS_HIDDEN) &&
3140
!(wild && wild[0] &&
3141
wild_case_compare(scs, tmp_cs->csname,wild)))
3143
const char *comment;
3144
restore_record(table, s->default_values);
3145
table->field[0]->store(tmp_cs->csname, strlen(tmp_cs->csname), scs);
3146
table->field[1]->store(tmp_cs->name, strlen(tmp_cs->name), scs);
3147
comment= tmp_cs->comment ? tmp_cs->comment : "";
3148
table->field[2]->store(comment, strlen(comment), scs);
3149
table->field[3]->store((int64_t) tmp_cs->mbmaxlen, true);
3150
if (schema_table_store_record(session, table))
3158
int fill_schema_collation(Session *session, TableList *tables, COND *)
3161
const char *wild= session->lex->wild ? session->lex->wild->ptr() : NULL;
3162
Table *table= tables->table;
3163
const CHARSET_INFO * const scs= system_charset_info;
3164
for (cs= all_charsets ; cs < all_charsets+255 ; cs++ )
3167
const CHARSET_INFO *tmp_cs= cs[0];
3168
if (!tmp_cs || !(tmp_cs->state & MY_CS_AVAILABLE) ||
3169
(tmp_cs->state & MY_CS_HIDDEN) ||
3170
!(tmp_cs->state & MY_CS_PRIMARY))
3172
for (cl= all_charsets; cl < all_charsets+255 ;cl ++)
3174
const CHARSET_INFO *tmp_cl= cl[0];
3175
if (!tmp_cl || !(tmp_cl->state & MY_CS_AVAILABLE) ||
3176
!my_charset_same(tmp_cs, tmp_cl))
3178
if (!(wild && wild[0] &&
3179
wild_case_compare(scs, tmp_cl->name,wild)))
3181
const char *tmp_buff;
3182
restore_record(table, s->default_values);
3183
table->field[0]->store(tmp_cl->name, strlen(tmp_cl->name), scs);
3184
table->field[1]->store(tmp_cl->csname , strlen(tmp_cl->csname), scs);
3185
table->field[2]->store((int64_t) tmp_cl->number, true);
3186
tmp_buff= (tmp_cl->state & MY_CS_PRIMARY) ? "Yes" : "";
3187
table->field[3]->store(tmp_buff, strlen(tmp_buff), scs);
3188
tmp_buff= (tmp_cl->state & MY_CS_COMPILED)? "Yes" : "";
3189
table->field[4]->store(tmp_buff, strlen(tmp_buff), scs);
3190
table->field[5]->store((int64_t) tmp_cl->strxfrm_multiply, true);
3191
if (schema_table_store_record(session, table))
3200
int fill_schema_coll_charset_app(Session *session, TableList *tables, COND *)
3203
Table *table= tables->table;
3204
const CHARSET_INFO * const scs= system_charset_info;
3205
for (cs= all_charsets ; cs < all_charsets+255 ; cs++ )
3208
const CHARSET_INFO *tmp_cs= cs[0];
3209
if (!tmp_cs || !(tmp_cs->state & MY_CS_AVAILABLE) ||
3210
!(tmp_cs->state & MY_CS_PRIMARY))
3212
for (cl= all_charsets; cl < all_charsets+255 ;cl ++)
3214
const CHARSET_INFO *tmp_cl= cl[0];
3215
if (!tmp_cl || !(tmp_cl->state & MY_CS_AVAILABLE) ||
3216
!my_charset_same(tmp_cs,tmp_cl))
3218
restore_record(table, s->default_values);
3219
table->field[0]->store(tmp_cl->name, strlen(tmp_cl->name), scs);
3220
table->field[1]->store(tmp_cl->csname , strlen(tmp_cl->csname), scs);
3221
if (schema_table_store_record(session, table))
3229
static int get_schema_stat_record(Session *session, TableList *tables,
3230
Table *table, bool res,
3231
LEX_STRING *db_name,
3232
LEX_STRING *table_name)
3234
const CHARSET_INFO * const cs= system_charset_info;
3237
if (session->lex->sql_command != SQLCOM_SHOW_KEYS)
3240
I.e. we are in SELECT FROM INFORMATION_SCHEMA.STATISTICS
3241
rather than in SHOW KEYS
3243
if (session->is_error())
3244
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3245
session->main_da.sql_errno(), session->main_da.message());
3246
session->clear_error();
3253
Table *show_table= tables->table;
3254
KEY *key_info=show_table->s->key_info;
3255
if (show_table->file)
3256
show_table->file->info(HA_STATUS_VARIABLE |
3259
for (uint32_t i=0 ; i < show_table->s->keys ; i++,key_info++)
3261
KEY_PART_INFO *key_part= key_info->key_part;
3263
for (uint32_t j=0 ; j < key_info->key_parts ; j++,key_part++)
3265
restore_record(table, s->default_values);
3266
table->field[1]->store(db_name->str, db_name->length, cs);
3267
table->field[2]->store(table_name->str, table_name->length, cs);
3268
table->field[3]->store((int64_t) ((key_info->flags &
3269
HA_NOSAME) ? 0 : 1), true);
3270
table->field[4]->store(db_name->str, db_name->length, cs);
3271
table->field[5]->store(key_info->name, strlen(key_info->name), cs);
3272
table->field[6]->store((int64_t) (j+1), true);
3273
str=(key_part->field ? key_part->field->field_name :
3275
table->field[7]->store(str, strlen(str), cs);
3276
if (show_table->file)
3278
if (show_table->file->index_flags(i, j, 0) & HA_READ_ORDER)
3280
table->field[8]->store(((key_part->key_part_flag &
3283
table->field[8]->set_notnull();
3285
KEY *key=show_table->key_info+i;
3286
if (key->rec_per_key[j])
3288
ha_rows records=(show_table->file->stats.records /
3289
key->rec_per_key[j]);
3290
table->field[9]->store((int64_t) records, true);
3291
table->field[9]->set_notnull();
3293
str= show_table->file->index_type(i);
3294
table->field[13]->store(str, strlen(str), cs);
3296
if ((key_part->field &&
3298
show_table->s->field[key_part->fieldnr-1]->key_length()))
3300
table->field[10]->store((int64_t) key_part->length /
3301
key_part->field->charset()->mbmaxlen, true);
3302
table->field[10]->set_notnull();
3304
uint32_t flags= key_part->field ? key_part->field->flags : 0;
3305
const char *pos=(char*) ((flags & NOT_NULL_FLAG) ? "" : "YES");
3306
table->field[12]->store(pos, strlen(pos), cs);
3307
if (!show_table->s->keys_in_use.is_set(i))
3308
table->field[14]->store(STRING_WITH_LEN("disabled"), cs);
3310
table->field[14]->store("", 0, cs);
3311
table->field[14]->set_notnull();
3312
assert(test(key_info->flags & HA_USES_COMMENT) ==
3313
(key_info->comment.length > 0));
3314
if (key_info->flags & HA_USES_COMMENT)
3315
table->field[15]->store(key_info->comment.str,
3316
key_info->comment.length, cs);
3317
if (schema_table_store_record(session, table))
3326
bool store_constraints(Session *session, Table *table, LEX_STRING *db_name,
3327
LEX_STRING *table_name, const char *key_name,
3328
uint32_t key_len, const char *con_type, uint32_t con_len)
3330
const CHARSET_INFO * const cs= system_charset_info;
3331
restore_record(table, s->default_values);
3332
table->field[1]->store(db_name->str, db_name->length, cs);
3333
table->field[2]->store(key_name, key_len, cs);
3334
table->field[3]->store(db_name->str, db_name->length, cs);
3335
table->field[4]->store(table_name->str, table_name->length, cs);
3336
table->field[5]->store(con_type, con_len, cs);
3337
return schema_table_store_record(session, table);
3341
static int get_schema_constraints_record(Session *session, TableList *tables,
3342
Table *table, bool res,
3343
LEX_STRING *db_name,
3344
LEX_STRING *table_name)
3348
if (session->is_error())
3349
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3350
session->main_da.sql_errno(), session->main_da.message());
3351
session->clear_error();
3356
List<FOREIGN_KEY_INFO> f_key_list;
3357
Table *show_table= tables->table;
3358
KEY *key_info=show_table->key_info;
3359
uint32_t primary_key= show_table->s->primary_key;
3360
show_table->file->info(HA_STATUS_VARIABLE |
3363
for (uint32_t i=0 ; i < show_table->s->keys ; i++, key_info++)
3365
if (i != primary_key && !(key_info->flags & HA_NOSAME))
3368
if (i == primary_key && is_primary_key(key_info))
3370
if (store_constraints(session, table, db_name, table_name, key_info->name,
3371
strlen(key_info->name),
3372
STRING_WITH_LEN("PRIMARY KEY")))
3375
else if (key_info->flags & HA_NOSAME)
3377
if (store_constraints(session, table, db_name, table_name, key_info->name,
3378
strlen(key_info->name),
3379
STRING_WITH_LEN("UNIQUE")))
3384
show_table->file->get_foreign_key_list(session, &f_key_list);
3385
FOREIGN_KEY_INFO *f_key_info;
3386
List_iterator_fast<FOREIGN_KEY_INFO> it(f_key_list);
3387
while ((f_key_info=it++))
3389
if (store_constraints(session, table, db_name, table_name,
3390
f_key_info->forein_id->str,
3391
strlen(f_key_info->forein_id->str),
3400
void store_key_column_usage(Table *table, LEX_STRING *db_name,
3401
LEX_STRING *table_name, const char *key_name,
3402
uint32_t key_len, const char *con_type, uint32_t con_len,
3405
const CHARSET_INFO * const cs= system_charset_info;
3406
table->field[1]->store(db_name->str, db_name->length, cs);
3407
table->field[2]->store(key_name, key_len, cs);
3408
table->field[4]->store(db_name->str, db_name->length, cs);
3409
table->field[5]->store(table_name->str, table_name->length, cs);
3410
table->field[6]->store(con_type, con_len, cs);
3411
table->field[7]->store((int64_t) idx, true);
3415
static int get_schema_key_column_usage_record(Session *session,
3417
Table *table, bool res,
3418
LEX_STRING *db_name,
3419
LEX_STRING *table_name)
3423
if (session->is_error())
3424
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3425
session->main_da.sql_errno(), session->main_da.message());
3426
session->clear_error();
3431
List<FOREIGN_KEY_INFO> f_key_list;
3432
Table *show_table= tables->table;
3433
KEY *key_info=show_table->key_info;
3434
uint32_t primary_key= show_table->s->primary_key;
3435
show_table->file->info(HA_STATUS_VARIABLE |
3438
for (uint32_t i=0 ; i < show_table->s->keys ; i++, key_info++)
3440
if (i != primary_key && !(key_info->flags & HA_NOSAME))
3443
KEY_PART_INFO *key_part= key_info->key_part;
3444
for (uint32_t j=0 ; j < key_info->key_parts ; j++,key_part++)
3446
if (key_part->field)
3449
restore_record(table, s->default_values);
3450
store_key_column_usage(table, db_name, table_name,
3452
strlen(key_info->name),
3453
key_part->field->field_name,
3454
strlen(key_part->field->field_name),
3456
if (schema_table_store_record(session, table))
3462
show_table->file->get_foreign_key_list(session, &f_key_list);
3463
FOREIGN_KEY_INFO *f_key_info;
3464
List_iterator_fast<FOREIGN_KEY_INFO> fkey_it(f_key_list);
3465
while ((f_key_info= fkey_it++))
3469
List_iterator_fast<LEX_STRING> it(f_key_info->foreign_fields),
3470
it1(f_key_info->referenced_fields);
3472
while ((f_info= it++))
3476
restore_record(table, s->default_values);
3477
store_key_column_usage(table, db_name, table_name,
3478
f_key_info->forein_id->str,
3479
f_key_info->forein_id->length,
3480
f_info->str, f_info->length,
3482
table->field[8]->store((int64_t) f_idx, true);
3483
table->field[8]->set_notnull();
3484
table->field[9]->store(f_key_info->referenced_db->str,
3485
f_key_info->referenced_db->length,
3486
system_charset_info);
3487
table->field[9]->set_notnull();
3488
table->field[10]->store(f_key_info->referenced_table->str,
3489
f_key_info->referenced_table->length,
3490
system_charset_info);
3491
table->field[10]->set_notnull();
3492
table->field[11]->store(r_info->str, r_info->length,
3493
system_charset_info);
3494
table->field[11]->set_notnull();
3495
if (schema_table_store_record(session, table))
3504
int fill_open_tables(Session *session, TableList *tables, COND *)
3506
const char *wild= session->lex->wild ? session->lex->wild->ptr() : NULL;
3507
Table *table= tables->table;
3508
const CHARSET_INFO * const cs= system_charset_info;
3509
OPEN_TableList *open_list;
3510
if (!(open_list=list_open_tables(session->lex->select_lex.db, wild))
3511
&& session->is_fatal_error)
3514
for (; open_list ; open_list=open_list->next)
3516
restore_record(table, s->default_values);
3517
table->field[0]->store(open_list->db, strlen(open_list->db), cs);
3518
table->field[1]->store(open_list->table, strlen(open_list->table), cs);
3519
table->field[2]->store((int64_t) open_list->in_use, true);
3520
table->field[3]->store((int64_t) open_list->locked, true);
3521
if (schema_table_store_record(session, table))
3528
int fill_variables(Session *session, TableList *tables, COND *)
3531
LEX *lex= session->lex;
3532
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3533
enum enum_schema_tables schema_table_idx=
3534
get_schema_table_idx(tables->schema_table);
3535
enum enum_var_type option_type= OPT_SESSION;
3536
bool upper_case_names= (schema_table_idx != SCH_VARIABLES);
3537
bool sorted_vars= (schema_table_idx == SCH_VARIABLES);
3539
if (lex->option_type == OPT_GLOBAL ||
3540
schema_table_idx == SCH_GLOBAL_VARIABLES)
3541
option_type= OPT_GLOBAL;
3543
pthread_rwlock_rdlock(&LOCK_system_variables_hash);
3544
res= show_status_array(session, wild, enumerate_sys_vars(session, sorted_vars),
3545
option_type, NULL, "", tables->table, upper_case_names);
3546
pthread_rwlock_unlock(&LOCK_system_variables_hash);
3551
int fill_status(Session *session, TableList *tables, COND *)
3553
LEX *lex= session->lex;
3554
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3556
STATUS_VAR *tmp1, tmp;
3557
enum enum_schema_tables schema_table_idx=
3558
get_schema_table_idx(tables->schema_table);
3559
enum enum_var_type option_type;
3560
bool upper_case_names= (schema_table_idx != SCH_STATUS);
3562
if (schema_table_idx == SCH_STATUS)
3564
option_type= lex->option_type;
3565
if (option_type == OPT_GLOBAL)
3568
tmp1= session->initial_status_var;
3570
else if (schema_table_idx == SCH_GLOBAL_STATUS)
3572
option_type= OPT_GLOBAL;
3577
option_type= OPT_SESSION;
3578
tmp1= &session->status_var;
3581
pthread_mutex_lock(&LOCK_status);
3582
if (option_type == OPT_GLOBAL)
3583
calc_sum_of_all_status(&tmp);
3584
res= show_status_array(session, wild,
3585
(SHOW_VAR *)all_status_vars.buffer,
3586
option_type, tmp1, "", tables->table,
3588
pthread_mutex_unlock(&LOCK_status);
3594
Fill and store records into I_S.referential_constraints table
3597
get_referential_constraints_record()
3598
session thread handle
3599
tables table list struct(processed table)
3601
res 1 means the error during opening of the processed table
3602
0 means processed table is opened without error
3604
file_name table name
3612
get_referential_constraints_record(Session *session, TableList *tables,
3613
Table *table, bool res,
3614
LEX_STRING *db_name, LEX_STRING *table_name)
3616
const CHARSET_INFO * const cs= system_charset_info;
3620
if (session->is_error())
3621
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3622
session->main_da.sql_errno(), session->main_da.message());
3623
session->clear_error();
3628
List<FOREIGN_KEY_INFO> f_key_list;
3629
Table *show_table= tables->table;
3630
show_table->file->info(HA_STATUS_VARIABLE |
3634
show_table->file->get_foreign_key_list(session, &f_key_list);
3635
FOREIGN_KEY_INFO *f_key_info;
3636
List_iterator_fast<FOREIGN_KEY_INFO> it(f_key_list);
3637
while ((f_key_info= it++))
3639
restore_record(table, s->default_values);
3640
table->field[1]->store(db_name->str, db_name->length, cs);
3641
table->field[9]->store(table_name->str, table_name->length, cs);
3642
table->field[2]->store(f_key_info->forein_id->str,
3643
f_key_info->forein_id->length, cs);
3644
table->field[4]->store(f_key_info->referenced_db->str,
3645
f_key_info->referenced_db->length, cs);
3646
table->field[10]->store(f_key_info->referenced_table->str,
3647
f_key_info->referenced_table->length, cs);
3648
if (f_key_info->referenced_key_name)
3650
table->field[5]->store(f_key_info->referenced_key_name->str,
3651
f_key_info->referenced_key_name->length, cs);
3652
table->field[5]->set_notnull();
3655
table->field[5]->set_null();
3656
table->field[6]->store(STRING_WITH_LEN("NONE"), cs);
3657
table->field[7]->store(f_key_info->update_method->str,
3658
f_key_info->update_method->length, cs);
3659
table->field[8]->store(f_key_info->delete_method->str,
3660
f_key_info->delete_method->length, cs);
3661
if (schema_table_store_record(session, table))
3669
struct schema_table_ref
3671
const char *table_name;
3672
ST_SCHEMA_TABLE *schema_table;
3677
Find schema_tables elment by name
3680
find_schema_table_in_plugin()
3681
session thread handler
3683
table_name table name
3687
1 found the schema table
3689
static bool find_schema_table_in_plugin(Session *, plugin_ref plugin,
3692
schema_table_ref *p_schema_table= (schema_table_ref *)p_table;
3693
const char* table_name= p_schema_table->table_name;
3694
ST_SCHEMA_TABLE *schema_table= plugin_data(plugin, ST_SCHEMA_TABLE *);
3696
if (!my_strcasecmp(system_charset_info,
3697
schema_table->table_name,
3699
p_schema_table->schema_table= schema_table;
3708
Find schema_tables elment by name
3712
session thread handler
3713
table_name table name
3717
# pointer to 'schema_tables' element
3720
ST_SCHEMA_TABLE *find_schema_table(Session *session, const char* table_name)
3722
schema_table_ref schema_table_a;
3723
ST_SCHEMA_TABLE *schema_table= schema_tables;
3725
for (; schema_table->table_name; schema_table++)
3727
if (!my_strcasecmp(system_charset_info,
3728
schema_table->table_name,
3730
return(schema_table);
3733
schema_table_a.table_name= table_name;
3734
if (plugin_foreach(session, find_schema_table_in_plugin,
3735
DRIZZLE_INFORMATION_SCHEMA_PLUGIN, &schema_table_a))
3736
return(schema_table_a.schema_table);
3742
ST_SCHEMA_TABLE *get_schema_table(enum enum_schema_tables schema_table_idx)
3744
return &schema_tables[schema_table_idx];
3749
Create information_schema table using schema_table data.
3754
session thread handler
3756
@param table_list Used to pass I_S table information(fields info, tables
3757
parameters etc) and table name.
3759
@retval \# Pointer to created table
3760
@retval NULL Can't create table
3763
Table *create_schema_table(Session *session, TableList *table_list)
3768
List<Item> field_list;
3769
ST_SCHEMA_TABLE *schema_table= table_list->schema_table;
3770
ST_FIELD_INFO *fields_info= schema_table->fields_info;
3771
const CHARSET_INFO * const cs= system_charset_info;
3773
for (; fields_info->field_name; fields_info++)
3775
switch (fields_info->field_type) {
3776
case DRIZZLE_TYPE_LONG:
3777
case DRIZZLE_TYPE_LONGLONG:
3778
if (!(item= new Item_return_int(fields_info->field_name,
3779
fields_info->field_length,
3780
fields_info->field_type,
3781
fields_info->value)))
3785
item->unsigned_flag= (fields_info->field_flags & MY_I_S_UNSIGNED);
3787
case DRIZZLE_TYPE_DATE:
3788
case DRIZZLE_TYPE_TIME:
3789
case DRIZZLE_TYPE_TIMESTAMP:
3790
case DRIZZLE_TYPE_DATETIME:
3791
if (!(item=new Item_return_date_time(fields_info->field_name,
3792
fields_info->field_type)))
3797
case DRIZZLE_TYPE_DOUBLE:
3798
if ((item= new Item_float(fields_info->field_name, 0.0, NOT_FIXED_DEC,
3799
fields_info->field_length)) == NULL)
3802
case DRIZZLE_TYPE_NEWDECIMAL:
3803
if (!(item= new Item_decimal((int64_t) fields_info->value, false)))
3807
item->unsigned_flag= (fields_info->field_flags & MY_I_S_UNSIGNED);
3808
item->decimals= fields_info->field_length%10;
3809
item->max_length= (fields_info->field_length/100)%100;
3810
if (item->unsigned_flag == 0)
3811
item->max_length+= 1;
3812
if (item->decimals > 0)
3813
item->max_length+= 1;
3814
item->set_name(fields_info->field_name,
3815
strlen(fields_info->field_name), cs);
3817
case DRIZZLE_TYPE_BLOB:
3818
if (!(item= new Item_blob(fields_info->field_name,
3819
fields_info->field_length)))
3825
if (!(item= new Item_empty_string("", fields_info->field_length, cs)))
3829
item->set_name(fields_info->field_name,
3830
strlen(fields_info->field_name), cs);
3833
field_list.push_back(item);
3834
item->maybe_null= (fields_info->field_flags & MY_I_S_MAYBE_NULL);
3837
TMP_TABLE_PARAM *tmp_table_param =
3838
(TMP_TABLE_PARAM*) (session->alloc(sizeof(TMP_TABLE_PARAM)));
3839
tmp_table_param->init();
3840
tmp_table_param->table_charset= cs;
3841
tmp_table_param->field_count= field_count;
3842
tmp_table_param->schema_table= 1;
3843
SELECT_LEX *select_lex= session->lex->current_select;
3844
if (!(table= create_tmp_table(session, tmp_table_param,
3845
field_list, (order_st*) 0, 0, 0,
3846
(select_lex->options | session->options |
3847
TMP_TABLE_ALL_COLUMNS),
3848
HA_POS_ERROR, table_list->alias)))
3850
my_bitmap_map* bitmaps=
3851
(my_bitmap_map*) session->alloc(bitmap_buffer_size(field_count));
3852
bitmap_init(&table->def_read_set, (my_bitmap_map*) bitmaps, field_count,
3854
table->read_set= &table->def_read_set;
3855
bitmap_clear_all(table->read_set);
3856
table_list->schema_table_param= tmp_table_param;
3862
For old SHOW compatibility. It is used when
3863
old SHOW doesn't have generated column names
3864
Make list of fields for SHOW
3868
session thread handler
3869
schema_table pointer to 'schema_tables' element
3876
int make_old_format(Session *session, ST_SCHEMA_TABLE *schema_table)
3878
ST_FIELD_INFO *field_info= schema_table->fields_info;
3879
Name_resolution_context *context= &session->lex->select_lex.context;
3880
for (; field_info->field_name; field_info++)
3882
if (field_info->old_name)
3884
Item_field *field= new Item_field(context,
3885
NULL, NULL, field_info->field_name);
3888
field->set_name(field_info->old_name,
3889
strlen(field_info->old_name),
3890
system_charset_info);
3891
if (add_item_to_list(session, field))
3900
int make_schemata_old_format(Session *session, ST_SCHEMA_TABLE *schema_table)
3903
LEX *lex= session->lex;
3904
SELECT_LEX *sel= lex->current_select;
3905
Name_resolution_context *context= &sel->context;
3907
if (!sel->item_list.elements)
3909
ST_FIELD_INFO *field_info= &schema_table->fields_info[1];
3910
String buffer(tmp,sizeof(tmp), system_charset_info);
3911
Item_field *field= new Item_field(context,
3912
NULL, NULL, field_info->field_name);
3913
if (!field || add_item_to_list(session, field))
3916
buffer.append(field_info->old_name);
3917
if (lex->wild && lex->wild->ptr())
3919
buffer.append(STRING_WITH_LEN(" ("));
3920
buffer.append(lex->wild->ptr());
3923
field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
3929
int make_table_names_old_format(Session *session, ST_SCHEMA_TABLE *schema_table)
3932
String buffer(tmp,sizeof(tmp), session->charset());
3933
LEX *lex= session->lex;
3934
Name_resolution_context *context= &lex->select_lex.context;
3936
ST_FIELD_INFO *field_info= &schema_table->fields_info[2];
3938
buffer.append(field_info->old_name);
3939
buffer.append(lex->select_lex.db);
3940
if (lex->wild && lex->wild->ptr())
3942
buffer.append(STRING_WITH_LEN(" ("));
3943
buffer.append(lex->wild->ptr());
3946
Item_field *field= new Item_field(context,
3947
NULL, NULL, field_info->field_name);
3948
if (add_item_to_list(session, field))
3950
field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
3951
if (session->lex->verbose)
3953
field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
3954
field_info= &schema_table->fields_info[3];
3955
field= new Item_field(context, NULL, NULL, field_info->field_name);
3956
if (add_item_to_list(session, field))
3958
field->set_name(field_info->old_name, strlen(field_info->old_name),
3959
system_charset_info);
3965
int make_columns_old_format(Session *session, ST_SCHEMA_TABLE *schema_table)
3967
int fields_arr[]= {3, 14, 13, 6, 15, 5, 16, 17, 18, -1};
3968
int *field_num= fields_arr;
3969
ST_FIELD_INFO *field_info;
3970
Name_resolution_context *context= &session->lex->select_lex.context;
3972
for (; *field_num >= 0; field_num++)
3974
field_info= &schema_table->fields_info[*field_num];
3975
if (!session->lex->verbose && (*field_num == 13 ||
3979
Item_field *field= new Item_field(context,
3980
NULL, NULL, field_info->field_name);
3983
field->set_name(field_info->old_name,
3984
strlen(field_info->old_name),
3985
system_charset_info);
3986
if (add_item_to_list(session, field))
3994
int make_character_sets_old_format(Session *session, ST_SCHEMA_TABLE *schema_table)
3996
int fields_arr[]= {0, 2, 1, 3, -1};
3997
int *field_num= fields_arr;
3998
ST_FIELD_INFO *field_info;
3999
Name_resolution_context *context= &session->lex->select_lex.context;
4001
for (; *field_num >= 0; field_num++)
4003
field_info= &schema_table->fields_info[*field_num];
4004
Item_field *field= new Item_field(context,
4005
NULL, NULL, field_info->field_name);
4008
field->set_name(field_info->old_name,
4009
strlen(field_info->old_name),
4010
system_charset_info);
4011
if (add_item_to_list(session, field))
4020
Create information_schema table
4023
mysql_schema_table()
4024
session thread handler
4026
table_list pointer to table_list
4033
int mysql_schema_table(Session *session, LEX *, TableList *table_list)
4036
if (!(table= table_list->schema_table->create_table(session, table_list)))
4038
table->s->tmp_table= SYSTEM_TMP_TABLE;
4040
This test is necessary to make
4041
case insensitive file systems +
4042
upper case table names(information schema tables) +
4046
if (table_list->schema_table_name)
4047
table->alias_name_used= my_strcasecmp(table_alias_charset,
4048
table_list->schema_table_name,
4050
table_list->table_name= table->s->table_name.str;
4051
table_list->table_name_length= table->s->table_name.length;
4052
table_list->table= table;
4053
table->next= session->derived_tables;
4054
session->derived_tables= table;
4055
table_list->select_lex->options |= OPTION_SCHEMA_TABLE;
4062
Generate select from information_schema table
4065
make_schema_select()
4066
session thread handler
4067
sel pointer to SELECT_LEX
4068
schema_table_idx index of 'schema_tables' element
4075
int make_schema_select(Session *session, SELECT_LEX *sel,
4076
enum enum_schema_tables schema_table_idx)
4078
ST_SCHEMA_TABLE *schema_table= get_schema_table(schema_table_idx);
4079
LEX_STRING db, table;
4081
We have to make non const db_name & table_name
4082
because of lower_case_table_names
4084
session->make_lex_string(&db, INFORMATION_SCHEMA_NAME.c_str(),
4085
INFORMATION_SCHEMA_NAME.length(), 0);
4086
session->make_lex_string(&table, schema_table->table_name,
4087
strlen(schema_table->table_name), 0);
4088
if (schema_table->old_format(session, schema_table) || /* Handle old syntax */
4089
!sel->add_table_to_list(session, new Table_ident(session, db, table, 0),
4099
Fill temporary schema tables before SELECT
4102
get_schema_tables_result()
4103
join join which use schema tables
4104
executed_place place where I_S table processed
4111
bool get_schema_tables_result(JOIN *join,
4112
enum enum_schema_table_state executed_place)
4114
JOIN_TAB *tmp_join_tab= join->join_tab+join->tables;
4115
Session *session= join->session;
4116
LEX *lex= session->lex;
4119
session->no_warnings_for_error= 1;
4120
for (JOIN_TAB *tab= join->join_tab; tab < tmp_join_tab; tab++)
4122
if (!tab->table || !tab->table->pos_in_table_list)
4125
TableList *table_list= tab->table->pos_in_table_list;
4126
if (table_list->schema_table)
4128
bool is_subselect= (&lex->unit != lex->current_select->master_unit() &&
4129
lex->current_select->master_unit()->item);
4132
/* skip I_S optimizations specific to get_all_tables */
4133
if (session->lex->describe &&
4134
(table_list->schema_table->fill_table != get_all_tables))
4138
If schema table is already processed and
4139
the statement is not a subselect then
4140
we don't need to fill this table again.
4141
If schema table is already processed and
4142
schema_table_state != executed_place then
4143
table is already processed and
4144
we should skip second data processing.
4146
if (table_list->schema_table_state &&
4147
(!is_subselect || table_list->schema_table_state != executed_place))
4151
if table is used in a subselect and
4152
table has been processed earlier with the same
4153
'executed_place' value then we should refresh the table.
4155
if (table_list->schema_table_state && is_subselect)
4157
table_list->table->file->extra(HA_EXTRA_NO_CACHE);
4158
table_list->table->file->extra(HA_EXTRA_RESET_STATE);
4159
table_list->table->file->ha_delete_all_rows();
4160
free_io_cache(table_list->table);
4161
filesort_free_buffers(table_list->table,1);
4162
table_list->table->null_row= 0;
4165
table_list->table->file->stats.records= 0;
4167
if (table_list->schema_table->fill_table(session, table_list,
4172
tab->read_record.file= table_list->table->file;
4173
table_list->schema_table_state= executed_place;
4176
tab->read_record.file= table_list->table->file;
4177
table_list->schema_table_state= executed_place;
4180
session->no_warnings_for_error= 0;
4184
ST_FIELD_INFO schema_fields_info[]=
4186
{"CATALOG_NAME", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, SKIP_OPEN_TABLE},
4187
{"SCHEMA_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Database",
4189
{"DEFAULT_CHARACTER_SET_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4191
{"DEFAULT_COLLATION_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE},
4192
{"SQL_PATH", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, SKIP_OPEN_TABLE},
4193
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4197
ST_FIELD_INFO tables_fields_info[]=
4199
{"TABLE_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, SKIP_OPEN_TABLE},
4200
{"TABLE_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE},
4201
{"TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Name",
4203
{"TABLE_TYPE", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FRM_ONLY},
4204
{"ENGINE", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 1, "Engine", OPEN_FRM_ONLY},
4205
{"VERSION", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4206
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Version", OPEN_FRM_ONLY},
4207
{"ROW_FORMAT", 10, DRIZZLE_TYPE_VARCHAR, 0, 1, "Row_format", OPEN_FULL_TABLE},
4208
{"TABLE_ROWS", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4209
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Rows", OPEN_FULL_TABLE},
4210
{"AVG_ROW_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4211
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Avg_row_length", OPEN_FULL_TABLE},
4212
{"DATA_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4213
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Data_length", OPEN_FULL_TABLE},
4214
{"MAX_DATA_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4215
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Max_data_length", OPEN_FULL_TABLE},
4216
{"INDEX_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4217
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Index_length", OPEN_FULL_TABLE},
4218
{"DATA_FREE", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4219
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Data_free", OPEN_FULL_TABLE},
4220
{"AUTO_INCREMENT", MY_INT64_NUM_DECIMAL_DIGITS , DRIZZLE_TYPE_LONGLONG, 0,
4221
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Auto_increment", OPEN_FULL_TABLE},
4222
{"CREATE_TIME", 0, DRIZZLE_TYPE_DATETIME, 0, 1, "Create_time", OPEN_FULL_TABLE},
4223
{"UPDATE_TIME", 0, DRIZZLE_TYPE_DATETIME, 0, 1, "Update_time", OPEN_FULL_TABLE},
4224
{"CHECK_TIME", 0, DRIZZLE_TYPE_DATETIME, 0, 1, "Check_time", OPEN_FULL_TABLE},
4225
{"TABLE_COLLATION", 64, DRIZZLE_TYPE_VARCHAR, 0, 1, "Collation", OPEN_FRM_ONLY},
4226
{"CHECKSUM", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4227
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Checksum", OPEN_FULL_TABLE},
4228
{"CREATE_OPTIONS", 255, DRIZZLE_TYPE_VARCHAR, 0, 1, "Create_options",
4230
{"TABLE_COMMENT", TABLE_COMMENT_MAXLEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Comment", OPEN_FRM_ONLY},
4231
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4235
ST_FIELD_INFO columns_fields_info[]=
4237
{"TABLE_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, OPEN_FRM_ONLY},
4238
{"TABLE_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FRM_ONLY},
4239
{"TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FRM_ONLY},
4240
{"COLUMN_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Field",
4242
{"ORDINAL_POSITION", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4243
MY_I_S_UNSIGNED, 0, OPEN_FRM_ONLY},
4244
{"COLUMN_DEFAULT", MAX_FIELD_VARCHARLENGTH, DRIZZLE_TYPE_VARCHAR, 0,
4245
1, "Default", OPEN_FRM_ONLY},
4246
{"IS_NULLABLE", 3, DRIZZLE_TYPE_VARCHAR, 0, 0, "Null", OPEN_FRM_ONLY},
4247
{"DATA_TYPE", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FRM_ONLY},
4248
{"CHARACTER_MAXIMUM_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG,
4249
0, (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), 0, OPEN_FRM_ONLY},
4250
{"CHARACTER_OCTET_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS , DRIZZLE_TYPE_LONGLONG,
4251
0, (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), 0, OPEN_FRM_ONLY},
4252
{"NUMERIC_PRECISION", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG,
4253
0, (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), 0, OPEN_FRM_ONLY},
4254
{"NUMERIC_SCALE", MY_INT64_NUM_DECIMAL_DIGITS , DRIZZLE_TYPE_LONGLONG,
4255
0, (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), 0, OPEN_FRM_ONLY},
4256
{"CHARACTER_SET_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, OPEN_FRM_ONLY},
4257
{"COLLATION_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 1, "Collation", OPEN_FRM_ONLY},
4258
{"COLUMN_TYPE", 65535, DRIZZLE_TYPE_VARCHAR, 0, 0, "Type", OPEN_FRM_ONLY},
4259
{"COLUMN_KEY", 3, DRIZZLE_TYPE_VARCHAR, 0, 0, "Key", OPEN_FRM_ONLY},
4260
{"EXTRA", 27, DRIZZLE_TYPE_VARCHAR, 0, 0, "Extra", OPEN_FRM_ONLY},
4261
{"PRIVILEGES", 80, DRIZZLE_TYPE_VARCHAR, 0, 0, "Privileges", OPEN_FRM_ONLY},
4262
{"COLUMN_COMMENT", COLUMN_COMMENT_MAXLEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Comment", OPEN_FRM_ONLY},
4263
{"STORAGE", 8, DRIZZLE_TYPE_VARCHAR, 0, 0, "Storage", OPEN_FRM_ONLY},
4264
{"FORMAT", 8, DRIZZLE_TYPE_VARCHAR, 0, 0, "Format", OPEN_FRM_ONLY},
4265
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4269
ST_FIELD_INFO charsets_fields_info[]=
4271
{"CHARACTER_SET_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, "Charset",
4273
{"DEFAULT_COLLATE_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, "Default collation",
4275
{"DESCRIPTION", 60, DRIZZLE_TYPE_VARCHAR, 0, 0, "Description",
4277
{"MAXLEN", 3, DRIZZLE_TYPE_LONGLONG, 0, 0, "Maxlen", SKIP_OPEN_TABLE},
4278
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4282
ST_FIELD_INFO collation_fields_info[]=
4284
{"COLLATION_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, "Collation", SKIP_OPEN_TABLE},
4285
{"CHARACTER_SET_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, "Charset",
4287
{"ID", MY_INT32_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0, 0, "Id",
4289
{"IS_DEFAULT", 3, DRIZZLE_TYPE_VARCHAR, 0, 0, "Default", SKIP_OPEN_TABLE},
4290
{"IS_COMPILED", 3, DRIZZLE_TYPE_VARCHAR, 0, 0, "Compiled", SKIP_OPEN_TABLE},
4291
{"SORTLEN", 3, DRIZZLE_TYPE_LONGLONG, 0, 0, "Sortlen", SKIP_OPEN_TABLE},
4292
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4297
ST_FIELD_INFO coll_charset_app_fields_info[]=
4299
{"COLLATION_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE},
4300
{"CHARACTER_SET_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE},
4301
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4305
ST_FIELD_INFO stat_fields_info[]=
4307
{"TABLE_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, OPEN_FRM_ONLY},
4308
{"TABLE_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FRM_ONLY},
4309
{"TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Table", OPEN_FRM_ONLY},
4310
{"NON_UNIQUE", 1, DRIZZLE_TYPE_LONGLONG, 0, 0, "Non_unique", OPEN_FRM_ONLY},
4311
{"INDEX_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FRM_ONLY},
4312
{"INDEX_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Key_name",
4314
{"SEQ_IN_INDEX", 2, DRIZZLE_TYPE_LONGLONG, 0, 0, "Seq_in_index", OPEN_FRM_ONLY},
4315
{"COLUMN_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Column_name",
4317
{"COLLATION", 1, DRIZZLE_TYPE_VARCHAR, 0, 1, "Collation", OPEN_FRM_ONLY},
4318
{"CARDINALITY", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0, 1,
4319
"Cardinality", OPEN_FULL_TABLE},
4320
{"SUB_PART", 3, DRIZZLE_TYPE_LONGLONG, 0, 1, "Sub_part", OPEN_FRM_ONLY},
4321
{"PACKED", 10, DRIZZLE_TYPE_VARCHAR, 0, 1, "Packed", OPEN_FRM_ONLY},
4322
{"NULLABLE", 3, DRIZZLE_TYPE_VARCHAR, 0, 0, "Null", OPEN_FRM_ONLY},
4323
{"INDEX_TYPE", 16, DRIZZLE_TYPE_VARCHAR, 0, 0, "Index_type", OPEN_FULL_TABLE},
4324
{"COMMENT", 16, DRIZZLE_TYPE_VARCHAR, 0, 1, "Comment", OPEN_FRM_ONLY},
4325
{"INDEX_COMMENT", INDEX_COMMENT_MAXLEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Index_Comment", OPEN_FRM_ONLY},
4326
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4330
ST_FIELD_INFO table_constraints_fields_info[]=
4332
{"CONSTRAINT_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, OPEN_FULL_TABLE},
4333
{"CONSTRAINT_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4335
{"CONSTRAINT_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4337
{"TABLE_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4338
{"TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4339
{"CONSTRAINT_TYPE", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4341
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4345
ST_FIELD_INFO key_column_usage_fields_info[]=
4347
{"CONSTRAINT_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, OPEN_FULL_TABLE},
4348
{"CONSTRAINT_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4350
{"CONSTRAINT_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4352
{"TABLE_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, OPEN_FULL_TABLE},
4353
{"TABLE_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4354
{"TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4355
{"COLUMN_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4356
{"ORDINAL_POSITION", 10 ,DRIZZLE_TYPE_LONGLONG, 0, 0, 0, OPEN_FULL_TABLE},
4357
{"POSITION_IN_UNIQUE_CONSTRAINT", 10 ,DRIZZLE_TYPE_LONGLONG, 0, 1, 0,
4359
{"REFERENCED_TABLE_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0,
4361
{"REFERENCED_TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0,
4363
{"REFERENCED_COLUMN_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0,
4365
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4369
ST_FIELD_INFO table_names_fields_info[]=
4371
{"TABLE_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, SKIP_OPEN_TABLE},
4372
{"TABLE_SCHEMA",NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE},
4373
{"TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Tables_in_",
4375
{"TABLE_TYPE", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Table_type",
4377
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4381
ST_FIELD_INFO open_tables_fields_info[]=
4383
{"Database", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Database",
4385
{"Table",NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Table", SKIP_OPEN_TABLE},
4386
{"In_use", 1, DRIZZLE_TYPE_LONGLONG, 0, 0, "In_use", SKIP_OPEN_TABLE},
4387
{"Name_locked", 4, DRIZZLE_TYPE_LONGLONG, 0, 0, "Name_locked", SKIP_OPEN_TABLE},
4388
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4392
ST_FIELD_INFO variables_fields_info[]=
4394
{"VARIABLE_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, "Variable_name",
4396
{"VARIABLE_VALUE", 16300, DRIZZLE_TYPE_VARCHAR, 0, 1, "Value", SKIP_OPEN_TABLE},
4397
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4401
ST_FIELD_INFO processlist_fields_info[]=
4403
{"ID", 4, DRIZZLE_TYPE_LONGLONG, 0, 0, "Id", SKIP_OPEN_TABLE},
4404
{"USER", 16, DRIZZLE_TYPE_VARCHAR, 0, 0, "User", SKIP_OPEN_TABLE},
4405
{"HOST", LIST_PROCESS_HOST_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Host",
4407
{"DB", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 1, "Db", SKIP_OPEN_TABLE},
4408
{"COMMAND", 16, DRIZZLE_TYPE_VARCHAR, 0, 0, "Command", SKIP_OPEN_TABLE},
4409
{"TIME", 7, DRIZZLE_TYPE_LONGLONG, 0, 0, "Time", SKIP_OPEN_TABLE},
4410
{"STATE", 64, DRIZZLE_TYPE_VARCHAR, 0, 1, "State", SKIP_OPEN_TABLE},
4411
{"INFO", PROCESS_LIST_INFO_WIDTH, DRIZZLE_TYPE_VARCHAR, 0, 1, "Info",
4413
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4417
ST_FIELD_INFO plugin_fields_info[]=
4419
{"PLUGIN_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Name",
4421
{"PLUGIN_VERSION", 20, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE},
4422
{"PLUGIN_STATUS", 10, DRIZZLE_TYPE_VARCHAR, 0, 0, "Status", SKIP_OPEN_TABLE},
4423
{"PLUGIN_TYPE", 80, DRIZZLE_TYPE_VARCHAR, 0, 0, "Type", SKIP_OPEN_TABLE},
4424
{"PLUGIN_LIBRARY", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 1, "Library",
4426
{"PLUGIN_AUTHOR", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, SKIP_OPEN_TABLE},
4427
{"PLUGIN_DESCRIPTION", 65535, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, SKIP_OPEN_TABLE},
4428
{"PLUGIN_LICENSE", 80, DRIZZLE_TYPE_VARCHAR, 0, 1, "License", SKIP_OPEN_TABLE},
4429
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4432
ST_FIELD_INFO referential_constraints_fields_info[]=
4434
{"CONSTRAINT_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, OPEN_FULL_TABLE},
4435
{"CONSTRAINT_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4437
{"CONSTRAINT_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4439
{"UNIQUE_CONSTRAINT_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0,
4441
{"UNIQUE_CONSTRAINT_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4443
{"UNIQUE_CONSTRAINT_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0,
4444
MY_I_S_MAYBE_NULL, 0, OPEN_FULL_TABLE},
4445
{"MATCH_OPTION", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4446
{"UPDATE_RULE", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4447
{"DELETE_RULE", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4448
{"TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4449
{"REFERENCED_TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4451
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4456
Description of ST_FIELD_INFO in table.h
4458
Make sure that the order of schema_tables and enum_schema_tables are the same.
4462
ST_SCHEMA_TABLE schema_tables[]=
4464
{"CHARACTER_SETS", charsets_fields_info, create_schema_table,
4465
fill_schema_charsets, make_character_sets_old_format, 0, -1, -1, 0, 0},
4466
{"COLLATIONS", collation_fields_info, create_schema_table,
4467
fill_schema_collation, make_old_format, 0, -1, -1, 0, 0},
4468
{"COLLATION_CHARACTER_SET_APPLICABILITY", coll_charset_app_fields_info,
4469
create_schema_table, fill_schema_coll_charset_app, 0, 0, -1, -1, 0, 0},
4470
{"COLUMNS", columns_fields_info, create_schema_table,
4471
get_all_tables, make_columns_old_format, get_schema_column_record, 1, 2, 0,
4472
OPTIMIZE_I_S_TABLE},
4473
{"GLOBAL_STATUS", variables_fields_info, create_schema_table,
4474
fill_status, make_old_format, 0, -1, -1, 0, 0},
4475
{"GLOBAL_VARIABLES", variables_fields_info, create_schema_table,
4476
fill_variables, make_old_format, 0, -1, -1, 0, 0},
4477
{"KEY_COLUMN_USAGE", key_column_usage_fields_info, create_schema_table,
4478
get_all_tables, 0, get_schema_key_column_usage_record, 4, 5, 0,
4480
{"OPEN_TABLES", open_tables_fields_info, create_schema_table,
4481
fill_open_tables, make_old_format, 0, -1, -1, 1, 0},
4482
{"PLUGINS", plugin_fields_info, create_schema_table,
4483
fill_plugins, make_old_format, 0, -1, -1, 0, 0},
4484
{"PROCESSLIST", processlist_fields_info, create_schema_table,
4485
fill_schema_processlist, make_old_format, 0, -1, -1, 0, 0},
4486
{"REFERENTIAL_CONSTRAINTS", referential_constraints_fields_info,
4487
create_schema_table, get_all_tables, 0, get_referential_constraints_record,
4488
1, 9, 0, OPEN_TABLE_ONLY},
4489
{"SCHEMATA", schema_fields_info, create_schema_table,
4490
fill_schema_schemata, make_schemata_old_format, 0, 1, -1, 0, 0},
4491
{"SESSION_STATUS", variables_fields_info, create_schema_table,
4492
fill_status, make_old_format, 0, -1, -1, 0, 0},
4493
{"SESSION_VARIABLES", variables_fields_info, create_schema_table,
4494
fill_variables, make_old_format, 0, -1, -1, 0, 0},
4495
{"STATISTICS", stat_fields_info, create_schema_table,
4496
get_all_tables, make_old_format, get_schema_stat_record, 1, 2, 0,
4497
OPEN_TABLE_ONLY|OPTIMIZE_I_S_TABLE},
4498
{"STATUS", variables_fields_info, create_schema_table, fill_status,
4499
make_old_format, 0, -1, -1, 1, 0},
4500
{"TABLES", tables_fields_info, create_schema_table,
4501
get_all_tables, make_old_format, get_schema_tables_record, 1, 2, 0,
4502
OPTIMIZE_I_S_TABLE},
4503
{"TABLE_CONSTRAINTS", table_constraints_fields_info, create_schema_table,
4504
get_all_tables, 0, get_schema_constraints_record, 3, 4, 0, OPEN_TABLE_ONLY},
4505
{"TABLE_NAMES", table_names_fields_info, create_schema_table,
4506
get_all_tables, make_table_names_old_format, 0, 1, 2, 1, 0},
4507
{"VARIABLES", variables_fields_info, create_schema_table, fill_variables,
4508
make_old_format, 0, -1, -1, 1, 0},
4509
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
4513
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
4514
template class List_iterator_fast<char>;
4515
template class List<char>;
4518
int initialize_schema_table(st_plugin_int *plugin)
4520
ST_SCHEMA_TABLE *schema_table;
4522
if ((schema_table= new ST_SCHEMA_TABLE) == NULL)
4524
memset(schema_table, 0, sizeof(ST_SCHEMA_TABLE));
4526
/* Historical Requirement */
4527
plugin->data= schema_table; // shortcut for the future
4528
if (plugin->plugin->init)
4530
schema_table->create_table= create_schema_table;
4531
schema_table->old_format= make_old_format;
4532
schema_table->idx_field1= -1,
4533
schema_table->idx_field2= -1;
4535
/* Make the name available to the init() function. */
4536
schema_table->table_name= plugin->name.str;
4538
if (plugin->plugin->init(schema_table))
4540
errmsg_printf(ERRMSG_LVL_ERROR,
4541
_("Plugin '%s' init function returned error."),
4546
/* Make sure the plugin name is not set inside the init() function. */
4547
schema_table->table_name= plugin->name.str;
4552
delete schema_table;
4557
int finalize_schema_table(st_plugin_int *plugin)
4559
ST_SCHEMA_TABLE *schema_table= (ST_SCHEMA_TABLE *)plugin->data;
4561
if (schema_table && plugin->plugin->deinit)
4562
delete schema_table;