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/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc
9 --- a/storage/innobase/handler/ha_innodb.cc 2010-12-03 15:53:54.615040167 +0900
10 +++ b/storage/innobase/handler/ha_innodb.cc 2010-12-03 16:07:26.851357007 +0900
11 @@ -11673,7 +11673,14 @@
15 -i_s_innodb_cmpmem_reset
16 +i_s_innodb_cmpmem_reset,
17 +i_s_innodb_sys_tables,
18 +i_s_innodb_sys_tablestats,
19 +i_s_innodb_sys_indexes,
20 +i_s_innodb_sys_columns,
21 +i_s_innodb_sys_fields,
22 +i_s_innodb_sys_foreign,
23 +i_s_innodb_sys_foreign_cols
24 mysql_declare_plugin_end;
26 /** @brief Initialize the default value of innodb_commit_concurrency.
27 diff -ruN a/storage/innobase/handler/i_s.cc b/storage/innobase/handler/i_s.cc
28 --- a/storage/innobase/handler/i_s.cc 2010-12-03 15:49:59.207956807 +0900
29 +++ b/storage/innobase/handler/i_s.cc 2010-12-03 17:10:02.719210529 +0900
31 #include <mysql/innodb_priv.h>
34 +#include "btr0pcur.h" /* for file sys_tables related info. */
35 #include "btr0types.h"
36 #include "buf0buddy.h" /* for i_s_cmpmem */
37 #include "buf0buf.h" /* for buf_pool and PAGE_ZIP_MIN_SIZE */
38 +#include "dict0load.h" /* for file sys_tables related info. */
40 #include "dict0types.h"
41 #include "ha_prototypes.h" /* for innobase_convert_name() */
42 @@ -1787,6 +1789,1675 @@
46 +/* Fields of the dynamic table INFORMATION_SCHEMA.SYS_TABLES */
47 +static ST_FIELD_INFO innodb_sys_tables_fields_info[] =
49 +#define SYS_TABLE_ID 0
50 + {STRUCT_FLD(field_name, "TABLE_ID"),
51 + STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
52 + STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
53 + STRUCT_FLD(value, 0),
54 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
55 + STRUCT_FLD(old_name, ""),
56 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
58 +#define SYS_TABLE_SCHEMA 1
59 + {STRUCT_FLD(field_name, "SCHEMA"),
60 + STRUCT_FLD(field_length, NAME_LEN + 1),
61 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
62 + STRUCT_FLD(value, 0),
63 + STRUCT_FLD(field_flags, 0),
64 + STRUCT_FLD(old_name, ""),
65 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
67 +#define SYS_TABLE_NAME 2
68 + {STRUCT_FLD(field_name, "NAME"),
69 + STRUCT_FLD(field_length, NAME_LEN + 1),
70 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
71 + STRUCT_FLD(value, 0),
72 + STRUCT_FLD(field_flags, 0),
73 + STRUCT_FLD(old_name, ""),
74 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
76 +#define SYS_TABLE_FLAG 3
77 + {STRUCT_FLD(field_name, "FLAG"),
78 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
79 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
80 + STRUCT_FLD(value, 0),
81 + STRUCT_FLD(field_flags, 0),
82 + STRUCT_FLD(old_name, ""),
83 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
85 +#define SYS_TABLE_NUM_COLUMN 4
86 + {STRUCT_FLD(field_name, "N_COLS"),
87 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
88 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
89 + STRUCT_FLD(value, 0),
90 + STRUCT_FLD(field_flags, 0),
91 + STRUCT_FLD(old_name, ""),
92 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
94 +#define SYS_TABLE_SPACE 5
95 + {STRUCT_FLD(field_name, "SPACE"),
96 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
97 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
98 + STRUCT_FLD(value, 0),
99 + STRUCT_FLD(field_flags, 0),
100 + STRUCT_FLD(old_name, ""),
101 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
103 + END_OF_ST_FIELD_INFO
106 +/**********************************************************************//**
107 +Populate information_schema.innodb_sys_tables table with information
109 +@return 0 on success */
112 +i_s_dict_fill_sys_tables(
113 +/*=====================*/
114 + THD* thd, /*!< in: thread */
115 + dict_table_t* table, /*!< in: table */
116 + TABLE* table_to_fill) /*!< in/out: fill this table */
119 + char buf[NAME_LEN * 2 + 2];
122 + DBUG_ENTER("i_s_dict_fill_sys_tables");
124 + fields = table_to_fill->field;
126 + OK(fields[SYS_TABLE_ID]->store(longlong(table->id), TRUE));
128 + strncpy(buf, table->name, NAME_LEN * 2 + 2);
129 + ptr = strchr(buf, '/');
134 + OK(field_store_string(fields[SYS_TABLE_SCHEMA], buf));
135 + OK(field_store_string(fields[SYS_TABLE_NAME], ptr));
137 + fields[SYS_TABLE_SCHEMA]->set_null();
138 + OK(field_store_string(fields[SYS_TABLE_NAME], buf));
141 + OK(fields[SYS_TABLE_FLAG]->store(table->flags));
143 + OK(fields[SYS_TABLE_NUM_COLUMN]->store(table->n_cols));
145 + OK(fields[SYS_TABLE_SPACE]->store(table->space));
147 + OK(schema_table_store_record(thd, table_to_fill));
151 +/*******************************************************************//**
152 +Function to go through each record in SYS_TABLES table, and fill the
153 +information_schema.innodb_sys_tables table with related table information
154 +@return 0 on success */
157 +i_s_sys_tables_fill_table(
158 +/*======================*/
159 + THD* thd, /*!< in: thread */
160 + TABLE_LIST* tables, /*!< in/out: tables to fill */
161 + COND* cond) /*!< in: condition (not used) */
168 + DBUG_ENTER("i_s_sys_tables_fill_table");
170 + /* deny access to non-superusers */
171 + if (check_global_access(thd, PROCESS_ACL)) {
176 + heap = mem_heap_create(1000);
177 + mutex_enter(&(dict_sys->mutex));
180 + rec = dict_startscan_system(&pcur, &mtr, SYS_TABLES);
183 + const char* err_msg;
184 + dict_table_t* table_rec;
186 + /* Create and populate a dict_table_t structure with
187 + information from SYS_TABLES row */
188 + err_msg = dict_process_sys_tables_rec(
189 + heap, rec, &table_rec, DICT_TABLE_LOAD_FROM_RECORD);
192 + mutex_exit(&dict_sys->mutex);
195 + i_s_dict_fill_sys_tables(thd, table_rec, tables->table);
197 + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
198 + ER_CANT_FIND_SYSTEM_REC,
202 + /* Since dict_process_sys_tables_rec() is called with
203 + DICT_TABLE_LOAD_FROM_RECORD, the table_rec is created in
204 + dict_process_sys_tables_rec(), we will need to free it */
206 + dict_mem_table_free(table_rec);
209 + mem_heap_empty(heap);
211 + /* Get the next record */
212 + mutex_enter(&dict_sys->mutex);
214 + rec = dict_getnext_system(&pcur, &mtr);
218 + mutex_exit(&dict_sys->mutex);
219 + mem_heap_free(heap);
224 +/*******************************************************************//**
225 +Bind the dynamic table INFORMATION_SCHEMA.innodb_sys_tables
226 +@return 0 on success */
229 +innodb_sys_tables_init(
230 +/*===================*/
231 + void* p) /*!< in/out: table schema object */
233 + ST_SCHEMA_TABLE* schema;
235 + DBUG_ENTER("innodb_sys_tables_init");
237 + schema = (ST_SCHEMA_TABLE*) p;
239 + schema->fields_info = innodb_sys_tables_fields_info;
240 + schema->fill_table = i_s_sys_tables_fill_table;
245 +UNIV_INTERN struct st_mysql_plugin i_s_innodb_sys_tables =
247 + /* the plugin type (a MYSQL_XXX_PLUGIN value) */
249 + STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
251 + /* pointer to type-specific plugin descriptor */
253 + STRUCT_FLD(info, &i_s_info),
257 + STRUCT_FLD(name, "INNODB_SYS_TABLES"),
259 + /* plugin author (for SHOW PLUGINS) */
261 + STRUCT_FLD(author, plugin_author),
263 + /* general descriptive text (for SHOW PLUGINS) */
265 + STRUCT_FLD(descr, "InnoDB SYS_TABLES"),
267 + /* the plugin license (PLUGIN_LICENSE_XXX) */
269 + STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
271 + /* the function to invoke when plugin is loaded */
272 + /* int (*)(void*); */
273 + STRUCT_FLD(init, innodb_sys_tables_init),
275 + /* the function to invoke when plugin is unloaded */
276 + /* int (*)(void*); */
277 + STRUCT_FLD(deinit, i_s_common_deinit),
279 + /* plugin version (for SHOW PLUGINS) */
281 + STRUCT_FLD(version, INNODB_VERSION_SHORT),
283 + /* struct st_mysql_show_var* */
284 + STRUCT_FLD(status_vars, NULL),
286 + /* struct st_mysql_sys_var** */
287 + STRUCT_FLD(system_vars, NULL),
289 + /* reserved for dependency checking */
291 + STRUCT_FLD(__reserved1, NULL)
294 +/* Fields of the dynamic table INFORMATION_SCHEMA.SYS_TABLESTATS */
295 +static ST_FIELD_INFO innodb_sys_tablestats_fields_info[] =
297 +#define SYS_TABLESTATS_ID 0
298 + {STRUCT_FLD(field_name, "TABLE_ID"),
299 + STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
300 + STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
301 + STRUCT_FLD(value, 0),
302 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
303 + STRUCT_FLD(old_name, ""),
304 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
306 +#define SYS_TABLESTATS_SCHEMA 1
307 + {STRUCT_FLD(field_name, "SCHEMA"),
308 + STRUCT_FLD(field_length, NAME_LEN + 1),
309 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
310 + STRUCT_FLD(value, 0),
311 + STRUCT_FLD(field_flags, 0),
312 + STRUCT_FLD(old_name, ""),
313 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
315 +#define SYS_TABLESTATS_NAME 2
316 + {STRUCT_FLD(field_name, "NAME"),
317 + STRUCT_FLD(field_length, NAME_LEN + 1),
318 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
319 + STRUCT_FLD(value, 0),
320 + STRUCT_FLD(field_flags, 0),
321 + STRUCT_FLD(old_name, ""),
322 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
324 +#define SYS_TABLESTATS_INIT 3
325 + {STRUCT_FLD(field_name, "STATS_INITIALIZED"),
326 + STRUCT_FLD(field_length, NAME_LEN + 1),
327 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
328 + STRUCT_FLD(value, 0),
329 + STRUCT_FLD(field_flags, 0),
330 + STRUCT_FLD(old_name, ""),
331 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
333 +#define SYS_TABLESTATS_NROW 4
334 + {STRUCT_FLD(field_name, "NUM_ROWS"),
335 + STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
336 + STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
337 + STRUCT_FLD(value, 0),
338 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
339 + STRUCT_FLD(old_name, ""),
340 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
342 +#define SYS_TABLESTATS_CLUST_SIZE 5
343 + {STRUCT_FLD(field_name, "CLUST_INDEX_SIZE"),
344 + STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
345 + STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
346 + STRUCT_FLD(value, 0),
347 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
348 + STRUCT_FLD(old_name, ""),
349 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
351 +#define SYS_TABLESTATS_INDEX_SIZE 6
352 + {STRUCT_FLD(field_name, "OTHER_INDEX_SIZE"),
353 + STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
354 + STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
355 + STRUCT_FLD(value, 0),
356 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
357 + STRUCT_FLD(old_name, ""),
358 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
360 +#define SYS_TABLESTATS_MODIFIED 7
361 + {STRUCT_FLD(field_name, "MODIFIED_COUNTER"),
362 + STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
363 + STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
364 + STRUCT_FLD(value, 0),
365 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
366 + STRUCT_FLD(old_name, ""),
367 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
369 +#define SYS_TABLESTATS_AUTONINC 8
370 + {STRUCT_FLD(field_name, "AUTOINC"),
371 + STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
372 + STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
373 + STRUCT_FLD(value, 0),
374 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
375 + STRUCT_FLD(old_name, ""),
376 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
378 +#define SYS_TABLESTATS_MYSQL_OPEN_HANDLE 9
379 + {STRUCT_FLD(field_name, "MYSQL_HANDLES_OPENED"),
380 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
381 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
382 + STRUCT_FLD(value, 0),
383 + STRUCT_FLD(field_flags, 0),
384 + STRUCT_FLD(old_name, ""),
385 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
387 + END_OF_ST_FIELD_INFO
390 +/**********************************************************************//**
391 +Populate information_schema.innodb_sys_tablestats table with information
393 +@return 0 on success */
396 +i_s_dict_fill_sys_tablestats(
397 +/*=========================*/
398 + THD* thd, /*!< in: thread */
399 + dict_table_t* table, /*!< in: table */
400 + TABLE* table_to_fill) /*!< in/out: fill this table */
403 + char buf[NAME_LEN * 2 + 2];
406 + DBUG_ENTER("i_s_dict_fill_sys_tablestats");
408 + fields = table_to_fill->field;
410 + OK(fields[SYS_TABLESTATS_ID]->store(longlong(table->id), TRUE));
412 + strncpy(buf, table->name, NAME_LEN * 2 + 2);
413 + ptr = strchr(buf, '/');
418 + OK(field_store_string(fields[SYS_TABLESTATS_SCHEMA], buf));
419 + OK(field_store_string(fields[SYS_TABLESTATS_NAME], ptr));
421 + fields[SYS_TABLESTATS_SCHEMA]->set_null();
422 + OK(field_store_string(fields[SYS_TABLESTATS_NAME], buf));
425 + if (table->stat_initialized) {
426 + OK(field_store_string(fields[SYS_TABLESTATS_INIT],
429 + OK(field_store_string(fields[SYS_TABLESTATS_INIT],
433 + OK(fields[SYS_TABLESTATS_NROW]->store(table->stat_n_rows, TRUE));
435 + OK(fields[SYS_TABLESTATS_CLUST_SIZE]->store(
436 + table->stat_clustered_index_size));
438 + OK(fields[SYS_TABLESTATS_INDEX_SIZE]->store(
439 + table->stat_sum_of_other_index_sizes));
441 + OK(fields[SYS_TABLESTATS_MODIFIED]->store(
442 + table->stat_modified_counter));
444 + OK(fields[SYS_TABLESTATS_AUTONINC]->store(table->autoinc, TRUE));
446 + OK(fields[SYS_TABLESTATS_MYSQL_OPEN_HANDLE]->store(
447 + table->n_mysql_handles_opened));
449 + OK(schema_table_store_record(thd, table_to_fill));
453 +/*******************************************************************//**
454 +Function to go through each record in SYS_TABLES table, and fill the
455 +information_schema.innodb_sys_tablestats table with table statistics
457 +@return 0 on success */
460 +i_s_sys_tables_fill_table_stats(
461 +/*============================*/
462 + THD* thd, /*!< in: thread */
463 + TABLE_LIST* tables, /*!< in/out: tables to fill */
464 + COND* cond) /*!< in: condition (not used) */
471 + DBUG_ENTER("i_s_sys_tables_fill_table_stats");
473 + /* deny access to non-superusers */
474 + if (check_global_access(thd, PROCESS_ACL)) {
479 + heap = mem_heap_create(1000);
480 + mutex_enter(&dict_sys->mutex);
483 + rec = dict_startscan_system(&pcur, &mtr, SYS_TABLES);
486 + const char* err_msg;
487 + dict_table_t* table_rec;
489 + /* Fetch the dict_table_t structure corresponding to
490 + this SYS_TABLES record */
491 + err_msg = dict_process_sys_tables_rec(
492 + heap, rec, &table_rec, DICT_TABLE_LOAD_FROM_CACHE);
495 + mutex_exit(&dict_sys->mutex);
498 + i_s_dict_fill_sys_tablestats(thd, table_rec,
501 + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
502 + ER_CANT_FIND_SYSTEM_REC,
506 + mem_heap_empty(heap);
508 + /* Get the next record */
509 + mutex_enter(&dict_sys->mutex);
511 + rec = dict_getnext_system(&pcur, &mtr);
515 + mutex_exit(&dict_sys->mutex);
516 + mem_heap_free(heap);
521 +/*******************************************************************//**
522 +Bind the dynamic table INFORMATION_SCHEMA.innodb_sys_tablestats
523 +@return 0 on success */
526 +innodb_sys_tablestats_init(
527 +/*=======================*/
528 + void* p) /*!< in/out: table schema object */
530 + ST_SCHEMA_TABLE* schema;
532 + DBUG_ENTER("innodb_sys_tablestats_init");
534 + schema = (ST_SCHEMA_TABLE*) p;
536 + schema->fields_info = innodb_sys_tablestats_fields_info;
537 + schema->fill_table = i_s_sys_tables_fill_table_stats;
542 +UNIV_INTERN struct st_mysql_plugin i_s_innodb_sys_tablestats =
544 + /* the plugin type (a MYSQL_XXX_PLUGIN value) */
546 + STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
548 + /* pointer to type-specific plugin descriptor */
550 + STRUCT_FLD(info, &i_s_info),
554 + STRUCT_FLD(name, "INNODB_SYS_TABLESTATS"),
556 + /* plugin author (for SHOW PLUGINS) */
558 + STRUCT_FLD(author, plugin_author),
560 + /* general descriptive text (for SHOW PLUGINS) */
562 + STRUCT_FLD(descr, "InnoDB SYS_TABLESTATS"),
564 + /* the plugin license (PLUGIN_LICENSE_XXX) */
566 + STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
568 + /* the function to invoke when plugin is loaded */
569 + /* int (*)(void*); */
570 + STRUCT_FLD(init, innodb_sys_tablestats_init),
572 + /* the function to invoke when plugin is unloaded */
573 + /* int (*)(void*); */
574 + STRUCT_FLD(deinit, i_s_common_deinit),
576 + /* plugin version (for SHOW PLUGINS) */
578 + STRUCT_FLD(version, INNODB_VERSION_SHORT),
580 + /* struct st_mysql_show_var* */
581 + STRUCT_FLD(status_vars, NULL),
583 + /* struct st_mysql_sys_var** */
584 + STRUCT_FLD(system_vars, NULL),
586 + /* reserved for dependency checking */
588 + STRUCT_FLD(__reserved1, NULL)
591 +/* Fields of the dynamic table INFORMATION_SCHEMA.SYS_INDEXES */
592 +static ST_FIELD_INFO innodb_sysindex_fields_info[] =
594 +#define SYS_INDEX_ID 0
595 + {STRUCT_FLD(field_name, "INDEX_ID"),
596 + STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
597 + STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
598 + STRUCT_FLD(value, 0),
599 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
600 + STRUCT_FLD(old_name, ""),
601 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
603 +#define SYS_INDEX_NAME 1
604 + {STRUCT_FLD(field_name, "NAME"),
605 + STRUCT_FLD(field_length, NAME_LEN + 1),
606 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
607 + STRUCT_FLD(value, 0),
608 + STRUCT_FLD(field_flags, 0),
609 + STRUCT_FLD(old_name, ""),
610 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
612 +#define SYS_INDEX_TABLE_ID 2
613 + {STRUCT_FLD(field_name, "TABLE_ID"),
614 + STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
615 + STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
616 + STRUCT_FLD(value, 0),
617 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
618 + STRUCT_FLD(old_name, ""),
619 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
621 +#define SYS_INDEX_TYPE 3
622 + {STRUCT_FLD(field_name, "TYPE"),
623 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
624 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
625 + STRUCT_FLD(value, 0),
626 + STRUCT_FLD(field_flags, 0),
627 + STRUCT_FLD(old_name, ""),
628 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
630 +#define SYS_INDEX_NUM_FIELDS 4
631 + {STRUCT_FLD(field_name, "N_FIELDS"),
632 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
633 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
634 + STRUCT_FLD(value, 0),
635 + STRUCT_FLD(field_flags, 0),
636 + STRUCT_FLD(old_name, ""),
637 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
639 +#define SYS_INDEX_PAGE_NO 5
640 + {STRUCT_FLD(field_name, "PAGE_NO"),
641 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
642 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
643 + STRUCT_FLD(value, 0),
644 + STRUCT_FLD(field_flags, 0),
645 + STRUCT_FLD(old_name, ""),
646 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
648 +#define SYS_INDEX_SPACE 6
649 + {STRUCT_FLD(field_name, "SPACE"),
650 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
651 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
652 + STRUCT_FLD(value, 0),
653 + STRUCT_FLD(field_flags, 0),
654 + STRUCT_FLD(old_name, ""),
655 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
657 + END_OF_ST_FIELD_INFO
660 +/**********************************************************************//**
661 +Function to populate the information_schema.innodb_sys_indexes table with
662 +collected index information
663 +@return 0 on success */
666 +i_s_dict_fill_sys_indexes(
667 +/*======================*/
668 + THD* thd, /*!< in: thread */
669 + table_id_t table_id, /*!< in: table id */
670 + dict_index_t* index, /*!< in: populated dict_index_t
671 + struct with index info */
672 + TABLE* table_to_fill) /*!< in/out: fill this table */
676 + DBUG_ENTER("i_s_dict_fill_sys_indexes");
678 + fields = table_to_fill->field;
680 + OK(fields[SYS_INDEX_ID]->store(longlong(index->id), TRUE));
682 + OK(field_store_string(fields[SYS_INDEX_NAME], index->name));
684 + OK(fields[SYS_INDEX_TABLE_ID]->store(longlong(table_id), TRUE));
686 + OK(fields[SYS_INDEX_TYPE]->store(index->type));
688 + OK(fields[SYS_INDEX_NUM_FIELDS]->store(index->n_fields));
690 + OK(fields[SYS_INDEX_PAGE_NO]->store(index->page));
692 + OK(fields[SYS_INDEX_SPACE]->store(index->space));
694 + OK(schema_table_store_record(thd, table_to_fill));
698 +/*******************************************************************//**
699 +Function to go through each record in SYS_INDEXES table, and fill the
700 +information_schema.innodb_sys_indexes table with related index information
701 +@return 0 on success */
704 +i_s_sys_indexes_fill_table(
705 +/*=======================*/
706 + THD* thd, /*!< in: thread */
707 + TABLE_LIST* tables, /*!< in/out: tables to fill */
708 + COND* cond) /*!< in: condition (not used) */
715 + DBUG_ENTER("i_s_sys_indexes_fill_table");
717 + /* deny access to non-superusers */
718 + if (check_global_access(thd, PROCESS_ACL)) {
723 + heap = mem_heap_create(1000);
724 + mutex_enter(&dict_sys->mutex);
727 + /* Start scan the SYS_INDEXES table */
728 + rec = dict_startscan_system(&pcur, &mtr, SYS_INDEXES);
730 + /* Process each record in the table */
732 + const char* err_msg;;
733 + table_id_t table_id;
734 + dict_index_t index_rec;
736 + /* Populate a dict_index_t structure with information from
737 + a SYS_INDEXES row */
738 + err_msg = dict_process_sys_indexes_rec(heap, rec, &index_rec,
742 + mutex_exit(&dict_sys->mutex);
745 + i_s_dict_fill_sys_indexes(thd, table_id, &index_rec,
748 + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
749 + ER_CANT_FIND_SYSTEM_REC,
753 + mem_heap_empty(heap);
755 + /* Get the next record */
756 + mutex_enter(&dict_sys->mutex);
758 + rec = dict_getnext_system(&pcur, &mtr);
762 + mutex_exit(&dict_sys->mutex);
763 + mem_heap_free(heap);
767 +/*******************************************************************//**
768 +Bind the dynamic table INFORMATION_SCHEMA.innodb_sys_indexes
769 +@return 0 on success */
772 +innodb_sys_indexes_init(
773 +/*====================*/
774 + void* p) /*!< in/out: table schema object */
776 + ST_SCHEMA_TABLE* schema;
778 + DBUG_ENTER("innodb_sys_index_init");
780 + schema = (ST_SCHEMA_TABLE*) p;
782 + schema->fields_info = innodb_sysindex_fields_info;
783 + schema->fill_table = i_s_sys_indexes_fill_table;
788 +UNIV_INTERN struct st_mysql_plugin i_s_innodb_sys_indexes =
790 + /* the plugin type (a MYSQL_XXX_PLUGIN value) */
792 + STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
794 + /* pointer to type-specific plugin descriptor */
796 + STRUCT_FLD(info, &i_s_info),
800 + STRUCT_FLD(name, "INNODB_SYS_INDEXES"),
802 + /* plugin author (for SHOW PLUGINS) */
804 + STRUCT_FLD(author, plugin_author),
806 + /* general descriptive text (for SHOW PLUGINS) */
808 + STRUCT_FLD(descr, "InnoDB SYS_INDEXES"),
810 + /* the plugin license (PLUGIN_LICENSE_XXX) */
812 + STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
814 + /* the function to invoke when plugin is loaded */
815 + /* int (*)(void*); */
816 + STRUCT_FLD(init, innodb_sys_indexes_init),
818 + /* the function to invoke when plugin is unloaded */
819 + /* int (*)(void*); */
820 + STRUCT_FLD(deinit, i_s_common_deinit),
822 + /* plugin version (for SHOW PLUGINS) */
824 + STRUCT_FLD(version, INNODB_VERSION_SHORT),
826 + /* struct st_mysql_show_var* */
827 + STRUCT_FLD(status_vars, NULL),
829 + /* struct st_mysql_sys_var** */
830 + STRUCT_FLD(system_vars, NULL),
832 + /* reserved for dependency checking */
834 + STRUCT_FLD(__reserved1, NULL)
837 +/* Fields of the dynamic table INFORMATION_SCHEMA.SYS_COLUMNS */
838 +static ST_FIELD_INFO innodb_sys_columns_fields_info[] =
840 +#define SYS_COLUMN_TABLE_ID 0
841 + {STRUCT_FLD(field_name, "TABLE_ID"),
842 + STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
843 + STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
844 + STRUCT_FLD(value, 0),
845 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
846 + STRUCT_FLD(old_name, ""),
847 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
849 +#define SYS_COLUMN_NAME 1
850 + {STRUCT_FLD(field_name, "NAME"),
851 + STRUCT_FLD(field_length, NAME_LEN + 1),
852 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
853 + STRUCT_FLD(value, 0),
854 + STRUCT_FLD(field_flags, 0),
855 + STRUCT_FLD(old_name, ""),
856 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
858 +#define SYS_COLUMN_POSITION 2
859 + {STRUCT_FLD(field_name, "POS"),
860 + STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
861 + STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
862 + STRUCT_FLD(value, 0),
863 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
864 + STRUCT_FLD(old_name, ""),
865 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
867 +#define SYS_COLUMN_MTYPE 3
868 + {STRUCT_FLD(field_name, "MTYPE"),
869 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
870 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
871 + STRUCT_FLD(value, 0),
872 + STRUCT_FLD(field_flags, 0),
873 + STRUCT_FLD(old_name, ""),
874 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
876 +#define SYS_COLUMN__PRTYPE 4
877 + {STRUCT_FLD(field_name, "PRTYPE"),
878 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
879 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
880 + STRUCT_FLD(value, 0),
881 + STRUCT_FLD(field_flags, 0),
882 + STRUCT_FLD(old_name, ""),
883 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
885 +#define SYS_COLUMN_COLUMN_LEN 5
886 + {STRUCT_FLD(field_name, "LEN"),
887 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
888 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
889 + STRUCT_FLD(value, 0),
890 + STRUCT_FLD(field_flags, 0),
891 + STRUCT_FLD(old_name, ""),
892 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
894 + END_OF_ST_FIELD_INFO
897 +/**********************************************************************//**
898 +Function to populate the information_schema.innodb_sys_columns with
899 +related column information
900 +@return 0 on success */
903 +i_s_dict_fill_sys_columns(
904 +/*======================*/
905 + THD* thd, /*!< in: thread */
906 + table_id_t table_id, /*!< in: table ID */
907 + const char* col_name, /*!< in: column name */
908 + dict_col_t* column, /*!< in: dict_col_t struct holding
909 + more column information */
910 + TABLE* table_to_fill) /*!< in/out: fill this table */
914 + DBUG_ENTER("i_s_dict_fill_sys_columns");
916 + fields = table_to_fill->field;
918 + OK(fields[SYS_COLUMN_TABLE_ID]->store(longlong(table_id), TRUE));
920 + OK(field_store_string(fields[SYS_COLUMN_NAME], col_name));
922 + OK(fields[SYS_COLUMN_POSITION]->store(column->ind));
924 + OK(fields[SYS_COLUMN_MTYPE]->store(column->mtype));
926 + OK(fields[SYS_COLUMN__PRTYPE]->store(column->prtype));
928 + OK(fields[SYS_COLUMN_COLUMN_LEN]->store(column->len));
930 + OK(schema_table_store_record(thd, table_to_fill));
934 +/*******************************************************************//**
935 +Function to fill information_schema.innodb_sys_columns with information
936 +collected by scanning SYS_COLUMNS table.
937 +@return 0 on success */
940 +i_s_sys_columns_fill_table(
941 +/*=======================*/
942 + THD* thd, /*!< in: thread */
943 + TABLE_LIST* tables, /*!< in/out: tables to fill */
944 + COND* cond) /*!< in: condition (not used) */
948 + const char* col_name;
952 + DBUG_ENTER("i_s_sys_columns_fill_table");
954 + /* deny access to non-superusers */
955 + if (check_global_access(thd, PROCESS_ACL)) {
960 + heap = mem_heap_create(1000);
961 + mutex_enter(&dict_sys->mutex);
964 + rec = dict_startscan_system(&pcur, &mtr, SYS_COLUMNS);
967 + const char* err_msg;
968 + dict_col_t column_rec;
969 + table_id_t table_id;
971 + /* populate a dict_col_t structure with information from
972 + a SYS_COLUMNS row */
973 + err_msg = dict_process_sys_columns_rec(heap, rec, &column_rec,
974 + &table_id, &col_name);
977 + mutex_exit(&dict_sys->mutex);
980 + i_s_dict_fill_sys_columns(thd, table_id, col_name,
984 + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
985 + ER_CANT_FIND_SYSTEM_REC,
989 + mem_heap_empty(heap);
991 + /* Get the next record */
992 + mutex_enter(&dict_sys->mutex);
994 + rec = dict_getnext_system(&pcur, &mtr);
998 + mutex_exit(&dict_sys->mutex);
999 + mem_heap_free(heap);
1003 +/*******************************************************************//**
1004 +Bind the dynamic table INFORMATION_SCHEMA.innodb_sys_columns
1005 +@return 0 on success */
1008 +innodb_sys_columns_init(
1009 +/*====================*/
1010 + void* p) /*!< in/out: table schema object */
1012 + ST_SCHEMA_TABLE* schema;
1014 + DBUG_ENTER("innodb_sys_columns_init");
1016 + schema = (ST_SCHEMA_TABLE*) p;
1018 + schema->fields_info = innodb_sys_columns_fields_info;
1019 + schema->fill_table = i_s_sys_columns_fill_table;
1024 +UNIV_INTERN struct st_mysql_plugin i_s_innodb_sys_columns =
1026 + /* the plugin type (a MYSQL_XXX_PLUGIN value) */
1028 + STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
1030 + /* pointer to type-specific plugin descriptor */
1032 + STRUCT_FLD(info, &i_s_info),
1036 + STRUCT_FLD(name, "INNODB_SYS_COLUMNS"),
1038 + /* plugin author (for SHOW PLUGINS) */
1040 + STRUCT_FLD(author, plugin_author),
1042 + /* general descriptive text (for SHOW PLUGINS) */
1044 + STRUCT_FLD(descr, "InnoDB SYS_COLUMNS"),
1046 + /* the plugin license (PLUGIN_LICENSE_XXX) */
1048 + STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
1050 + /* the function to invoke when plugin is loaded */
1051 + /* int (*)(void*); */
1052 + STRUCT_FLD(init, innodb_sys_columns_init),
1054 + /* the function to invoke when plugin is unloaded */
1055 + /* int (*)(void*); */
1056 + STRUCT_FLD(deinit, i_s_common_deinit),
1058 + /* plugin version (for SHOW PLUGINS) */
1059 + /* unsigned int */
1060 + STRUCT_FLD(version, INNODB_VERSION_SHORT),
1062 + /* struct st_mysql_show_var* */
1063 + STRUCT_FLD(status_vars, NULL),
1065 + /* struct st_mysql_sys_var** */
1066 + STRUCT_FLD(system_vars, NULL),
1068 + /* reserved for dependency checking */
1070 + STRUCT_FLD(__reserved1, NULL)
1072 +/* Fields of the dynamic table INFORMATION_SCHEMA.innodb_sys_fields */
1073 +static ST_FIELD_INFO innodb_sys_fields_fields_info[] =
1075 +#define SYS_FIELD_INDEX_ID 0
1076 + {STRUCT_FLD(field_name, "INDEX_ID"),
1077 + STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
1078 + STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
1079 + STRUCT_FLD(value, 0),
1080 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
1081 + STRUCT_FLD(old_name, ""),
1082 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
1084 +#define SYS_FIELD_NAME 1
1085 + {STRUCT_FLD(field_name, "NAME"),
1086 + STRUCT_FLD(field_length, NAME_LEN + 1),
1087 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
1088 + STRUCT_FLD(value, 0),
1089 + STRUCT_FLD(field_flags, 0),
1090 + STRUCT_FLD(old_name, ""),
1091 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
1093 +#define SYS_FIELD_POS 2
1094 + {STRUCT_FLD(field_name, "POS"),
1095 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
1096 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
1097 + STRUCT_FLD(value, 0),
1098 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
1099 + STRUCT_FLD(old_name, ""),
1100 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
1102 + END_OF_ST_FIELD_INFO
1105 +/**********************************************************************//**
1106 +Function to fill information_schema.innodb_sys_fields with information
1107 +collected by scanning SYS_FIELDS table.
1108 +@return 0 on success */
1111 +i_s_dict_fill_sys_fields(
1112 +/*=====================*/
1113 + THD* thd, /*!< in: thread */
1114 + index_id_t index_id, /*!< in: index id for the field */
1115 + dict_field_t* field, /*!< in: table */
1116 + ulint pos, /*!< in: Field position */
1117 + TABLE* table_to_fill) /*!< in/out: fill this table */
1121 + DBUG_ENTER("i_s_dict_fill_sys_fields");
1123 + fields = table_to_fill->field;
1125 + OK(fields[SYS_FIELD_INDEX_ID]->store(longlong(index_id), TRUE));
1127 + OK(field_store_string(fields[SYS_FIELD_NAME], field->name));
1129 + OK(fields[SYS_FIELD_POS]->store(pos));
1131 + OK(schema_table_store_record(thd, table_to_fill));
1135 +/*******************************************************************//**
1136 +Function to go through each record in SYS_FIELDS table, and fill the
1137 +information_schema.innodb_sys_fields table with related index field
1139 +@return 0 on success */
1142 +i_s_sys_fields_fill_table(
1143 +/*======================*/
1144 + THD* thd, /*!< in: thread */
1145 + TABLE_LIST* tables, /*!< in/out: tables to fill */
1146 + COND* cond) /*!< in: condition (not used) */
1151 + index_id_t last_id;
1154 + DBUG_ENTER("i_s_sys_fields_fill_table");
1156 + /* deny access to non-superusers */
1157 + if (check_global_access(thd, PROCESS_ACL)) {
1162 + heap = mem_heap_create(1000);
1163 + mutex_enter(&dict_sys->mutex);
1166 + /* will save last index id so that we know whether we move to
1167 + the next index. This is used to calculate prefix length */
1170 + rec = dict_startscan_system(&pcur, &mtr, SYS_FIELDS);
1174 + const char* err_msg;
1175 + index_id_t index_id;
1176 + dict_field_t field_rec;
1178 + /* Populate a dict_field_t structure with information from
1179 + a SYS_FIELDS row */
1180 + err_msg = dict_process_sys_fields_rec(heap, rec, &field_rec,
1181 + &pos, &index_id, last_id);
1184 + mutex_exit(&dict_sys->mutex);
1187 + i_s_dict_fill_sys_fields(thd, index_id, &field_rec,
1188 + pos, tables->table);
1189 + last_id = index_id;
1191 + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
1192 + ER_CANT_FIND_SYSTEM_REC,
1196 + mem_heap_empty(heap);
1198 + /* Get the next record */
1199 + mutex_enter(&dict_sys->mutex);
1201 + rec = dict_getnext_system(&pcur, &mtr);
1205 + mutex_exit(&dict_sys->mutex);
1206 + mem_heap_free(heap);
1210 +/*******************************************************************//**
1211 +Bind the dynamic table INFORMATION_SCHEMA.innodb_sys_fields
1212 +@return 0 on success */
1215 +innodb_sys_fields_init(
1216 +/*===================*/
1217 + void* p) /*!< in/out: table schema object */
1219 + ST_SCHEMA_TABLE* schema;
1221 + DBUG_ENTER("innodb_sys_field_init");
1223 + schema = (ST_SCHEMA_TABLE*) p;
1225 + schema->fields_info = innodb_sys_fields_fields_info;
1226 + schema->fill_table = i_s_sys_fields_fill_table;
1231 +UNIV_INTERN struct st_mysql_plugin i_s_innodb_sys_fields =
1233 + /* the plugin type (a MYSQL_XXX_PLUGIN value) */
1235 + STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
1237 + /* pointer to type-specific plugin descriptor */
1239 + STRUCT_FLD(info, &i_s_info),
1243 + STRUCT_FLD(name, "INNODB_SYS_FIELDS"),
1245 + /* plugin author (for SHOW PLUGINS) */
1247 + STRUCT_FLD(author, plugin_author),
1249 + /* general descriptive text (for SHOW PLUGINS) */
1251 + STRUCT_FLD(descr, "InnoDB SYS_FIELDS"),
1253 + /* the plugin license (PLUGIN_LICENSE_XXX) */
1255 + STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
1257 + /* the function to invoke when plugin is loaded */
1258 + /* int (*)(void*); */
1259 + STRUCT_FLD(init, innodb_sys_fields_init),
1261 + /* the function to invoke when plugin is unloaded */
1262 + /* int (*)(void*); */
1263 + STRUCT_FLD(deinit, i_s_common_deinit),
1265 + /* plugin version (for SHOW PLUGINS) */
1266 + /* unsigned int */
1267 + STRUCT_FLD(version, INNODB_VERSION_SHORT),
1269 + /* struct st_mysql_show_var* */
1270 + STRUCT_FLD(status_vars, NULL),
1272 + /* struct st_mysql_sys_var** */
1273 + STRUCT_FLD(system_vars, NULL),
1275 + /* reserved for dependency checking */
1277 + STRUCT_FLD(__reserved1, NULL)
1280 +/* Fields of the dynamic table INFORMATION_SCHEMA.innodb_sys_foreign */
1281 +static ST_FIELD_INFO innodb_sys_foreign_fields_info[] =
1283 +#define SYS_FOREIGN_ID 0
1284 + {STRUCT_FLD(field_name, "ID"),
1285 + STRUCT_FLD(field_length, NAME_LEN + 1),
1286 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
1287 + STRUCT_FLD(value, 0),
1288 + STRUCT_FLD(field_flags, 0),
1289 + STRUCT_FLD(old_name, ""),
1290 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
1292 +#define SYS_FOREIGN_FOR_NAME 1
1293 + {STRUCT_FLD(field_name, "FOR_NAME"),
1294 + STRUCT_FLD(field_length, NAME_LEN + 1),
1295 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
1296 + STRUCT_FLD(value, 0),
1297 + STRUCT_FLD(field_flags, 0),
1298 + STRUCT_FLD(old_name, ""),
1299 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
1301 +#define SYS_FOREIGN_REF_NAME 2
1302 + {STRUCT_FLD(field_name, "REF_NAME"),
1303 + STRUCT_FLD(field_length, NAME_LEN + 1),
1304 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
1305 + STRUCT_FLD(value, 0),
1306 + STRUCT_FLD(field_flags, 0),
1307 + STRUCT_FLD(old_name, ""),
1308 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
1310 +#define SYS_FOREIGN_NUM_COL 3
1311 + {STRUCT_FLD(field_name, "N_COLS"),
1312 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
1313 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
1314 + STRUCT_FLD(value, 0),
1315 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
1316 + STRUCT_FLD(old_name, ""),
1317 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
1319 +#define SYS_FOREIGN_TYPE 4
1320 + {STRUCT_FLD(field_name, "TYPE"),
1321 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
1322 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
1323 + STRUCT_FLD(value, 0),
1324 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
1325 + STRUCT_FLD(old_name, ""),
1326 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
1328 + END_OF_ST_FIELD_INFO
1331 +/**********************************************************************//**
1332 +Function to fill information_schema.innodb_sys_foreign with information
1333 +collected by scanning SYS_FOREIGN table.
1334 +@return 0 on success */
1337 +i_s_dict_fill_sys_foreign(
1338 +/*======================*/
1339 + THD* thd, /*!< in: thread */
1340 + dict_foreign_t* foreign, /*!< in: table */
1341 + TABLE* table_to_fill) /*!< in/out: fill this table */
1345 + DBUG_ENTER("i_s_dict_fill_sys_foreign");
1347 + fields = table_to_fill->field;
1349 + OK(field_store_string(fields[SYS_FOREIGN_ID], foreign->id));
1351 + OK(field_store_string(fields[SYS_FOREIGN_FOR_NAME],
1352 + foreign->foreign_table_name));
1354 + OK(field_store_string(fields[SYS_FOREIGN_REF_NAME],
1355 + foreign->referenced_table_name));
1357 + OK(fields[SYS_FOREIGN_NUM_COL]->store(foreign->n_fields));
1359 + OK(fields[SYS_FOREIGN_TYPE]->store(foreign->type));
1361 + OK(schema_table_store_record(thd, table_to_fill));
1365 +/*******************************************************************//**
1366 +Function to populate INFORMATION_SCHEMA.innodb_sys_foreign table. Loop
1367 +through each record in SYS_FOREIGN, and extract the foreign key
1369 +@return 0 on success */
1372 +i_s_sys_foreign_fill_table(
1373 +/*=======================*/
1374 + THD* thd, /*!< in: thread */
1375 + TABLE_LIST* tables, /*!< in/out: tables to fill */
1376 + COND* cond) /*!< in: condition (not used) */
1383 + DBUG_ENTER("i_s_sys_foreign_fill_table");
1385 + /* deny access to non-superusers */
1386 + if (check_global_access(thd, PROCESS_ACL)) {
1391 + heap = mem_heap_create(1000);
1392 + mutex_enter(&dict_sys->mutex);
1395 + rec = dict_startscan_system(&pcur, &mtr, SYS_FOREIGN);
1398 + const char* err_msg;
1399 + dict_foreign_t foreign_rec;
1401 + /* Populate a dict_foreign_t structure with information from
1402 + a SYS_FOREIGN row */
1403 + err_msg = dict_process_sys_foreign_rec(heap, rec, &foreign_rec);
1406 + mutex_exit(&dict_sys->mutex);
1409 + i_s_dict_fill_sys_foreign(thd, &foreign_rec,
1412 + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
1413 + ER_CANT_FIND_SYSTEM_REC,
1417 + mem_heap_empty(heap);
1419 + /* Get the next record */
1421 + mutex_enter(&dict_sys->mutex);
1422 + rec = dict_getnext_system(&pcur, &mtr);
1426 + mutex_exit(&dict_sys->mutex);
1427 + mem_heap_free(heap);
1431 +/*******************************************************************//**
1432 +Bind the dynamic table INFORMATION_SCHEMA.innodb_sys_foreign
1433 +@return 0 on success */
1436 +innodb_sys_foreign_init(
1437 +/*====================*/
1438 + void* p) /*!< in/out: table schema object */
1440 + ST_SCHEMA_TABLE* schema;
1442 + DBUG_ENTER("innodb_sys_foreign_init");
1444 + schema = (ST_SCHEMA_TABLE*) p;
1446 + schema->fields_info = innodb_sys_foreign_fields_info;
1447 + schema->fill_table = i_s_sys_foreign_fill_table;
1452 +UNIV_INTERN struct st_mysql_plugin i_s_innodb_sys_foreign =
1454 + /* the plugin type (a MYSQL_XXX_PLUGIN value) */
1456 + STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
1458 + /* pointer to type-specific plugin descriptor */
1460 + STRUCT_FLD(info, &i_s_info),
1464 + STRUCT_FLD(name, "INNODB_SYS_FOREIGN"),
1466 + /* plugin author (for SHOW PLUGINS) */
1468 + STRUCT_FLD(author, plugin_author),
1470 + /* general descriptive text (for SHOW PLUGINS) */
1472 + STRUCT_FLD(descr, "InnoDB SYS_FOREIGN"),
1474 + /* the plugin license (PLUGIN_LICENSE_XXX) */
1476 + STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
1478 + /* the function to invoke when plugin is loaded */
1479 + /* int (*)(void*); */
1480 + STRUCT_FLD(init, innodb_sys_foreign_init),
1482 + /* the function to invoke when plugin is unloaded */
1483 + /* int (*)(void*); */
1484 + STRUCT_FLD(deinit, i_s_common_deinit),
1486 + /* plugin version (for SHOW PLUGINS) */
1487 + /* unsigned int */
1488 + STRUCT_FLD(version, INNODB_VERSION_SHORT),
1490 + /* struct st_mysql_show_var* */
1491 + STRUCT_FLD(status_vars, NULL),
1493 + /* struct st_mysql_sys_var** */
1494 + STRUCT_FLD(system_vars, NULL),
1496 + /* reserved for dependency checking */
1498 + STRUCT_FLD(__reserved1, NULL)
1500 +/* Fields of the dynamic table INFORMATION_SCHEMA.innodb_sys_foreign_cols */
1501 +static ST_FIELD_INFO innodb_sys_foreign_cols_fields_info[] =
1503 +#define SYS_FOREIGN_COL_ID 0
1504 + {STRUCT_FLD(field_name, "ID"),
1505 + STRUCT_FLD(field_length, NAME_LEN + 1),
1506 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
1507 + STRUCT_FLD(value, 0),
1508 + STRUCT_FLD(field_flags, 0),
1509 + STRUCT_FLD(old_name, ""),
1510 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
1512 +#define SYS_FOREIGN_COL_FOR_NAME 1
1513 + {STRUCT_FLD(field_name, "FOR_COL_NAME"),
1514 + STRUCT_FLD(field_length, NAME_LEN + 1),
1515 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
1516 + STRUCT_FLD(value, 0),
1517 + STRUCT_FLD(field_flags, 0),
1518 + STRUCT_FLD(old_name, ""),
1519 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
1521 +#define SYS_FOREIGN_COL_REF_NAME 2
1522 + {STRUCT_FLD(field_name, "REF_COL_NAME"),
1523 + STRUCT_FLD(field_length, NAME_LEN + 1),
1524 + STRUCT_FLD(field_type, MYSQL_TYPE_STRING),
1525 + STRUCT_FLD(value, 0),
1526 + STRUCT_FLD(field_flags, 0),
1527 + STRUCT_FLD(old_name, ""),
1528 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
1530 +#define SYS_FOREIGN_COL_POS 3
1531 + {STRUCT_FLD(field_name, "POS"),
1532 + STRUCT_FLD(field_length, MY_INT32_NUM_DECIMAL_DIGITS),
1533 + STRUCT_FLD(field_type, MYSQL_TYPE_LONG),
1534 + STRUCT_FLD(value, 0),
1535 + STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
1536 + STRUCT_FLD(old_name, ""),
1537 + STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
1539 + END_OF_ST_FIELD_INFO
1542 +/**********************************************************************//**
1543 +Function to fill information_schema.innodb_sys_foreign_cols with information
1544 +collected by scanning SYS_FOREIGN_COLS table.
1545 +@return 0 on success */
1548 +i_s_dict_fill_sys_foreign_cols(
1549 +/*==========================*/
1550 + THD* thd, /*!< in: thread */
1551 + const char* name, /*!< in: foreign key constraint name */
1552 + const char* for_col_name, /*!< in: referencing column name*/
1553 + const char* ref_col_name, /*!< in: referenced column
1555 + ulint pos, /*!< in: column position */
1556 + TABLE* table_to_fill) /*!< in/out: fill this table */
1560 + DBUG_ENTER("i_s_dict_fill_sys_foreign_cols");
1562 + fields = table_to_fill->field;
1564 + OK(field_store_string(fields[SYS_FOREIGN_COL_ID], name));
1566 + OK(field_store_string(fields[SYS_FOREIGN_COL_FOR_NAME], for_col_name));
1568 + OK(field_store_string(fields[SYS_FOREIGN_COL_REF_NAME], ref_col_name));
1570 + OK(fields[SYS_FOREIGN_COL_POS]->store(pos));
1572 + OK(schema_table_store_record(thd, table_to_fill));
1576 +/*******************************************************************//**
1577 +Function to populate INFORMATION_SCHEMA.innodb_sys_foreign_cols table. Loop
1578 +through each record in SYS_FOREIGN_COLS, and extract the foreign key column
1579 +information and fill the INFORMATION_SCHEMA.innodb_sys_foreign_cols table.
1580 +@return 0 on success */
1583 +i_s_sys_foreign_cols_fill_table(
1584 +/*============================*/
1585 + THD* thd, /*!< in: thread */
1586 + TABLE_LIST* tables, /*!< in/out: tables to fill */
1587 + COND* cond) /*!< in: condition (not used) */
1594 + DBUG_ENTER("i_s_sys_foreign_cols_fill_table");
1596 + /* deny access to non-superusers */
1597 + if (check_global_access(thd, PROCESS_ACL)) {
1601 + heap = mem_heap_create(1000);
1602 + mutex_enter(&dict_sys->mutex);
1605 + rec = dict_startscan_system(&pcur, &mtr, SYS_FOREIGN_COLS);
1608 + const char* err_msg;
1610 + const char* for_col_name;
1611 + const char* ref_col_name;
1614 + /* Extract necessary information from a SYS_FOREIGN_COLS row */
1615 + err_msg = dict_process_sys_foreign_col_rec(
1616 + heap, rec, &name, &for_col_name, &ref_col_name, &pos);
1619 + mutex_exit(&dict_sys->mutex);
1622 + i_s_dict_fill_sys_foreign_cols(
1623 + thd, name, for_col_name, ref_col_name, pos,
1626 + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
1627 + ER_CANT_FIND_SYSTEM_REC,
1631 + mem_heap_empty(heap);
1633 + /* Get the next record */
1634 + mutex_enter(&dict_sys->mutex);
1636 + rec = dict_getnext_system(&pcur, &mtr);
1640 + mutex_exit(&dict_sys->mutex);
1641 + mem_heap_free(heap);
1645 +/*******************************************************************//**
1646 +Bind the dynamic table INFORMATION_SCHEMA.innodb_sys_foreign_cols
1647 +@return 0 on success */
1650 +innodb_sys_foreign_cols_init(
1651 +/*========================*/
1652 + void* p) /*!< in/out: table schema object */
1654 + ST_SCHEMA_TABLE* schema;
1656 + DBUG_ENTER("innodb_sys_foreign_cols_init");
1658 + schema = (ST_SCHEMA_TABLE*) p;
1660 + schema->fields_info = innodb_sys_foreign_cols_fields_info;
1661 + schema->fill_table = i_s_sys_foreign_cols_fill_table;
1666 +UNIV_INTERN struct st_mysql_plugin i_s_innodb_sys_foreign_cols =
1668 + /* the plugin type (a MYSQL_XXX_PLUGIN value) */
1670 + STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
1672 + /* pointer to type-specific plugin descriptor */
1674 + STRUCT_FLD(info, &i_s_info),
1678 + STRUCT_FLD(name, "INNODB_SYS_FOREIGN_COLS"),
1680 + /* plugin author (for SHOW PLUGINS) */
1682 + STRUCT_FLD(author, plugin_author),
1684 + /* general descriptive text (for SHOW PLUGINS) */
1686 + STRUCT_FLD(descr, "InnoDB SYS_FOREIGN_COLS"),
1688 + /* the plugin license (PLUGIN_LICENSE_XXX) */
1690 + STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
1692 + /* the function to invoke when plugin is loaded */
1693 + /* int (*)(void*); */
1694 + STRUCT_FLD(init, innodb_sys_foreign_cols_init),
1696 + /* the function to invoke when plugin is unloaded */
1697 + /* int (*)(void*); */
1698 + STRUCT_FLD(deinit, i_s_common_deinit),
1700 + /* plugin version (for SHOW PLUGINS) */
1701 + /* unsigned int */
1702 + STRUCT_FLD(version, INNODB_VERSION_SHORT),
1704 + /* struct st_mysql_show_var* */
1705 + STRUCT_FLD(status_vars, NULL),
1707 + /* struct st_mysql_sys_var** */
1708 + STRUCT_FLD(system_vars, NULL),
1710 + /* reserved for dependency checking */
1712 + STRUCT_FLD(__reserved1, NULL)
1715 /***********************************************************************
1717 static ST_FIELD_INFO i_s_innodb_rseg_fields_info[] =
1718 diff -ruN a/storage/innobase/handler/i_s.h b/storage/innobase/handler/i_s.h
1719 --- a/storage/innobase/handler/i_s.h 2010-12-03 15:37:45.540456499 +0900
1720 +++ b/storage/innobase/handler/i_s.h 2010-12-03 16:08:57.596941207 +0900
1722 extern struct st_mysql_plugin i_s_innodb_cmp_reset;
1723 extern struct st_mysql_plugin i_s_innodb_cmpmem;
1724 extern struct st_mysql_plugin i_s_innodb_cmpmem_reset;
1725 +extern struct st_mysql_plugin i_s_innodb_sys_tables;
1726 +extern struct st_mysql_plugin i_s_innodb_sys_tablestats;
1727 +extern struct st_mysql_plugin i_s_innodb_sys_indexes;
1728 +extern struct st_mysql_plugin i_s_innodb_sys_columns;
1729 +extern struct st_mysql_plugin i_s_innodb_sys_fields;
1730 +extern struct st_mysql_plugin i_s_innodb_sys_foreign;
1731 +extern struct st_mysql_plugin i_s_innodb_sys_foreign_cols;
1732 extern struct st_mysql_plugin i_s_innodb_rseg;