]> git.pld-linux.org Git - packages/mysql.git/blob - innodb_show_sys_tables.patch
- up to 5.5.17
[packages/mysql.git] / innodb_show_sys_tables.patch
1 # name       : innodb_show_sys_tables.patch
2 # introduced : 13?
3 # maintainer : Yasufumi
4 # (It is revived from mysql-5.5.6-rc)
5 #!!! notice !!!
6 # Any small change to this file in the main branch
7 # should be done or reviewed by the maintainer!
8 --- a/storage/innobase/dict/dict0load.c
9 +++ b/storage/innobase/dict/dict0load.c
10 @@ -442,7 +442,7 @@
11  
12  }
13  
14 -#ifdef FOREIGN_NOT_USED
15 +//#ifdef FOREIGN_NOT_USED
16  /********************************************************************//**
17  This function parses a SYS_FOREIGN record and populate a dict_foreign_t
18  structure with the information from the record. For detail information
19 @@ -518,9 +518,9 @@
20  
21         return(NULL);
22  }
23 -#endif  /* FOREIGN_NOT_USED */
24 +//#endif  /* FOREIGN_NOT_USED */
25  
26 -#ifdef FOREIGN_NOT_USED
27 +//#ifdef FOREIGN_NOT_USED
28  /********************************************************************//**
29  This function parses a SYS_FOREIGN_COLS record and extract necessary
30  information from the record and return to caller.
31 @@ -584,7 +584,7 @@
32  
33         return(NULL);
34  }
35 -#endif  /* FOREIGN_NOT_USED */
36 +//#endif  /* FOREIGN_NOT_USED */
37  
38  /********************************************************************//**
39  Determine the flags of a table described in SYS_TABLES.
40 --- a/storage/innobase/handler/ha_innodb.cc
41 +++ b/storage/innobase/handler/ha_innodb.cc
42 @@ -11899,7 +11899,14 @@
43  i_s_innodb_cmp,
44  i_s_innodb_cmp_reset,
45  i_s_innodb_cmpmem,
46 -i_s_innodb_cmpmem_reset
47 +i_s_innodb_cmpmem_reset,
48 +i_s_innodb_sys_tables,
49 +i_s_innodb_sys_tablestats,
50 +i_s_innodb_sys_indexes,
51 +i_s_innodb_sys_columns,
52 +i_s_innodb_sys_fields,
53 +i_s_innodb_sys_foreign,
54 +i_s_innodb_sys_foreign_cols
55  mysql_declare_plugin_end;
56  
57  /** @brief Initialize the default value of innodb_commit_concurrency.
58 --- a/storage/innobase/handler/i_s.cc
59 +++ b/storage/innobase/handler/i_s.cc
60 @@ -36,9 +36,11 @@
61  #include <mysql/innodb_priv.h>
62  
63  extern "C" {
64 +#include "btr0pcur.h"  /* for file sys_tables related info. */
65  #include "btr0types.h"
66  #include "buf0buddy.h" /* for i_s_cmpmem */
67  #include "buf0buf.h" /* for buf_pool and PAGE_ZIP_MIN_SIZE */
68 +#include "dict0load.h" /* for file sys_tables related info. */
69  #include "dict0mem.h"
70  #include "dict0types.h"
71  #include "ha_prototypes.h" /* for innobase_convert_name() */
72 @@ -1812,6 +1814,1675 @@
73         DBUG_RETURN(0);
74  }
75  
76 +/* Fields of the dynamic table INFORMATION_SCHEMA.SYS_TABLES */
77 +static ST_FIELD_INFO    innodb_sys_tables_fields_info[] =
78 +{
79 +#define SYS_TABLE_ID           0
80 +       {STRUCT_FLD(field_name,         "TABLE_ID"),
81 +        STRUCT_FLD(field_length,       MY_INT64_NUM_DECIMAL_DIGITS),
82 +        STRUCT_FLD(field_type,         MYSQL_TYPE_LONGLONG),
83 +        STRUCT_FLD(value,              0),
84 +        STRUCT_FLD(field_flags,        MY_I_S_UNSIGNED),
85 +        STRUCT_FLD(old_name,           ""),
86 +        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
87 +
88 +#define SYS_TABLE_SCHEMA       1
89 +       {STRUCT_FLD(field_name,         "SCHEMA"),
90 +        STRUCT_FLD(field_length,       NAME_LEN + 1),
91 +        STRUCT_FLD(field_type,         MYSQL_TYPE_STRING),
92 +        STRUCT_FLD(value,              0),
93 +        STRUCT_FLD(field_flags,        0),
94 +        STRUCT_FLD(old_name,           ""),
95 +        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
96 +
97 +#define SYS_TABLE_NAME         2
98 +       {STRUCT_FLD(field_name,         "NAME"),
99 +        STRUCT_FLD(field_length,       NAME_LEN + 1),
100 +        STRUCT_FLD(field_type,         MYSQL_TYPE_STRING),
101 +        STRUCT_FLD(value,              0),
102 +        STRUCT_FLD(field_flags,        0),
103 +        STRUCT_FLD(old_name,           ""),
104 +        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
105 +
106 +#define SYS_TABLE_FLAG         3
107 +       {STRUCT_FLD(field_name,         "FLAG"),
108 +        STRUCT_FLD(field_length,       MY_INT32_NUM_DECIMAL_DIGITS),
109 +        STRUCT_FLD(field_type,         MYSQL_TYPE_LONG),
110 +        STRUCT_FLD(value,              0),
111 +        STRUCT_FLD(field_flags,        0),
112 +        STRUCT_FLD(old_name,           ""),
113 +        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
114 +
115 +#define SYS_TABLE_NUM_COLUMN   4
116 +       {STRUCT_FLD(field_name,         "N_COLS"),
117 +        STRUCT_FLD(field_length,       MY_INT32_NUM_DECIMAL_DIGITS),
118 +        STRUCT_FLD(field_type,         MYSQL_TYPE_LONG),
119 +        STRUCT_FLD(value,              0),
120 +        STRUCT_FLD(field_flags,        0),
121 +        STRUCT_FLD(old_name,           ""),
122 +        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
123 +
124 +#define SYS_TABLE_SPACE                5
125 +       {STRUCT_FLD(field_name,         "SPACE"),
126 +        STRUCT_FLD(field_length,       MY_INT32_NUM_DECIMAL_DIGITS),
127 +        STRUCT_FLD(field_type,         MYSQL_TYPE_LONG),
128 +        STRUCT_FLD(value,              0),
129 +        STRUCT_FLD(field_flags,        0),
130 +        STRUCT_FLD(old_name,           ""),
131 +        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
132 +
133 +       END_OF_ST_FIELD_INFO
134 +};
135 +
136 +/**********************************************************************//**
137 +Populate information_schema.innodb_sys_tables table with information
138 +from SYS_TABLES.
139 +@return        0 on success */
140 +static
141 +int
142 +i_s_dict_fill_sys_tables(
143 +/*=====================*/
144 +       THD*            thd,            /*!< in: thread */
145 +       dict_table_t*   table,          /*!< in: table */
146 +       TABLE*          table_to_fill)  /*!< in/out: fill this table */
147 +{
148 +       Field**         fields;
149 +       char            buf[NAME_LEN * 2 + 2];
150 +       char*           ptr;
151 +
152 +       DBUG_ENTER("i_s_dict_fill_sys_tables");
153 +
154 +       fields = table_to_fill->field;
155 +
156 +       OK(fields[SYS_TABLE_ID]->store(longlong(table->id), TRUE));
157 +
158 +       strncpy(buf, table->name, NAME_LEN * 2 + 2);
159 +       ptr = strchr(buf, '/');
160 +       if (ptr) {
161 +               *ptr = '\0';
162 +               ++ptr;
163 +
164 +               OK(field_store_string(fields[SYS_TABLE_SCHEMA], buf));
165 +               OK(field_store_string(fields[SYS_TABLE_NAME], ptr));
166 +       } else {
167 +               fields[SYS_TABLE_SCHEMA]->set_null();
168 +               OK(field_store_string(fields[SYS_TABLE_NAME], buf));
169 +       }
170 +
171 +       OK(fields[SYS_TABLE_FLAG]->store(table->flags));
172 +
173 +       OK(fields[SYS_TABLE_NUM_COLUMN]->store(table->n_cols));
174 +
175 +       OK(fields[SYS_TABLE_SPACE]->store(table->space));
176 +
177 +       OK(schema_table_store_record(thd, table_to_fill));
178 +
179 +       DBUG_RETURN(0);
180 +}
181 +/*******************************************************************//**
182 +Function to go through each record in SYS_TABLES table, and fill the
183 +information_schema.innodb_sys_tables table with related table information
184 +@return 0 on success */
185 +static
186 +int
187 +i_s_sys_tables_fill_table(
188 +/*======================*/
189 +       THD*            thd,    /*!< in: thread */
190 +       TABLE_LIST*     tables, /*!< in/out: tables to fill */
191 +       COND*           cond)   /*!< in: condition (not used) */
192 +{
193 +        btr_pcur_t     pcur;
194 +       const rec_t*    rec;
195 +       mem_heap_t*     heap;
196 +       mtr_t           mtr;
197 +
198 +       DBUG_ENTER("i_s_sys_tables_fill_table");
199 +
200 +       /* deny access to non-superusers */
201 +       if (check_global_access(thd, PROCESS_ACL)) {
202 +
203 +                DBUG_RETURN(0);
204 +       }
205 +
206 +        heap = mem_heap_create(1000);
207 +        mutex_enter(&(dict_sys->mutex));
208 +        mtr_start(&mtr);
209 +
210 +       rec = dict_startscan_system(&pcur, &mtr, SYS_TABLES);
211 +
212 +       while (rec) {
213 +               const char*     err_msg;
214 +               dict_table_t*   table_rec;
215 +
216 +               /* Create and populate a dict_table_t structure with
217 +               information from SYS_TABLES row */
218 +               err_msg = dict_process_sys_tables_rec(
219 +                       heap, rec, &table_rec, DICT_TABLE_LOAD_FROM_RECORD);
220 +
221 +               mtr_commit(&mtr);
222 +               mutex_exit(&dict_sys->mutex);
223 +
224 +               if (!err_msg) {
225 +                       i_s_dict_fill_sys_tables(thd, table_rec, tables->table);
226 +               } else {
227 +                       push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
228 +                                           ER_CANT_FIND_SYSTEM_REC,
229 +                                           err_msg);
230 +               }
231 +
232 +               /* Since dict_process_sys_tables_rec() is called with
233 +               DICT_TABLE_LOAD_FROM_RECORD, the table_rec is created in
234 +               dict_process_sys_tables_rec(), we will need to free it */
235 +               if (table_rec) {
236 +                       dict_mem_table_free(table_rec);
237 +               }
238 +
239 +               mem_heap_empty(heap);
240 +
241 +               /* Get the next record */
242 +               mutex_enter(&dict_sys->mutex);
243 +               mtr_start(&mtr);
244 +               rec = dict_getnext_system(&pcur, &mtr);
245 +       }
246 +
247 +       mtr_commit(&mtr);
248 +       mutex_exit(&dict_sys->mutex);
249 +       mem_heap_free(heap);
250 +
251 +       DBUG_RETURN(0);
252 +}
253 +
254 +/*******************************************************************//**
255 +Bind the dynamic table INFORMATION_SCHEMA.innodb_sys_tables
256 +@return 0 on success */
257 +static
258 +int
259 +innodb_sys_tables_init(
260 +/*===================*/
261 +        void*   p)      /*!< in/out: table schema object */
262 +{
263 +        ST_SCHEMA_TABLE*        schema;
264 +
265 +        DBUG_ENTER("innodb_sys_tables_init");
266 +
267 +        schema = (ST_SCHEMA_TABLE*) p;
268 +
269 +        schema->fields_info = innodb_sys_tables_fields_info;
270 +        schema->fill_table = i_s_sys_tables_fill_table;
271 +
272 +        DBUG_RETURN(0);
273 +}
274 +
275 +UNIV_INTERN struct st_mysql_plugin     i_s_innodb_sys_tables =
276 +{
277 +       /* the plugin type (a MYSQL_XXX_PLUGIN value) */
278 +       /* int */
279 +       STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
280 +
281 +       /* pointer to type-specific plugin descriptor */
282 +       /* void* */
283 +       STRUCT_FLD(info, &i_s_info),
284 +
285 +       /* plugin name */
286 +       /* const char* */
287 +       STRUCT_FLD(name, "INNODB_SYS_TABLES"),
288 +
289 +       /* plugin author (for SHOW PLUGINS) */
290 +       /* const char* */
291 +       STRUCT_FLD(author, "Percona"),
292 +
293 +       /* general descriptive text (for SHOW PLUGINS) */
294 +       /* const char* */
295 +       STRUCT_FLD(descr, "InnoDB SYS_TABLES"),
296 +
297 +       /* the plugin license (PLUGIN_LICENSE_XXX) */
298 +       /* int */
299 +       STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
300 +
301 +       /* the function to invoke when plugin is loaded */
302 +       /* int (*)(void*); */
303 +       STRUCT_FLD(init, innodb_sys_tables_init),
304 +
305 +       /* the function to invoke when plugin is unloaded */
306 +       /* int (*)(void*); */
307 +       STRUCT_FLD(deinit, i_s_common_deinit),
308 +
309 +       /* plugin version (for SHOW PLUGINS) */
310 +       /* unsigned int */
311 +       STRUCT_FLD(version, INNODB_VERSION_SHORT),
312 +
313 +       /* struct st_mysql_show_var* */
314 +       STRUCT_FLD(status_vars, NULL),
315 +
316 +       /* struct st_mysql_sys_var** */
317 +       STRUCT_FLD(system_vars, NULL),
318 +
319 +       /* reserved for dependency checking */
320 +       /* void* */
321 +       STRUCT_FLD(__reserved1, NULL)
322 +};
323 +
324 +/* Fields of the dynamic table INFORMATION_SCHEMA.SYS_TABLESTATS */
325 +static ST_FIELD_INFO    innodb_sys_tablestats_fields_info[] =
326 +{
327 +#define SYS_TABLESTATS_ID              0
328 +       {STRUCT_FLD(field_name,         "TABLE_ID"),
329 +        STRUCT_FLD(field_length,       MY_INT64_NUM_DECIMAL_DIGITS),
330 +        STRUCT_FLD(field_type,         MYSQL_TYPE_LONGLONG),
331 +        STRUCT_FLD(value,              0),
332 +        STRUCT_FLD(field_flags,        MY_I_S_UNSIGNED),
333 +        STRUCT_FLD(old_name,           ""),
334 +        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
335 +
336 +#define SYS_TABLESTATS_SCHEMA          1
337 +       {STRUCT_FLD(field_name,         "SCHEMA"),
338 +        STRUCT_FLD(field_length,       NAME_LEN + 1),
339 +        STRUCT_FLD(field_type,         MYSQL_TYPE_STRING),
340 +        STRUCT_FLD(value,              0),
341 +        STRUCT_FLD(field_flags,        0),
342 +        STRUCT_FLD(old_name,           ""),
343 +        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
344 +
345 +#define SYS_TABLESTATS_NAME            2
346 +       {STRUCT_FLD(field_name,         "NAME"),
347 +        STRUCT_FLD(field_length,       NAME_LEN + 1),
348 +        STRUCT_FLD(field_type,         MYSQL_TYPE_STRING),
349 +        STRUCT_FLD(value,              0),
350 +        STRUCT_FLD(field_flags,        0),
351 +        STRUCT_FLD(old_name,           ""),
352 +        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
353 +
354 +#define SYS_TABLESTATS_INIT            3
355 +       {STRUCT_FLD(field_name,         "STATS_INITIALIZED"),
356 +        STRUCT_FLD(field_length,       NAME_LEN + 1),
357 +        STRUCT_FLD(field_type,         MYSQL_TYPE_STRING),
358 +        STRUCT_FLD(value,              0),
359 +        STRUCT_FLD(field_flags,        0),
360 +        STRUCT_FLD(old_name,           ""),
361 +        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
362 +
363 +#define SYS_TABLESTATS_NROW            4
364 +       {STRUCT_FLD(field_name,         "NUM_ROWS"),
365 +        STRUCT_FLD(field_length,       MY_INT64_NUM_DECIMAL_DIGITS),
366 +        STRUCT_FLD(field_type,         MYSQL_TYPE_LONGLONG),
367 +        STRUCT_FLD(value,              0),
368 +        STRUCT_FLD(field_flags,        MY_I_S_UNSIGNED),
369 +        STRUCT_FLD(old_name,           ""),
370 +        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
371 +
372 +#define SYS_TABLESTATS_CLUST_SIZE      5
373 +       {STRUCT_FLD(field_name,         "CLUST_INDEX_SIZE"),
374 +        STRUCT_FLD(field_length,       MY_INT64_NUM_DECIMAL_DIGITS),
375 +        STRUCT_FLD(field_type,         MYSQL_TYPE_LONGLONG),
376 +        STRUCT_FLD(value,              0),
377 +        STRUCT_FLD(field_flags,        MY_I_S_UNSIGNED),
378 +        STRUCT_FLD(old_name,           ""),
379 +        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
380 +
381 +#define SYS_TABLESTATS_INDEX_SIZE      6
382 +       {STRUCT_FLD(field_name,         "OTHER_INDEX_SIZE"),
383 +        STRUCT_FLD(field_length,       MY_INT64_NUM_DECIMAL_DIGITS),
384 +        STRUCT_FLD(field_type,         MYSQL_TYPE_LONGLONG),
385 +        STRUCT_FLD(value,              0),
386 +        STRUCT_FLD(field_flags,        MY_I_S_UNSIGNED),
387 +        STRUCT_FLD(old_name,           ""),
388 +        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
389 +
390 +#define SYS_TABLESTATS_MODIFIED                7
391 +       {STRUCT_FLD(field_name,         "MODIFIED_COUNTER"),
392 +        STRUCT_FLD(field_length,       MY_INT64_NUM_DECIMAL_DIGITS),
393 +        STRUCT_FLD(field_type,         MYSQL_TYPE_LONGLONG),
394 +        STRUCT_FLD(value,              0),
395 +        STRUCT_FLD(field_flags,        MY_I_S_UNSIGNED),
396 +        STRUCT_FLD(old_name,           ""),
397 +        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
398 +
399 +#define SYS_TABLESTATS_AUTONINC                8
400 +       {STRUCT_FLD(field_name,         "AUTOINC"),
401 +        STRUCT_FLD(field_length,       MY_INT64_NUM_DECIMAL_DIGITS),
402 +        STRUCT_FLD(field_type,         MYSQL_TYPE_LONGLONG),
403 +        STRUCT_FLD(value,              0),
404 +        STRUCT_FLD(field_flags,        MY_I_S_UNSIGNED),
405 +        STRUCT_FLD(old_name,           ""),
406 +        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
407 +
408 +#define SYS_TABLESTATS_MYSQL_OPEN_HANDLE       9
409 +       {STRUCT_FLD(field_name,         "MYSQL_HANDLES_OPENED"),
410 +        STRUCT_FLD(field_length,       MY_INT32_NUM_DECIMAL_DIGITS),
411 +        STRUCT_FLD(field_type,         MYSQL_TYPE_LONG),
412 +        STRUCT_FLD(value,              0),
413 +        STRUCT_FLD(field_flags,        0),
414 +        STRUCT_FLD(old_name,           ""),
415 +        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
416 +
417 +       END_OF_ST_FIELD_INFO
418 +};
419 +
420 +/**********************************************************************//**
421 +Populate information_schema.innodb_sys_tablestats table with information
422 +from SYS_TABLES.
423 +@return        0 on success */
424 +static
425 +int
426 +i_s_dict_fill_sys_tablestats(
427 +/*=========================*/
428 +       THD*            thd,            /*!< in: thread */
429 +       dict_table_t*   table,          /*!< in: table */
430 +       TABLE*          table_to_fill)  /*!< in/out: fill this table */
431 +{
432 +       Field**         fields;
433 +       char            buf[NAME_LEN * 2 + 2];
434 +       char*           ptr;
435 +
436 +       DBUG_ENTER("i_s_dict_fill_sys_tablestats");
437 +
438 +       fields = table_to_fill->field;
439 +
440 +       OK(fields[SYS_TABLESTATS_ID]->store(longlong(table->id), TRUE));
441 +
442 +       strncpy(buf, table->name, NAME_LEN * 2 + 2);
443 +       ptr = strchr(buf, '/');
444 +       if (ptr) {
445 +               *ptr = '\0';
446 +               ++ptr;
447 +
448 +               OK(field_store_string(fields[SYS_TABLESTATS_SCHEMA], buf));
449 +               OK(field_store_string(fields[SYS_TABLESTATS_NAME], ptr));
450 +       } else {
451 +               fields[SYS_TABLESTATS_SCHEMA]->set_null();
452 +               OK(field_store_string(fields[SYS_TABLESTATS_NAME], buf));
453 +       }
454 +
455 +       if (table->stat_initialized) {
456 +               OK(field_store_string(fields[SYS_TABLESTATS_INIT],
457 +                                     "Initialized"));
458 +       } else {
459 +               OK(field_store_string(fields[SYS_TABLESTATS_INIT],
460 +                                     "Uninitialized"));
461 +       }
462 +
463 +       OK(fields[SYS_TABLESTATS_NROW]->store(table->stat_n_rows, TRUE));
464 +
465 +       OK(fields[SYS_TABLESTATS_CLUST_SIZE]->store(
466 +               table->stat_clustered_index_size));
467 +
468 +       OK(fields[SYS_TABLESTATS_INDEX_SIZE]->store(
469 +               table->stat_sum_of_other_index_sizes));
470 +
471 +       OK(fields[SYS_TABLESTATS_MODIFIED]->store(
472 +               table->stat_modified_counter));
473 +
474 +       OK(fields[SYS_TABLESTATS_AUTONINC]->store(table->autoinc, TRUE));
475 +
476 +       OK(fields[SYS_TABLESTATS_MYSQL_OPEN_HANDLE]->store(
477 +               table->n_mysql_handles_opened));
478 +
479 +       OK(schema_table_store_record(thd, table_to_fill));
480 +
481 +       DBUG_RETURN(0);
482 +}
483 +/*******************************************************************//**
484 +Function to go through each record in SYS_TABLES table, and fill the
485 +information_schema.innodb_sys_tablestats table with table statistics
486 +related information
487 +@return 0 on success */
488 +static
489 +int
490 +i_s_sys_tables_fill_table_stats(
491 +/*============================*/
492 +       THD*            thd,    /*!< in: thread */
493 +       TABLE_LIST*     tables, /*!< in/out: tables to fill */
494 +       COND*           cond)   /*!< in: condition (not used) */
495 +{
496 +        btr_pcur_t     pcur;
497 +       const rec_t*    rec;
498 +       mem_heap_t*     heap;
499 +       mtr_t           mtr;
500 +
501 +       DBUG_ENTER("i_s_sys_tables_fill_table_stats");
502 +
503 +       /* deny access to non-superusers */
504 +       if (check_global_access(thd, PROCESS_ACL)) {
505 +
506 +                DBUG_RETURN(0);
507 +       }
508 +
509 +        heap = mem_heap_create(1000);
510 +        mutex_enter(&dict_sys->mutex);
511 +        mtr_start(&mtr);
512 +
513 +       rec = dict_startscan_system(&pcur, &mtr, SYS_TABLES);
514 +
515 +       while (rec) {
516 +               const char*     err_msg;
517 +               dict_table_t*   table_rec;
518 +
519 +               /* Fetch the dict_table_t structure corresponding to
520 +               this SYS_TABLES record */
521 +               err_msg = dict_process_sys_tables_rec(
522 +                       heap, rec, &table_rec, DICT_TABLE_LOAD_FROM_CACHE);
523 +
524 +               mtr_commit(&mtr);
525 +               mutex_exit(&dict_sys->mutex);
526 +
527 +               if (!err_msg) {
528 +                       i_s_dict_fill_sys_tablestats(thd, table_rec,
529 +                                                    tables->table);
530 +               } else {
531 +                       push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
532 +                                           ER_CANT_FIND_SYSTEM_REC,
533 +                                           err_msg);
534 +               }
535 +
536 +               mem_heap_empty(heap);
537 +
538 +               /* Get the next record */
539 +               mutex_enter(&dict_sys->mutex);
540 +               mtr_start(&mtr);
541 +               rec = dict_getnext_system(&pcur, &mtr);
542 +       }
543 +
544 +       mtr_commit(&mtr);
545 +       mutex_exit(&dict_sys->mutex);
546 +       mem_heap_free(heap);
547 +
548 +       DBUG_RETURN(0);
549 +}
550 +
551 +/*******************************************************************//**
552 +Bind the dynamic table INFORMATION_SCHEMA.innodb_sys_tablestats
553 +@return 0 on success */
554 +static
555 +int
556 +innodb_sys_tablestats_init(
557 +/*=======================*/
558 +        void*   p)      /*!< in/out: table schema object */
559 +{
560 +        ST_SCHEMA_TABLE*        schema;
561 +
562 +        DBUG_ENTER("innodb_sys_tablestats_init");
563 +
564 +        schema = (ST_SCHEMA_TABLE*) p;
565 +
566 +        schema->fields_info = innodb_sys_tablestats_fields_info;
567 +        schema->fill_table = i_s_sys_tables_fill_table_stats;
568 +
569 +        DBUG_RETURN(0);
570 +}
571 +
572 +UNIV_INTERN struct st_mysql_plugin     i_s_innodb_sys_tablestats =
573 +{
574 +       /* the plugin type (a MYSQL_XXX_PLUGIN value) */
575 +       /* int */
576 +       STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
577 +
578 +       /* pointer to type-specific plugin descriptor */
579 +       /* void* */
580 +       STRUCT_FLD(info, &i_s_info),
581 +
582 +       /* plugin name */
583 +       /* const char* */
584 +       STRUCT_FLD(name, "INNODB_SYS_TABLESTATS"),
585 +
586 +       /* plugin author (for SHOW PLUGINS) */
587 +       /* const char* */
588 +       STRUCT_FLD(author, "Percona"),
589 +
590 +       /* general descriptive text (for SHOW PLUGINS) */
591 +       /* const char* */
592 +       STRUCT_FLD(descr, "InnoDB SYS_TABLESTATS"),
593 +
594 +       /* the plugin license (PLUGIN_LICENSE_XXX) */
595 +       /* int */
596 +       STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
597 +
598 +       /* the function to invoke when plugin is loaded */
599 +       /* int (*)(void*); */
600 +       STRUCT_FLD(init, innodb_sys_tablestats_init),
601 +
602 +       /* the function to invoke when plugin is unloaded */
603 +       /* int (*)(void*); */
604 +       STRUCT_FLD(deinit, i_s_common_deinit),
605 +
606 +       /* plugin version (for SHOW PLUGINS) */
607 +       /* unsigned int */
608 +       STRUCT_FLD(version, INNODB_VERSION_SHORT),
609 +
610 +       /* struct st_mysql_show_var* */
611 +       STRUCT_FLD(status_vars, NULL),
612 +
613 +       /* struct st_mysql_sys_var** */
614 +       STRUCT_FLD(system_vars, NULL),
615 +
616 +       /* reserved for dependency checking */
617 +       /* void* */
618 +       STRUCT_FLD(__reserved1, NULL)
619 +};
620 +
621 +/* Fields of the dynamic table INFORMATION_SCHEMA.SYS_INDEXES */
622 +static ST_FIELD_INFO    innodb_sysindex_fields_info[] =
623 +{
624 +#define SYS_INDEX_ID           0
625 +       {STRUCT_FLD(field_name,         "INDEX_ID"),
626 +        STRUCT_FLD(field_length,       MY_INT64_NUM_DECIMAL_DIGITS),
627 +        STRUCT_FLD(field_type,         MYSQL_TYPE_LONGLONG),
628 +        STRUCT_FLD(value,              0),
629 +        STRUCT_FLD(field_flags,        MY_I_S_UNSIGNED),
630 +        STRUCT_FLD(old_name,           ""),
631 +        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
632 +
633 +#define SYS_INDEX_NAME         1
634 +       {STRUCT_FLD(field_name,         "NAME"),
635 +        STRUCT_FLD(field_length,       NAME_LEN + 1),
636 +        STRUCT_FLD(field_type,         MYSQL_TYPE_STRING),
637 +        STRUCT_FLD(value,              0),
638 +        STRUCT_FLD(field_flags,        0),
639 +        STRUCT_FLD(old_name,           ""),
640 +        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
641 +
642 +#define SYS_INDEX_TABLE_ID     2
643 +       {STRUCT_FLD(field_name,         "TABLE_ID"),
644 +        STRUCT_FLD(field_length,       MY_INT64_NUM_DECIMAL_DIGITS),
645 +        STRUCT_FLD(field_type,         MYSQL_TYPE_LONGLONG),
646 +        STRUCT_FLD(value,              0),
647 +        STRUCT_FLD(field_flags,        MY_I_S_UNSIGNED),
648 +        STRUCT_FLD(old_name,           ""),
649 +        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
650 +
651 +#define SYS_INDEX_TYPE         3
652 +       {STRUCT_FLD(field_name,         "TYPE"),
653 +        STRUCT_FLD(field_length,       MY_INT32_NUM_DECIMAL_DIGITS),
654 +        STRUCT_FLD(field_type,         MYSQL_TYPE_LONG),
655 +        STRUCT_FLD(value,              0),
656 +        STRUCT_FLD(field_flags,        0),
657 +        STRUCT_FLD(old_name,           ""),
658 +        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
659 +
660 +#define SYS_INDEX_NUM_FIELDS   4
661 +       {STRUCT_FLD(field_name,         "N_FIELDS"),
662 +        STRUCT_FLD(field_length,       MY_INT32_NUM_DECIMAL_DIGITS),
663 +        STRUCT_FLD(field_type,         MYSQL_TYPE_LONG),
664 +        STRUCT_FLD(value,              0),
665 +        STRUCT_FLD(field_flags,        0),
666 +        STRUCT_FLD(old_name,           ""),
667 +        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
668 +
669 +#define SYS_INDEX_PAGE_NO      5
670 +       {STRUCT_FLD(field_name,         "PAGE_NO"),
671 +        STRUCT_FLD(field_length,       MY_INT32_NUM_DECIMAL_DIGITS),
672 +        STRUCT_FLD(field_type,         MYSQL_TYPE_LONG),
673 +        STRUCT_FLD(value,              0),
674 +        STRUCT_FLD(field_flags,        0),
675 +        STRUCT_FLD(old_name,           ""),
676 +        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
677 +
678 +#define SYS_INDEX_SPACE                6
679 +       {STRUCT_FLD(field_name,         "SPACE"),
680 +        STRUCT_FLD(field_length,       MY_INT32_NUM_DECIMAL_DIGITS),
681 +        STRUCT_FLD(field_type,         MYSQL_TYPE_LONG),
682 +        STRUCT_FLD(value,              0),
683 +        STRUCT_FLD(field_flags,        0),
684 +        STRUCT_FLD(old_name,           ""),
685 +        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
686 +
687 +       END_OF_ST_FIELD_INFO
688 +};
689 +
690 +/**********************************************************************//**
691 +Function to populate the information_schema.innodb_sys_indexes table with
692 +collected index information
693 +@return 0 on success */
694 +static
695 +int
696 +i_s_dict_fill_sys_indexes(
697 +/*======================*/
698 +       THD*            thd,            /*!< in: thread */
699 +       table_id_t      table_id,       /*!< in: table id */
700 +       dict_index_t*   index,          /*!< in: populated dict_index_t
701 +                                       struct with index info */
702 +       TABLE*          table_to_fill)  /*!< in/out: fill this table */
703 +{
704 +       Field**         fields;
705 +
706 +       DBUG_ENTER("i_s_dict_fill_sys_indexes");
707 +
708 +       fields = table_to_fill->field;
709 +
710 +       OK(fields[SYS_INDEX_ID]->store(longlong(index->id), TRUE));
711 +
712 +       OK(field_store_string(fields[SYS_INDEX_NAME], index->name));
713 +
714 +       OK(fields[SYS_INDEX_TABLE_ID]->store(longlong(table_id), TRUE));
715 +
716 +       OK(fields[SYS_INDEX_TYPE]->store(index->type));
717 +
718 +       OK(fields[SYS_INDEX_NUM_FIELDS]->store(index->n_fields));
719 +
720 +       OK(fields[SYS_INDEX_PAGE_NO]->store(index->page));
721 +
722 +       OK(fields[SYS_INDEX_SPACE]->store(index->space));
723 +
724 +       OK(schema_table_store_record(thd, table_to_fill));
725 +
726 +       DBUG_RETURN(0);
727 +}
728 +/*******************************************************************//**
729 +Function to go through each record in SYS_INDEXES table, and fill the
730 +information_schema.innodb_sys_indexes table with related index information
731 +@return 0 on success */
732 +static
733 +int
734 +i_s_sys_indexes_fill_table(
735 +/*=======================*/
736 +       THD*            thd,    /*!< in: thread */
737 +       TABLE_LIST*     tables, /*!< in/out: tables to fill */
738 +       COND*           cond)   /*!< in: condition (not used) */
739 +{
740 +        btr_pcur_t             pcur;
741 +       const rec_t*            rec;
742 +       mem_heap_t*             heap;
743 +       mtr_t                   mtr;
744 +
745 +       DBUG_ENTER("i_s_sys_indexes_fill_table");
746 +
747 +       /* deny access to non-superusers */
748 +       if (check_global_access(thd, PROCESS_ACL)) {
749 +
750 +                DBUG_RETURN(0);
751 +       }
752 +
753 +        heap = mem_heap_create(1000);
754 +        mutex_enter(&dict_sys->mutex);
755 +        mtr_start(&mtr);
756 +
757 +       /* Start scan the SYS_INDEXES table */
758 +       rec = dict_startscan_system(&pcur, &mtr, SYS_INDEXES);
759 +
760 +       /* Process each record in the table */
761 +       while (rec) {
762 +               const char*     err_msg;;
763 +               table_id_t      table_id;
764 +               dict_index_t    index_rec;
765 +
766 +               /* Populate a dict_index_t structure with information from
767 +               a SYS_INDEXES row */
768 +               err_msg = dict_process_sys_indexes_rec(heap, rec, &index_rec,
769 +                                                      &table_id);
770 +
771 +               mtr_commit(&mtr);
772 +               mutex_exit(&dict_sys->mutex);
773 +
774 +               if (!err_msg) {
775 +                       i_s_dict_fill_sys_indexes(thd, table_id, &index_rec,
776 +                                                tables->table);
777 +               } else {
778 +                       push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
779 +                                           ER_CANT_FIND_SYSTEM_REC,
780 +                                           err_msg);
781 +               }
782 +
783 +               mem_heap_empty(heap);
784 +
785 +               /* Get the next record */
786 +               mutex_enter(&dict_sys->mutex);
787 +               mtr_start(&mtr);
788 +               rec = dict_getnext_system(&pcur, &mtr);
789 +       }
790 +
791 +       mtr_commit(&mtr);
792 +       mutex_exit(&dict_sys->mutex);
793 +       mem_heap_free(heap);
794 +
795 +       DBUG_RETURN(0);
796 +}
797 +/*******************************************************************//**
798 +Bind the dynamic table INFORMATION_SCHEMA.innodb_sys_indexes
799 +@return 0 on success */
800 +static
801 +int
802 +innodb_sys_indexes_init(
803 +/*====================*/
804 +        void*   p)      /*!< in/out: table schema object */
805 +{
806 +        ST_SCHEMA_TABLE*        schema;
807 +
808 +        DBUG_ENTER("innodb_sys_index_init");
809 +
810 +        schema = (ST_SCHEMA_TABLE*) p;
811 +
812 +        schema->fields_info = innodb_sysindex_fields_info;
813 +        schema->fill_table = i_s_sys_indexes_fill_table;
814 +
815 +        DBUG_RETURN(0);
816 +}
817 +
818 +UNIV_INTERN struct st_mysql_plugin     i_s_innodb_sys_indexes =
819 +{
820 +       /* the plugin type (a MYSQL_XXX_PLUGIN value) */
821 +       /* int */
822 +       STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
823 +
824 +       /* pointer to type-specific plugin descriptor */
825 +       /* void* */
826 +       STRUCT_FLD(info, &i_s_info),
827 +
828 +       /* plugin name */
829 +       /* const char* */
830 +       STRUCT_FLD(name, "INNODB_SYS_INDEXES"),
831 +
832 +       /* plugin author (for SHOW PLUGINS) */
833 +       /* const char* */
834 +       STRUCT_FLD(author, "Percona"),
835 +
836 +       /* general descriptive text (for SHOW PLUGINS) */
837 +       /* const char* */
838 +       STRUCT_FLD(descr, "InnoDB SYS_INDEXES"),
839 +
840 +       /* the plugin license (PLUGIN_LICENSE_XXX) */
841 +       /* int */
842 +       STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
843 +
844 +       /* the function to invoke when plugin is loaded */
845 +       /* int (*)(void*); */
846 +       STRUCT_FLD(init, innodb_sys_indexes_init),
847 +
848 +       /* the function to invoke when plugin is unloaded */
849 +       /* int (*)(void*); */
850 +       STRUCT_FLD(deinit, i_s_common_deinit),
851 +
852 +       /* plugin version (for SHOW PLUGINS) */
853 +       /* unsigned int */
854 +       STRUCT_FLD(version, INNODB_VERSION_SHORT),
855 +
856 +       /* struct st_mysql_show_var* */
857 +       STRUCT_FLD(status_vars, NULL),
858 +
859 +       /* struct st_mysql_sys_var** */
860 +       STRUCT_FLD(system_vars, NULL),
861 +
862 +       /* reserved for dependency checking */
863 +       /* void* */
864 +       STRUCT_FLD(__reserved1, NULL)
865 +};
866 +
867 +/* Fields of the dynamic table INFORMATION_SCHEMA.SYS_COLUMNS */
868 +static ST_FIELD_INFO    innodb_sys_columns_fields_info[] =
869 +{
870 +#define SYS_COLUMN_TABLE_ID            0
871 +       {STRUCT_FLD(field_name,         "TABLE_ID"),
872 +        STRUCT_FLD(field_length,       MY_INT64_NUM_DECIMAL_DIGITS),
873 +        STRUCT_FLD(field_type,         MYSQL_TYPE_LONGLONG),
874 +        STRUCT_FLD(value,              0),
875 +        STRUCT_FLD(field_flags,        MY_I_S_UNSIGNED),
876 +        STRUCT_FLD(old_name,           ""),
877 +        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
878 +
879 +#define SYS_COLUMN_NAME                1
880 +       {STRUCT_FLD(field_name,         "NAME"),
881 +        STRUCT_FLD(field_length,       NAME_LEN + 1),
882 +        STRUCT_FLD(field_type,         MYSQL_TYPE_STRING),
883 +        STRUCT_FLD(value,              0),
884 +        STRUCT_FLD(field_flags,        0),
885 +        STRUCT_FLD(old_name,           ""),
886 +        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
887 +
888 +#define SYS_COLUMN_POSITION    2
889 +       {STRUCT_FLD(field_name,         "POS"),
890 +        STRUCT_FLD(field_length,       MY_INT64_NUM_DECIMAL_DIGITS),
891 +        STRUCT_FLD(field_type,         MYSQL_TYPE_LONGLONG),
892 +        STRUCT_FLD(value,              0),
893 +        STRUCT_FLD(field_flags,        MY_I_S_UNSIGNED),
894 +        STRUCT_FLD(old_name,           ""),
895 +        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
896 +
897 +#define SYS_COLUMN_MTYPE               3
898 +       {STRUCT_FLD(field_name,         "MTYPE"),
899 +        STRUCT_FLD(field_length,       MY_INT32_NUM_DECIMAL_DIGITS),
900 +        STRUCT_FLD(field_type,         MYSQL_TYPE_LONG),
901 +        STRUCT_FLD(value,              0),
902 +        STRUCT_FLD(field_flags,        0),
903 +        STRUCT_FLD(old_name,           ""),
904 +        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
905 +
906 +#define SYS_COLUMN__PRTYPE     4
907 +       {STRUCT_FLD(field_name,         "PRTYPE"),
908 +        STRUCT_FLD(field_length,       MY_INT32_NUM_DECIMAL_DIGITS),
909 +        STRUCT_FLD(field_type,         MYSQL_TYPE_LONG),
910 +        STRUCT_FLD(value,              0),
911 +        STRUCT_FLD(field_flags,        0),
912 +        STRUCT_FLD(old_name,           ""),
913 +        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
914 +
915 +#define SYS_COLUMN_COLUMN_LEN  5
916 +       {STRUCT_FLD(field_name,         "LEN"),
917 +        STRUCT_FLD(field_length,       MY_INT32_NUM_DECIMAL_DIGITS),
918 +        STRUCT_FLD(field_type,         MYSQL_TYPE_LONG),
919 +        STRUCT_FLD(value,              0),
920 +        STRUCT_FLD(field_flags,        0),
921 +        STRUCT_FLD(old_name,           ""),
922 +        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
923 +
924 +       END_OF_ST_FIELD_INFO
925 +};
926 +
927 +/**********************************************************************//**
928 +Function to populate the information_schema.innodb_sys_columns with
929 +related column information
930 +@return 0 on success */
931 +static
932 +int
933 +i_s_dict_fill_sys_columns(
934 +/*======================*/
935 +       THD*            thd,            /*!< in: thread */
936 +       table_id_t      table_id,       /*!< in: table ID */
937 +       const char*     col_name,       /*!< in: column name */
938 +       dict_col_t*     column,         /*!< in: dict_col_t struct holding
939 +                                       more column information */
940 +       TABLE*          table_to_fill)  /*!< in/out: fill this table */
941 +{
942 +       Field**         fields;
943 +
944 +       DBUG_ENTER("i_s_dict_fill_sys_columns");
945 +
946 +       fields = table_to_fill->field;
947 +
948 +       OK(fields[SYS_COLUMN_TABLE_ID]->store(longlong(table_id), TRUE));
949 +
950 +       OK(field_store_string(fields[SYS_COLUMN_NAME], col_name));
951 +
952 +       OK(fields[SYS_COLUMN_POSITION]->store(column->ind));
953 +
954 +       OK(fields[SYS_COLUMN_MTYPE]->store(column->mtype));
955 +
956 +       OK(fields[SYS_COLUMN__PRTYPE]->store(column->prtype));
957 +
958 +       OK(fields[SYS_COLUMN_COLUMN_LEN]->store(column->len));
959 +
960 +       OK(schema_table_store_record(thd, table_to_fill));
961 +
962 +       DBUG_RETURN(0);
963 +}
964 +/*******************************************************************//**
965 +Function to fill information_schema.innodb_sys_columns with information
966 +collected by scanning SYS_COLUMNS table.
967 +@return 0 on success */
968 +static
969 +int
970 +i_s_sys_columns_fill_table(
971 +/*=======================*/
972 +       THD*            thd,    /*!< in: thread */
973 +       TABLE_LIST*     tables, /*!< in/out: tables to fill */
974 +       COND*           cond)   /*!< in: condition (not used) */
975 +{
976 +        btr_pcur_t     pcur;
977 +       const rec_t*    rec;
978 +       const char*     col_name;
979 +       mem_heap_t*     heap;
980 +       mtr_t           mtr;
981 +
982 +       DBUG_ENTER("i_s_sys_columns_fill_table");
983 +
984 +       /* deny access to non-superusers */
985 +       if (check_global_access(thd, PROCESS_ACL)) {
986 +
987 +                DBUG_RETURN(0);
988 +       }
989 +
990 +        heap = mem_heap_create(1000);
991 +        mutex_enter(&dict_sys->mutex);
992 +        mtr_start(&mtr);
993 +
994 +       rec = dict_startscan_system(&pcur, &mtr, SYS_COLUMNS);
995 +
996 +       while (rec) {
997 +               const char*     err_msg;
998 +               dict_col_t      column_rec;
999 +               table_id_t      table_id;
1000 +
1001 +               /* populate a dict_col_t structure with information from
1002 +               a SYS_COLUMNS row */
1003 +               err_msg = dict_process_sys_columns_rec(heap, rec, &column_rec,
1004 +                                                      &table_id, &col_name);
1005 +
1006 +               mtr_commit(&mtr);
1007 +               mutex_exit(&dict_sys->mutex);
1008 +
1009 +               if (!err_msg) {
1010 +                       i_s_dict_fill_sys_columns(thd, table_id, col_name,
1011 +                                                &column_rec,
1012 +                                                tables->table);
1013 +               } else {
1014 +                       push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
1015 +                                           ER_CANT_FIND_SYSTEM_REC,
1016 +                                           err_msg);
1017 +               }
1018 +
1019 +               mem_heap_empty(heap);
1020 +
1021 +               /* Get the next record */
1022 +               mutex_enter(&dict_sys->mutex);
1023 +               mtr_start(&mtr);
1024 +               rec = dict_getnext_system(&pcur, &mtr);
1025 +       }
1026 +
1027 +       mtr_commit(&mtr);
1028 +       mutex_exit(&dict_sys->mutex);
1029 +       mem_heap_free(heap);
1030 +
1031 +       DBUG_RETURN(0);
1032 +}
1033 +/*******************************************************************//**
1034 +Bind the dynamic table INFORMATION_SCHEMA.innodb_sys_columns
1035 +@return 0 on success */
1036 +static
1037 +int
1038 +innodb_sys_columns_init(
1039 +/*====================*/
1040 +        void*   p)      /*!< in/out: table schema object */
1041 +{
1042 +        ST_SCHEMA_TABLE*        schema;
1043 +
1044 +        DBUG_ENTER("innodb_sys_columns_init");
1045 +
1046 +        schema = (ST_SCHEMA_TABLE*) p;
1047 +
1048 +        schema->fields_info = innodb_sys_columns_fields_info;
1049 +        schema->fill_table = i_s_sys_columns_fill_table;
1050 +
1051 +        DBUG_RETURN(0);
1052 +}
1053 +
1054 +UNIV_INTERN struct st_mysql_plugin     i_s_innodb_sys_columns =
1055 +{
1056 +       /* the plugin type (a MYSQL_XXX_PLUGIN value) */
1057 +       /* int */
1058 +       STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
1059 +
1060 +       /* pointer to type-specific plugin descriptor */
1061 +       /* void* */
1062 +       STRUCT_FLD(info, &i_s_info),
1063 +
1064 +       /* plugin name */
1065 +       /* const char* */
1066 +       STRUCT_FLD(name, "INNODB_SYS_COLUMNS"),
1067 +
1068 +       /* plugin author (for SHOW PLUGINS) */
1069 +       /* const char* */
1070 +       STRUCT_FLD(author, "Percona"),
1071 +
1072 +       /* general descriptive text (for SHOW PLUGINS) */
1073 +       /* const char* */
1074 +       STRUCT_FLD(descr, "InnoDB SYS_COLUMNS"),
1075 +
1076 +       /* the plugin license (PLUGIN_LICENSE_XXX) */
1077 +       /* int */
1078 +       STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
1079 +
1080 +       /* the function to invoke when plugin is loaded */
1081 +       /* int (*)(void*); */
1082 +       STRUCT_FLD(init, innodb_sys_columns_init),
1083 +
1084 +       /* the function to invoke when plugin is unloaded */
1085 +       /* int (*)(void*); */
1086 +       STRUCT_FLD(deinit, i_s_common_deinit),
1087 +
1088 +       /* plugin version (for SHOW PLUGINS) */
1089 +       /* unsigned int */
1090 +       STRUCT_FLD(version, INNODB_VERSION_SHORT),
1091 +
1092 +       /* struct st_mysql_show_var* */
1093 +       STRUCT_FLD(status_vars, NULL),
1094 +
1095 +       /* struct st_mysql_sys_var** */
1096 +       STRUCT_FLD(system_vars, NULL),
1097 +
1098 +       /* reserved for dependency checking */
1099 +       /* void* */
1100 +       STRUCT_FLD(__reserved1, NULL)
1101 +};
1102 +/* Fields of the dynamic table INFORMATION_SCHEMA.innodb_sys_fields */
1103 +static ST_FIELD_INFO    innodb_sys_fields_fields_info[] =
1104 +{
1105 +#define SYS_FIELD_INDEX_ID     0
1106 +       {STRUCT_FLD(field_name,         "INDEX_ID"),
1107 +        STRUCT_FLD(field_length,       MY_INT64_NUM_DECIMAL_DIGITS),
1108 +        STRUCT_FLD(field_type,         MYSQL_TYPE_LONGLONG),
1109 +        STRUCT_FLD(value,              0),
1110 +        STRUCT_FLD(field_flags,        MY_I_S_UNSIGNED),
1111 +        STRUCT_FLD(old_name,           ""),
1112 +        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
1113 +
1114 +#define SYS_FIELD_NAME         1
1115 +       {STRUCT_FLD(field_name,         "NAME"),
1116 +        STRUCT_FLD(field_length,       NAME_LEN + 1),
1117 +        STRUCT_FLD(field_type,         MYSQL_TYPE_STRING),
1118 +        STRUCT_FLD(value,              0),
1119 +        STRUCT_FLD(field_flags,        0),
1120 +        STRUCT_FLD(old_name,           ""),
1121 +        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
1122 +
1123 +#define SYS_FIELD_POS          2
1124 +       {STRUCT_FLD(field_name,         "POS"),
1125 +        STRUCT_FLD(field_length,       MY_INT32_NUM_DECIMAL_DIGITS),
1126 +        STRUCT_FLD(field_type,         MYSQL_TYPE_LONG),
1127 +        STRUCT_FLD(value,              0),
1128 +        STRUCT_FLD(field_flags,        MY_I_S_UNSIGNED),
1129 +        STRUCT_FLD(old_name,           ""),
1130 +        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
1131 +
1132 +       END_OF_ST_FIELD_INFO
1133 +};
1134 +
1135 +/**********************************************************************//**
1136 +Function to fill information_schema.innodb_sys_fields with information
1137 +collected by scanning SYS_FIELDS table.
1138 +@return 0 on success */
1139 +static
1140 +int
1141 +i_s_dict_fill_sys_fields(
1142 +/*=====================*/
1143 +       THD*            thd,            /*!< in: thread */
1144 +       index_id_t      index_id,       /*!< in: index id for the field */
1145 +       dict_field_t*   field,          /*!< in: table */
1146 +       ulint           pos,            /*!< in: Field position */
1147 +       TABLE*          table_to_fill)  /*!< in/out: fill this table */
1148 +{
1149 +       Field**         fields;
1150 +
1151 +       DBUG_ENTER("i_s_dict_fill_sys_fields");
1152 +
1153 +       fields = table_to_fill->field;
1154 +
1155 +       OK(fields[SYS_FIELD_INDEX_ID]->store(longlong(index_id), TRUE));
1156 +
1157 +       OK(field_store_string(fields[SYS_FIELD_NAME], field->name));
1158 +
1159 +       OK(fields[SYS_FIELD_POS]->store(pos));
1160 +
1161 +       OK(schema_table_store_record(thd, table_to_fill));
1162 +
1163 +       DBUG_RETURN(0);
1164 +}
1165 +/*******************************************************************//**
1166 +Function to go through each record in SYS_FIELDS table, and fill the
1167 +information_schema.innodb_sys_fields table with related index field
1168 +information
1169 +@return 0 on success */
1170 +static
1171 +int
1172 +i_s_sys_fields_fill_table(
1173 +/*======================*/
1174 +       THD*            thd,    /*!< in: thread */
1175 +       TABLE_LIST*     tables, /*!< in/out: tables to fill */
1176 +       COND*           cond)   /*!< in: condition (not used) */
1177 +{
1178 +        btr_pcur_t     pcur;
1179 +       const rec_t*    rec;
1180 +       mem_heap_t*     heap;
1181 +       index_id_t      last_id;
1182 +       mtr_t           mtr;
1183 +
1184 +       DBUG_ENTER("i_s_sys_fields_fill_table");
1185 +
1186 +       /* deny access to non-superusers */
1187 +       if (check_global_access(thd, PROCESS_ACL)) {
1188 +
1189 +                DBUG_RETURN(0);
1190 +       }
1191 +
1192 +        heap = mem_heap_create(1000);
1193 +        mutex_enter(&dict_sys->mutex);
1194 +        mtr_start(&mtr);
1195 +
1196 +       /* will save last index id so that we know whether we move to
1197 +       the next index. This is used to calculate prefix length */
1198 +       last_id = 0;
1199 +
1200 +       rec = dict_startscan_system(&pcur, &mtr, SYS_FIELDS);
1201 +
1202 +       while (rec) {
1203 +               ulint           pos;
1204 +               const char*     err_msg;
1205 +               index_id_t      index_id;
1206 +               dict_field_t    field_rec;
1207 +
1208 +               /* Populate a dict_field_t structure with information from
1209 +               a SYS_FIELDS row */
1210 +               err_msg = dict_process_sys_fields_rec(heap, rec, &field_rec,
1211 +                                                     &pos, &index_id, last_id);
1212 +
1213 +               mtr_commit(&mtr);
1214 +               mutex_exit(&dict_sys->mutex);
1215 +
1216 +               if (!err_msg) {
1217 +                       i_s_dict_fill_sys_fields(thd, index_id, &field_rec,
1218 +                                                pos, tables->table);
1219 +                       last_id = index_id;
1220 +               } else {
1221 +                       push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
1222 +                                           ER_CANT_FIND_SYSTEM_REC,
1223 +                                           err_msg);
1224 +               }
1225 +
1226 +               mem_heap_empty(heap);
1227 +
1228 +               /* Get the next record */
1229 +               mutex_enter(&dict_sys->mutex);
1230 +               mtr_start(&mtr);
1231 +               rec = dict_getnext_system(&pcur, &mtr);
1232 +       }
1233 +
1234 +       mtr_commit(&mtr);
1235 +       mutex_exit(&dict_sys->mutex);
1236 +       mem_heap_free(heap);
1237 +
1238 +       DBUG_RETURN(0);
1239 +}
1240 +/*******************************************************************//**
1241 +Bind the dynamic table INFORMATION_SCHEMA.innodb_sys_fields
1242 +@return 0 on success */
1243 +static
1244 +int
1245 +innodb_sys_fields_init(
1246 +/*===================*/
1247 +        void*   p)      /*!< in/out: table schema object */
1248 +{
1249 +        ST_SCHEMA_TABLE*        schema;
1250 +
1251 +        DBUG_ENTER("innodb_sys_field_init");
1252 +
1253 +        schema = (ST_SCHEMA_TABLE*) p;
1254 +
1255 +        schema->fields_info = innodb_sys_fields_fields_info;
1256 +        schema->fill_table = i_s_sys_fields_fill_table;
1257 +
1258 +        DBUG_RETURN(0);
1259 +}
1260 +
1261 +UNIV_INTERN struct st_mysql_plugin     i_s_innodb_sys_fields =
1262 +{
1263 +       /* the plugin type (a MYSQL_XXX_PLUGIN value) */
1264 +       /* int */
1265 +       STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
1266 +
1267 +       /* pointer to type-specific plugin descriptor */
1268 +       /* void* */
1269 +       STRUCT_FLD(info, &i_s_info),
1270 +
1271 +       /* plugin name */
1272 +       /* const char* */
1273 +       STRUCT_FLD(name, "INNODB_SYS_FIELDS"),
1274 +
1275 +       /* plugin author (for SHOW PLUGINS) */
1276 +       /* const char* */
1277 +       STRUCT_FLD(author, "Percona"),
1278 +
1279 +       /* general descriptive text (for SHOW PLUGINS) */
1280 +       /* const char* */
1281 +       STRUCT_FLD(descr, "InnoDB SYS_FIELDS"),
1282 +
1283 +       /* the plugin license (PLUGIN_LICENSE_XXX) */
1284 +       /* int */
1285 +       STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
1286 +
1287 +       /* the function to invoke when plugin is loaded */
1288 +       /* int (*)(void*); */
1289 +       STRUCT_FLD(init, innodb_sys_fields_init),
1290 +
1291 +       /* the function to invoke when plugin is unloaded */
1292 +       /* int (*)(void*); */
1293 +       STRUCT_FLD(deinit, i_s_common_deinit),
1294 +
1295 +       /* plugin version (for SHOW PLUGINS) */
1296 +       /* unsigned int */
1297 +       STRUCT_FLD(version, INNODB_VERSION_SHORT),
1298 +
1299 +       /* struct st_mysql_show_var* */
1300 +       STRUCT_FLD(status_vars, NULL),
1301 +
1302 +       /* struct st_mysql_sys_var** */
1303 +       STRUCT_FLD(system_vars, NULL),
1304 +
1305 +       /* reserved for dependency checking */
1306 +       /* void* */
1307 +       STRUCT_FLD(__reserved1, NULL)
1308 +};
1309 +
1310 +/* Fields of the dynamic table INFORMATION_SCHEMA.innodb_sys_foreign */
1311 +static ST_FIELD_INFO    innodb_sys_foreign_fields_info[] =
1312 +{
1313 +#define SYS_FOREIGN_ID         0
1314 +       {STRUCT_FLD(field_name,         "ID"),
1315 +        STRUCT_FLD(field_length,       NAME_LEN + 1),
1316 +        STRUCT_FLD(field_type,         MYSQL_TYPE_STRING),
1317 +        STRUCT_FLD(value,              0),
1318 +        STRUCT_FLD(field_flags,        0),
1319 +        STRUCT_FLD(old_name,           ""),
1320 +        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
1321 +
1322 +#define SYS_FOREIGN_FOR_NAME   1
1323 +       {STRUCT_FLD(field_name,         "FOR_NAME"),
1324 +        STRUCT_FLD(field_length,       NAME_LEN + 1),
1325 +        STRUCT_FLD(field_type,         MYSQL_TYPE_STRING),
1326 +        STRUCT_FLD(value,              0),
1327 +        STRUCT_FLD(field_flags,        0),
1328 +        STRUCT_FLD(old_name,           ""),
1329 +        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
1330 +
1331 +#define SYS_FOREIGN_REF_NAME   2
1332 +       {STRUCT_FLD(field_name,         "REF_NAME"),
1333 +        STRUCT_FLD(field_length,       NAME_LEN + 1),
1334 +        STRUCT_FLD(field_type,         MYSQL_TYPE_STRING),
1335 +        STRUCT_FLD(value,              0),
1336 +        STRUCT_FLD(field_flags,        0),
1337 +        STRUCT_FLD(old_name,           ""),
1338 +        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
1339 +
1340 +#define SYS_FOREIGN_NUM_COL    3
1341 +       {STRUCT_FLD(field_name,         "N_COLS"),
1342 +        STRUCT_FLD(field_length,       MY_INT32_NUM_DECIMAL_DIGITS),
1343 +        STRUCT_FLD(field_type,         MYSQL_TYPE_LONG),
1344 +        STRUCT_FLD(value,              0),
1345 +        STRUCT_FLD(field_flags,        MY_I_S_UNSIGNED),
1346 +        STRUCT_FLD(old_name,           ""),
1347 +        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
1348 +
1349 +#define SYS_FOREIGN_TYPE       4
1350 +       {STRUCT_FLD(field_name,         "TYPE"),
1351 +        STRUCT_FLD(field_length,       MY_INT32_NUM_DECIMAL_DIGITS),
1352 +        STRUCT_FLD(field_type,         MYSQL_TYPE_LONG),
1353 +        STRUCT_FLD(value,              0),
1354 +        STRUCT_FLD(field_flags,        MY_I_S_UNSIGNED),
1355 +        STRUCT_FLD(old_name,           ""),
1356 +        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
1357 +
1358 +       END_OF_ST_FIELD_INFO
1359 +};
1360 +
1361 +/**********************************************************************//**
1362 +Function to fill information_schema.innodb_sys_foreign with information
1363 +collected by scanning SYS_FOREIGN table.
1364 +@return 0 on success */
1365 +static
1366 +int
1367 +i_s_dict_fill_sys_foreign(
1368 +/*======================*/
1369 +       THD*            thd,            /*!< in: thread */
1370 +       dict_foreign_t* foreign,        /*!< in: table */
1371 +       TABLE*          table_to_fill)  /*!< in/out: fill this table */
1372 +{
1373 +       Field**         fields;
1374 +
1375 +       DBUG_ENTER("i_s_dict_fill_sys_foreign");
1376 +
1377 +       fields = table_to_fill->field;
1378 +
1379 +       OK(field_store_string(fields[SYS_FOREIGN_ID], foreign->id));
1380 +
1381 +       OK(field_store_string(fields[SYS_FOREIGN_FOR_NAME],
1382 +                             foreign->foreign_table_name));
1383 +
1384 +       OK(field_store_string(fields[SYS_FOREIGN_REF_NAME],
1385 +                             foreign->referenced_table_name));
1386 +
1387 +       OK(fields[SYS_FOREIGN_NUM_COL]->store(foreign->n_fields));
1388 +
1389 +       OK(fields[SYS_FOREIGN_TYPE]->store(foreign->type));
1390 +
1391 +       OK(schema_table_store_record(thd, table_to_fill));
1392 +
1393 +       DBUG_RETURN(0);
1394 +}
1395 +/*******************************************************************//**
1396 +Function to populate INFORMATION_SCHEMA.innodb_sys_foreign table. Loop
1397 +through each record in SYS_FOREIGN, and extract the foreign key
1398 +information.
1399 +@return 0 on success */
1400 +static
1401 +int
1402 +i_s_sys_foreign_fill_table(
1403 +/*=======================*/
1404 +       THD*            thd,    /*!< in: thread */
1405 +       TABLE_LIST*     tables, /*!< in/out: tables to fill */
1406 +       COND*           cond)   /*!< in: condition (not used) */
1407 +{
1408 +        btr_pcur_t     pcur;
1409 +       const rec_t*    rec;
1410 +       mem_heap_t*     heap;
1411 +       mtr_t           mtr;
1412 +
1413 +       DBUG_ENTER("i_s_sys_foreign_fill_table");
1414 +
1415 +       /* deny access to non-superusers */
1416 +       if (check_global_access(thd, PROCESS_ACL)) {
1417 +
1418 +                DBUG_RETURN(0);
1419 +       }
1420 +
1421 +        heap = mem_heap_create(1000);
1422 +        mutex_enter(&dict_sys->mutex);
1423 +        mtr_start(&mtr);
1424 +
1425 +       rec = dict_startscan_system(&pcur, &mtr, SYS_FOREIGN);
1426 +
1427 +       while (rec) {
1428 +               const char*     err_msg;
1429 +               dict_foreign_t  foreign_rec;
1430 +
1431 +               /* Populate a dict_foreign_t structure with information from
1432 +               a SYS_FOREIGN row */
1433 +               err_msg = dict_process_sys_foreign_rec(heap, rec, &foreign_rec);
1434 +
1435 +               mtr_commit(&mtr);
1436 +               mutex_exit(&dict_sys->mutex);
1437 +
1438 +               if (!err_msg) {
1439 +                       i_s_dict_fill_sys_foreign(thd, &foreign_rec,
1440 +                                                tables->table);
1441 +               } else {
1442 +                       push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
1443 +                                           ER_CANT_FIND_SYSTEM_REC,
1444 +                                           err_msg);
1445 +               }
1446 +
1447 +               mem_heap_empty(heap);
1448 +
1449 +               /* Get the next record */
1450 +               mtr_start(&mtr);
1451 +               mutex_enter(&dict_sys->mutex);
1452 +               rec = dict_getnext_system(&pcur, &mtr);
1453 +       }
1454 +
1455 +       mtr_commit(&mtr);
1456 +       mutex_exit(&dict_sys->mutex);
1457 +       mem_heap_free(heap);
1458 +
1459 +       DBUG_RETURN(0);
1460 +}
1461 +/*******************************************************************//**
1462 +Bind the dynamic table INFORMATION_SCHEMA.innodb_sys_foreign
1463 +@return 0 on success */
1464 +static
1465 +int
1466 +innodb_sys_foreign_init(
1467 +/*====================*/
1468 +        void*   p)      /*!< in/out: table schema object */
1469 +{
1470 +        ST_SCHEMA_TABLE*        schema;
1471 +
1472 +        DBUG_ENTER("innodb_sys_foreign_init");
1473 +
1474 +        schema = (ST_SCHEMA_TABLE*) p;
1475 +
1476 +        schema->fields_info = innodb_sys_foreign_fields_info;
1477 +        schema->fill_table = i_s_sys_foreign_fill_table;
1478 +
1479 +        DBUG_RETURN(0);
1480 +}
1481 +
1482 +UNIV_INTERN struct st_mysql_plugin     i_s_innodb_sys_foreign =
1483 +{
1484 +       /* the plugin type (a MYSQL_XXX_PLUGIN value) */
1485 +       /* int */
1486 +       STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
1487 +
1488 +       /* pointer to type-specific plugin descriptor */
1489 +       /* void* */
1490 +       STRUCT_FLD(info, &i_s_info),
1491 +
1492 +       /* plugin name */
1493 +       /* const char* */
1494 +       STRUCT_FLD(name, "INNODB_SYS_FOREIGN"),
1495 +
1496 +       /* plugin author (for SHOW PLUGINS) */
1497 +       /* const char* */
1498 +       STRUCT_FLD(author, "Percona"),
1499 +
1500 +       /* general descriptive text (for SHOW PLUGINS) */
1501 +       /* const char* */
1502 +       STRUCT_FLD(descr, "InnoDB SYS_FOREIGN"),
1503 +
1504 +       /* the plugin license (PLUGIN_LICENSE_XXX) */
1505 +       /* int */
1506 +       STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
1507 +
1508 +       /* the function to invoke when plugin is loaded */
1509 +       /* int (*)(void*); */
1510 +       STRUCT_FLD(init, innodb_sys_foreign_init),
1511 +
1512 +       /* the function to invoke when plugin is unloaded */
1513 +       /* int (*)(void*); */
1514 +       STRUCT_FLD(deinit, i_s_common_deinit),
1515 +
1516 +       /* plugin version (for SHOW PLUGINS) */
1517 +       /* unsigned int */
1518 +       STRUCT_FLD(version, INNODB_VERSION_SHORT),
1519 +
1520 +       /* struct st_mysql_show_var* */
1521 +       STRUCT_FLD(status_vars, NULL),
1522 +
1523 +       /* struct st_mysql_sys_var** */
1524 +       STRUCT_FLD(system_vars, NULL),
1525 +
1526 +       /* reserved for dependency checking */
1527 +       /* void* */
1528 +       STRUCT_FLD(__reserved1, NULL)
1529 +};
1530 +/* Fields of the dynamic table INFORMATION_SCHEMA.innodb_sys_foreign_cols */
1531 +static ST_FIELD_INFO    innodb_sys_foreign_cols_fields_info[] =
1532 +{
1533 +#define SYS_FOREIGN_COL_ID             0
1534 +       {STRUCT_FLD(field_name,         "ID"),
1535 +        STRUCT_FLD(field_length,       NAME_LEN + 1),
1536 +        STRUCT_FLD(field_type,         MYSQL_TYPE_STRING),
1537 +        STRUCT_FLD(value,              0),
1538 +        STRUCT_FLD(field_flags,        0),
1539 +        STRUCT_FLD(old_name,           ""),
1540 +        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
1541 +
1542 +#define SYS_FOREIGN_COL_FOR_NAME       1
1543 +       {STRUCT_FLD(field_name,         "FOR_COL_NAME"),
1544 +        STRUCT_FLD(field_length,       NAME_LEN + 1),
1545 +        STRUCT_FLD(field_type,         MYSQL_TYPE_STRING),
1546 +        STRUCT_FLD(value,              0),
1547 +        STRUCT_FLD(field_flags,        0),
1548 +        STRUCT_FLD(old_name,           ""),
1549 +        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
1550 +
1551 +#define SYS_FOREIGN_COL_REF_NAME       2
1552 +       {STRUCT_FLD(field_name,         "REF_COL_NAME"),
1553 +        STRUCT_FLD(field_length,       NAME_LEN + 1),
1554 +        STRUCT_FLD(field_type,         MYSQL_TYPE_STRING),
1555 +        STRUCT_FLD(value,              0),
1556 +        STRUCT_FLD(field_flags,        0),
1557 +        STRUCT_FLD(old_name,           ""),
1558 +        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
1559 +
1560 +#define SYS_FOREIGN_COL_POS            3
1561 +       {STRUCT_FLD(field_name,         "POS"),
1562 +        STRUCT_FLD(field_length,       MY_INT32_NUM_DECIMAL_DIGITS),
1563 +        STRUCT_FLD(field_type,         MYSQL_TYPE_LONG),
1564 +        STRUCT_FLD(value,              0),
1565 +        STRUCT_FLD(field_flags,        MY_I_S_UNSIGNED),
1566 +        STRUCT_FLD(old_name,           ""),
1567 +        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
1568 +
1569 +       END_OF_ST_FIELD_INFO
1570 +};
1571 +
1572 +/**********************************************************************//**
1573 +Function to fill information_schema.innodb_sys_foreign_cols with information
1574 +collected by scanning SYS_FOREIGN_COLS table.
1575 +@return 0 on success */
1576 +static
1577 +int
1578 +i_s_dict_fill_sys_foreign_cols(
1579 +/*==========================*/
1580 +       THD*            thd,            /*!< in: thread */
1581 +       const char*     name,           /*!< in: foreign key constraint name */
1582 +       const char*     for_col_name,   /*!< in: referencing column name*/
1583 +       const char*     ref_col_name,   /*!< in: referenced column
1584 +                                       name */
1585 +       ulint           pos,            /*!< in: column position */
1586 +       TABLE*          table_to_fill)  /*!< in/out: fill this table */
1587 +{
1588 +       Field**         fields;
1589 +
1590 +       DBUG_ENTER("i_s_dict_fill_sys_foreign_cols");
1591 +
1592 +       fields = table_to_fill->field;
1593 +
1594 +       OK(field_store_string(fields[SYS_FOREIGN_COL_ID], name));
1595 +
1596 +       OK(field_store_string(fields[SYS_FOREIGN_COL_FOR_NAME], for_col_name));
1597 +
1598 +       OK(field_store_string(fields[SYS_FOREIGN_COL_REF_NAME], ref_col_name));
1599 +
1600 +       OK(fields[SYS_FOREIGN_COL_POS]->store(pos));
1601 +
1602 +       OK(schema_table_store_record(thd, table_to_fill));
1603 +
1604 +       DBUG_RETURN(0);
1605 +}
1606 +/*******************************************************************//**
1607 +Function to populate INFORMATION_SCHEMA.innodb_sys_foreign_cols table. Loop
1608 +through each record in SYS_FOREIGN_COLS, and extract the foreign key column
1609 +information and fill the INFORMATION_SCHEMA.innodb_sys_foreign_cols table.
1610 +@return 0 on success */
1611 +static
1612 +int
1613 +i_s_sys_foreign_cols_fill_table(
1614 +/*============================*/
1615 +       THD*            thd,    /*!< in: thread */
1616 +       TABLE_LIST*     tables, /*!< in/out: tables to fill */
1617 +       COND*           cond)   /*!< in: condition (not used) */
1618 +{
1619 +        btr_pcur_t     pcur;
1620 +       const rec_t*    rec;
1621 +       mem_heap_t*     heap;
1622 +       mtr_t           mtr;
1623 +
1624 +       DBUG_ENTER("i_s_sys_foreign_cols_fill_table");
1625 +
1626 +       /* deny access to non-superusers */
1627 +       if (check_global_access(thd, PROCESS_ACL)) {
1628 +                DBUG_RETURN(0);
1629 +       }
1630 +
1631 +        heap = mem_heap_create(1000);
1632 +        mutex_enter(&dict_sys->mutex);
1633 +        mtr_start(&mtr);
1634 +
1635 +       rec = dict_startscan_system(&pcur, &mtr, SYS_FOREIGN_COLS);
1636 +
1637 +       while (rec) {
1638 +               const char*     err_msg;
1639 +               const char*     name;
1640 +               const char*     for_col_name;
1641 +               const char*     ref_col_name;
1642 +               ulint           pos;
1643 +
1644 +               /* Extract necessary information from a SYS_FOREIGN_COLS row */
1645 +               err_msg = dict_process_sys_foreign_col_rec(
1646 +                       heap, rec, &name, &for_col_name, &ref_col_name, &pos);
1647 +
1648 +               mtr_commit(&mtr);
1649 +               mutex_exit(&dict_sys->mutex);
1650 +
1651 +               if (!err_msg) {
1652 +                       i_s_dict_fill_sys_foreign_cols(
1653 +                               thd, name, for_col_name, ref_col_name, pos,
1654 +                               tables->table);
1655 +               } else {
1656 +                       push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
1657 +                                           ER_CANT_FIND_SYSTEM_REC,
1658 +                                           err_msg);
1659 +               }
1660 +
1661 +               mem_heap_empty(heap);
1662 +
1663 +               /* Get the next record */
1664 +               mutex_enter(&dict_sys->mutex);
1665 +               mtr_start(&mtr);
1666 +               rec = dict_getnext_system(&pcur, &mtr);
1667 +       }
1668 +
1669 +       mtr_commit(&mtr);
1670 +       mutex_exit(&dict_sys->mutex);
1671 +       mem_heap_free(heap);
1672 +
1673 +       DBUG_RETURN(0);
1674 +}
1675 +/*******************************************************************//**
1676 +Bind the dynamic table INFORMATION_SCHEMA.innodb_sys_foreign_cols
1677 +@return 0 on success */
1678 +static
1679 +int
1680 +innodb_sys_foreign_cols_init(
1681 +/*========================*/
1682 +        void*   p)      /*!< in/out: table schema object */
1683 +{
1684 +        ST_SCHEMA_TABLE*        schema;
1685 +
1686 +        DBUG_ENTER("innodb_sys_foreign_cols_init");
1687 +
1688 +        schema = (ST_SCHEMA_TABLE*) p;
1689 +
1690 +        schema->fields_info = innodb_sys_foreign_cols_fields_info;
1691 +        schema->fill_table = i_s_sys_foreign_cols_fill_table;
1692 +
1693 +        DBUG_RETURN(0);
1694 +}
1695 +
1696 +UNIV_INTERN struct st_mysql_plugin     i_s_innodb_sys_foreign_cols =
1697 +{
1698 +       /* the plugin type (a MYSQL_XXX_PLUGIN value) */
1699 +       /* int */
1700 +       STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
1701 +
1702 +       /* pointer to type-specific plugin descriptor */
1703 +       /* void* */
1704 +       STRUCT_FLD(info, &i_s_info),
1705 +
1706 +       /* plugin name */
1707 +       /* const char* */
1708 +       STRUCT_FLD(name, "INNODB_SYS_FOREIGN_COLS"),
1709 +
1710 +       /* plugin author (for SHOW PLUGINS) */
1711 +       /* const char* */
1712 +       STRUCT_FLD(author, "Percona"),
1713 +
1714 +       /* general descriptive text (for SHOW PLUGINS) */
1715 +       /* const char* */
1716 +       STRUCT_FLD(descr, "InnoDB SYS_FOREIGN_COLS"),
1717 +
1718 +       /* the plugin license (PLUGIN_LICENSE_XXX) */
1719 +       /* int */
1720 +       STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
1721 +
1722 +       /* the function to invoke when plugin is loaded */
1723 +       /* int (*)(void*); */
1724 +       STRUCT_FLD(init, innodb_sys_foreign_cols_init),
1725 +
1726 +       /* the function to invoke when plugin is unloaded */
1727 +       /* int (*)(void*); */
1728 +       STRUCT_FLD(deinit, i_s_common_deinit),
1729 +
1730 +       /* plugin version (for SHOW PLUGINS) */
1731 +       /* unsigned int */
1732 +       STRUCT_FLD(version, INNODB_VERSION_SHORT),
1733 +
1734 +       /* struct st_mysql_show_var* */
1735 +       STRUCT_FLD(status_vars, NULL),
1736 +
1737 +       /* struct st_mysql_sys_var** */
1738 +       STRUCT_FLD(system_vars, NULL),
1739 +
1740 +       /* reserved for dependency checking */
1741 +       /* void* */
1742 +       STRUCT_FLD(__reserved1, NULL)
1743 +};
1744 +
1745  /***********************************************************************
1746  */
1747  static ST_FIELD_INFO   i_s_innodb_rseg_fields_info[] =
1748 --- a/storage/innobase/handler/i_s.h
1749 +++ b/storage/innobase/handler/i_s.h
1750 @@ -35,6 +35,13 @@
1751  extern struct st_mysql_plugin  i_s_innodb_cmp_reset;
1752  extern struct st_mysql_plugin  i_s_innodb_cmpmem;
1753  extern struct st_mysql_plugin  i_s_innodb_cmpmem_reset;
1754 +extern struct st_mysql_plugin  i_s_innodb_sys_tables;
1755 +extern struct st_mysql_plugin  i_s_innodb_sys_tablestats;
1756 +extern struct st_mysql_plugin  i_s_innodb_sys_indexes;
1757 +extern struct st_mysql_plugin   i_s_innodb_sys_columns;
1758 +extern struct st_mysql_plugin   i_s_innodb_sys_fields;
1759 +extern struct st_mysql_plugin   i_s_innodb_sys_foreign;
1760 +extern struct st_mysql_plugin   i_s_innodb_sys_foreign_cols;
1761  extern struct st_mysql_plugin  i_s_innodb_rseg;
1762  
1763  #endif /* i_s_h */
1764 --- /dev/null
1765 +++ b/mysql-test/r/percona_innodb_use_sys_stats_table.result
1766 @@ -0,0 +1,3 @@
1767 +show variables like 'innodb_use_sys_stats%';
1768 +Variable_name  Value
1769 +innodb_use_sys_stats_table     ON
1770 --- /dev/null
1771 +++ b/mysql-test/t/percona_innodb_use_sys_stats_table-master.opt
1772 @@ -0,0 +1 @@
1773 +--innodb_use_sys_stats_table
1774 --- /dev/null
1775 +++ b/mysql-test/t/percona_innodb_use_sys_stats_table.test
1776 @@ -0,0 +1,2 @@
1777 +--source include/have_innodb.inc
1778 +show variables like 'innodb_use_sys_stats%';
This page took 3.691777 seconds and 4 git commands to generate.