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 diff -ruN a/storage/innobase/dict/dict0load.c b/storage/innobase/dict/dict0load.c
9 --- a/storage/innobase/dict/dict0load.c 2011-01-20 07:37:08.000000000 +0900
10 +++ b/storage/innobase/dict/dict0load.c 2011-02-14 18:59:40.774162959 +0900
15 -#ifdef FOREIGN_NOT_USED
16 +//#ifdef FOREIGN_NOT_USED
17 /********************************************************************//**
18 This function parses a SYS_FOREIGN record and populate a dict_foreign_t
19 structure with the information from the record. For detail information
24 -#endif /* FOREIGN_NOT_USED */
25 +//#endif /* FOREIGN_NOT_USED */
27 -#ifdef FOREIGN_NOT_USED
28 +//#ifdef FOREIGN_NOT_USED
29 /********************************************************************//**
30 This function parses a SYS_FOREIGN_COLS record and extract necessary
31 information from the record and return to caller.
36 -#endif /* FOREIGN_NOT_USED */
37 +//#endif /* FOREIGN_NOT_USED */
39 /********************************************************************//**
40 Determine the flags of a table described in SYS_TABLES.
41 diff -ruN a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc
42 --- a/storage/innobase/handler/ha_innodb.cc 2010-12-03 15:53:54.615040167 +0900
43 +++ b/storage/innobase/handler/ha_innodb.cc 2010-12-03 16:07:26.851357007 +0900
44 @@ -11665,7 +11665,14 @@
48 -i_s_innodb_cmpmem_reset
49 +i_s_innodb_cmpmem_reset,
50 +i_s_innodb_sys_tables,
51 +i_s_innodb_sys_tablestats,
52 +i_s_innodb_sys_indexes,
53 +i_s_innodb_sys_columns,
54 +i_s_innodb_sys_fields,
55 +i_s_innodb_sys_foreign,
56 +i_s_innodb_sys_foreign_cols
57 mysql_declare_plugin_end;
59 /** @brief Initialize the default value of innodb_commit_concurrency.
60 diff -ruN a/storage/innobase/handler/i_s.cc b/storage/innobase/handler/i_s.cc
61 --- a/storage/innobase/handler/i_s.cc 2010-12-03 15:49:59.207956807 +0900
62 +++ b/storage/innobase/handler/i_s.cc 2010-12-03 17:10:02.719210529 +0900
64 #include <mysql/innodb_priv.h>
67 +#include "btr0pcur.h" /* for file sys_tables related info. */
68 #include "btr0types.h"
69 #include "buf0buddy.h" /* for i_s_cmpmem */
70 #include "buf0buf.h" /* for buf_pool and PAGE_ZIP_MIN_SIZE */
71 +#include "dict0load.h" /* for file sys_tables related info. */
73 #include "dict0types.h"
74 #include "ha_prototypes.h" /* for innobase_convert_name() */
75 @@ -1786,6 +1788,1675 @@
79 +/* Fields of the dynamic table INFORMATION_SCHEMA.SYS_TABLES */
80 +static ST_FIELD_INFO innodb_sys_tables_fields_info[] =
82 +#define SYS_TABLE_ID 0
83 + {STRUCT_FLD(field_name, "TABLE_ID"),
84 + STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
85 + STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
86 + STRUCT_FLD(value, 0),
87 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
88 + STRUCT_FLD(old_name, ""),
89 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
91 +#define SYS_TABLE_SCHEMA 1
92 + {STRUCT_FLD(field_name, "SCHEMA"),
93 + STRUCT_FLD(field_length, NAME_LEN + 1),
94 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
95 + STRUCT_FLD(value, 0),
96 + STRUCT_FLD(field_flags, 0),
97 + STRUCT_FLD(old_name, ""),
98 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
100 +#define SYS_TABLE_NAME 2
101 + {STRUCT_FLD(field_name, "NAME"),
102 + STRUCT_FLD(field_length, NAME_LEN + 1),
103 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
104 + STRUCT_FLD(value, 0),
105 + STRUCT_FLD(field_flags, 0),
106 + STRUCT_FLD(old_name, ""),
107 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
109 +#define SYS_TABLE_FLAG 3
110 + {STRUCT_FLD(field_name, "FLAG"),
111 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
112 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
113 + STRUCT_FLD(value, 0),
114 + STRUCT_FLD(field_flags, 0),
115 + STRUCT_FLD(old_name, ""),
116 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
118 +#define SYS_TABLE_NUM_COLUMN 4
119 + {STRUCT_FLD(field_name, "N_COLS"),
120 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
121 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
122 + STRUCT_FLD(value, 0),
123 + STRUCT_FLD(field_flags, 0),
124 + STRUCT_FLD(old_name, ""),
125 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
127 +#define SYS_TABLE_SPACE 5
128 + {STRUCT_FLD(field_name, "SPACE"),
129 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
130 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
131 + STRUCT_FLD(value, 0),
132 + STRUCT_FLD(field_flags, 0),
133 + STRUCT_FLD(old_name, ""),
134 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
136 + END_OF_ST_FIELD_INFO
139 +/**********************************************************************//**
140 +Populate information_schema.innodb_sys_tables table with information
142 +@return 0 on success */
145 +i_s_dict_fill_sys_tables(
146 +/*=====================*/
147 + THD* thd, /*!< in: thread */
148 + dict_table_t* table, /*!< in: table */
149 + TABLE* table_to_fill) /*!< in/out: fill this table */
152 + char buf[NAME_LEN * 2 + 2];
155 + DBUG_ENTER("i_s_dict_fill_sys_tables");
157 + fields = table_to_fill->field;
159 + OK(fields[SYS_TABLE_ID]->store(longlong(table->id), TRUE));
161 + strncpy(buf, table->name, NAME_LEN * 2 + 2);
162 + ptr = strchr(buf, '/');
167 + OK(field_store_string(fields[SYS_TABLE_SCHEMA], buf));
168 + OK(field_store_string(fields[SYS_TABLE_NAME], ptr));
170 + fields[SYS_TABLE_SCHEMA]->set_null();
171 + OK(field_store_string(fields[SYS_TABLE_NAME], buf));
174 + OK(fields[SYS_TABLE_FLAG]->store(table->flags));
176 + OK(fields[SYS_TABLE_NUM_COLUMN]->store(table->n_cols));
178 + OK(fields[SYS_TABLE_SPACE]->store(table->space));
180 + OK(schema_table_store_record(thd, table_to_fill));
184 +/*******************************************************************//**
185 +Function to go through each record in SYS_TABLES table, and fill the
186 +information_schema.innodb_sys_tables table with related table information
187 +@return 0 on success */
190 +i_s_sys_tables_fill_table(
191 +/*======================*/
192 + THD* thd, /*!< in: thread */
193 + TABLE_LIST* tables, /*!< in/out: tables to fill */
194 + COND* cond) /*!< in: condition (not used) */
201 + DBUG_ENTER("i_s_sys_tables_fill_table");
203 + /* deny access to non-superusers */
204 + if (check_global_access(thd, PROCESS_ACL)) {
209 + heap = mem_heap_create(1000);
210 + mutex_enter(&(dict_sys->mutex));
213 + rec = dict_startscan_system(&pcur, &mtr, SYS_TABLES);
216 + const char* err_msg;
217 + dict_table_t* table_rec;
219 + /* Create and populate a dict_table_t structure with
220 + information from SYS_TABLES row */
221 + err_msg = dict_process_sys_tables_rec(
222 + heap, rec, &table_rec, DICT_TABLE_LOAD_FROM_RECORD);
225 + mutex_exit(&dict_sys->mutex);
228 + i_s_dict_fill_sys_tables(thd, table_rec, tables->table);
230 + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
231 + ER_CANT_FIND_SYSTEM_REC,
235 + /* Since dict_process_sys_tables_rec() is called with
236 + DICT_TABLE_LOAD_FROM_RECORD, the table_rec is created in
237 + dict_process_sys_tables_rec(), we will need to free it */
239 + dict_mem_table_free(table_rec);
242 + mem_heap_empty(heap);
244 + /* Get the next record */
245 + mutex_enter(&dict_sys->mutex);
247 + rec = dict_getnext_system(&pcur, &mtr);
251 + mutex_exit(&dict_sys->mutex);
252 + mem_heap_free(heap);
257 +/*******************************************************************//**
258 +Bind the dynamic table INFORMATION_SCHEMA.innodb_sys_tables
259 +@return 0 on success */
262 +innodb_sys_tables_init(
263 +/*===================*/
264 + void* p) /*!< in/out: table schema object */
266 + ST_SCHEMA_TABLE* schema;
268 + DBUG_ENTER("innodb_sys_tables_init");
270 + schema = (ST_SCHEMA_TABLE*) p;
272 + schema->fields_info = innodb_sys_tables_fields_info;
273 + schema->fill_table = i_s_sys_tables_fill_table;
278 +UNIV_INTERN struct st_mysql_plugin i_s_innodb_sys_tables =
280 + /* the plugin type (a MYSQL_XXX_PLUGIN value) */
282 + STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
284 + /* pointer to type-specific plugin descriptor */
286 + STRUCT_FLD(info, &i_s_info),
290 + STRUCT_FLD(name, "INNODB_SYS_TABLES"),
292 + /* plugin author (for SHOW PLUGINS) */
294 + STRUCT_FLD(author, plugin_author),
296 + /* general descriptive text (for SHOW PLUGINS) */
298 + STRUCT_FLD(descr, "InnoDB SYS_TABLES"),
300 + /* the plugin license (PLUGIN_LICENSE_XXX) */
302 + STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
304 + /* the function to invoke when plugin is loaded */
305 + /* int (*)(void*); */
306 + STRUCT_FLD(init, innodb_sys_tables_init),
308 + /* the function to invoke when plugin is unloaded */
309 + /* int (*)(void*); */
310 + STRUCT_FLD(deinit, i_s_common_deinit),
312 + /* plugin version (for SHOW PLUGINS) */
314 + STRUCT_FLD(version, INNODB_VERSION_SHORT),
316 + /* struct st_mysql_show_var* */
317 + STRUCT_FLD(status_vars, NULL),
319 + /* struct st_mysql_sys_var** */
320 + STRUCT_FLD(system_vars, NULL),
322 + /* reserved for dependency checking */
324 + STRUCT_FLD(__reserved1, NULL)
327 +/* Fields of the dynamic table INFORMATION_SCHEMA.SYS_TABLESTATS */
328 +static ST_FIELD_INFO innodb_sys_tablestats_fields_info[] =
330 +#define SYS_TABLESTATS_ID 0
331 + {STRUCT_FLD(field_name, "TABLE_ID"),
332 + STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
333 + STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
334 + STRUCT_FLD(value, 0),
335 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
336 + STRUCT_FLD(old_name, ""),
337 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
339 +#define SYS_TABLESTATS_SCHEMA 1
340 + {STRUCT_FLD(field_name, "SCHEMA"),
341 + STRUCT_FLD(field_length, NAME_LEN + 1),
342 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
343 + STRUCT_FLD(value, 0),
344 + STRUCT_FLD(field_flags, 0),
345 + STRUCT_FLD(old_name, ""),
346 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
348 +#define SYS_TABLESTATS_NAME 2
349 + {STRUCT_FLD(field_name, "NAME"),
350 + STRUCT_FLD(field_length, NAME_LEN + 1),
351 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
352 + STRUCT_FLD(value, 0),
353 + STRUCT_FLD(field_flags, 0),
354 + STRUCT_FLD(old_name, ""),
355 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
357 +#define SYS_TABLESTATS_INIT 3
358 + {STRUCT_FLD(field_name, "STATS_INITIALIZED"),
359 + STRUCT_FLD(field_length, NAME_LEN + 1),
360 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
361 + STRUCT_FLD(value, 0),
362 + STRUCT_FLD(field_flags, 0),
363 + STRUCT_FLD(old_name, ""),
364 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
366 +#define SYS_TABLESTATS_NROW 4
367 + {STRUCT_FLD(field_name, "NUM_ROWS"),
368 + STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
369 + STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
370 + STRUCT_FLD(value, 0),
371 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
372 + STRUCT_FLD(old_name, ""),
373 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
375 +#define SYS_TABLESTATS_CLUST_SIZE 5
376 + {STRUCT_FLD(field_name, "CLUST_INDEX_SIZE"),
377 + STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
378 + STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
379 + STRUCT_FLD(value, 0),
380 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
381 + STRUCT_FLD(old_name, ""),
382 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
384 +#define SYS_TABLESTATS_INDEX_SIZE 6
385 + {STRUCT_FLD(field_name, "OTHER_INDEX_SIZE"),
386 + STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
387 + STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
388 + STRUCT_FLD(value, 0),
389 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
390 + STRUCT_FLD(old_name, ""),
391 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
393 +#define SYS_TABLESTATS_MODIFIED 7
394 + {STRUCT_FLD(field_name, "MODIFIED_COUNTER"),
395 + STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
396 + STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
397 + STRUCT_FLD(value, 0),
398 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
399 + STRUCT_FLD(old_name, ""),
400 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
402 +#define SYS_TABLESTATS_AUTONINC 8
403 + {STRUCT_FLD(field_name, "AUTOINC"),
404 + STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
405 + STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
406 + STRUCT_FLD(value, 0),
407 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
408 + STRUCT_FLD(old_name, ""),
409 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
411 +#define SYS_TABLESTATS_MYSQL_OPEN_HANDLE 9
412 + {STRUCT_FLD(field_name, "MYSQL_HANDLES_OPENED"),
413 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
414 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
415 + STRUCT_FLD(value, 0),
416 + STRUCT_FLD(field_flags, 0),
417 + STRUCT_FLD(old_name, ""),
418 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
420 + END_OF_ST_FIELD_INFO
423 +/**********************************************************************//**
424 +Populate information_schema.innodb_sys_tablestats table with information
426 +@return 0 on success */
429 +i_s_dict_fill_sys_tablestats(
430 +/*=========================*/
431 + THD* thd, /*!< in: thread */
432 + dict_table_t* table, /*!< in: table */
433 + TABLE* table_to_fill) /*!< in/out: fill this table */
436 + char buf[NAME_LEN * 2 + 2];
439 + DBUG_ENTER("i_s_dict_fill_sys_tablestats");
441 + fields = table_to_fill->field;
443 + OK(fields[SYS_TABLESTATS_ID]->store(longlong(table->id), TRUE));
445 + strncpy(buf, table->name, NAME_LEN * 2 + 2);
446 + ptr = strchr(buf, '/');
451 + OK(field_store_string(fields[SYS_TABLESTATS_SCHEMA], buf));
452 + OK(field_store_string(fields[SYS_TABLESTATS_NAME], ptr));
454 + fields[SYS_TABLESTATS_SCHEMA]->set_null();
455 + OK(field_store_string(fields[SYS_TABLESTATS_NAME], buf));
458 + if (table->stat_initialized) {
459 + OK(field_store_string(fields[SYS_TABLESTATS_INIT],
462 + OK(field_store_string(fields[SYS_TABLESTATS_INIT],
466 + OK(fields[SYS_TABLESTATS_NROW]->store(table->stat_n_rows, TRUE));
468 + OK(fields[SYS_TABLESTATS_CLUST_SIZE]->store(
469 + table->stat_clustered_index_size));
471 + OK(fields[SYS_TABLESTATS_INDEX_SIZE]->store(
472 + table->stat_sum_of_other_index_sizes));
474 + OK(fields[SYS_TABLESTATS_MODIFIED]->store(
475 + table->stat_modified_counter));
477 + OK(fields[SYS_TABLESTATS_AUTONINC]->store(table->autoinc, TRUE));
479 + OK(fields[SYS_TABLESTATS_MYSQL_OPEN_HANDLE]->store(
480 + table->n_mysql_handles_opened));
482 + OK(schema_table_store_record(thd, table_to_fill));
486 +/*******************************************************************//**
487 +Function to go through each record in SYS_TABLES table, and fill the
488 +information_schema.innodb_sys_tablestats table with table statistics
490 +@return 0 on success */
493 +i_s_sys_tables_fill_table_stats(
494 +/*============================*/
495 + THD* thd, /*!< in: thread */
496 + TABLE_LIST* tables, /*!< in/out: tables to fill */
497 + COND* cond) /*!< in: condition (not used) */
504 + DBUG_ENTER("i_s_sys_tables_fill_table_stats");
506 + /* deny access to non-superusers */
507 + if (check_global_access(thd, PROCESS_ACL)) {
512 + heap = mem_heap_create(1000);
513 + mutex_enter(&dict_sys->mutex);
516 + rec = dict_startscan_system(&pcur, &mtr, SYS_TABLES);
519 + const char* err_msg;
520 + dict_table_t* table_rec;
522 + /* Fetch the dict_table_t structure corresponding to
523 + this SYS_TABLES record */
524 + err_msg = dict_process_sys_tables_rec(
525 + heap, rec, &table_rec, DICT_TABLE_LOAD_FROM_CACHE);
528 + mutex_exit(&dict_sys->mutex);
531 + i_s_dict_fill_sys_tablestats(thd, table_rec,
534 + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
535 + ER_CANT_FIND_SYSTEM_REC,
539 + mem_heap_empty(heap);
541 + /* Get the next record */
542 + mutex_enter(&dict_sys->mutex);
544 + rec = dict_getnext_system(&pcur, &mtr);
548 + mutex_exit(&dict_sys->mutex);
549 + mem_heap_free(heap);
554 +/*******************************************************************//**
555 +Bind the dynamic table INFORMATION_SCHEMA.innodb_sys_tablestats
556 +@return 0 on success */
559 +innodb_sys_tablestats_init(
560 +/*=======================*/
561 + void* p) /*!< in/out: table schema object */
563 + ST_SCHEMA_TABLE* schema;
565 + DBUG_ENTER("innodb_sys_tablestats_init");
567 + schema = (ST_SCHEMA_TABLE*) p;
569 + schema->fields_info = innodb_sys_tablestats_fields_info;
570 + schema->fill_table = i_s_sys_tables_fill_table_stats;
575 +UNIV_INTERN struct st_mysql_plugin i_s_innodb_sys_tablestats =
577 + /* the plugin type (a MYSQL_XXX_PLUGIN value) */
579 + STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
581 + /* pointer to type-specific plugin descriptor */
583 + STRUCT_FLD(info, &i_s_info),
587 + STRUCT_FLD(name, "INNODB_SYS_TABLESTATS"),
589 + /* plugin author (for SHOW PLUGINS) */
591 + STRUCT_FLD(author, plugin_author),
593 + /* general descriptive text (for SHOW PLUGINS) */
595 + STRUCT_FLD(descr, "InnoDB SYS_TABLESTATS"),
597 + /* the plugin license (PLUGIN_LICENSE_XXX) */
599 + STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
601 + /* the function to invoke when plugin is loaded */
602 + /* int (*)(void*); */
603 + STRUCT_FLD(init, innodb_sys_tablestats_init),
605 + /* the function to invoke when plugin is unloaded */
606 + /* int (*)(void*); */
607 + STRUCT_FLD(deinit, i_s_common_deinit),
609 + /* plugin version (for SHOW PLUGINS) */
611 + STRUCT_FLD(version, INNODB_VERSION_SHORT),
613 + /* struct st_mysql_show_var* */
614 + STRUCT_FLD(status_vars, NULL),
616 + /* struct st_mysql_sys_var** */
617 + STRUCT_FLD(system_vars, NULL),
619 + /* reserved for dependency checking */
621 + STRUCT_FLD(__reserved1, NULL)
624 +/* Fields of the dynamic table INFORMATION_SCHEMA.SYS_INDEXES */
625 +static ST_FIELD_INFO innodb_sysindex_fields_info[] =
627 +#define SYS_INDEX_ID 0
628 + {STRUCT_FLD(field_name, "INDEX_ID"),
629 + STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
630 + STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
631 + STRUCT_FLD(value, 0),
632 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
633 + STRUCT_FLD(old_name, ""),
634 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
636 +#define SYS_INDEX_NAME 1
637 + {STRUCT_FLD(field_name, "NAME"),
638 + STRUCT_FLD(field_length, NAME_LEN + 1),
639 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
640 + STRUCT_FLD(value, 0),
641 + STRUCT_FLD(field_flags, 0),
642 + STRUCT_FLD(old_name, ""),
643 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
645 +#define SYS_INDEX_TABLE_ID 2
646 + {STRUCT_FLD(field_name, "TABLE_ID"),
647 + STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
648 + STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
649 + STRUCT_FLD(value, 0),
650 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
651 + STRUCT_FLD(old_name, ""),
652 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
654 +#define SYS_INDEX_TYPE 3
655 + {STRUCT_FLD(field_name, "TYPE"),
656 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
657 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
658 + STRUCT_FLD(value, 0),
659 + STRUCT_FLD(field_flags, 0),
660 + STRUCT_FLD(old_name, ""),
661 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
663 +#define SYS_INDEX_NUM_FIELDS 4
664 + {STRUCT_FLD(field_name, "N_FIELDS"),
665 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
666 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
667 + STRUCT_FLD(value, 0),
668 + STRUCT_FLD(field_flags, 0),
669 + STRUCT_FLD(old_name, ""),
670 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
672 +#define SYS_INDEX_PAGE_NO 5
673 + {STRUCT_FLD(field_name, "PAGE_NO"),
674 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
675 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
676 + STRUCT_FLD(value, 0),
677 + STRUCT_FLD(field_flags, 0),
678 + STRUCT_FLD(old_name, ""),
679 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
681 +#define SYS_INDEX_SPACE 6
682 + {STRUCT_FLD(field_name, "SPACE"),
683 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
684 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
685 + STRUCT_FLD(value, 0),
686 + STRUCT_FLD(field_flags, 0),
687 + STRUCT_FLD(old_name, ""),
688 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
690 + END_OF_ST_FIELD_INFO
693 +/**********************************************************************//**
694 +Function to populate the information_schema.innodb_sys_indexes table with
695 +collected index information
696 +@return 0 on success */
699 +i_s_dict_fill_sys_indexes(
700 +/*======================*/
701 + THD* thd, /*!< in: thread */
702 + table_id_t table_id, /*!< in: table id */
703 + dict_index_t* index, /*!< in: populated dict_index_t
704 + struct with index info */
705 + TABLE* table_to_fill) /*!< in/out: fill this table */
709 + DBUG_ENTER("i_s_dict_fill_sys_indexes");
711 + fields = table_to_fill->field;
713 + OK(fields[SYS_INDEX_ID]->store(longlong(index->id), TRUE));
715 + OK(field_store_string(fields[SYS_INDEX_NAME], index->name));
717 + OK(fields[SYS_INDEX_TABLE_ID]->store(longlong(table_id), TRUE));
719 + OK(fields[SYS_INDEX_TYPE]->store(index->type));
721 + OK(fields[SYS_INDEX_NUM_FIELDS]->store(index->n_fields));
723 + OK(fields[SYS_INDEX_PAGE_NO]->store(index->page));
725 + OK(fields[SYS_INDEX_SPACE]->store(index->space));
727 + OK(schema_table_store_record(thd, table_to_fill));
731 +/*******************************************************************//**
732 +Function to go through each record in SYS_INDEXES table, and fill the
733 +information_schema.innodb_sys_indexes table with related index information
734 +@return 0 on success */
737 +i_s_sys_indexes_fill_table(
738 +/*=======================*/
739 + THD* thd, /*!< in: thread */
740 + TABLE_LIST* tables, /*!< in/out: tables to fill */
741 + COND* cond) /*!< in: condition (not used) */
748 + DBUG_ENTER("i_s_sys_indexes_fill_table");
750 + /* deny access to non-superusers */
751 + if (check_global_access(thd, PROCESS_ACL)) {
756 + heap = mem_heap_create(1000);
757 + mutex_enter(&dict_sys->mutex);
760 + /* Start scan the SYS_INDEXES table */
761 + rec = dict_startscan_system(&pcur, &mtr, SYS_INDEXES);
763 + /* Process each record in the table */
765 + const char* err_msg;;
766 + table_id_t table_id;
767 + dict_index_t index_rec;
769 + /* Populate a dict_index_t structure with information from
770 + a SYS_INDEXES row */
771 + err_msg = dict_process_sys_indexes_rec(heap, rec, &index_rec,
775 + mutex_exit(&dict_sys->mutex);
778 + i_s_dict_fill_sys_indexes(thd, table_id, &index_rec,
781 + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
782 + ER_CANT_FIND_SYSTEM_REC,
786 + mem_heap_empty(heap);
788 + /* Get the next record */
789 + mutex_enter(&dict_sys->mutex);
791 + rec = dict_getnext_system(&pcur, &mtr);
795 + mutex_exit(&dict_sys->mutex);
796 + mem_heap_free(heap);
800 +/*******************************************************************//**
801 +Bind the dynamic table INFORMATION_SCHEMA.innodb_sys_indexes
802 +@return 0 on success */
805 +innodb_sys_indexes_init(
806 +/*====================*/
807 + void* p) /*!< in/out: table schema object */
809 + ST_SCHEMA_TABLE* schema;
811 + DBUG_ENTER("innodb_sys_index_init");
813 + schema = (ST_SCHEMA_TABLE*) p;
815 + schema->fields_info = innodb_sysindex_fields_info;
816 + schema->fill_table = i_s_sys_indexes_fill_table;
821 +UNIV_INTERN struct st_mysql_plugin i_s_innodb_sys_indexes =
823 + /* the plugin type (a MYSQL_XXX_PLUGIN value) */
825 + STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
827 + /* pointer to type-specific plugin descriptor */
829 + STRUCT_FLD(info, &i_s_info),
833 + STRUCT_FLD(name, "INNODB_SYS_INDEXES"),
835 + /* plugin author (for SHOW PLUGINS) */
837 + STRUCT_FLD(author, plugin_author),
839 + /* general descriptive text (for SHOW PLUGINS) */
841 + STRUCT_FLD(descr, "InnoDB SYS_INDEXES"),
843 + /* the plugin license (PLUGIN_LICENSE_XXX) */
845 + STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
847 + /* the function to invoke when plugin is loaded */
848 + /* int (*)(void*); */
849 + STRUCT_FLD(init, innodb_sys_indexes_init),
851 + /* the function to invoke when plugin is unloaded */
852 + /* int (*)(void*); */
853 + STRUCT_FLD(deinit, i_s_common_deinit),
855 + /* plugin version (for SHOW PLUGINS) */
857 + STRUCT_FLD(version, INNODB_VERSION_SHORT),
859 + /* struct st_mysql_show_var* */
860 + STRUCT_FLD(status_vars, NULL),
862 + /* struct st_mysql_sys_var** */
863 + STRUCT_FLD(system_vars, NULL),
865 + /* reserved for dependency checking */
867 + STRUCT_FLD(__reserved1, NULL)
870 +/* Fields of the dynamic table INFORMATION_SCHEMA.SYS_COLUMNS */
871 +static ST_FIELD_INFO innodb_sys_columns_fields_info[] =
873 +#define SYS_COLUMN_TABLE_ID 0
874 + {STRUCT_FLD(field_name, "TABLE_ID"),
875 + STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
876 + STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
877 + STRUCT_FLD(value, 0),
878 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
879 + STRUCT_FLD(old_name, ""),
880 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
882 +#define SYS_COLUMN_NAME 1
883 + {STRUCT_FLD(field_name, "NAME"),
884 + STRUCT_FLD(field_length, NAME_LEN + 1),
885 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
886 + STRUCT_FLD(value, 0),
887 + STRUCT_FLD(field_flags, 0),
888 + STRUCT_FLD(old_name, ""),
889 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
891 +#define SYS_COLUMN_POSITION 2
892 + {STRUCT_FLD(field_name, "POS"),
893 + STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
894 + STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
895 + STRUCT_FLD(value, 0),
896 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
897 + STRUCT_FLD(old_name, ""),
898 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
900 +#define SYS_COLUMN_MTYPE 3
901 + {STRUCT_FLD(field_name, "MTYPE"),
902 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
903 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
904 + STRUCT_FLD(value, 0),
905 + STRUCT_FLD(field_flags, 0),
906 + STRUCT_FLD(old_name, ""),
907 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
909 +#define SYS_COLUMN__PRTYPE 4
910 + {STRUCT_FLD(field_name, "PRTYPE"),
911 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
912 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
913 + STRUCT_FLD(value, 0),
914 + STRUCT_FLD(field_flags, 0),
915 + STRUCT_FLD(old_name, ""),
916 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
918 +#define SYS_COLUMN_COLUMN_LEN 5
919 + {STRUCT_FLD(field_name, "LEN"),
920 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
921 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
922 + STRUCT_FLD(value, 0),
923 + STRUCT_FLD(field_flags, 0),
924 + STRUCT_FLD(old_name, ""),
925 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
927 + END_OF_ST_FIELD_INFO
930 +/**********************************************************************//**
931 +Function to populate the information_schema.innodb_sys_columns with
932 +related column information
933 +@return 0 on success */
936 +i_s_dict_fill_sys_columns(
937 +/*======================*/
938 + THD* thd, /*!< in: thread */
939 + table_id_t table_id, /*!< in: table ID */
940 + const char* col_name, /*!< in: column name */
941 + dict_col_t* column, /*!< in: dict_col_t struct holding
942 + more column information */
943 + TABLE* table_to_fill) /*!< in/out: fill this table */
947 + DBUG_ENTER("i_s_dict_fill_sys_columns");
949 + fields = table_to_fill->field;
951 + OK(fields[SYS_COLUMN_TABLE_ID]->store(longlong(table_id), TRUE));
953 + OK(field_store_string(fields[SYS_COLUMN_NAME], col_name));
955 + OK(fields[SYS_COLUMN_POSITION]->store(column->ind));
957 + OK(fields[SYS_COLUMN_MTYPE]->store(column->mtype));
959 + OK(fields[SYS_COLUMN__PRTYPE]->store(column->prtype));
961 + OK(fields[SYS_COLUMN_COLUMN_LEN]->store(column->len));
963 + OK(schema_table_store_record(thd, table_to_fill));
967 +/*******************************************************************//**
968 +Function to fill information_schema.innodb_sys_columns with information
969 +collected by scanning SYS_COLUMNS table.
970 +@return 0 on success */
973 +i_s_sys_columns_fill_table(
974 +/*=======================*/
975 + THD* thd, /*!< in: thread */
976 + TABLE_LIST* tables, /*!< in/out: tables to fill */
977 + COND* cond) /*!< in: condition (not used) */
981 + const char* col_name;
985 + DBUG_ENTER("i_s_sys_columns_fill_table");
987 + /* deny access to non-superusers */
988 + if (check_global_access(thd, PROCESS_ACL)) {
993 + heap = mem_heap_create(1000);
994 + mutex_enter(&dict_sys->mutex);
997 + rec = dict_startscan_system(&pcur, &mtr, SYS_COLUMNS);
1000 + const char* err_msg;
1001 + dict_col_t column_rec;
1002 + table_id_t table_id;
1004 + /* populate a dict_col_t structure with information from
1005 + a SYS_COLUMNS row */
1006 + err_msg = dict_process_sys_columns_rec(heap, rec, &column_rec,
1007 + &table_id, &col_name);
1010 + mutex_exit(&dict_sys->mutex);
1013 + i_s_dict_fill_sys_columns(thd, table_id, col_name,
1017 + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
1018 + ER_CANT_FIND_SYSTEM_REC,
1022 + mem_heap_empty(heap);
1024 + /* Get the next record */
1025 + mutex_enter(&dict_sys->mutex);
1027 + rec = dict_getnext_system(&pcur, &mtr);
1031 + mutex_exit(&dict_sys->mutex);
1032 + mem_heap_free(heap);
1036 +/*******************************************************************//**
1037 +Bind the dynamic table INFORMATION_SCHEMA.innodb_sys_columns
1038 +@return 0 on success */
1041 +innodb_sys_columns_init(
1042 +/*====================*/
1043 + void* p) /*!< in/out: table schema object */
1045 + ST_SCHEMA_TABLE* schema;
1047 + DBUG_ENTER("innodb_sys_columns_init");
1049 + schema = (ST_SCHEMA_TABLE*) p;
1051 + schema->fields_info = innodb_sys_columns_fields_info;
1052 + schema->fill_table = i_s_sys_columns_fill_table;
1057 +UNIV_INTERN struct st_mysql_plugin i_s_innodb_sys_columns =
1059 + /* the plugin type (a MYSQL_XXX_PLUGIN value) */
1061 + STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
1063 + /* pointer to type-specific plugin descriptor */
1065 + STRUCT_FLD(info, &i_s_info),
1069 + STRUCT_FLD(name, "INNODB_SYS_COLUMNS"),
1071 + /* plugin author (for SHOW PLUGINS) */
1073 + STRUCT_FLD(author, plugin_author),
1075 + /* general descriptive text (for SHOW PLUGINS) */
1077 + STRUCT_FLD(descr, "InnoDB SYS_COLUMNS"),
1079 + /* the plugin license (PLUGIN_LICENSE_XXX) */
1081 + STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
1083 + /* the function to invoke when plugin is loaded */
1084 + /* int (*)(void*); */
1085 + STRUCT_FLD(init, innodb_sys_columns_init),
1087 + /* the function to invoke when plugin is unloaded */
1088 + /* int (*)(void*); */
1089 + STRUCT_FLD(deinit, i_s_common_deinit),
1091 + /* plugin version (for SHOW PLUGINS) */
1092 + /* unsigned int */
1093 + STRUCT_FLD(version, INNODB_VERSION_SHORT),
1095 + /* struct st_mysql_show_var* */
1096 + STRUCT_FLD(status_vars, NULL),
1098 + /* struct st_mysql_sys_var** */
1099 + STRUCT_FLD(system_vars, NULL),
1101 + /* reserved for dependency checking */
1103 + STRUCT_FLD(__reserved1, NULL)
1105 +/* Fields of the dynamic table INFORMATION_SCHEMA.innodb_sys_fields */
1106 +static ST_FIELD_INFO innodb_sys_fields_fields_info[] =
1108 +#define SYS_FIELD_INDEX_ID 0
1109 + {STRUCT_FLD(field_name, "INDEX_ID"),
1110 + STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
1111 + STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
1112 + STRUCT_FLD(value, 0),
1113 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
1114 + STRUCT_FLD(old_name, ""),
1115 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
1117 +#define SYS_FIELD_NAME 1
1118 + {STRUCT_FLD(field_name, "NAME"),
1119 + STRUCT_FLD(field_length, NAME_LEN + 1),
1120 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
1121 + STRUCT_FLD(value, 0),
1122 + STRUCT_FLD(field_flags, 0),
1123 + STRUCT_FLD(old_name, ""),
1124 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
1126 +#define SYS_FIELD_POS 2
1127 + {STRUCT_FLD(field_name, "POS"),
1128 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
1129 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
1130 + STRUCT_FLD(value, 0),
1131 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
1132 + STRUCT_FLD(old_name, ""),
1133 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
1135 + END_OF_ST_FIELD_INFO
1138 +/**********************************************************************//**
1139 +Function to fill information_schema.innodb_sys_fields with information
1140 +collected by scanning SYS_FIELDS table.
1141 +@return 0 on success */
1144 +i_s_dict_fill_sys_fields(
1145 +/*=====================*/
1146 + THD* thd, /*!< in: thread */
1147 + index_id_t index_id, /*!< in: index id for the field */
1148 + dict_field_t* field, /*!< in: table */
1149 + ulint pos, /*!< in: Field position */
1150 + TABLE* table_to_fill) /*!< in/out: fill this table */
1154 + DBUG_ENTER("i_s_dict_fill_sys_fields");
1156 + fields = table_to_fill->field;
1158 + OK(fields[SYS_FIELD_INDEX_ID]->store(longlong(index_id), TRUE));
1160 + OK(field_store_string(fields[SYS_FIELD_NAME], field->name));
1162 + OK(fields[SYS_FIELD_POS]->store(pos));
1164 + OK(schema_table_store_record(thd, table_to_fill));
1168 +/*******************************************************************//**
1169 +Function to go through each record in SYS_FIELDS table, and fill the
1170 +information_schema.innodb_sys_fields table with related index field
1172 +@return 0 on success */
1175 +i_s_sys_fields_fill_table(
1176 +/*======================*/
1177 + THD* thd, /*!< in: thread */
1178 + TABLE_LIST* tables, /*!< in/out: tables to fill */
1179 + COND* cond) /*!< in: condition (not used) */
1184 + index_id_t last_id;
1187 + DBUG_ENTER("i_s_sys_fields_fill_table");
1189 + /* deny access to non-superusers */
1190 + if (check_global_access(thd, PROCESS_ACL)) {
1195 + heap = mem_heap_create(1000);
1196 + mutex_enter(&dict_sys->mutex);
1199 + /* will save last index id so that we know whether we move to
1200 + the next index. This is used to calculate prefix length */
1203 + rec = dict_startscan_system(&pcur, &mtr, SYS_FIELDS);
1207 + const char* err_msg;
1208 + index_id_t index_id;
1209 + dict_field_t field_rec;
1211 + /* Populate a dict_field_t structure with information from
1212 + a SYS_FIELDS row */
1213 + err_msg = dict_process_sys_fields_rec(heap, rec, &field_rec,
1214 + &pos, &index_id, last_id);
1217 + mutex_exit(&dict_sys->mutex);
1220 + i_s_dict_fill_sys_fields(thd, index_id, &field_rec,
1221 + pos, tables->table);
1222 + last_id = index_id;
1224 + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
1225 + ER_CANT_FIND_SYSTEM_REC,
1229 + mem_heap_empty(heap);
1231 + /* Get the next record */
1232 + mutex_enter(&dict_sys->mutex);
1234 + rec = dict_getnext_system(&pcur, &mtr);
1238 + mutex_exit(&dict_sys->mutex);
1239 + mem_heap_free(heap);
1243 +/*******************************************************************//**
1244 +Bind the dynamic table INFORMATION_SCHEMA.innodb_sys_fields
1245 +@return 0 on success */
1248 +innodb_sys_fields_init(
1249 +/*===================*/
1250 + void* p) /*!< in/out: table schema object */
1252 + ST_SCHEMA_TABLE* schema;
1254 + DBUG_ENTER("innodb_sys_field_init");
1256 + schema = (ST_SCHEMA_TABLE*) p;
1258 + schema->fields_info = innodb_sys_fields_fields_info;
1259 + schema->fill_table = i_s_sys_fields_fill_table;
1264 +UNIV_INTERN struct st_mysql_plugin i_s_innodb_sys_fields =
1266 + /* the plugin type (a MYSQL_XXX_PLUGIN value) */
1268 + STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
1270 + /* pointer to type-specific plugin descriptor */
1272 + STRUCT_FLD(info, &i_s_info),
1276 + STRUCT_FLD(name, "INNODB_SYS_FIELDS"),
1278 + /* plugin author (for SHOW PLUGINS) */
1280 + STRUCT_FLD(author, plugin_author),
1282 + /* general descriptive text (for SHOW PLUGINS) */
1284 + STRUCT_FLD(descr, "InnoDB SYS_FIELDS"),
1286 + /* the plugin license (PLUGIN_LICENSE_XXX) */
1288 + STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
1290 + /* the function to invoke when plugin is loaded */
1291 + /* int (*)(void*); */
1292 + STRUCT_FLD(init, innodb_sys_fields_init),
1294 + /* the function to invoke when plugin is unloaded */
1295 + /* int (*)(void*); */
1296 + STRUCT_FLD(deinit, i_s_common_deinit),
1298 + /* plugin version (for SHOW PLUGINS) */
1299 + /* unsigned int */
1300 + STRUCT_FLD(version, INNODB_VERSION_SHORT),
1302 + /* struct st_mysql_show_var* */
1303 + STRUCT_FLD(status_vars, NULL),
1305 + /* struct st_mysql_sys_var** */
1306 + STRUCT_FLD(system_vars, NULL),
1308 + /* reserved for dependency checking */
1310 + STRUCT_FLD(__reserved1, NULL)
1313 +/* Fields of the dynamic table INFORMATION_SCHEMA.innodb_sys_foreign */
1314 +static ST_FIELD_INFO innodb_sys_foreign_fields_info[] =
1316 +#define SYS_FOREIGN_ID 0
1317 + {STRUCT_FLD(field_name, "ID"),
1318 + STRUCT_FLD(field_length, NAME_LEN + 1),
1319 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
1320 + STRUCT_FLD(value, 0),
1321 + STRUCT_FLD(field_flags, 0),
1322 + STRUCT_FLD(old_name, ""),
1323 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
1325 +#define SYS_FOREIGN_FOR_NAME 1
1326 + {STRUCT_FLD(field_name, "FOR_NAME"),
1327 + STRUCT_FLD(field_length, NAME_LEN + 1),
1328 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
1329 + STRUCT_FLD(value, 0),
1330 + STRUCT_FLD(field_flags, 0),
1331 + STRUCT_FLD(old_name, ""),
1332 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
1334 +#define SYS_FOREIGN_REF_NAME 2
1335 + {STRUCT_FLD(field_name, "REF_NAME"),
1336 + STRUCT_FLD(field_length, NAME_LEN + 1),
1337 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
1338 + STRUCT_FLD(value, 0),
1339 + STRUCT_FLD(field_flags, 0),
1340 + STRUCT_FLD(old_name, ""),
1341 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
1343 +#define SYS_FOREIGN_NUM_COL 3
1344 + {STRUCT_FLD(field_name, "N_COLS"),
1345 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
1346 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
1347 + STRUCT_FLD(value, 0),
1348 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
1349 + STRUCT_FLD(old_name, ""),
1350 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
1352 +#define SYS_FOREIGN_TYPE 4
1353 + {STRUCT_FLD(field_name, "TYPE"),
1354 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
1355 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
1356 + STRUCT_FLD(value, 0),
1357 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
1358 + STRUCT_FLD(old_name, ""),
1359 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
1361 + END_OF_ST_FIELD_INFO
1364 +/**********************************************************************//**
1365 +Function to fill information_schema.innodb_sys_foreign with information
1366 +collected by scanning SYS_FOREIGN table.
1367 +@return 0 on success */
1370 +i_s_dict_fill_sys_foreign(
1371 +/*======================*/
1372 + THD* thd, /*!< in: thread */
1373 + dict_foreign_t* foreign, /*!< in: table */
1374 + TABLE* table_to_fill) /*!< in/out: fill this table */
1378 + DBUG_ENTER("i_s_dict_fill_sys_foreign");
1380 + fields = table_to_fill->field;
1382 + OK(field_store_string(fields[SYS_FOREIGN_ID], foreign->id));
1384 + OK(field_store_string(fields[SYS_FOREIGN_FOR_NAME],
1385 + foreign->foreign_table_name));
1387 + OK(field_store_string(fields[SYS_FOREIGN_REF_NAME],
1388 + foreign->referenced_table_name));
1390 + OK(fields[SYS_FOREIGN_NUM_COL]->store(foreign->n_fields));
1392 + OK(fields[SYS_FOREIGN_TYPE]->store(foreign->type));
1394 + OK(schema_table_store_record(thd, table_to_fill));
1398 +/*******************************************************************//**
1399 +Function to populate INFORMATION_SCHEMA.innodb_sys_foreign table. Loop
1400 +through each record in SYS_FOREIGN, and extract the foreign key
1402 +@return 0 on success */
1405 +i_s_sys_foreign_fill_table(
1406 +/*=======================*/
1407 + THD* thd, /*!< in: thread */
1408 + TABLE_LIST* tables, /*!< in/out: tables to fill */
1409 + COND* cond) /*!< in: condition (not used) */
1416 + DBUG_ENTER("i_s_sys_foreign_fill_table");
1418 + /* deny access to non-superusers */
1419 + if (check_global_access(thd, PROCESS_ACL)) {
1424 + heap = mem_heap_create(1000);
1425 + mutex_enter(&dict_sys->mutex);
1428 + rec = dict_startscan_system(&pcur, &mtr, SYS_FOREIGN);
1431 + const char* err_msg;
1432 + dict_foreign_t foreign_rec;
1434 + /* Populate a dict_foreign_t structure with information from
1435 + a SYS_FOREIGN row */
1436 + err_msg = dict_process_sys_foreign_rec(heap, rec, &foreign_rec);
1439 + mutex_exit(&dict_sys->mutex);
1442 + i_s_dict_fill_sys_foreign(thd, &foreign_rec,
1445 + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
1446 + ER_CANT_FIND_SYSTEM_REC,
1450 + mem_heap_empty(heap);
1452 + /* Get the next record */
1454 + mutex_enter(&dict_sys->mutex);
1455 + rec = dict_getnext_system(&pcur, &mtr);
1459 + mutex_exit(&dict_sys->mutex);
1460 + mem_heap_free(heap);
1464 +/*******************************************************************//**
1465 +Bind the dynamic table INFORMATION_SCHEMA.innodb_sys_foreign
1466 +@return 0 on success */
1469 +innodb_sys_foreign_init(
1470 +/*====================*/
1471 + void* p) /*!< in/out: table schema object */
1473 + ST_SCHEMA_TABLE* schema;
1475 + DBUG_ENTER("innodb_sys_foreign_init");
1477 + schema = (ST_SCHEMA_TABLE*) p;
1479 + schema->fields_info = innodb_sys_foreign_fields_info;
1480 + schema->fill_table = i_s_sys_foreign_fill_table;
1485 +UNIV_INTERN struct st_mysql_plugin i_s_innodb_sys_foreign =
1487 + /* the plugin type (a MYSQL_XXX_PLUGIN value) */
1489 + STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
1491 + /* pointer to type-specific plugin descriptor */
1493 + STRUCT_FLD(info, &i_s_info),
1497 + STRUCT_FLD(name, "INNODB_SYS_FOREIGN"),
1499 + /* plugin author (for SHOW PLUGINS) */
1501 + STRUCT_FLD(author, plugin_author),
1503 + /* general descriptive text (for SHOW PLUGINS) */
1505 + STRUCT_FLD(descr, "InnoDB SYS_FOREIGN"),
1507 + /* the plugin license (PLUGIN_LICENSE_XXX) */
1509 + STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
1511 + /* the function to invoke when plugin is loaded */
1512 + /* int (*)(void*); */
1513 + STRUCT_FLD(init, innodb_sys_foreign_init),
1515 + /* the function to invoke when plugin is unloaded */
1516 + /* int (*)(void*); */
1517 + STRUCT_FLD(deinit, i_s_common_deinit),
1519 + /* plugin version (for SHOW PLUGINS) */
1520 + /* unsigned int */
1521 + STRUCT_FLD(version, INNODB_VERSION_SHORT),
1523 + /* struct st_mysql_show_var* */
1524 + STRUCT_FLD(status_vars, NULL),
1526 + /* struct st_mysql_sys_var** */
1527 + STRUCT_FLD(system_vars, NULL),
1529 + /* reserved for dependency checking */
1531 + STRUCT_FLD(__reserved1, NULL)
1533 +/* Fields of the dynamic table INFORMATION_SCHEMA.innodb_sys_foreign_cols */
1534 +static ST_FIELD_INFO innodb_sys_foreign_cols_fields_info[] =
1536 +#define SYS_FOREIGN_COL_ID 0
1537 + {STRUCT_FLD(field_name, "ID"),
1538 + STRUCT_FLD(field_length, NAME_LEN + 1),
1539 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
1540 + STRUCT_FLD(value, 0),
1541 + STRUCT_FLD(field_flags, 0),
1542 + STRUCT_FLD(old_name, ""),
1543 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
1545 +#define SYS_FOREIGN_COL_FOR_NAME 1
1546 + {STRUCT_FLD(field_name, "FOR_COL_NAME"),
1547 + STRUCT_FLD(field_length, NAME_LEN + 1),
1548 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
1549 + STRUCT_FLD(value, 0),
1550 + STRUCT_FLD(field_flags, 0),
1551 + STRUCT_FLD(old_name, ""),
1552 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
1554 +#define SYS_FOREIGN_COL_REF_NAME 2
1555 + {STRUCT_FLD(field_name, "REF_COL_NAME"),
1556 + STRUCT_FLD(field_length, NAME_LEN + 1),
1557 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
1558 + STRUCT_FLD(value, 0),
1559 + STRUCT_FLD(field_flags, 0),
1560 + STRUCT_FLD(old_name, ""),
1561 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
1563 +#define SYS_FOREIGN_COL_POS 3
1564 + {STRUCT_FLD(field_name, "POS"),
1565 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
1566 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
1567 + STRUCT_FLD(value, 0),
1568 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
1569 + STRUCT_FLD(old_name, ""),
1570 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
1572 + END_OF_ST_FIELD_INFO
1575 +/**********************************************************************//**
1576 +Function to fill information_schema.innodb_sys_foreign_cols with information
1577 +collected by scanning SYS_FOREIGN_COLS table.
1578 +@return 0 on success */
1581 +i_s_dict_fill_sys_foreign_cols(
1582 +/*==========================*/
1583 + THD* thd, /*!< in: thread */
1584 + const char* name, /*!< in: foreign key constraint name */
1585 + const char* for_col_name, /*!< in: referencing column name*/
1586 + const char* ref_col_name, /*!< in: referenced column
1588 + ulint pos, /*!< in: column position */
1589 + TABLE* table_to_fill) /*!< in/out: fill this table */
1593 + DBUG_ENTER("i_s_dict_fill_sys_foreign_cols");
1595 + fields = table_to_fill->field;
1597 + OK(field_store_string(fields[SYS_FOREIGN_COL_ID], name));
1599 + OK(field_store_string(fields[SYS_FOREIGN_COL_FOR_NAME], for_col_name));
1601 + OK(field_store_string(fields[SYS_FOREIGN_COL_REF_NAME], ref_col_name));
1603 + OK(fields[SYS_FOREIGN_COL_POS]->store(pos));
1605 + OK(schema_table_store_record(thd, table_to_fill));
1609 +/*******************************************************************//**
1610 +Function to populate INFORMATION_SCHEMA.innodb_sys_foreign_cols table. Loop
1611 +through each record in SYS_FOREIGN_COLS, and extract the foreign key column
1612 +information and fill the INFORMATION_SCHEMA.innodb_sys_foreign_cols table.
1613 +@return 0 on success */
1616 +i_s_sys_foreign_cols_fill_table(
1617 +/*============================*/
1618 + THD* thd, /*!< in: thread */
1619 + TABLE_LIST* tables, /*!< in/out: tables to fill */
1620 + COND* cond) /*!< in: condition (not used) */
1627 + DBUG_ENTER("i_s_sys_foreign_cols_fill_table");
1629 + /* deny access to non-superusers */
1630 + if (check_global_access(thd, PROCESS_ACL)) {
1634 + heap = mem_heap_create(1000);
1635 + mutex_enter(&dict_sys->mutex);
1638 + rec = dict_startscan_system(&pcur, &mtr, SYS_FOREIGN_COLS);
1641 + const char* err_msg;
1643 + const char* for_col_name;
1644 + const char* ref_col_name;
1647 + /* Extract necessary information from a SYS_FOREIGN_COLS row */
1648 + err_msg = dict_process_sys_foreign_col_rec(
1649 + heap, rec, &name, &for_col_name, &ref_col_name, &pos);
1652 + mutex_exit(&dict_sys->mutex);
1655 + i_s_dict_fill_sys_foreign_cols(
1656 + thd, name, for_col_name, ref_col_name, pos,
1659 + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
1660 + ER_CANT_FIND_SYSTEM_REC,
1664 + mem_heap_empty(heap);
1666 + /* Get the next record */
1667 + mutex_enter(&dict_sys->mutex);
1669 + rec = dict_getnext_system(&pcur, &mtr);
1673 + mutex_exit(&dict_sys->mutex);
1674 + mem_heap_free(heap);
1678 +/*******************************************************************//**
1679 +Bind the dynamic table INFORMATION_SCHEMA.innodb_sys_foreign_cols
1680 +@return 0 on success */
1683 +innodb_sys_foreign_cols_init(
1684 +/*========================*/
1685 + void* p) /*!< in/out: table schema object */
1687 + ST_SCHEMA_TABLE* schema;
1689 + DBUG_ENTER("innodb_sys_foreign_cols_init");
1691 + schema = (ST_SCHEMA_TABLE*) p;
1693 + schema->fields_info = innodb_sys_foreign_cols_fields_info;
1694 + schema->fill_table = i_s_sys_foreign_cols_fill_table;
1699 +UNIV_INTERN struct st_mysql_plugin i_s_innodb_sys_foreign_cols =
1701 + /* the plugin type (a MYSQL_XXX_PLUGIN value) */
1703 + STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
1705 + /* pointer to type-specific plugin descriptor */
1707 + STRUCT_FLD(info, &i_s_info),
1711 + STRUCT_FLD(name, "INNODB_SYS_FOREIGN_COLS"),
1713 + /* plugin author (for SHOW PLUGINS) */
1715 + STRUCT_FLD(author, plugin_author),
1717 + /* general descriptive text (for SHOW PLUGINS) */
1719 + STRUCT_FLD(descr, "InnoDB SYS_FOREIGN_COLS"),
1721 + /* the plugin license (PLUGIN_LICENSE_XXX) */
1723 + STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
1725 + /* the function to invoke when plugin is loaded */
1726 + /* int (*)(void*); */
1727 + STRUCT_FLD(init, innodb_sys_foreign_cols_init),
1729 + /* the function to invoke when plugin is unloaded */
1730 + /* int (*)(void*); */
1731 + STRUCT_FLD(deinit, i_s_common_deinit),
1733 + /* plugin version (for SHOW PLUGINS) */
1734 + /* unsigned int */
1735 + STRUCT_FLD(version, INNODB_VERSION_SHORT),
1737 + /* struct st_mysql_show_var* */
1738 + STRUCT_FLD(status_vars, NULL),
1740 + /* struct st_mysql_sys_var** */
1741 + STRUCT_FLD(system_vars, NULL),
1743 + /* reserved for dependency checking */
1745 + STRUCT_FLD(__reserved1, NULL)
1748 /***********************************************************************
1750 static ST_FIELD_INFO i_s_innodb_rseg_fields_info[] =
1751 diff -ruN a/storage/innobase/handler/i_s.h b/storage/innobase/handler/i_s.h
1752 --- a/storage/innobase/handler/i_s.h 2010-12-03 15:37:45.540456499 +0900
1753 +++ b/storage/innobase/handler/i_s.h 2010-12-03 16:08:57.596941207 +0900
1755 extern struct st_mysql_plugin i_s_innodb_cmp_reset;
1756 extern struct st_mysql_plugin i_s_innodb_cmpmem;
1757 extern struct st_mysql_plugin i_s_innodb_cmpmem_reset;
1758 +extern struct st_mysql_plugin i_s_innodb_sys_tables;
1759 +extern struct st_mysql_plugin i_s_innodb_sys_tablestats;
1760 +extern struct st_mysql_plugin i_s_innodb_sys_indexes;
1761 +extern struct st_mysql_plugin i_s_innodb_sys_columns;
1762 +extern struct st_mysql_plugin i_s_innodb_sys_fields;
1763 +extern struct st_mysql_plugin i_s_innodb_sys_foreign;
1764 +extern struct st_mysql_plugin i_s_innodb_sys_foreign_cols;
1765 extern struct st_mysql_plugin i_s_innodb_rseg;