1 # name : innodb_show_sys_tables.patch
3 # maintainer : Yasufumi
4 # (It is revived from mysql-5.5.6-rc)
6 # Any small change to this file in the main branch
7 # should be done or reviewed by the maintainer!
8 --- a/storage/innobase/dict/dict0load.c
9 +++ b/storage/innobase/dict/dict0load.c
14 -#ifdef FOREIGN_NOT_USED
15 +//#ifdef FOREIGN_NOT_USED
16 /********************************************************************//**
17 This function parses a SYS_FOREIGN record and populate a dict_foreign_t
18 structure with the information from the record. For detail information
23 -#endif /* FOREIGN_NOT_USED */
24 +//#endif /* FOREIGN_NOT_USED */
26 -#ifdef FOREIGN_NOT_USED
27 +//#ifdef FOREIGN_NOT_USED
28 /********************************************************************//**
29 This function parses a SYS_FOREIGN_COLS record and extract necessary
30 information from the record and return to caller.
35 -#endif /* FOREIGN_NOT_USED */
36 +//#endif /* FOREIGN_NOT_USED */
38 /********************************************************************//**
39 Determine the flags of a table described in SYS_TABLES.
40 --- a/storage/innobase/handler/ha_innodb.cc
41 +++ b/storage/innobase/handler/ha_innodb.cc
42 @@ -11899,7 +11899,14 @@
46 -i_s_innodb_cmpmem_reset
47 +i_s_innodb_cmpmem_reset,
48 +i_s_innodb_sys_tables,
49 +i_s_innodb_sys_tablestats,
50 +i_s_innodb_sys_indexes,
51 +i_s_innodb_sys_columns,
52 +i_s_innodb_sys_fields,
53 +i_s_innodb_sys_foreign,
54 +i_s_innodb_sys_foreign_cols
55 mysql_declare_plugin_end;
57 /** @brief Initialize the default value of innodb_commit_concurrency.
58 --- a/storage/innobase/handler/i_s.cc
59 +++ b/storage/innobase/handler/i_s.cc
61 #include <mysql/innodb_priv.h>
64 +#include "btr0pcur.h" /* for file sys_tables related info. */
65 #include "btr0types.h"
66 #include "buf0buddy.h" /* for i_s_cmpmem */
67 #include "buf0buf.h" /* for buf_pool and PAGE_ZIP_MIN_SIZE */
68 +#include "dict0load.h" /* for file sys_tables related info. */
70 #include "dict0types.h"
71 #include "ha_prototypes.h" /* for innobase_convert_name() */
72 @@ -1812,6 +1814,1675 @@
76 +/* Fields of the dynamic table INFORMATION_SCHEMA.SYS_TABLES */
77 +static ST_FIELD_INFO innodb_sys_tables_fields_info[] =
79 +#define SYS_TABLE_ID 0
80 + {STRUCT_FLD(field_name, "TABLE_ID"),
81 + STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
82 + STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
83 + STRUCT_FLD(value, 0),
84 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
85 + STRUCT_FLD(old_name, ""),
86 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
88 +#define SYS_TABLE_SCHEMA 1
89 + {STRUCT_FLD(field_name, "SCHEMA"),
90 + STRUCT_FLD(field_length, NAME_LEN + 1),
91 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
92 + STRUCT_FLD(value, 0),
93 + STRUCT_FLD(field_flags, 0),
94 + STRUCT_FLD(old_name, ""),
95 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
97 +#define SYS_TABLE_NAME 2
98 + {STRUCT_FLD(field_name, "NAME"),
99 + STRUCT_FLD(field_length, NAME_LEN + 1),
100 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
101 + STRUCT_FLD(value, 0),
102 + STRUCT_FLD(field_flags, 0),
103 + STRUCT_FLD(old_name, ""),
104 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
106 +#define SYS_TABLE_FLAG 3
107 + {STRUCT_FLD(field_name, "FLAG"),
108 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
109 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
110 + STRUCT_FLD(value, 0),
111 + STRUCT_FLD(field_flags, 0),
112 + STRUCT_FLD(old_name, ""),
113 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
115 +#define SYS_TABLE_NUM_COLUMN 4
116 + {STRUCT_FLD(field_name, "N_COLS"),
117 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
118 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
119 + STRUCT_FLD(value, 0),
120 + STRUCT_FLD(field_flags, 0),
121 + STRUCT_FLD(old_name, ""),
122 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
124 +#define SYS_TABLE_SPACE 5
125 + {STRUCT_FLD(field_name, "SPACE"),
126 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
127 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
128 + STRUCT_FLD(value, 0),
129 + STRUCT_FLD(field_flags, 0),
130 + STRUCT_FLD(old_name, ""),
131 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
133 + END_OF_ST_FIELD_INFO
136 +/**********************************************************************//**
137 +Populate information_schema.innodb_sys_tables table with information
139 +@return 0 on success */
142 +i_s_dict_fill_sys_tables(
143 +/*=====================*/
144 + THD* thd, /*!< in: thread */
145 + dict_table_t* table, /*!< in: table */
146 + TABLE* table_to_fill) /*!< in/out: fill this table */
149 + char buf[NAME_LEN * 2 + 2];
152 + DBUG_ENTER("i_s_dict_fill_sys_tables");
154 + fields = table_to_fill->field;
156 + OK(fields[SYS_TABLE_ID]->store(longlong(table->id), TRUE));
158 + strncpy(buf, table->name, NAME_LEN * 2 + 2);
159 + ptr = strchr(buf, '/');
164 + OK(field_store_string(fields[SYS_TABLE_SCHEMA], buf));
165 + OK(field_store_string(fields[SYS_TABLE_NAME], ptr));
167 + fields[SYS_TABLE_SCHEMA]->set_null();
168 + OK(field_store_string(fields[SYS_TABLE_NAME], buf));
171 + OK(fields[SYS_TABLE_FLAG]->store(table->flags));
173 + OK(fields[SYS_TABLE_NUM_COLUMN]->store(table->n_cols));
175 + OK(fields[SYS_TABLE_SPACE]->store(table->space));
177 + OK(schema_table_store_record(thd, table_to_fill));
181 +/*******************************************************************//**
182 +Function to go through each record in SYS_TABLES table, and fill the
183 +information_schema.innodb_sys_tables table with related table information
184 +@return 0 on success */
187 +i_s_sys_tables_fill_table(
188 +/*======================*/
189 + THD* thd, /*!< in: thread */
190 + TABLE_LIST* tables, /*!< in/out: tables to fill */
191 + COND* cond) /*!< in: condition (not used) */
198 + DBUG_ENTER("i_s_sys_tables_fill_table");
200 + /* deny access to non-superusers */
201 + if (check_global_access(thd, PROCESS_ACL)) {
206 + heap = mem_heap_create(1000);
207 + mutex_enter(&(dict_sys->mutex));
210 + rec = dict_startscan_system(&pcur, &mtr, SYS_TABLES);
213 + const char* err_msg;
214 + dict_table_t* table_rec;
216 + /* Create and populate a dict_table_t structure with
217 + information from SYS_TABLES row */
218 + err_msg = dict_process_sys_tables_rec(
219 + heap, rec, &table_rec, DICT_TABLE_LOAD_FROM_RECORD);
222 + mutex_exit(&dict_sys->mutex);
225 + i_s_dict_fill_sys_tables(thd, table_rec, tables->table);
227 + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
228 + ER_CANT_FIND_SYSTEM_REC,
232 + /* Since dict_process_sys_tables_rec() is called with
233 + DICT_TABLE_LOAD_FROM_RECORD, the table_rec is created in
234 + dict_process_sys_tables_rec(), we will need to free it */
236 + dict_mem_table_free(table_rec);
239 + mem_heap_empty(heap);
241 + /* Get the next record */
242 + mutex_enter(&dict_sys->mutex);
244 + rec = dict_getnext_system(&pcur, &mtr);
248 + mutex_exit(&dict_sys->mutex);
249 + mem_heap_free(heap);
254 +/*******************************************************************//**
255 +Bind the dynamic table INFORMATION_SCHEMA.innodb_sys_tables
256 +@return 0 on success */
259 +innodb_sys_tables_init(
260 +/*===================*/
261 + void* p) /*!< in/out: table schema object */
263 + ST_SCHEMA_TABLE* schema;
265 + DBUG_ENTER("innodb_sys_tables_init");
267 + schema = (ST_SCHEMA_TABLE*) p;
269 + schema->fields_info = innodb_sys_tables_fields_info;
270 + schema->fill_table = i_s_sys_tables_fill_table;
275 +UNIV_INTERN struct st_mysql_plugin i_s_innodb_sys_tables =
277 + /* the plugin type (a MYSQL_XXX_PLUGIN value) */
279 + STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
281 + /* pointer to type-specific plugin descriptor */
283 + STRUCT_FLD(info, &i_s_info),
287 + STRUCT_FLD(name, "INNODB_SYS_TABLES"),
289 + /* plugin author (for SHOW PLUGINS) */
291 + STRUCT_FLD(author, "Percona"),
293 + /* general descriptive text (for SHOW PLUGINS) */
295 + STRUCT_FLD(descr, "InnoDB SYS_TABLES"),
297 + /* the plugin license (PLUGIN_LICENSE_XXX) */
299 + STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
301 + /* the function to invoke when plugin is loaded */
302 + /* int (*)(void*); */
303 + STRUCT_FLD(init, innodb_sys_tables_init),
305 + /* the function to invoke when plugin is unloaded */
306 + /* int (*)(void*); */
307 + STRUCT_FLD(deinit, i_s_common_deinit),
309 + /* plugin version (for SHOW PLUGINS) */
311 + STRUCT_FLD(version, INNODB_VERSION_SHORT),
313 + /* struct st_mysql_show_var* */
314 + STRUCT_FLD(status_vars, NULL),
316 + /* struct st_mysql_sys_var** */
317 + STRUCT_FLD(system_vars, NULL),
319 + /* reserved for dependency checking */
321 + STRUCT_FLD(__reserved1, NULL)
324 +/* Fields of the dynamic table INFORMATION_SCHEMA.SYS_TABLESTATS */
325 +static ST_FIELD_INFO innodb_sys_tablestats_fields_info[] =
327 +#define SYS_TABLESTATS_ID 0
328 + {STRUCT_FLD(field_name, "TABLE_ID"),
329 + STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
330 + STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
331 + STRUCT_FLD(value, 0),
332 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
333 + STRUCT_FLD(old_name, ""),
334 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
336 +#define SYS_TABLESTATS_SCHEMA 1
337 + {STRUCT_FLD(field_name, "SCHEMA"),
338 + STRUCT_FLD(field_length, NAME_LEN + 1),
339 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
340 + STRUCT_FLD(value, 0),
341 + STRUCT_FLD(field_flags, 0),
342 + STRUCT_FLD(old_name, ""),
343 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
345 +#define SYS_TABLESTATS_NAME 2
346 + {STRUCT_FLD(field_name, "NAME"),
347 + STRUCT_FLD(field_length, NAME_LEN + 1),
348 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
349 + STRUCT_FLD(value, 0),
350 + STRUCT_FLD(field_flags, 0),
351 + STRUCT_FLD(old_name, ""),
352 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
354 +#define SYS_TABLESTATS_INIT 3
355 + {STRUCT_FLD(field_name, "STATS_INITIALIZED"),
356 + STRUCT_FLD(field_length, NAME_LEN + 1),
357 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
358 + STRUCT_FLD(value, 0),
359 + STRUCT_FLD(field_flags, 0),
360 + STRUCT_FLD(old_name, ""),
361 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
363 +#define SYS_TABLESTATS_NROW 4
364 + {STRUCT_FLD(field_name, "NUM_ROWS"),
365 + STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
366 + STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
367 + STRUCT_FLD(value, 0),
368 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
369 + STRUCT_FLD(old_name, ""),
370 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
372 +#define SYS_TABLESTATS_CLUST_SIZE 5
373 + {STRUCT_FLD(field_name, "CLUST_INDEX_SIZE"),
374 + STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
375 + STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
376 + STRUCT_FLD(value, 0),
377 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
378 + STRUCT_FLD(old_name, ""),
379 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
381 +#define SYS_TABLESTATS_INDEX_SIZE 6
382 + {STRUCT_FLD(field_name, "OTHER_INDEX_SIZE"),
383 + STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
384 + STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
385 + STRUCT_FLD(value, 0),
386 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
387 + STRUCT_FLD(old_name, ""),
388 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
390 +#define SYS_TABLESTATS_MODIFIED 7
391 + {STRUCT_FLD(field_name, "MODIFIED_COUNTER"),
392 + STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
393 + STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
394 + STRUCT_FLD(value, 0),
395 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
396 + STRUCT_FLD(old_name, ""),
397 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
399 +#define SYS_TABLESTATS_AUTONINC 8
400 + {STRUCT_FLD(field_name, "AUTOINC"),
401 + STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
402 + STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
403 + STRUCT_FLD(value, 0),
404 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
405 + STRUCT_FLD(old_name, ""),
406 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
408 +#define SYS_TABLESTATS_MYSQL_OPEN_HANDLE 9
409 + {STRUCT_FLD(field_name, "MYSQL_HANDLES_OPENED"),
410 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
411 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
412 + STRUCT_FLD(value, 0),
413 + STRUCT_FLD(field_flags, 0),
414 + STRUCT_FLD(old_name, ""),
415 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
417 + END_OF_ST_FIELD_INFO
420 +/**********************************************************************//**
421 +Populate information_schema.innodb_sys_tablestats table with information
423 +@return 0 on success */
426 +i_s_dict_fill_sys_tablestats(
427 +/*=========================*/
428 + THD* thd, /*!< in: thread */
429 + dict_table_t* table, /*!< in: table */
430 + TABLE* table_to_fill) /*!< in/out: fill this table */
433 + char buf[NAME_LEN * 2 + 2];
436 + DBUG_ENTER("i_s_dict_fill_sys_tablestats");
438 + fields = table_to_fill->field;
440 + OK(fields[SYS_TABLESTATS_ID]->store(longlong(table->id), TRUE));
442 + strncpy(buf, table->name, NAME_LEN * 2 + 2);
443 + ptr = strchr(buf, '/');
448 + OK(field_store_string(fields[SYS_TABLESTATS_SCHEMA], buf));
449 + OK(field_store_string(fields[SYS_TABLESTATS_NAME], ptr));
451 + fields[SYS_TABLESTATS_SCHEMA]->set_null();
452 + OK(field_store_string(fields[SYS_TABLESTATS_NAME], buf));
455 + if (table->stat_initialized) {
456 + OK(field_store_string(fields[SYS_TABLESTATS_INIT],
459 + OK(field_store_string(fields[SYS_TABLESTATS_INIT],
463 + OK(fields[SYS_TABLESTATS_NROW]->store(table->stat_n_rows, TRUE));
465 + OK(fields[SYS_TABLESTATS_CLUST_SIZE]->store(
466 + table->stat_clustered_index_size));
468 + OK(fields[SYS_TABLESTATS_INDEX_SIZE]->store(
469 + table->stat_sum_of_other_index_sizes));
471 + OK(fields[SYS_TABLESTATS_MODIFIED]->store(
472 + table->stat_modified_counter));
474 + OK(fields[SYS_TABLESTATS_AUTONINC]->store(table->autoinc, TRUE));
476 + OK(fields[SYS_TABLESTATS_MYSQL_OPEN_HANDLE]->store(
477 + table->n_mysql_handles_opened));
479 + OK(schema_table_store_record(thd, table_to_fill));
483 +/*******************************************************************//**
484 +Function to go through each record in SYS_TABLES table, and fill the
485 +information_schema.innodb_sys_tablestats table with table statistics
487 +@return 0 on success */
490 +i_s_sys_tables_fill_table_stats(
491 +/*============================*/
492 + THD* thd, /*!< in: thread */
493 + TABLE_LIST* tables, /*!< in/out: tables to fill */
494 + COND* cond) /*!< in: condition (not used) */
501 + DBUG_ENTER("i_s_sys_tables_fill_table_stats");
503 + /* deny access to non-superusers */
504 + if (check_global_access(thd, PROCESS_ACL)) {
509 + heap = mem_heap_create(1000);
510 + mutex_enter(&dict_sys->mutex);
513 + rec = dict_startscan_system(&pcur, &mtr, SYS_TABLES);
516 + const char* err_msg;
517 + dict_table_t* table_rec;
519 + /* Fetch the dict_table_t structure corresponding to
520 + this SYS_TABLES record */
521 + err_msg = dict_process_sys_tables_rec(
522 + heap, rec, &table_rec, DICT_TABLE_LOAD_FROM_CACHE);
525 + mutex_exit(&dict_sys->mutex);
528 + i_s_dict_fill_sys_tablestats(thd, table_rec,
531 + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
532 + ER_CANT_FIND_SYSTEM_REC,
536 + mem_heap_empty(heap);
538 + /* Get the next record */
539 + mutex_enter(&dict_sys->mutex);
541 + rec = dict_getnext_system(&pcur, &mtr);
545 + mutex_exit(&dict_sys->mutex);
546 + mem_heap_free(heap);
551 +/*******************************************************************//**
552 +Bind the dynamic table INFORMATION_SCHEMA.innodb_sys_tablestats
553 +@return 0 on success */
556 +innodb_sys_tablestats_init(
557 +/*=======================*/
558 + void* p) /*!< in/out: table schema object */
560 + ST_SCHEMA_TABLE* schema;
562 + DBUG_ENTER("innodb_sys_tablestats_init");
564 + schema = (ST_SCHEMA_TABLE*) p;
566 + schema->fields_info = innodb_sys_tablestats_fields_info;
567 + schema->fill_table = i_s_sys_tables_fill_table_stats;
572 +UNIV_INTERN struct st_mysql_plugin i_s_innodb_sys_tablestats =
574 + /* the plugin type (a MYSQL_XXX_PLUGIN value) */
576 + STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
578 + /* pointer to type-specific plugin descriptor */
580 + STRUCT_FLD(info, &i_s_info),
584 + STRUCT_FLD(name, "INNODB_SYS_TABLESTATS"),
586 + /* plugin author (for SHOW PLUGINS) */
588 + STRUCT_FLD(author, "Percona"),
590 + /* general descriptive text (for SHOW PLUGINS) */
592 + STRUCT_FLD(descr, "InnoDB SYS_TABLESTATS"),
594 + /* the plugin license (PLUGIN_LICENSE_XXX) */
596 + STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
598 + /* the function to invoke when plugin is loaded */
599 + /* int (*)(void*); */
600 + STRUCT_FLD(init, innodb_sys_tablestats_init),
602 + /* the function to invoke when plugin is unloaded */
603 + /* int (*)(void*); */
604 + STRUCT_FLD(deinit, i_s_common_deinit),
606 + /* plugin version (for SHOW PLUGINS) */
608 + STRUCT_FLD(version, INNODB_VERSION_SHORT),
610 + /* struct st_mysql_show_var* */
611 + STRUCT_FLD(status_vars, NULL),
613 + /* struct st_mysql_sys_var** */
614 + STRUCT_FLD(system_vars, NULL),
616 + /* reserved for dependency checking */
618 + STRUCT_FLD(__reserved1, NULL)
621 +/* Fields of the dynamic table INFORMATION_SCHEMA.SYS_INDEXES */
622 +static ST_FIELD_INFO innodb_sysindex_fields_info[] =
624 +#define SYS_INDEX_ID 0
625 + {STRUCT_FLD(field_name, "INDEX_ID"),
626 + STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
627 + STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
628 + STRUCT_FLD(value, 0),
629 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
630 + STRUCT_FLD(old_name, ""),
631 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
633 +#define SYS_INDEX_NAME 1
634 + {STRUCT_FLD(field_name, "NAME"),
635 + STRUCT_FLD(field_length, NAME_LEN + 1),
636 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
637 + STRUCT_FLD(value, 0),
638 + STRUCT_FLD(field_flags, 0),
639 + STRUCT_FLD(old_name, ""),
640 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
642 +#define SYS_INDEX_TABLE_ID 2
643 + {STRUCT_FLD(field_name, "TABLE_ID"),
644 + STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
645 + STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
646 + STRUCT_FLD(value, 0),
647 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
648 + STRUCT_FLD(old_name, ""),
649 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
651 +#define SYS_INDEX_TYPE 3
652 + {STRUCT_FLD(field_name, "TYPE"),
653 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
654 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
655 + STRUCT_FLD(value, 0),
656 + STRUCT_FLD(field_flags, 0),
657 + STRUCT_FLD(old_name, ""),
658 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
660 +#define SYS_INDEX_NUM_FIELDS 4
661 + {STRUCT_FLD(field_name, "N_FIELDS"),
662 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
663 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
664 + STRUCT_FLD(value, 0),
665 + STRUCT_FLD(field_flags, 0),
666 + STRUCT_FLD(old_name, ""),
667 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
669 +#define SYS_INDEX_PAGE_NO 5
670 + {STRUCT_FLD(field_name, "PAGE_NO"),
671 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
672 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
673 + STRUCT_FLD(value, 0),
674 + STRUCT_FLD(field_flags, 0),
675 + STRUCT_FLD(old_name, ""),
676 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
678 +#define SYS_INDEX_SPACE 6
679 + {STRUCT_FLD(field_name, "SPACE"),
680 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
681 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
682 + STRUCT_FLD(value, 0),
683 + STRUCT_FLD(field_flags, 0),
684 + STRUCT_FLD(old_name, ""),
685 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
687 + END_OF_ST_FIELD_INFO
690 +/**********************************************************************//**
691 +Function to populate the information_schema.innodb_sys_indexes table with
692 +collected index information
693 +@return 0 on success */
696 +i_s_dict_fill_sys_indexes(
697 +/*======================*/
698 + THD* thd, /*!< in: thread */
699 + table_id_t table_id, /*!< in: table id */
700 + dict_index_t* index, /*!< in: populated dict_index_t
701 + struct with index info */
702 + TABLE* table_to_fill) /*!< in/out: fill this table */
706 + DBUG_ENTER("i_s_dict_fill_sys_indexes");
708 + fields = table_to_fill->field;
710 + OK(fields[SYS_INDEX_ID]->store(longlong(index->id), TRUE));
712 + OK(field_store_string(fields[SYS_INDEX_NAME], index->name));
714 + OK(fields[SYS_INDEX_TABLE_ID]->store(longlong(table_id), TRUE));
716 + OK(fields[SYS_INDEX_TYPE]->store(index->type));
718 + OK(fields[SYS_INDEX_NUM_FIELDS]->store(index->n_fields));
720 + OK(fields[SYS_INDEX_PAGE_NO]->store(index->page));
722 + OK(fields[SYS_INDEX_SPACE]->store(index->space));
724 + OK(schema_table_store_record(thd, table_to_fill));
728 +/*******************************************************************//**
729 +Function to go through each record in SYS_INDEXES table, and fill the
730 +information_schema.innodb_sys_indexes table with related index information
731 +@return 0 on success */
734 +i_s_sys_indexes_fill_table(
735 +/*=======================*/
736 + THD* thd, /*!< in: thread */
737 + TABLE_LIST* tables, /*!< in/out: tables to fill */
738 + COND* cond) /*!< in: condition (not used) */
745 + DBUG_ENTER("i_s_sys_indexes_fill_table");
747 + /* deny access to non-superusers */
748 + if (check_global_access(thd, PROCESS_ACL)) {
753 + heap = mem_heap_create(1000);
754 + mutex_enter(&dict_sys->mutex);
757 + /* Start scan the SYS_INDEXES table */
758 + rec = dict_startscan_system(&pcur, &mtr, SYS_INDEXES);
760 + /* Process each record in the table */
762 + const char* err_msg;;
763 + table_id_t table_id;
764 + dict_index_t index_rec;
766 + /* Populate a dict_index_t structure with information from
767 + a SYS_INDEXES row */
768 + err_msg = dict_process_sys_indexes_rec(heap, rec, &index_rec,
772 + mutex_exit(&dict_sys->mutex);
775 + i_s_dict_fill_sys_indexes(thd, table_id, &index_rec,
778 + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
779 + ER_CANT_FIND_SYSTEM_REC,
783 + mem_heap_empty(heap);
785 + /* Get the next record */
786 + mutex_enter(&dict_sys->mutex);
788 + rec = dict_getnext_system(&pcur, &mtr);
792 + mutex_exit(&dict_sys->mutex);
793 + mem_heap_free(heap);
797 +/*******************************************************************//**
798 +Bind the dynamic table INFORMATION_SCHEMA.innodb_sys_indexes
799 +@return 0 on success */
802 +innodb_sys_indexes_init(
803 +/*====================*/
804 + void* p) /*!< in/out: table schema object */
806 + ST_SCHEMA_TABLE* schema;
808 + DBUG_ENTER("innodb_sys_index_init");
810 + schema = (ST_SCHEMA_TABLE*) p;
812 + schema->fields_info = innodb_sysindex_fields_info;
813 + schema->fill_table = i_s_sys_indexes_fill_table;
818 +UNIV_INTERN struct st_mysql_plugin i_s_innodb_sys_indexes =
820 + /* the plugin type (a MYSQL_XXX_PLUGIN value) */
822 + STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
824 + /* pointer to type-specific plugin descriptor */
826 + STRUCT_FLD(info, &i_s_info),
830 + STRUCT_FLD(name, "INNODB_SYS_INDEXES"),
832 + /* plugin author (for SHOW PLUGINS) */
834 + STRUCT_FLD(author, "Percona"),
836 + /* general descriptive text (for SHOW PLUGINS) */
838 + STRUCT_FLD(descr, "InnoDB SYS_INDEXES"),
840 + /* the plugin license (PLUGIN_LICENSE_XXX) */
842 + STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
844 + /* the function to invoke when plugin is loaded */
845 + /* int (*)(void*); */
846 + STRUCT_FLD(init, innodb_sys_indexes_init),
848 + /* the function to invoke when plugin is unloaded */
849 + /* int (*)(void*); */
850 + STRUCT_FLD(deinit, i_s_common_deinit),
852 + /* plugin version (for SHOW PLUGINS) */
854 + STRUCT_FLD(version, INNODB_VERSION_SHORT),
856 + /* struct st_mysql_show_var* */
857 + STRUCT_FLD(status_vars, NULL),
859 + /* struct st_mysql_sys_var** */
860 + STRUCT_FLD(system_vars, NULL),
862 + /* reserved for dependency checking */
864 + STRUCT_FLD(__reserved1, NULL)
867 +/* Fields of the dynamic table INFORMATION_SCHEMA.SYS_COLUMNS */
868 +static ST_FIELD_INFO innodb_sys_columns_fields_info[] =
870 +#define SYS_COLUMN_TABLE_ID 0
871 + {STRUCT_FLD(field_name, "TABLE_ID"),
872 + STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
873 + STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
874 + STRUCT_FLD(value, 0),
875 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
876 + STRUCT_FLD(old_name, ""),
877 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
879 +#define SYS_COLUMN_NAME 1
880 + {STRUCT_FLD(field_name, "NAME"),
881 + STRUCT_FLD(field_length, NAME_LEN + 1),
882 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
883 + STRUCT_FLD(value, 0),
884 + STRUCT_FLD(field_flags, 0),
885 + STRUCT_FLD(old_name, ""),
886 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
888 +#define SYS_COLUMN_POSITION 2
889 + {STRUCT_FLD(field_name, "POS"),
890 + STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
891 + STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
892 + STRUCT_FLD(value, 0),
893 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
894 + STRUCT_FLD(old_name, ""),
895 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
897 +#define SYS_COLUMN_MTYPE 3
898 + {STRUCT_FLD(field_name, "MTYPE"),
899 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
900 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
901 + STRUCT_FLD(value, 0),
902 + STRUCT_FLD(field_flags, 0),
903 + STRUCT_FLD(old_name, ""),
904 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
906 +#define SYS_COLUMN__PRTYPE 4
907 + {STRUCT_FLD(field_name, "PRTYPE"),
908 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
909 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
910 + STRUCT_FLD(value, 0),
911 + STRUCT_FLD(field_flags, 0),
912 + STRUCT_FLD(old_name, ""),
913 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
915 +#define SYS_COLUMN_COLUMN_LEN 5
916 + {STRUCT_FLD(field_name, "LEN"),
917 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
918 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
919 + STRUCT_FLD(value, 0),
920 + STRUCT_FLD(field_flags, 0),
921 + STRUCT_FLD(old_name, ""),
922 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
924 + END_OF_ST_FIELD_INFO
927 +/**********************************************************************//**
928 +Function to populate the information_schema.innodb_sys_columns with
929 +related column information
930 +@return 0 on success */
933 +i_s_dict_fill_sys_columns(
934 +/*======================*/
935 + THD* thd, /*!< in: thread */
936 + table_id_t table_id, /*!< in: table ID */
937 + const char* col_name, /*!< in: column name */
938 + dict_col_t* column, /*!< in: dict_col_t struct holding
939 + more column information */
940 + TABLE* table_to_fill) /*!< in/out: fill this table */
944 + DBUG_ENTER("i_s_dict_fill_sys_columns");
946 + fields = table_to_fill->field;
948 + OK(fields[SYS_COLUMN_TABLE_ID]->store(longlong(table_id), TRUE));
950 + OK(field_store_string(fields[SYS_COLUMN_NAME], col_name));
952 + OK(fields[SYS_COLUMN_POSITION]->store(column->ind));
954 + OK(fields[SYS_COLUMN_MTYPE]->store(column->mtype));
956 + OK(fields[SYS_COLUMN__PRTYPE]->store(column->prtype));
958 + OK(fields[SYS_COLUMN_COLUMN_LEN]->store(column->len));
960 + OK(schema_table_store_record(thd, table_to_fill));
964 +/*******************************************************************//**
965 +Function to fill information_schema.innodb_sys_columns with information
966 +collected by scanning SYS_COLUMNS table.
967 +@return 0 on success */
970 +i_s_sys_columns_fill_table(
971 +/*=======================*/
972 + THD* thd, /*!< in: thread */
973 + TABLE_LIST* tables, /*!< in/out: tables to fill */
974 + COND* cond) /*!< in: condition (not used) */
978 + const char* col_name;
982 + DBUG_ENTER("i_s_sys_columns_fill_table");
984 + /* deny access to non-superusers */
985 + if (check_global_access(thd, PROCESS_ACL)) {
990 + heap = mem_heap_create(1000);
991 + mutex_enter(&dict_sys->mutex);
994 + rec = dict_startscan_system(&pcur, &mtr, SYS_COLUMNS);
997 + const char* err_msg;
998 + dict_col_t column_rec;
999 + table_id_t table_id;
1001 + /* populate a dict_col_t structure with information from
1002 + a SYS_COLUMNS row */
1003 + err_msg = dict_process_sys_columns_rec(heap, rec, &column_rec,
1004 + &table_id, &col_name);
1007 + mutex_exit(&dict_sys->mutex);
1010 + i_s_dict_fill_sys_columns(thd, table_id, col_name,
1014 + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
1015 + ER_CANT_FIND_SYSTEM_REC,
1019 + mem_heap_empty(heap);
1021 + /* Get the next record */
1022 + mutex_enter(&dict_sys->mutex);
1024 + rec = dict_getnext_system(&pcur, &mtr);
1028 + mutex_exit(&dict_sys->mutex);
1029 + mem_heap_free(heap);
1033 +/*******************************************************************//**
1034 +Bind the dynamic table INFORMATION_SCHEMA.innodb_sys_columns
1035 +@return 0 on success */
1038 +innodb_sys_columns_init(
1039 +/*====================*/
1040 + void* p) /*!< in/out: table schema object */
1042 + ST_SCHEMA_TABLE* schema;
1044 + DBUG_ENTER("innodb_sys_columns_init");
1046 + schema = (ST_SCHEMA_TABLE*) p;
1048 + schema->fields_info = innodb_sys_columns_fields_info;
1049 + schema->fill_table = i_s_sys_columns_fill_table;
1054 +UNIV_INTERN struct st_mysql_plugin i_s_innodb_sys_columns =
1056 + /* the plugin type (a MYSQL_XXX_PLUGIN value) */
1058 + STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
1060 + /* pointer to type-specific plugin descriptor */
1062 + STRUCT_FLD(info, &i_s_info),
1066 + STRUCT_FLD(name, "INNODB_SYS_COLUMNS"),
1068 + /* plugin author (for SHOW PLUGINS) */
1070 + STRUCT_FLD(author, "Percona"),
1072 + /* general descriptive text (for SHOW PLUGINS) */
1074 + STRUCT_FLD(descr, "InnoDB SYS_COLUMNS"),
1076 + /* the plugin license (PLUGIN_LICENSE_XXX) */
1078 + STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
1080 + /* the function to invoke when plugin is loaded */
1081 + /* int (*)(void*); */
1082 + STRUCT_FLD(init, innodb_sys_columns_init),
1084 + /* the function to invoke when plugin is unloaded */
1085 + /* int (*)(void*); */
1086 + STRUCT_FLD(deinit, i_s_common_deinit),
1088 + /* plugin version (for SHOW PLUGINS) */
1089 + /* unsigned int */
1090 + STRUCT_FLD(version, INNODB_VERSION_SHORT),
1092 + /* struct st_mysql_show_var* */
1093 + STRUCT_FLD(status_vars, NULL),
1095 + /* struct st_mysql_sys_var** */
1096 + STRUCT_FLD(system_vars, NULL),
1098 + /* reserved for dependency checking */
1100 + STRUCT_FLD(__reserved1, NULL)
1102 +/* Fields of the dynamic table INFORMATION_SCHEMA.innodb_sys_fields */
1103 +static ST_FIELD_INFO innodb_sys_fields_fields_info[] =
1105 +#define SYS_FIELD_INDEX_ID 0
1106 + {STRUCT_FLD(field_name, "INDEX_ID"),
1107 + STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
1108 + STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
1109 + STRUCT_FLD(value, 0),
1110 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
1111 + STRUCT_FLD(old_name, ""),
1112 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
1114 +#define SYS_FIELD_NAME 1
1115 + {STRUCT_FLD(field_name, "NAME"),
1116 + STRUCT_FLD(field_length, NAME_LEN + 1),
1117 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
1118 + STRUCT_FLD(value, 0),
1119 + STRUCT_FLD(field_flags, 0),
1120 + STRUCT_FLD(old_name, ""),
1121 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
1123 +#define SYS_FIELD_POS 2
1124 + {STRUCT_FLD(field_name, "POS"),
1125 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
1126 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
1127 + STRUCT_FLD(value, 0),
1128 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
1129 + STRUCT_FLD(old_name, ""),
1130 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
1132 + END_OF_ST_FIELD_INFO
1135 +/**********************************************************************//**
1136 +Function to fill information_schema.innodb_sys_fields with information
1137 +collected by scanning SYS_FIELDS table.
1138 +@return 0 on success */
1141 +i_s_dict_fill_sys_fields(
1142 +/*=====================*/
1143 + THD* thd, /*!< in: thread */
1144 + index_id_t index_id, /*!< in: index id for the field */
1145 + dict_field_t* field, /*!< in: table */
1146 + ulint pos, /*!< in: Field position */
1147 + TABLE* table_to_fill) /*!< in/out: fill this table */
1151 + DBUG_ENTER("i_s_dict_fill_sys_fields");
1153 + fields = table_to_fill->field;
1155 + OK(fields[SYS_FIELD_INDEX_ID]->store(longlong(index_id), TRUE));
1157 + OK(field_store_string(fields[SYS_FIELD_NAME], field->name));
1159 + OK(fields[SYS_FIELD_POS]->store(pos));
1161 + OK(schema_table_store_record(thd, table_to_fill));
1165 +/*******************************************************************//**
1166 +Function to go through each record in SYS_FIELDS table, and fill the
1167 +information_schema.innodb_sys_fields table with related index field
1169 +@return 0 on success */
1172 +i_s_sys_fields_fill_table(
1173 +/*======================*/
1174 + THD* thd, /*!< in: thread */
1175 + TABLE_LIST* tables, /*!< in/out: tables to fill */
1176 + COND* cond) /*!< in: condition (not used) */
1181 + index_id_t last_id;
1184 + DBUG_ENTER("i_s_sys_fields_fill_table");
1186 + /* deny access to non-superusers */
1187 + if (check_global_access(thd, PROCESS_ACL)) {
1192 + heap = mem_heap_create(1000);
1193 + mutex_enter(&dict_sys->mutex);
1196 + /* will save last index id so that we know whether we move to
1197 + the next index. This is used to calculate prefix length */
1200 + rec = dict_startscan_system(&pcur, &mtr, SYS_FIELDS);
1204 + const char* err_msg;
1205 + index_id_t index_id;
1206 + dict_field_t field_rec;
1208 + /* Populate a dict_field_t structure with information from
1209 + a SYS_FIELDS row */
1210 + err_msg = dict_process_sys_fields_rec(heap, rec, &field_rec,
1211 + &pos, &index_id, last_id);
1214 + mutex_exit(&dict_sys->mutex);
1217 + i_s_dict_fill_sys_fields(thd, index_id, &field_rec,
1218 + pos, tables->table);
1219 + last_id = index_id;
1221 + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
1222 + ER_CANT_FIND_SYSTEM_REC,
1226 + mem_heap_empty(heap);
1228 + /* Get the next record */
1229 + mutex_enter(&dict_sys->mutex);
1231 + rec = dict_getnext_system(&pcur, &mtr);
1235 + mutex_exit(&dict_sys->mutex);
1236 + mem_heap_free(heap);
1240 +/*******************************************************************//**
1241 +Bind the dynamic table INFORMATION_SCHEMA.innodb_sys_fields
1242 +@return 0 on success */
1245 +innodb_sys_fields_init(
1246 +/*===================*/
1247 + void* p) /*!< in/out: table schema object */
1249 + ST_SCHEMA_TABLE* schema;
1251 + DBUG_ENTER("innodb_sys_field_init");
1253 + schema = (ST_SCHEMA_TABLE*) p;
1255 + schema->fields_info = innodb_sys_fields_fields_info;
1256 + schema->fill_table = i_s_sys_fields_fill_table;
1261 +UNIV_INTERN struct st_mysql_plugin i_s_innodb_sys_fields =
1263 + /* the plugin type (a MYSQL_XXX_PLUGIN value) */
1265 + STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
1267 + /* pointer to type-specific plugin descriptor */
1269 + STRUCT_FLD(info, &i_s_info),
1273 + STRUCT_FLD(name, "INNODB_SYS_FIELDS"),
1275 + /* plugin author (for SHOW PLUGINS) */
1277 + STRUCT_FLD(author, "Percona"),
1279 + /* general descriptive text (for SHOW PLUGINS) */
1281 + STRUCT_FLD(descr, "InnoDB SYS_FIELDS"),
1283 + /* the plugin license (PLUGIN_LICENSE_XXX) */
1285 + STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
1287 + /* the function to invoke when plugin is loaded */
1288 + /* int (*)(void*); */
1289 + STRUCT_FLD(init, innodb_sys_fields_init),
1291 + /* the function to invoke when plugin is unloaded */
1292 + /* int (*)(void*); */
1293 + STRUCT_FLD(deinit, i_s_common_deinit),
1295 + /* plugin version (for SHOW PLUGINS) */
1296 + /* unsigned int */
1297 + STRUCT_FLD(version, INNODB_VERSION_SHORT),
1299 + /* struct st_mysql_show_var* */
1300 + STRUCT_FLD(status_vars, NULL),
1302 + /* struct st_mysql_sys_var** */
1303 + STRUCT_FLD(system_vars, NULL),
1305 + /* reserved for dependency checking */
1307 + STRUCT_FLD(__reserved1, NULL)
1310 +/* Fields of the dynamic table INFORMATION_SCHEMA.innodb_sys_foreign */
1311 +static ST_FIELD_INFO innodb_sys_foreign_fields_info[] =
1313 +#define SYS_FOREIGN_ID 0
1314 + {STRUCT_FLD(field_name, "ID"),
1315 + STRUCT_FLD(field_length, NAME_LEN + 1),
1316 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
1317 + STRUCT_FLD(value, 0),
1318 + STRUCT_FLD(field_flags, 0),
1319 + STRUCT_FLD(old_name, ""),
1320 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
1322 +#define SYS_FOREIGN_FOR_NAME 1
1323 + {STRUCT_FLD(field_name, "FOR_NAME"),
1324 + STRUCT_FLD(field_length, NAME_LEN + 1),
1325 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
1326 + STRUCT_FLD(value, 0),
1327 + STRUCT_FLD(field_flags, 0),
1328 + STRUCT_FLD(old_name, ""),
1329 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
1331 +#define SYS_FOREIGN_REF_NAME 2
1332 + {STRUCT_FLD(field_name, "REF_NAME"),
1333 + STRUCT_FLD(field_length, NAME_LEN + 1),
1334 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
1335 + STRUCT_FLD(value, 0),
1336 + STRUCT_FLD(field_flags, 0),
1337 + STRUCT_FLD(old_name, ""),
1338 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
1340 +#define SYS_FOREIGN_NUM_COL 3
1341 + {STRUCT_FLD(field_name, "N_COLS"),
1342 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
1343 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
1344 + STRUCT_FLD(value, 0),
1345 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
1346 + STRUCT_FLD(old_name, ""),
1347 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
1349 +#define SYS_FOREIGN_TYPE 4
1350 + {STRUCT_FLD(field_name, "TYPE"),
1351 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
1352 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
1353 + STRUCT_FLD(value, 0),
1354 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
1355 + STRUCT_FLD(old_name, ""),
1356 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
1358 + END_OF_ST_FIELD_INFO
1361 +/**********************************************************************//**
1362 +Function to fill information_schema.innodb_sys_foreign with information
1363 +collected by scanning SYS_FOREIGN table.
1364 +@return 0 on success */
1367 +i_s_dict_fill_sys_foreign(
1368 +/*======================*/
1369 + THD* thd, /*!< in: thread */
1370 + dict_foreign_t* foreign, /*!< in: table */
1371 + TABLE* table_to_fill) /*!< in/out: fill this table */
1375 + DBUG_ENTER("i_s_dict_fill_sys_foreign");
1377 + fields = table_to_fill->field;
1379 + OK(field_store_string(fields[SYS_FOREIGN_ID], foreign->id));
1381 + OK(field_store_string(fields[SYS_FOREIGN_FOR_NAME],
1382 + foreign->foreign_table_name));
1384 + OK(field_store_string(fields[SYS_FOREIGN_REF_NAME],
1385 + foreign->referenced_table_name));
1387 + OK(fields[SYS_FOREIGN_NUM_COL]->store(foreign->n_fields));
1389 + OK(fields[SYS_FOREIGN_TYPE]->store(foreign->type));
1391 + OK(schema_table_store_record(thd, table_to_fill));
1395 +/*******************************************************************//**
1396 +Function to populate INFORMATION_SCHEMA.innodb_sys_foreign table. Loop
1397 +through each record in SYS_FOREIGN, and extract the foreign key
1399 +@return 0 on success */
1402 +i_s_sys_foreign_fill_table(
1403 +/*=======================*/
1404 + THD* thd, /*!< in: thread */
1405 + TABLE_LIST* tables, /*!< in/out: tables to fill */
1406 + COND* cond) /*!< in: condition (not used) */
1413 + DBUG_ENTER("i_s_sys_foreign_fill_table");
1415 + /* deny access to non-superusers */
1416 + if (check_global_access(thd, PROCESS_ACL)) {
1421 + heap = mem_heap_create(1000);
1422 + mutex_enter(&dict_sys->mutex);
1425 + rec = dict_startscan_system(&pcur, &mtr, SYS_FOREIGN);
1428 + const char* err_msg;
1429 + dict_foreign_t foreign_rec;
1431 + /* Populate a dict_foreign_t structure with information from
1432 + a SYS_FOREIGN row */
1433 + err_msg = dict_process_sys_foreign_rec(heap, rec, &foreign_rec);
1436 + mutex_exit(&dict_sys->mutex);
1439 + i_s_dict_fill_sys_foreign(thd, &foreign_rec,
1442 + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
1443 + ER_CANT_FIND_SYSTEM_REC,
1447 + mem_heap_empty(heap);
1449 + /* Get the next record */
1451 + mutex_enter(&dict_sys->mutex);
1452 + rec = dict_getnext_system(&pcur, &mtr);
1456 + mutex_exit(&dict_sys->mutex);
1457 + mem_heap_free(heap);
1461 +/*******************************************************************//**
1462 +Bind the dynamic table INFORMATION_SCHEMA.innodb_sys_foreign
1463 +@return 0 on success */
1466 +innodb_sys_foreign_init(
1467 +/*====================*/
1468 + void* p) /*!< in/out: table schema object */
1470 + ST_SCHEMA_TABLE* schema;
1472 + DBUG_ENTER("innodb_sys_foreign_init");
1474 + schema = (ST_SCHEMA_TABLE*) p;
1476 + schema->fields_info = innodb_sys_foreign_fields_info;
1477 + schema->fill_table = i_s_sys_foreign_fill_table;
1482 +UNIV_INTERN struct st_mysql_plugin i_s_innodb_sys_foreign =
1484 + /* the plugin type (a MYSQL_XXX_PLUGIN value) */
1486 + STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
1488 + /* pointer to type-specific plugin descriptor */
1490 + STRUCT_FLD(info, &i_s_info),
1494 + STRUCT_FLD(name, "INNODB_SYS_FOREIGN"),
1496 + /* plugin author (for SHOW PLUGINS) */
1498 + STRUCT_FLD(author, "Percona"),
1500 + /* general descriptive text (for SHOW PLUGINS) */
1502 + STRUCT_FLD(descr, "InnoDB SYS_FOREIGN"),
1504 + /* the plugin license (PLUGIN_LICENSE_XXX) */
1506 + STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
1508 + /* the function to invoke when plugin is loaded */
1509 + /* int (*)(void*); */
1510 + STRUCT_FLD(init, innodb_sys_foreign_init),
1512 + /* the function to invoke when plugin is unloaded */
1513 + /* int (*)(void*); */
1514 + STRUCT_FLD(deinit, i_s_common_deinit),
1516 + /* plugin version (for SHOW PLUGINS) */
1517 + /* unsigned int */
1518 + STRUCT_FLD(version, INNODB_VERSION_SHORT),
1520 + /* struct st_mysql_show_var* */
1521 + STRUCT_FLD(status_vars, NULL),
1523 + /* struct st_mysql_sys_var** */
1524 + STRUCT_FLD(system_vars, NULL),
1526 + /* reserved for dependency checking */
1528 + STRUCT_FLD(__reserved1, NULL)
1530 +/* Fields of the dynamic table INFORMATION_SCHEMA.innodb_sys_foreign_cols */
1531 +static ST_FIELD_INFO innodb_sys_foreign_cols_fields_info[] =
1533 +#define SYS_FOREIGN_COL_ID 0
1534 + {STRUCT_FLD(field_name, "ID"),
1535 + STRUCT_FLD(field_length, NAME_LEN + 1),
1536 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
1537 + STRUCT_FLD(value, 0),
1538 + STRUCT_FLD(field_flags, 0),
1539 + STRUCT_FLD(old_name, ""),
1540 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
1542 +#define SYS_FOREIGN_COL_FOR_NAME 1
1543 + {STRUCT_FLD(field_name, "FOR_COL_NAME"),
1544 + STRUCT_FLD(field_length, NAME_LEN + 1),
1545 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
1546 + STRUCT_FLD(value, 0),
1547 + STRUCT_FLD(field_flags, 0),
1548 + STRUCT_FLD(old_name, ""),
1549 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
1551 +#define SYS_FOREIGN_COL_REF_NAME 2
1552 + {STRUCT_FLD(field_name, "REF_COL_NAME"),
1553 + STRUCT_FLD(field_length, NAME_LEN + 1),
1554 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
1555 + STRUCT_FLD(value, 0),
1556 + STRUCT_FLD(field_flags, 0),
1557 + STRUCT_FLD(old_name, ""),
1558 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
1560 +#define SYS_FOREIGN_COL_POS 3
1561 + {STRUCT_FLD(field_name, "POS"),
1562 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
1563 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
1564 + STRUCT_FLD(value, 0),
1565 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
1566 + STRUCT_FLD(old_name, ""),
1567 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
1569 + END_OF_ST_FIELD_INFO
1572 +/**********************************************************************//**
1573 +Function to fill information_schema.innodb_sys_foreign_cols with information
1574 +collected by scanning SYS_FOREIGN_COLS table.
1575 +@return 0 on success */
1578 +i_s_dict_fill_sys_foreign_cols(
1579 +/*==========================*/
1580 + THD* thd, /*!< in: thread */
1581 + const char* name, /*!< in: foreign key constraint name */
1582 + const char* for_col_name, /*!< in: referencing column name*/
1583 + const char* ref_col_name, /*!< in: referenced column
1585 + ulint pos, /*!< in: column position */
1586 + TABLE* table_to_fill) /*!< in/out: fill this table */
1590 + DBUG_ENTER("i_s_dict_fill_sys_foreign_cols");
1592 + fields = table_to_fill->field;
1594 + OK(field_store_string(fields[SYS_FOREIGN_COL_ID], name));
1596 + OK(field_store_string(fields[SYS_FOREIGN_COL_FOR_NAME], for_col_name));
1598 + OK(field_store_string(fields[SYS_FOREIGN_COL_REF_NAME], ref_col_name));
1600 + OK(fields[SYS_FOREIGN_COL_POS]->store(pos));
1602 + OK(schema_table_store_record(thd, table_to_fill));
1606 +/*******************************************************************//**
1607 +Function to populate INFORMATION_SCHEMA.innodb_sys_foreign_cols table. Loop
1608 +through each record in SYS_FOREIGN_COLS, and extract the foreign key column
1609 +information and fill the INFORMATION_SCHEMA.innodb_sys_foreign_cols table.
1610 +@return 0 on success */
1613 +i_s_sys_foreign_cols_fill_table(
1614 +/*============================*/
1615 + THD* thd, /*!< in: thread */
1616 + TABLE_LIST* tables, /*!< in/out: tables to fill */
1617 + COND* cond) /*!< in: condition (not used) */
1624 + DBUG_ENTER("i_s_sys_foreign_cols_fill_table");
1626 + /* deny access to non-superusers */
1627 + if (check_global_access(thd, PROCESS_ACL)) {
1631 + heap = mem_heap_create(1000);
1632 + mutex_enter(&dict_sys->mutex);
1635 + rec = dict_startscan_system(&pcur, &mtr, SYS_FOREIGN_COLS);
1638 + const char* err_msg;
1640 + const char* for_col_name;
1641 + const char* ref_col_name;
1644 + /* Extract necessary information from a SYS_FOREIGN_COLS row */
1645 + err_msg = dict_process_sys_foreign_col_rec(
1646 + heap, rec, &name, &for_col_name, &ref_col_name, &pos);
1649 + mutex_exit(&dict_sys->mutex);
1652 + i_s_dict_fill_sys_foreign_cols(
1653 + thd, name, for_col_name, ref_col_name, pos,
1656 + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
1657 + ER_CANT_FIND_SYSTEM_REC,
1661 + mem_heap_empty(heap);
1663 + /* Get the next record */
1664 + mutex_enter(&dict_sys->mutex);
1666 + rec = dict_getnext_system(&pcur, &mtr);
1670 + mutex_exit(&dict_sys->mutex);
1671 + mem_heap_free(heap);
1675 +/*******************************************************************//**
1676 +Bind the dynamic table INFORMATION_SCHEMA.innodb_sys_foreign_cols
1677 +@return 0 on success */
1680 +innodb_sys_foreign_cols_init(
1681 +/*========================*/
1682 + void* p) /*!< in/out: table schema object */
1684 + ST_SCHEMA_TABLE* schema;
1686 + DBUG_ENTER("innodb_sys_foreign_cols_init");
1688 + schema = (ST_SCHEMA_TABLE*) p;
1690 + schema->fields_info = innodb_sys_foreign_cols_fields_info;
1691 + schema->fill_table = i_s_sys_foreign_cols_fill_table;
1696 +UNIV_INTERN struct st_mysql_plugin i_s_innodb_sys_foreign_cols =
1698 + /* the plugin type (a MYSQL_XXX_PLUGIN value) */
1700 + STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
1702 + /* pointer to type-specific plugin descriptor */
1704 + STRUCT_FLD(info, &i_s_info),
1708 + STRUCT_FLD(name, "INNODB_SYS_FOREIGN_COLS"),
1710 + /* plugin author (for SHOW PLUGINS) */
1712 + STRUCT_FLD(author, "Percona"),
1714 + /* general descriptive text (for SHOW PLUGINS) */
1716 + STRUCT_FLD(descr, "InnoDB SYS_FOREIGN_COLS"),
1718 + /* the plugin license (PLUGIN_LICENSE_XXX) */
1720 + STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
1722 + /* the function to invoke when plugin is loaded */
1723 + /* int (*)(void*); */
1724 + STRUCT_FLD(init, innodb_sys_foreign_cols_init),
1726 + /* the function to invoke when plugin is unloaded */
1727 + /* int (*)(void*); */
1728 + STRUCT_FLD(deinit, i_s_common_deinit),
1730 + /* plugin version (for SHOW PLUGINS) */
1731 + /* unsigned int */
1732 + STRUCT_FLD(version, INNODB_VERSION_SHORT),
1734 + /* struct st_mysql_show_var* */
1735 + STRUCT_FLD(status_vars, NULL),
1737 + /* struct st_mysql_sys_var** */
1738 + STRUCT_FLD(system_vars, NULL),
1740 + /* reserved for dependency checking */
1742 + STRUCT_FLD(__reserved1, NULL)
1745 /***********************************************************************
1747 static ST_FIELD_INFO i_s_innodb_rseg_fields_info[] =
1748 --- a/storage/innobase/handler/i_s.h
1749 +++ b/storage/innobase/handler/i_s.h
1751 extern struct st_mysql_plugin i_s_innodb_cmp_reset;
1752 extern struct st_mysql_plugin i_s_innodb_cmpmem;
1753 extern struct st_mysql_plugin i_s_innodb_cmpmem_reset;
1754 +extern struct st_mysql_plugin i_s_innodb_sys_tables;
1755 +extern struct st_mysql_plugin i_s_innodb_sys_tablestats;
1756 +extern struct st_mysql_plugin i_s_innodb_sys_indexes;
1757 +extern struct st_mysql_plugin i_s_innodb_sys_columns;
1758 +extern struct st_mysql_plugin i_s_innodb_sys_fields;
1759 +extern struct st_mysql_plugin i_s_innodb_sys_foreign;
1760 +extern struct st_mysql_plugin i_s_innodb_sys_foreign_cols;
1761 extern struct st_mysql_plugin i_s_innodb_rseg;
1765 +++ b/mysql-test/r/percona_innodb_use_sys_stats_table.result
1767 +show variables like 'innodb_use_sys_stats%';
1768 +Variable_name Value
1769 +innodb_use_sys_stats_table ON
1771 +++ b/mysql-test/t/percona_innodb_use_sys_stats_table-master.opt
1773 +--innodb_use_sys_stats_table
1775 +++ b/mysql-test/t/percona_innodb_use_sys_stats_table.test
1777 +--source include/have_innodb.inc
1778 +show variables like 'innodb_use_sys_stats%';