]>
Commit | Line | Data |
---|---|---|
b4e1fa2c AM |
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 | 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 @@ | |
12 | i_s_innodb_cmp, | |
13 | i_s_innodb_cmp_reset, | |
14 | i_s_innodb_cmpmem, | |
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; | |
25 | ||
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 | |
30 | @@ -36,9 +36,11 @@ | |
31 | #include <mysql/innodb_priv.h> | |
32 | ||
33 | extern "C" { | |
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. */ | |
39 | #include "dict0mem.h" | |
40 | #include "dict0types.h" | |
41 | #include "ha_prototypes.h" /* for innobase_convert_name() */ | |
42 | @@ -1787,6 +1789,1675 @@ | |
43 | DBUG_RETURN(0); | |
44 | } | |
45 | ||
46 | +/* Fields of the dynamic table INFORMATION_SCHEMA.SYS_TABLES */ | |
47 | +static ST_FIELD_INFO innodb_sys_tables_fields_info[] = | |
48 | +{ | |
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)}, | |
57 | + | |
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)}, | |
66 | + | |
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)}, | |
75 | + | |
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)}, | |
84 | + | |
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)}, | |
93 | + | |
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)}, | |
102 | + | |
103 | + END_OF_ST_FIELD_INFO | |
104 | +}; | |
105 | + | |
106 | +/**********************************************************************//** | |
107 | +Populate information_schema.innodb_sys_tables table with information | |
108 | +from SYS_TABLES. | |
109 | +@return 0 on success */ | |
110 | +static | |
111 | +int | |
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 */ | |
117 | +{ | |
118 | + Field** fields; | |
119 | + char buf[NAME_LEN * 2 + 2]; | |
120 | + char* ptr; | |
121 | + | |
122 | + DBUG_ENTER("i_s_dict_fill_sys_tables"); | |
123 | + | |
124 | + fields = table_to_fill->field; | |
125 | + | |
126 | + OK(fields[SYS_TABLE_ID]->store(longlong(table->id), TRUE)); | |
127 | + | |
128 | + strncpy(buf, table->name, NAME_LEN * 2 + 2); | |
129 | + ptr = strchr(buf, '/'); | |
130 | + if (ptr) { | |
131 | + *ptr = '\0'; | |
132 | + ++ptr; | |
133 | + | |
134 | + OK(field_store_string(fields[SYS_TABLE_SCHEMA], buf)); | |
135 | + OK(field_store_string(fields[SYS_TABLE_NAME], ptr)); | |
136 | + } else { | |
137 | + fields[SYS_TABLE_SCHEMA]->set_null(); | |
138 | + OK(field_store_string(fields[SYS_TABLE_NAME], buf)); | |
139 | + } | |
140 | + | |
141 | + OK(fields[SYS_TABLE_FLAG]->store(table->flags)); | |
142 | + | |
143 | + OK(fields[SYS_TABLE_NUM_COLUMN]->store(table->n_cols)); | |
144 | + | |
145 | + OK(fields[SYS_TABLE_SPACE]->store(table->space)); | |
146 | + | |
147 | + OK(schema_table_store_record(thd, table_to_fill)); | |
148 | + | |
149 | + DBUG_RETURN(0); | |
150 | +} | |
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 */ | |
155 | +static | |
156 | +int | |
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) */ | |
162 | +{ | |
163 | + btr_pcur_t pcur; | |
164 | + const rec_t* rec; | |
165 | + mem_heap_t* heap; | |
166 | + mtr_t mtr; | |
167 | + | |
168 | + DBUG_ENTER("i_s_sys_tables_fill_table"); | |
169 | + | |
170 | + /* deny access to non-superusers */ | |
171 | + if (check_global_access(thd, PROCESS_ACL)) { | |
172 | + | |
173 | + DBUG_RETURN(0); | |
174 | + } | |
175 | + | |
176 | + heap = mem_heap_create(1000); | |
177 | + mutex_enter(&(dict_sys->mutex)); | |
178 | + mtr_start(&mtr); | |
179 | + | |
180 | + rec = dict_startscan_system(&pcur, &mtr, SYS_TABLES); | |
181 | + | |
182 | + while (rec) { | |
183 | + const char* err_msg; | |
184 | + dict_table_t* table_rec; | |
185 | + | |
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); | |
190 | + | |
191 | + mtr_commit(&mtr); | |
192 | + mutex_exit(&dict_sys->mutex); | |
193 | + | |
194 | + if (!err_msg) { | |
195 | + i_s_dict_fill_sys_tables(thd, table_rec, tables->table); | |
196 | + } else { | |
197 | + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, | |
198 | + ER_CANT_FIND_SYSTEM_REC, | |
199 | + err_msg); | |
200 | + } | |
201 | + | |
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 */ | |
205 | + if (table_rec) { | |
206 | + dict_mem_table_free(table_rec); | |
207 | + } | |
208 | + | |
209 | + mem_heap_empty(heap); | |
210 | + | |
211 | + /* Get the next record */ | |
212 | + mutex_enter(&dict_sys->mutex); | |
213 | + mtr_start(&mtr); | |
214 | + rec = dict_getnext_system(&pcur, &mtr); | |
215 | + } | |
216 | + | |
217 | + mtr_commit(&mtr); | |
218 | + mutex_exit(&dict_sys->mutex); | |
219 | + mem_heap_free(heap); | |
220 | + | |
221 | + DBUG_RETURN(0); | |
222 | +} | |
223 | + | |
224 | +/*******************************************************************//** | |
225 | +Bind the dynamic table INFORMATION_SCHEMA.innodb_sys_tables | |
226 | +@return 0 on success */ | |
227 | +static | |
228 | +int | |
229 | +innodb_sys_tables_init( | |
230 | +/*===================*/ | |
231 | + void* p) /*!< in/out: table schema object */ | |
232 | +{ | |
233 | + ST_SCHEMA_TABLE* schema; | |
234 | + | |
235 | + DBUG_ENTER("innodb_sys_tables_init"); | |
236 | + | |
237 | + schema = (ST_SCHEMA_TABLE*) p; | |
238 | + | |
239 | + schema->fields_info = innodb_sys_tables_fields_info; | |
240 | + schema->fill_table = i_s_sys_tables_fill_table; | |
241 | + | |
242 | + DBUG_RETURN(0); | |
243 | +} | |
244 | + | |
245 | +UNIV_INTERN struct st_mysql_plugin i_s_innodb_sys_tables = | |
246 | +{ | |
247 | + /* the plugin type (a MYSQL_XXX_PLUGIN value) */ | |
248 | + /* int */ | |
249 | + STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN), | |
250 | + | |
251 | + /* pointer to type-specific plugin descriptor */ | |
252 | + /* void* */ | |
253 | + STRUCT_FLD(info, &i_s_info), | |
254 | + | |
255 | + /* plugin name */ | |
256 | + /* const char* */ | |
257 | + STRUCT_FLD(name, "INNODB_SYS_TABLES"), | |
258 | + | |
259 | + /* plugin author (for SHOW PLUGINS) */ | |
260 | + /* const char* */ | |
261 | + STRUCT_FLD(author, plugin_author), | |
262 | + | |
263 | + /* general descriptive text (for SHOW PLUGINS) */ | |
264 | + /* const char* */ | |
265 | + STRUCT_FLD(descr, "InnoDB SYS_TABLES"), | |
266 | + | |
267 | + /* the plugin license (PLUGIN_LICENSE_XXX) */ | |
268 | + /* int */ | |
269 | + STRUCT_FLD(license, PLUGIN_LICENSE_GPL), | |
270 | + | |
271 | + /* the function to invoke when plugin is loaded */ | |
272 | + /* int (*)(void*); */ | |
273 | + STRUCT_FLD(init, innodb_sys_tables_init), | |
274 | + | |
275 | + /* the function to invoke when plugin is unloaded */ | |
276 | + /* int (*)(void*); */ | |
277 | + STRUCT_FLD(deinit, i_s_common_deinit), | |
278 | + | |
279 | + /* plugin version (for SHOW PLUGINS) */ | |
280 | + /* unsigned int */ | |
281 | + STRUCT_FLD(version, INNODB_VERSION_SHORT), | |
282 | + | |
283 | + /* struct st_mysql_show_var* */ | |
284 | + STRUCT_FLD(status_vars, NULL), | |
285 | + | |
286 | + /* struct st_mysql_sys_var** */ | |
287 | + STRUCT_FLD(system_vars, NULL), | |
288 | + | |
289 | + /* reserved for dependency checking */ | |
290 | + /* void* */ | |
291 | + STRUCT_FLD(__reserved1, NULL) | |
292 | +}; | |
293 | + | |
294 | +/* Fields of the dynamic table INFORMATION_SCHEMA.SYS_TABLESTATS */ | |
295 | +static ST_FIELD_INFO innodb_sys_tablestats_fields_info[] = | |
296 | +{ | |
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)}, | |
305 | + | |
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)}, | |
314 | + | |
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)}, | |
323 | + | |
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)}, | |
332 | + | |
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)}, | |
341 | + | |
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)}, | |
350 | + | |
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)}, | |
359 | + | |
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)}, | |
368 | + | |
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)}, | |
377 | + | |
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)}, | |
386 | + | |
387 | + END_OF_ST_FIELD_INFO | |
388 | +}; | |
389 | + | |
390 | +/**********************************************************************//** | |
391 | +Populate information_schema.innodb_sys_tablestats table with information | |
392 | +from SYS_TABLES. | |
393 | +@return 0 on success */ | |
394 | +static | |
395 | +int | |
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 */ | |
401 | +{ | |
402 | + Field** fields; | |
403 | + char buf[NAME_LEN * 2 + 2]; | |
404 | + char* ptr; | |
405 | + | |
406 | + DBUG_ENTER("i_s_dict_fill_sys_tablestats"); | |
407 | + | |
408 | + fields = table_to_fill->field; | |
409 | + | |
410 | + OK(fields[SYS_TABLESTATS_ID]->store(longlong(table->id), TRUE)); | |
411 | + | |
412 | + strncpy(buf, table->name, NAME_LEN * 2 + 2); | |
413 | + ptr = strchr(buf, '/'); | |
414 | + if (ptr) { | |
415 | + *ptr = '\0'; | |
416 | + ++ptr; | |
417 | + | |
418 | + OK(field_store_string(fields[SYS_TABLESTATS_SCHEMA], buf)); | |
419 | + OK(field_store_string(fields[SYS_TABLESTATS_NAME], ptr)); | |
420 | + } else { | |
421 | + fields[SYS_TABLESTATS_SCHEMA]->set_null(); | |
422 | + OK(field_store_string(fields[SYS_TABLESTATS_NAME], buf)); | |
423 | + } | |
424 | + | |
425 | + if (table->stat_initialized) { | |
426 | + OK(field_store_string(fields[SYS_TABLESTATS_INIT], | |
427 | + "Initialized")); | |
428 | + } else { | |
429 | + OK(field_store_string(fields[SYS_TABLESTATS_INIT], | |
430 | + "Uninitialized")); | |
431 | + } | |
432 | + | |
433 | + OK(fields[SYS_TABLESTATS_NROW]->store(table->stat_n_rows, TRUE)); | |
434 | + | |
435 | + OK(fields[SYS_TABLESTATS_CLUST_SIZE]->store( | |
436 | + table->stat_clustered_index_size)); | |
437 | + | |
438 | + OK(fields[SYS_TABLESTATS_INDEX_SIZE]->store( | |
439 | + table->stat_sum_of_other_index_sizes)); | |
440 | + | |
441 | + OK(fields[SYS_TABLESTATS_MODIFIED]->store( | |
442 | + table->stat_modified_counter)); | |
443 | + | |
444 | + OK(fields[SYS_TABLESTATS_AUTONINC]->store(table->autoinc, TRUE)); | |
445 | + | |
446 | + OK(fields[SYS_TABLESTATS_MYSQL_OPEN_HANDLE]->store( | |
447 | + table->n_mysql_handles_opened)); | |
448 | + | |
449 | + OK(schema_table_store_record(thd, table_to_fill)); | |
450 | + | |
451 | + DBUG_RETURN(0); | |
452 | +} | |
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 | |
456 | +related information | |
457 | +@return 0 on success */ | |
458 | +static | |
459 | +int | |
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) */ | |
465 | +{ | |
466 | + btr_pcur_t pcur; | |
467 | + const rec_t* rec; | |
468 | + mem_heap_t* heap; | |
469 | + mtr_t mtr; | |
470 | + | |
471 | + DBUG_ENTER("i_s_sys_tables_fill_table_stats"); | |
472 | + | |
473 | + /* deny access to non-superusers */ | |
474 | + if (check_global_access(thd, PROCESS_ACL)) { | |
475 | + | |
476 | + DBUG_RETURN(0); | |
477 | + } | |
478 | + | |
479 | + heap = mem_heap_create(1000); | |
480 | + mutex_enter(&dict_sys->mutex); | |
481 | + mtr_start(&mtr); | |
482 | + | |
483 | + rec = dict_startscan_system(&pcur, &mtr, SYS_TABLES); | |
484 | + | |
485 | + while (rec) { | |
486 | + const char* err_msg; | |
487 | + dict_table_t* table_rec; | |
488 | + | |
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); | |
493 | + | |
494 | + mtr_commit(&mtr); | |
495 | + mutex_exit(&dict_sys->mutex); | |
496 | + | |
497 | + if (!err_msg) { | |
498 | + i_s_dict_fill_sys_tablestats(thd, table_rec, | |
499 | + tables->table); | |
500 | + } else { | |
501 | + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, | |
502 | + ER_CANT_FIND_SYSTEM_REC, | |
503 | + err_msg); | |
504 | + } | |
505 | + | |
506 | + mem_heap_empty(heap); | |
507 | + | |
508 | + /* Get the next record */ | |
509 | + mutex_enter(&dict_sys->mutex); | |
510 | + mtr_start(&mtr); | |
511 | + rec = dict_getnext_system(&pcur, &mtr); | |
512 | + } | |
513 | + | |
514 | + mtr_commit(&mtr); | |
515 | + mutex_exit(&dict_sys->mutex); | |
516 | + mem_heap_free(heap); | |
517 | + | |
518 | + DBUG_RETURN(0); | |
519 | +} | |
520 | + | |
521 | +/*******************************************************************//** | |
522 | +Bind the dynamic table INFORMATION_SCHEMA.innodb_sys_tablestats | |
523 | +@return 0 on success */ | |
524 | +static | |
525 | +int | |
526 | +innodb_sys_tablestats_init( | |
527 | +/*=======================*/ | |
528 | + void* p) /*!< in/out: table schema object */ | |
529 | +{ | |
530 | + ST_SCHEMA_TABLE* schema; | |
531 | + | |
532 | + DBUG_ENTER("innodb_sys_tablestats_init"); | |
533 | + | |
534 | + schema = (ST_SCHEMA_TABLE*) p; | |
535 | + | |
536 | + schema->fields_info = innodb_sys_tablestats_fields_info; | |
537 | + schema->fill_table = i_s_sys_tables_fill_table_stats; | |
538 | + | |
539 | + DBUG_RETURN(0); | |
540 | +} | |
541 | + | |
542 | +UNIV_INTERN struct st_mysql_plugin i_s_innodb_sys_tablestats = | |
543 | +{ | |
544 | + /* the plugin type (a MYSQL_XXX_PLUGIN value) */ | |
545 | + /* int */ | |
546 | + STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN), | |
547 | + | |
548 | + /* pointer to type-specific plugin descriptor */ | |
549 | + /* void* */ | |
550 | + STRUCT_FLD(info, &i_s_info), | |
551 | + | |
552 | + /* plugin name */ | |
553 | + /* const char* */ | |
554 | + STRUCT_FLD(name, "INNODB_SYS_TABLESTATS"), | |
555 | + | |
556 | + /* plugin author (for SHOW PLUGINS) */ | |
557 | + /* const char* */ | |
558 | + STRUCT_FLD(author, plugin_author), | |
559 | + | |
560 | + /* general descriptive text (for SHOW PLUGINS) */ | |
561 | + /* const char* */ | |
562 | + STRUCT_FLD(descr, "InnoDB SYS_TABLESTATS"), | |
563 | + | |
564 | + /* the plugin license (PLUGIN_LICENSE_XXX) */ | |
565 | + /* int */ | |
566 | + STRUCT_FLD(license, PLUGIN_LICENSE_GPL), | |
567 | + | |
568 | + /* the function to invoke when plugin is loaded */ | |
569 | + /* int (*)(void*); */ | |
570 | + STRUCT_FLD(init, innodb_sys_tablestats_init), | |
571 | + | |
572 | + /* the function to invoke when plugin is unloaded */ | |
573 | + /* int (*)(void*); */ | |
574 | + STRUCT_FLD(deinit, i_s_common_deinit), | |
575 | + | |
576 | + /* plugin version (for SHOW PLUGINS) */ | |
577 | + /* unsigned int */ | |
578 | + STRUCT_FLD(version, INNODB_VERSION_SHORT), | |
579 | + | |
580 | + /* struct st_mysql_show_var* */ | |
581 | + STRUCT_FLD(status_vars, NULL), | |
582 | + | |
583 | + /* struct st_mysql_sys_var** */ | |
584 | + STRUCT_FLD(system_vars, NULL), | |
585 | + | |
586 | + /* reserved for dependency checking */ | |
587 | + /* void* */ | |
588 | + STRUCT_FLD(__reserved1, NULL) | |
589 | +}; | |
590 | + | |
591 | +/* Fields of the dynamic table INFORMATION_SCHEMA.SYS_INDEXES */ | |
592 | +static ST_FIELD_INFO innodb_sysindex_fields_info[] = | |
593 | +{ | |
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)}, | |
602 | + | |
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)}, | |
611 | + | |
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)}, | |
620 | + | |
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)}, | |
629 | + | |
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)}, | |
638 | + | |
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)}, | |
647 | + | |
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)}, | |
656 | + | |
657 | + END_OF_ST_FIELD_INFO | |
658 | +}; | |
659 | + | |
660 | +/**********************************************************************//** | |
661 | +Function to populate the information_schema.innodb_sys_indexes table with | |
662 | +collected index information | |
663 | +@return 0 on success */ | |
664 | +static | |
665 | +int | |
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 */ | |
673 | +{ | |
674 | + Field** fields; | |
675 | + | |
676 | + DBUG_ENTER("i_s_dict_fill_sys_indexes"); | |
677 | + | |
678 | + fields = table_to_fill->field; | |
679 | + | |
680 | + OK(fields[SYS_INDEX_ID]->store(longlong(index->id), TRUE)); | |
681 | + | |
682 | + OK(field_store_string(fields[SYS_INDEX_NAME], index->name)); | |
683 | + | |
684 | + OK(fields[SYS_INDEX_TABLE_ID]->store(longlong(table_id), TRUE)); | |
685 | + | |
686 | + OK(fields[SYS_INDEX_TYPE]->store(index->type)); | |
687 | + | |
688 | + OK(fields[SYS_INDEX_NUM_FIELDS]->store(index->n_fields)); | |
689 | + | |
690 | + OK(fields[SYS_INDEX_PAGE_NO]->store(index->page)); | |
691 | + | |
692 | + OK(fields[SYS_INDEX_SPACE]->store(index->space)); | |
693 | + | |
694 | + OK(schema_table_store_record(thd, table_to_fill)); | |
695 | + | |
696 | + DBUG_RETURN(0); | |
697 | +} | |
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 */ | |
702 | +static | |
703 | +int | |
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) */ | |
709 | +{ | |
710 | + btr_pcur_t pcur; | |
711 | + const rec_t* rec; | |
712 | + mem_heap_t* heap; | |
713 | + mtr_t mtr; | |
714 | + | |
715 | + DBUG_ENTER("i_s_sys_indexes_fill_table"); | |
716 | + | |
717 | + /* deny access to non-superusers */ | |
718 | + if (check_global_access(thd, PROCESS_ACL)) { | |
719 | + | |
720 | + DBUG_RETURN(0); | |
721 | + } | |
722 | + | |
723 | + heap = mem_heap_create(1000); | |
724 | + mutex_enter(&dict_sys->mutex); | |
725 | + mtr_start(&mtr); | |
726 | + | |
727 | + /* Start scan the SYS_INDEXES table */ | |
728 | + rec = dict_startscan_system(&pcur, &mtr, SYS_INDEXES); | |
729 | + | |
730 | + /* Process each record in the table */ | |
731 | + while (rec) { | |
732 | + const char* err_msg;; | |
733 | + table_id_t table_id; | |
734 | + dict_index_t index_rec; | |
735 | + | |
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, | |
739 | + &table_id); | |
740 | + | |
741 | + mtr_commit(&mtr); | |
742 | + mutex_exit(&dict_sys->mutex); | |
743 | + | |
744 | + if (!err_msg) { | |
745 | + i_s_dict_fill_sys_indexes(thd, table_id, &index_rec, | |
746 | + tables->table); | |
747 | + } else { | |
748 | + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, | |
749 | + ER_CANT_FIND_SYSTEM_REC, | |
750 | + err_msg); | |
751 | + } | |
752 | + | |
753 | + mem_heap_empty(heap); | |
754 | + | |
755 | + /* Get the next record */ | |
756 | + mutex_enter(&dict_sys->mutex); | |
757 | + mtr_start(&mtr); | |
758 | + rec = dict_getnext_system(&pcur, &mtr); | |
759 | + } | |
760 | + | |
761 | + mtr_commit(&mtr); | |
762 | + mutex_exit(&dict_sys->mutex); | |
763 | + mem_heap_free(heap); | |
764 | + | |
765 | + DBUG_RETURN(0); | |
766 | +} | |
767 | +/*******************************************************************//** | |
768 | +Bind the dynamic table INFORMATION_SCHEMA.innodb_sys_indexes | |
769 | +@return 0 on success */ | |
770 | +static | |
771 | +int | |
772 | +innodb_sys_indexes_init( | |
773 | +/*====================*/ | |
774 | + void* p) /*!< in/out: table schema object */ | |
775 | +{ | |
776 | + ST_SCHEMA_TABLE* schema; | |
777 | + | |
778 | + DBUG_ENTER("innodb_sys_index_init"); | |
779 | + | |
780 | + schema = (ST_SCHEMA_TABLE*) p; | |
781 | + | |
782 | + schema->fields_info = innodb_sysindex_fields_info; | |
783 | + schema->fill_table = i_s_sys_indexes_fill_table; | |
784 | + | |
785 | + DBUG_RETURN(0); | |
786 | +} | |
787 | + | |
788 | +UNIV_INTERN struct st_mysql_plugin i_s_innodb_sys_indexes = | |
789 | +{ | |
790 | + /* the plugin type (a MYSQL_XXX_PLUGIN value) */ | |
791 | + /* int */ | |
792 | + STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN), | |
793 | + | |
794 | + /* pointer to type-specific plugin descriptor */ | |
795 | + /* void* */ | |
796 | + STRUCT_FLD(info, &i_s_info), | |
797 | + | |
798 | + /* plugin name */ | |
799 | + /* const char* */ | |
800 | + STRUCT_FLD(name, "INNODB_SYS_INDEXES"), | |
801 | + | |
802 | + /* plugin author (for SHOW PLUGINS) */ | |
803 | + /* const char* */ | |
804 | + STRUCT_FLD(author, plugin_author), | |
805 | + | |
806 | + /* general descriptive text (for SHOW PLUGINS) */ | |
807 | + /* const char* */ | |
808 | + STRUCT_FLD(descr, "InnoDB SYS_INDEXES"), | |
809 | + | |
810 | + /* the plugin license (PLUGIN_LICENSE_XXX) */ | |
811 | + /* int */ | |
812 | + STRUCT_FLD(license, PLUGIN_LICENSE_GPL), | |
813 | + | |
814 | + /* the function to invoke when plugin is loaded */ | |
815 | + /* int (*)(void*); */ | |
816 | + STRUCT_FLD(init, innodb_sys_indexes_init), | |
817 | + | |
818 | + /* the function to invoke when plugin is unloaded */ | |
819 | + /* int (*)(void*); */ | |
820 | + STRUCT_FLD(deinit, i_s_common_deinit), | |
821 | + | |
822 | + /* plugin version (for SHOW PLUGINS) */ | |
823 | + /* unsigned int */ | |
824 | + STRUCT_FLD(version, INNODB_VERSION_SHORT), | |
825 | + | |
826 | + /* struct st_mysql_show_var* */ | |
827 | + STRUCT_FLD(status_vars, NULL), | |
828 | + | |
829 | + /* struct st_mysql_sys_var** */ | |
830 | + STRUCT_FLD(system_vars, NULL), | |
831 | + | |
832 | + /* reserved for dependency checking */ | |
833 | + /* void* */ | |
834 | + STRUCT_FLD(__reserved1, NULL) | |
835 | +}; | |
836 | + | |
837 | +/* Fields of the dynamic table INFORMATION_SCHEMA.SYS_COLUMNS */ | |
838 | +static ST_FIELD_INFO innodb_sys_columns_fields_info[] = | |
839 | +{ | |
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)}, | |
848 | + | |
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)}, | |
857 | + | |
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)}, | |
866 | + | |
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)}, | |
875 | + | |
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)}, | |
884 | + | |
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)}, | |
893 | + | |
894 | + END_OF_ST_FIELD_INFO | |
895 | +}; | |
896 | + | |
897 | +/**********************************************************************//** | |
898 | +Function to populate the information_schema.innodb_sys_columns with | |
899 | +related column information | |
900 | +@return 0 on success */ | |
901 | +static | |
902 | +int | |
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 */ | |
911 | +{ | |
912 | + Field** fields; | |
913 | + | |
914 | + DBUG_ENTER("i_s_dict_fill_sys_columns"); | |
915 | + | |
916 | + fields = table_to_fill->field; | |
917 | + | |
918 | + OK(fields[SYS_COLUMN_TABLE_ID]->store(longlong(table_id), TRUE)); | |
919 | + | |
920 | + OK(field_store_string(fields[SYS_COLUMN_NAME], col_name)); | |
921 | + | |
922 | + OK(fields[SYS_COLUMN_POSITION]->store(column->ind)); | |
923 | + | |
924 | + OK(fields[SYS_COLUMN_MTYPE]->store(column->mtype)); | |
925 | + | |
926 | + OK(fields[SYS_COLUMN__PRTYPE]->store(column->prtype)); | |
927 | + | |
928 | + OK(fields[SYS_COLUMN_COLUMN_LEN]->store(column->len)); | |
929 | + | |
930 | + OK(schema_table_store_record(thd, table_to_fill)); | |
931 | + | |
932 | + DBUG_RETURN(0); | |
933 | +} | |
934 | +/*******************************************************************//** | |
935 | +Function to fill information_schema.innodb_sys_columns with information | |
936 | +collected by scanning SYS_COLUMNS table. | |
937 | +@return 0 on success */ | |
938 | +static | |
939 | +int | |
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) */ | |
945 | +{ | |
946 | + btr_pcur_t pcur; | |
947 | + const rec_t* rec; | |
948 | + const char* col_name; | |
949 | + mem_heap_t* heap; | |
950 | + mtr_t mtr; | |
951 | + | |
952 | + DBUG_ENTER("i_s_sys_columns_fill_table"); | |
953 | + | |
954 | + /* deny access to non-superusers */ | |
955 | + if (check_global_access(thd, PROCESS_ACL)) { | |
956 | + | |
957 | + DBUG_RETURN(0); | |
958 | + } | |
959 | + | |
960 | + heap = mem_heap_create(1000); | |
961 | + mutex_enter(&dict_sys->mutex); | |
962 | + mtr_start(&mtr); | |
963 | + | |
964 | + rec = dict_startscan_system(&pcur, &mtr, SYS_COLUMNS); | |
965 | + | |
966 | + while (rec) { | |
967 | + const char* err_msg; | |
968 | + dict_col_t column_rec; | |
969 | + table_id_t table_id; | |
970 | + | |
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); | |
975 | + | |
976 | + mtr_commit(&mtr); | |
977 | + mutex_exit(&dict_sys->mutex); | |
978 | + | |
979 | + if (!err_msg) { | |
980 | + i_s_dict_fill_sys_columns(thd, table_id, col_name, | |
981 | + &column_rec, | |
982 | + tables->table); | |
983 | + } else { | |
984 | + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, | |
985 | + ER_CANT_FIND_SYSTEM_REC, | |
986 | + err_msg); | |
987 | + } | |
988 | + | |
989 | + mem_heap_empty(heap); | |
990 | + | |
991 | + /* Get the next record */ | |
992 | + mutex_enter(&dict_sys->mutex); | |
993 | + mtr_start(&mtr); | |
994 | + rec = dict_getnext_system(&pcur, &mtr); | |
995 | + } | |
996 | + | |
997 | + mtr_commit(&mtr); | |
998 | + mutex_exit(&dict_sys->mutex); | |
999 | + mem_heap_free(heap); | |
1000 | + | |
1001 | + DBUG_RETURN(0); | |
1002 | +} | |
1003 | +/*******************************************************************//** | |
1004 | +Bind the dynamic table INFORMATION_SCHEMA.innodb_sys_columns | |
1005 | +@return 0 on success */ | |
1006 | +static | |
1007 | +int | |
1008 | +innodb_sys_columns_init( | |
1009 | +/*====================*/ | |
1010 | + void* p) /*!< in/out: table schema object */ | |
1011 | +{ | |
1012 | + ST_SCHEMA_TABLE* schema; | |
1013 | + | |
1014 | + DBUG_ENTER("innodb_sys_columns_init"); | |
1015 | + | |
1016 | + schema = (ST_SCHEMA_TABLE*) p; | |
1017 | + | |
1018 | + schema->fields_info = innodb_sys_columns_fields_info; | |
1019 | + schema->fill_table = i_s_sys_columns_fill_table; | |
1020 | + | |
1021 | + DBUG_RETURN(0); | |
1022 | +} | |
1023 | + | |
1024 | +UNIV_INTERN struct st_mysql_plugin i_s_innodb_sys_columns = | |
1025 | +{ | |
1026 | + /* the plugin type (a MYSQL_XXX_PLUGIN value) */ | |
1027 | + /* int */ | |
1028 | + STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN), | |
1029 | + | |
1030 | + /* pointer to type-specific plugin descriptor */ | |
1031 | + /* void* */ | |
1032 | + STRUCT_FLD(info, &i_s_info), | |
1033 | + | |
1034 | + /* plugin name */ | |
1035 | + /* const char* */ | |
1036 | + STRUCT_FLD(name, "INNODB_SYS_COLUMNS"), | |
1037 | + | |
1038 | + /* plugin author (for SHOW PLUGINS) */ | |
1039 | + /* const char* */ | |
1040 | + STRUCT_FLD(author, plugin_author), | |
1041 | + | |
1042 | + /* general descriptive text (for SHOW PLUGINS) */ | |
1043 | + /* const char* */ | |
1044 | + STRUCT_FLD(descr, "InnoDB SYS_COLUMNS"), | |
1045 | + | |
1046 | + /* the plugin license (PLUGIN_LICENSE_XXX) */ | |
1047 | + /* int */ | |
1048 | + STRUCT_FLD(license, PLUGIN_LICENSE_GPL), | |
1049 | + | |
1050 | + /* the function to invoke when plugin is loaded */ | |
1051 | + /* int (*)(void*); */ | |
1052 | + STRUCT_FLD(init, innodb_sys_columns_init), | |
1053 | + | |
1054 | + /* the function to invoke when plugin is unloaded */ | |
1055 | + /* int (*)(void*); */ | |
1056 | + STRUCT_FLD(deinit, i_s_common_deinit), | |
1057 | + | |
1058 | + /* plugin version (for SHOW PLUGINS) */ | |
1059 | + /* unsigned int */ | |
1060 | + STRUCT_FLD(version, INNODB_VERSION_SHORT), | |
1061 | + | |
1062 | + /* struct st_mysql_show_var* */ | |
1063 | + STRUCT_FLD(status_vars, NULL), | |
1064 | + | |
1065 | + /* struct st_mysql_sys_var** */ | |
1066 | + STRUCT_FLD(system_vars, NULL), | |
1067 | + | |
1068 | + /* reserved for dependency checking */ | |
1069 | + /* void* */ | |
1070 | + STRUCT_FLD(__reserved1, NULL) | |
1071 | +}; | |
1072 | +/* Fields of the dynamic table INFORMATION_SCHEMA.innodb_sys_fields */ | |
1073 | +static ST_FIELD_INFO innodb_sys_fields_fields_info[] = | |
1074 | +{ | |
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)}, | |
1083 | + | |
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)}, | |
1092 | + | |
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)}, | |
1101 | + | |
1102 | + END_OF_ST_FIELD_INFO | |
1103 | +}; | |
1104 | + | |
1105 | +/**********************************************************************//** | |
1106 | +Function to fill information_schema.innodb_sys_fields with information | |
1107 | +collected by scanning SYS_FIELDS table. | |
1108 | +@return 0 on success */ | |
1109 | +static | |
1110 | +int | |
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 */ | |
1118 | +{ | |
1119 | + Field** fields; | |
1120 | + | |
1121 | + DBUG_ENTER("i_s_dict_fill_sys_fields"); | |
1122 | + | |
1123 | + fields = table_to_fill->field; | |
1124 | + | |
1125 | + OK(fields[SYS_FIELD_INDEX_ID]->store(longlong(index_id), TRUE)); | |
1126 | + | |
1127 | + OK(field_store_string(fields[SYS_FIELD_NAME], field->name)); | |
1128 | + | |
1129 | + OK(fields[SYS_FIELD_POS]->store(pos)); | |
1130 | + | |
1131 | + OK(schema_table_store_record(thd, table_to_fill)); | |
1132 | + | |
1133 | + DBUG_RETURN(0); | |
1134 | +} | |
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 | |
1138 | +information | |
1139 | +@return 0 on success */ | |
1140 | +static | |
1141 | +int | |
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) */ | |
1147 | +{ | |
1148 | + btr_pcur_t pcur; | |
1149 | + const rec_t* rec; | |
1150 | + mem_heap_t* heap; | |
1151 | + index_id_t last_id; | |
1152 | + mtr_t mtr; | |
1153 | + | |
1154 | + DBUG_ENTER("i_s_sys_fields_fill_table"); | |
1155 | + | |
1156 | + /* deny access to non-superusers */ | |
1157 | + if (check_global_access(thd, PROCESS_ACL)) { | |
1158 | + | |
1159 | + DBUG_RETURN(0); | |
1160 | + } | |
1161 | + | |
1162 | + heap = mem_heap_create(1000); | |
1163 | + mutex_enter(&dict_sys->mutex); | |
1164 | + mtr_start(&mtr); | |
1165 | + | |
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 */ | |
1168 | + last_id = 0; | |
1169 | + | |
1170 | + rec = dict_startscan_system(&pcur, &mtr, SYS_FIELDS); | |
1171 | + | |
1172 | + while (rec) { | |
1173 | + ulint pos; | |
1174 | + const char* err_msg; | |
1175 | + index_id_t index_id; | |
1176 | + dict_field_t field_rec; | |
1177 | + | |
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); | |
1182 | + | |
1183 | + mtr_commit(&mtr); | |
1184 | + mutex_exit(&dict_sys->mutex); | |
1185 | + | |
1186 | + if (!err_msg) { | |
1187 | + i_s_dict_fill_sys_fields(thd, index_id, &field_rec, | |
1188 | + pos, tables->table); | |
1189 | + last_id = index_id; | |
1190 | + } else { | |
1191 | + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, | |
1192 | + ER_CANT_FIND_SYSTEM_REC, | |
1193 | + err_msg); | |
1194 | + } | |
1195 | + | |
1196 | + mem_heap_empty(heap); | |
1197 | + | |
1198 | + /* Get the next record */ | |
1199 | + mutex_enter(&dict_sys->mutex); | |
1200 | + mtr_start(&mtr); | |
1201 | + rec = dict_getnext_system(&pcur, &mtr); | |
1202 | + } | |
1203 | + | |
1204 | + mtr_commit(&mtr); | |
1205 | + mutex_exit(&dict_sys->mutex); | |
1206 | + mem_heap_free(heap); | |
1207 | + | |
1208 | + DBUG_RETURN(0); | |
1209 | +} | |
1210 | +/*******************************************************************//** | |
1211 | +Bind the dynamic table INFORMATION_SCHEMA.innodb_sys_fields | |
1212 | +@return 0 on success */ | |
1213 | +static | |
1214 | +int | |
1215 | +innodb_sys_fields_init( | |
1216 | +/*===================*/ | |
1217 | + void* p) /*!< in/out: table schema object */ | |
1218 | +{ | |
1219 | + ST_SCHEMA_TABLE* schema; | |
1220 | + | |
1221 | + DBUG_ENTER("innodb_sys_field_init"); | |
1222 | + | |
1223 | + schema = (ST_SCHEMA_TABLE*) p; | |
1224 | + | |
1225 | + schema->fields_info = innodb_sys_fields_fields_info; | |
1226 | + schema->fill_table = i_s_sys_fields_fill_table; | |
1227 | + | |
1228 | + DBUG_RETURN(0); | |
1229 | +} | |
1230 | + | |
1231 | +UNIV_INTERN struct st_mysql_plugin i_s_innodb_sys_fields = | |
1232 | +{ | |
1233 | + /* the plugin type (a MYSQL_XXX_PLUGIN value) */ | |
1234 | + /* int */ | |
1235 | + STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN), | |
1236 | + | |
1237 | + /* pointer to type-specific plugin descriptor */ | |
1238 | + /* void* */ | |
1239 | + STRUCT_FLD(info, &i_s_info), | |
1240 | + | |
1241 | + /* plugin name */ | |
1242 | + /* const char* */ | |
1243 | + STRUCT_FLD(name, "INNODB_SYS_FIELDS"), | |
1244 | + | |
1245 | + /* plugin author (for SHOW PLUGINS) */ | |
1246 | + /* const char* */ | |
1247 | + STRUCT_FLD(author, plugin_author), | |
1248 | + | |
1249 | + /* general descriptive text (for SHOW PLUGINS) */ | |
1250 | + /* const char* */ | |
1251 | + STRUCT_FLD(descr, "InnoDB SYS_FIELDS"), | |
1252 | + | |
1253 | + /* the plugin license (PLUGIN_LICENSE_XXX) */ | |
1254 | + /* int */ | |
1255 | + STRUCT_FLD(license, PLUGIN_LICENSE_GPL), | |
1256 | + | |
1257 | + /* the function to invoke when plugin is loaded */ | |
1258 | + /* int (*)(void*); */ | |
1259 | + STRUCT_FLD(init, innodb_sys_fields_init), | |
1260 | + | |
1261 | + /* the function to invoke when plugin is unloaded */ | |
1262 | + /* int (*)(void*); */ | |
1263 | + STRUCT_FLD(deinit, i_s_common_deinit), | |
1264 | + | |
1265 | + /* plugin version (for SHOW PLUGINS) */ | |
1266 | + /* unsigned int */ | |
1267 | + STRUCT_FLD(version, INNODB_VERSION_SHORT), | |
1268 | + | |
1269 | + /* struct st_mysql_show_var* */ | |
1270 | + STRUCT_FLD(status_vars, NULL), | |
1271 | + | |
1272 | + /* struct st_mysql_sys_var** */ | |
1273 | + STRUCT_FLD(system_vars, NULL), | |
1274 | + | |
1275 | + /* reserved for dependency checking */ | |
1276 | + /* void* */ | |
1277 | + STRUCT_FLD(__reserved1, NULL) | |
1278 | +}; | |
1279 | + | |
1280 | +/* Fields of the dynamic table INFORMATION_SCHEMA.innodb_sys_foreign */ | |
1281 | +static ST_FIELD_INFO innodb_sys_foreign_fields_info[] = | |
1282 | +{ | |
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)}, | |
1291 | + | |
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)}, | |
1300 | + | |
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)}, | |
1309 | + | |
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)}, | |
1318 | + | |
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)}, | |
1327 | + | |
1328 | + END_OF_ST_FIELD_INFO | |
1329 | +}; | |
1330 | + | |
1331 | +/**********************************************************************//** | |
1332 | +Function to fill information_schema.innodb_sys_foreign with information | |
1333 | +collected by scanning SYS_FOREIGN table. | |
1334 | +@return 0 on success */ | |
1335 | +static | |
1336 | +int | |
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 */ | |
1342 | +{ | |
1343 | + Field** fields; | |
1344 | + | |
1345 | + DBUG_ENTER("i_s_dict_fill_sys_foreign"); | |
1346 | + | |
1347 | + fields = table_to_fill->field; | |
1348 | + | |
1349 | + OK(field_store_string(fields[SYS_FOREIGN_ID], foreign->id)); | |
1350 | + | |
1351 | + OK(field_store_string(fields[SYS_FOREIGN_FOR_NAME], | |
1352 | + foreign->foreign_table_name)); | |
1353 | + | |
1354 | + OK(field_store_string(fields[SYS_FOREIGN_REF_NAME], | |
1355 | + foreign->referenced_table_name)); | |
1356 | + | |
1357 | + OK(fields[SYS_FOREIGN_NUM_COL]->store(foreign->n_fields)); | |
1358 | + | |
1359 | + OK(fields[SYS_FOREIGN_TYPE]->store(foreign->type)); | |
1360 | + | |
1361 | + OK(schema_table_store_record(thd, table_to_fill)); | |
1362 | + | |
1363 | + DBUG_RETURN(0); | |
1364 | +} | |
1365 | +/*******************************************************************//** | |
1366 | +Function to populate INFORMATION_SCHEMA.innodb_sys_foreign table. Loop | |
1367 | +through each record in SYS_FOREIGN, and extract the foreign key | |
1368 | +information. | |
1369 | +@return 0 on success */ | |
1370 | +static | |
1371 | +int | |
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) */ | |
1377 | +{ | |
1378 | + btr_pcur_t pcur; | |
1379 | + const rec_t* rec; | |
1380 | + mem_heap_t* heap; | |
1381 | + mtr_t mtr; | |
1382 | + | |
1383 | + DBUG_ENTER("i_s_sys_foreign_fill_table"); | |
1384 | + | |
1385 | + /* deny access to non-superusers */ | |
1386 | + if (check_global_access(thd, PROCESS_ACL)) { | |
1387 | + | |
1388 | + DBUG_RETURN(0); | |
1389 | + } | |
1390 | + | |
1391 | + heap = mem_heap_create(1000); | |
1392 | + mutex_enter(&dict_sys->mutex); | |
1393 | + mtr_start(&mtr); | |
1394 | + | |
1395 | + rec = dict_startscan_system(&pcur, &mtr, SYS_FOREIGN); | |
1396 | + | |
1397 | + while (rec) { | |
1398 | + const char* err_msg; | |
1399 | + dict_foreign_t foreign_rec; | |
1400 | + | |
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); | |
1404 | + | |
1405 | + mtr_commit(&mtr); | |
1406 | + mutex_exit(&dict_sys->mutex); | |
1407 | + | |
1408 | + if (!err_msg) { | |
1409 | + i_s_dict_fill_sys_foreign(thd, &foreign_rec, | |
1410 | + tables->table); | |
1411 | + } else { | |
1412 | + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, | |
1413 | + ER_CANT_FIND_SYSTEM_REC, | |
1414 | + err_msg); | |
1415 | + } | |
1416 | + | |
1417 | + mem_heap_empty(heap); | |
1418 | + | |
1419 | + /* Get the next record */ | |
1420 | + mtr_start(&mtr); | |
1421 | + mutex_enter(&dict_sys->mutex); | |
1422 | + rec = dict_getnext_system(&pcur, &mtr); | |
1423 | + } | |
1424 | + | |
1425 | + mtr_commit(&mtr); | |
1426 | + mutex_exit(&dict_sys->mutex); | |
1427 | + mem_heap_free(heap); | |
1428 | + | |
1429 | + DBUG_RETURN(0); | |
1430 | +} | |
1431 | +/*******************************************************************//** | |
1432 | +Bind the dynamic table INFORMATION_SCHEMA.innodb_sys_foreign | |
1433 | +@return 0 on success */ | |
1434 | +static | |
1435 | +int | |
1436 | +innodb_sys_foreign_init( | |
1437 | +/*====================*/ | |
1438 | + void* p) /*!< in/out: table schema object */ | |
1439 | +{ | |
1440 | + ST_SCHEMA_TABLE* schema; | |
1441 | + | |
1442 | + DBUG_ENTER("innodb_sys_foreign_init"); | |
1443 | + | |
1444 | + schema = (ST_SCHEMA_TABLE*) p; | |
1445 | + | |
1446 | + schema->fields_info = innodb_sys_foreign_fields_info; | |
1447 | + schema->fill_table = i_s_sys_foreign_fill_table; | |
1448 | + | |
1449 | + DBUG_RETURN(0); | |
1450 | +} | |
1451 | + | |
1452 | +UNIV_INTERN struct st_mysql_plugin i_s_innodb_sys_foreign = | |
1453 | +{ | |
1454 | + /* the plugin type (a MYSQL_XXX_PLUGIN value) */ | |
1455 | + /* int */ | |
1456 | + STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN), | |
1457 | + | |
1458 | + /* pointer to type-specific plugin descriptor */ | |
1459 | + /* void* */ | |
1460 | + STRUCT_FLD(info, &i_s_info), | |
1461 | + | |
1462 | + /* plugin name */ | |
1463 | + /* const char* */ | |
1464 | + STRUCT_FLD(name, "INNODB_SYS_FOREIGN"), | |
1465 | + | |
1466 | + /* plugin author (for SHOW PLUGINS) */ | |
1467 | + /* const char* */ | |
1468 | + STRUCT_FLD(author, plugin_author), | |
1469 | + | |
1470 | + /* general descriptive text (for SHOW PLUGINS) */ | |
1471 | + /* const char* */ | |
1472 | + STRUCT_FLD(descr, "InnoDB SYS_FOREIGN"), | |
1473 | + | |
1474 | + /* the plugin license (PLUGIN_LICENSE_XXX) */ | |
1475 | + /* int */ | |
1476 | + STRUCT_FLD(license, PLUGIN_LICENSE_GPL), | |
1477 | + | |
1478 | + /* the function to invoke when plugin is loaded */ | |
1479 | + /* int (*)(void*); */ | |
1480 | + STRUCT_FLD(init, innodb_sys_foreign_init), | |
1481 | + | |
1482 | + /* the function to invoke when plugin is unloaded */ | |
1483 | + /* int (*)(void*); */ | |
1484 | + STRUCT_FLD(deinit, i_s_common_deinit), | |
1485 | + | |
1486 | + /* plugin version (for SHOW PLUGINS) */ | |
1487 | + /* unsigned int */ | |
1488 | + STRUCT_FLD(version, INNODB_VERSION_SHORT), | |
1489 | + | |
1490 | + /* struct st_mysql_show_var* */ | |
1491 | + STRUCT_FLD(status_vars, NULL), | |
1492 | + | |
1493 | + /* struct st_mysql_sys_var** */ | |
1494 | + STRUCT_FLD(system_vars, NULL), | |
1495 | + | |
1496 | + /* reserved for dependency checking */ | |
1497 | + /* void* */ | |
1498 | + STRUCT_FLD(__reserved1, NULL) | |
1499 | +}; | |
1500 | +/* Fields of the dynamic table INFORMATION_SCHEMA.innodb_sys_foreign_cols */ | |
1501 | +static ST_FIELD_INFO innodb_sys_foreign_cols_fields_info[] = | |
1502 | +{ | |
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)}, | |
1511 | + | |
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)}, | |
1520 | + | |
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)}, | |
1529 | + | |
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)}, | |
1538 | + | |
1539 | + END_OF_ST_FIELD_INFO | |
1540 | +}; | |
1541 | + | |
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 */ | |
1546 | +static | |
1547 | +int | |
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 | |
1554 | + name */ | |
1555 | + ulint pos, /*!< in: column position */ | |
1556 | + TABLE* table_to_fill) /*!< in/out: fill this table */ | |
1557 | +{ | |
1558 | + Field** fields; | |
1559 | + | |
1560 | + DBUG_ENTER("i_s_dict_fill_sys_foreign_cols"); | |
1561 | + | |
1562 | + fields = table_to_fill->field; | |
1563 | + | |
1564 | + OK(field_store_string(fields[SYS_FOREIGN_COL_ID], name)); | |
1565 | + | |
1566 | + OK(field_store_string(fields[SYS_FOREIGN_COL_FOR_NAME], for_col_name)); | |
1567 | + | |
1568 | + OK(field_store_string(fields[SYS_FOREIGN_COL_REF_NAME], ref_col_name)); | |
1569 | + | |
1570 | + OK(fields[SYS_FOREIGN_COL_POS]->store(pos)); | |
1571 | + | |
1572 | + OK(schema_table_store_record(thd, table_to_fill)); | |
1573 | + | |
1574 | + DBUG_RETURN(0); | |
1575 | +} | |
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 */ | |
1581 | +static | |
1582 | +int | |
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) */ | |
1588 | +{ | |
1589 | + btr_pcur_t pcur; | |
1590 | + const rec_t* rec; | |
1591 | + mem_heap_t* heap; | |
1592 | + mtr_t mtr; | |
1593 | + | |
1594 | + DBUG_ENTER("i_s_sys_foreign_cols_fill_table"); | |
1595 | + | |
1596 | + /* deny access to non-superusers */ | |
1597 | + if (check_global_access(thd, PROCESS_ACL)) { | |
1598 | + DBUG_RETURN(0); | |
1599 | + } | |
1600 | + | |
1601 | + heap = mem_heap_create(1000); | |
1602 | + mutex_enter(&dict_sys->mutex); | |
1603 | + mtr_start(&mtr); | |
1604 | + | |
1605 | + rec = dict_startscan_system(&pcur, &mtr, SYS_FOREIGN_COLS); | |
1606 | + | |
1607 | + while (rec) { | |
1608 | + const char* err_msg; | |
1609 | + const char* name; | |
1610 | + const char* for_col_name; | |
1611 | + const char* ref_col_name; | |
1612 | + ulint pos; | |
1613 | + | |
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); | |
1617 | + | |
1618 | + mtr_commit(&mtr); | |
1619 | + mutex_exit(&dict_sys->mutex); | |
1620 | + | |
1621 | + if (!err_msg) { | |
1622 | + i_s_dict_fill_sys_foreign_cols( | |
1623 | + thd, name, for_col_name, ref_col_name, pos, | |
1624 | + tables->table); | |
1625 | + } else { | |
1626 | + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, | |
1627 | + ER_CANT_FIND_SYSTEM_REC, | |
1628 | + err_msg); | |
1629 | + } | |
1630 | + | |
1631 | + mem_heap_empty(heap); | |
1632 | + | |
1633 | + /* Get the next record */ | |
1634 | + mutex_enter(&dict_sys->mutex); | |
1635 | + mtr_start(&mtr); | |
1636 | + rec = dict_getnext_system(&pcur, &mtr); | |
1637 | + } | |
1638 | + | |
1639 | + mtr_commit(&mtr); | |
1640 | + mutex_exit(&dict_sys->mutex); | |
1641 | + mem_heap_free(heap); | |
1642 | + | |
1643 | + DBUG_RETURN(0); | |
1644 | +} | |
1645 | +/*******************************************************************//** | |
1646 | +Bind the dynamic table INFORMATION_SCHEMA.innodb_sys_foreign_cols | |
1647 | +@return 0 on success */ | |
1648 | +static | |
1649 | +int | |
1650 | +innodb_sys_foreign_cols_init( | |
1651 | +/*========================*/ | |
1652 | + void* p) /*!< in/out: table schema object */ | |
1653 | +{ | |
1654 | + ST_SCHEMA_TABLE* schema; | |
1655 | + | |
1656 | + DBUG_ENTER("innodb_sys_foreign_cols_init"); | |
1657 | + | |
1658 | + schema = (ST_SCHEMA_TABLE*) p; | |
1659 | + | |
1660 | + schema->fields_info = innodb_sys_foreign_cols_fields_info; | |
1661 | + schema->fill_table = i_s_sys_foreign_cols_fill_table; | |
1662 | + | |
1663 | + DBUG_RETURN(0); | |
1664 | +} | |
1665 | + | |
1666 | +UNIV_INTERN struct st_mysql_plugin i_s_innodb_sys_foreign_cols = | |
1667 | +{ | |
1668 | + /* the plugin type (a MYSQL_XXX_PLUGIN value) */ | |
1669 | + /* int */ | |
1670 | + STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN), | |
1671 | + | |
1672 | + /* pointer to type-specific plugin descriptor */ | |
1673 | + /* void* */ | |
1674 | + STRUCT_FLD(info, &i_s_info), | |
1675 | + | |
1676 | + /* plugin name */ | |
1677 | + /* const char* */ | |
1678 | + STRUCT_FLD(name, "INNODB_SYS_FOREIGN_COLS"), | |
1679 | + | |
1680 | + /* plugin author (for SHOW PLUGINS) */ | |
1681 | + /* const char* */ | |
1682 | + STRUCT_FLD(author, plugin_author), | |
1683 | + | |
1684 | + /* general descriptive text (for SHOW PLUGINS) */ | |
1685 | + /* const char* */ | |
1686 | + STRUCT_FLD(descr, "InnoDB SYS_FOREIGN_COLS"), | |
1687 | + | |
1688 | + /* the plugin license (PLUGIN_LICENSE_XXX) */ | |
1689 | + /* int */ | |
1690 | + STRUCT_FLD(license, PLUGIN_LICENSE_GPL), | |
1691 | + | |
1692 | + /* the function to invoke when plugin is loaded */ | |
1693 | + /* int (*)(void*); */ | |
1694 | + STRUCT_FLD(init, innodb_sys_foreign_cols_init), | |
1695 | + | |
1696 | + /* the function to invoke when plugin is unloaded */ | |
1697 | + /* int (*)(void*); */ | |
1698 | + STRUCT_FLD(deinit, i_s_common_deinit), | |
1699 | + | |
1700 | + /* plugin version (for SHOW PLUGINS) */ | |
1701 | + /* unsigned int */ | |
1702 | + STRUCT_FLD(version, INNODB_VERSION_SHORT), | |
1703 | + | |
1704 | + /* struct st_mysql_show_var* */ | |
1705 | + STRUCT_FLD(status_vars, NULL), | |
1706 | + | |
1707 | + /* struct st_mysql_sys_var** */ | |
1708 | + STRUCT_FLD(system_vars, NULL), | |
1709 | + | |
1710 | + /* reserved for dependency checking */ | |
1711 | + /* void* */ | |
1712 | + STRUCT_FLD(__reserved1, NULL) | |
1713 | +}; | |
1714 | + | |
1715 | /*********************************************************************** | |
1716 | */ | |
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 | |
1721 | @@ -33,6 +33,13 @@ | |
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; | |
1733 | ||
1734 | #endif /* i_s_h */ |