~percona-core/percona-server/5.1

« back to all changes in this revision

Viewing changes to patches/innodb_show_sys_tables.patch

  • Committer: Stewart Smith
  • Date: 2011-11-24 08:14:40 UTC
  • Revision ID: stewart@flamingspork.com-20111124081440-jffloqgkbgytzgl5
remove now unneeded patches as we're part of a happy bzr tree

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# name       : innodb_show_sys_tables.patch
2
 
# introduced : 11 or before
3
 
# maintainer : Yasufumi
4
 
#
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/innodb_plugin/handler/ha_innodb.cc
9
 
+++ b/storage/innodb_plugin/handler/ha_innodb.cc
10
 
@@ -11874,6 +11874,9 @@
11
 
 i_s_innodb_table_stats,
12
 
 i_s_innodb_index_stats,
13
 
 i_s_innodb_admin_command,
14
 
+i_s_innodb_sys_tables,
15
 
+i_s_innodb_sys_indexes,
16
 
+i_s_innodb_sys_stats,
17
 
 i_s_innodb_patches
18
 
 mysql_declare_plugin_end;
19
 
 
20
 
--- a/storage/innodb_plugin/handler/i_s.cc
21
 
+++ b/storage/innodb_plugin/handler/i_s.cc
22
 
@@ -46,6 +46,7 @@
23
 
 #include "trx0rseg.h" /* for trx_rseg_struct */
24
 
 #include "trx0sys.h" /* for trx_sys */
25
 
 #include "dict0dict.h" /* for dict_sys */
26
 
+#include "btr0pcur.h"
27
 
 #include "buf0lru.h" /* for XTRA_LRU_[DUMP/RESTORE] */
28
 
 }
29
 
 
30
 
@@ -3114,3 +3115,671 @@
31
 
        STRUCT_FLD(system_vars, NULL),
32
 
        STRUCT_FLD(__reserved1, NULL)
33
 
 };
34
 
+
35
 
+static ST_FIELD_INFO   i_s_innodb_sys_tables_info[] =
36
 
+{
37
 
+       {STRUCT_FLD(field_name,         "SCHEMA"),
38
 
+        STRUCT_FLD(field_length,       NAME_LEN),
39
 
+        STRUCT_FLD(field_type,         MYSQL_TYPE_STRING),
40
 
+        STRUCT_FLD(value,              0),
41
 
+        STRUCT_FLD(field_flags,        0),
42
 
+        STRUCT_FLD(old_name,           ""),
43
 
+        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
44
 
+
45
 
+       {STRUCT_FLD(field_name,         "NAME"),
46
 
+        STRUCT_FLD(field_length,       NAME_LEN),
47
 
+        STRUCT_FLD(field_type,         MYSQL_TYPE_STRING),
48
 
+        STRUCT_FLD(value,              0),
49
 
+        STRUCT_FLD(field_flags,        0),
50
 
+        STRUCT_FLD(old_name,           ""),
51
 
+        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
52
 
+
53
 
+       {STRUCT_FLD(field_name,         "ID"),
54
 
+        STRUCT_FLD(field_length,       MY_INT64_NUM_DECIMAL_DIGITS),
55
 
+        STRUCT_FLD(field_type,         MYSQL_TYPE_LONGLONG),
56
 
+        STRUCT_FLD(value,              0),
57
 
+        STRUCT_FLD(field_flags,        MY_I_S_UNSIGNED),
58
 
+        STRUCT_FLD(old_name,           ""),
59
 
+        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
60
 
+
61
 
+       {STRUCT_FLD(field_name,         "N_COLS"),
62
 
+        STRUCT_FLD(field_length,       MY_INT64_NUM_DECIMAL_DIGITS),
63
 
+        STRUCT_FLD(field_type,         MYSQL_TYPE_LONGLONG),
64
 
+        STRUCT_FLD(value,              0),
65
 
+        STRUCT_FLD(field_flags,        MY_I_S_UNSIGNED),
66
 
+        STRUCT_FLD(old_name,           ""),
67
 
+        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
68
 
+
69
 
+       {STRUCT_FLD(field_name,         "TYPE"),
70
 
+        STRUCT_FLD(field_length,       MY_INT64_NUM_DECIMAL_DIGITS),
71
 
+        STRUCT_FLD(field_type,         MYSQL_TYPE_LONGLONG),
72
 
+        STRUCT_FLD(value,              0),
73
 
+        STRUCT_FLD(field_flags,        MY_I_S_UNSIGNED),
74
 
+        STRUCT_FLD(old_name,           ""),
75
 
+        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
76
 
+
77
 
+       {STRUCT_FLD(field_name,         "MIX_ID"),
78
 
+        STRUCT_FLD(field_length,       MY_INT64_NUM_DECIMAL_DIGITS),
79
 
+        STRUCT_FLD(field_type,         MYSQL_TYPE_LONGLONG),
80
 
+        STRUCT_FLD(value,              0),
81
 
+        STRUCT_FLD(field_flags,        MY_I_S_UNSIGNED),
82
 
+        STRUCT_FLD(old_name,           ""),
83
 
+        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
84
 
+
85
 
+       {STRUCT_FLD(field_name,         "MIX_LEN"),
86
 
+        STRUCT_FLD(field_length,       MY_INT64_NUM_DECIMAL_DIGITS),
87
 
+        STRUCT_FLD(field_type,         MYSQL_TYPE_LONGLONG),
88
 
+        STRUCT_FLD(value,              0),
89
 
+        STRUCT_FLD(field_flags,        MY_I_S_UNSIGNED),
90
 
+        STRUCT_FLD(old_name,           ""),
91
 
+        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
92
 
+
93
 
+       {STRUCT_FLD(field_name,         "CLUSTER_NAME"),
94
 
+        STRUCT_FLD(field_length,       NAME_LEN),
95
 
+        STRUCT_FLD(field_type,         MYSQL_TYPE_STRING),
96
 
+        STRUCT_FLD(value,              0),
97
 
+        STRUCT_FLD(field_flags,        0),
98
 
+        STRUCT_FLD(old_name,           ""),
99
 
+        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
100
 
+
101
 
+       {STRUCT_FLD(field_name,         "SPACE"),
102
 
+        STRUCT_FLD(field_length,       MY_INT64_NUM_DECIMAL_DIGITS),
103
 
+        STRUCT_FLD(field_type,         MYSQL_TYPE_LONGLONG),
104
 
+        STRUCT_FLD(value,              0),
105
 
+        STRUCT_FLD(field_flags,        MY_I_S_UNSIGNED),
106
 
+        STRUCT_FLD(old_name,           ""),
107
 
+        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
108
 
+
109
 
+        END_OF_ST_FIELD_INFO
110
 
+};
111
 
+
112
 
+static ST_FIELD_INFO   i_s_innodb_sys_indexes_info[] =
113
 
+{
114
 
+       {STRUCT_FLD(field_name,         "TABLE_ID"),
115
 
+        STRUCT_FLD(field_length,       MY_INT64_NUM_DECIMAL_DIGITS),
116
 
+        STRUCT_FLD(field_type,         MYSQL_TYPE_LONGLONG),
117
 
+        STRUCT_FLD(value,              0),
118
 
+        STRUCT_FLD(field_flags,        MY_I_S_UNSIGNED),
119
 
+        STRUCT_FLD(old_name,           ""),
120
 
+        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
121
 
+
122
 
+       {STRUCT_FLD(field_name,         "ID"),
123
 
+        STRUCT_FLD(field_length,       MY_INT64_NUM_DECIMAL_DIGITS),
124
 
+        STRUCT_FLD(field_type,         MYSQL_TYPE_LONGLONG),
125
 
+        STRUCT_FLD(value,              0),
126
 
+        STRUCT_FLD(field_flags,        MY_I_S_UNSIGNED),
127
 
+        STRUCT_FLD(old_name,           ""),
128
 
+        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
129
 
+
130
 
+       {STRUCT_FLD(field_name,         "NAME"),
131
 
+        STRUCT_FLD(field_length,       NAME_LEN),
132
 
+        STRUCT_FLD(field_type,         MYSQL_TYPE_STRING),
133
 
+        STRUCT_FLD(value,              0),
134
 
+        STRUCT_FLD(field_flags,        0),
135
 
+        STRUCT_FLD(old_name,           ""),
136
 
+        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
137
 
+
138
 
+       {STRUCT_FLD(field_name,         "N_FIELDS"),
139
 
+        STRUCT_FLD(field_length,       MY_INT64_NUM_DECIMAL_DIGITS),
140
 
+        STRUCT_FLD(field_type,         MYSQL_TYPE_LONGLONG),
141
 
+        STRUCT_FLD(value,              0),
142
 
+        STRUCT_FLD(field_flags,        MY_I_S_UNSIGNED),
143
 
+        STRUCT_FLD(old_name,           ""),
144
 
+        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
145
 
+
146
 
+       {STRUCT_FLD(field_name,         "TYPE"),
147
 
+        STRUCT_FLD(field_length,       MY_INT64_NUM_DECIMAL_DIGITS),
148
 
+        STRUCT_FLD(field_type,         MYSQL_TYPE_LONGLONG),
149
 
+        STRUCT_FLD(value,              0),
150
 
+        STRUCT_FLD(field_flags,        MY_I_S_UNSIGNED),
151
 
+        STRUCT_FLD(old_name,           ""),
152
 
+        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
153
 
+
154
 
+       {STRUCT_FLD(field_name,         "SPACE"),
155
 
+        STRUCT_FLD(field_length,       MY_INT64_NUM_DECIMAL_DIGITS),
156
 
+        STRUCT_FLD(field_type,         MYSQL_TYPE_LONGLONG),
157
 
+        STRUCT_FLD(value,              0),
158
 
+        STRUCT_FLD(field_flags,        MY_I_S_UNSIGNED),
159
 
+        STRUCT_FLD(old_name,           ""),
160
 
+        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
161
 
+
162
 
+       {STRUCT_FLD(field_name,         "PAGE_NO"),
163
 
+        STRUCT_FLD(field_length,       MY_INT64_NUM_DECIMAL_DIGITS),
164
 
+        STRUCT_FLD(field_type,         MYSQL_TYPE_LONGLONG),
165
 
+        STRUCT_FLD(value,              0),
166
 
+        STRUCT_FLD(field_flags,        MY_I_S_UNSIGNED),
167
 
+        STRUCT_FLD(old_name,           ""),
168
 
+        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
169
 
+
170
 
+        END_OF_ST_FIELD_INFO
171
 
+};
172
 
+
173
 
+static ST_FIELD_INFO   i_s_innodb_sys_stats_info[] =
174
 
+{
175
 
+       {STRUCT_FLD(field_name,         "INDEX_ID"),
176
 
+        STRUCT_FLD(field_length,       MY_INT64_NUM_DECIMAL_DIGITS),
177
 
+        STRUCT_FLD(field_type,         MYSQL_TYPE_LONGLONG),
178
 
+        STRUCT_FLD(value,              0),
179
 
+        STRUCT_FLD(field_flags,        MY_I_S_UNSIGNED),
180
 
+        STRUCT_FLD(old_name,           ""),
181
 
+        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
182
 
+
183
 
+       {STRUCT_FLD(field_name,         "KEY_COLS"),
184
 
+        STRUCT_FLD(field_length,       MY_INT64_NUM_DECIMAL_DIGITS),
185
 
+        STRUCT_FLD(field_type,         MYSQL_TYPE_LONGLONG),
186
 
+        STRUCT_FLD(value,              0),
187
 
+        STRUCT_FLD(field_flags,        MY_I_S_UNSIGNED),
188
 
+        STRUCT_FLD(old_name,           ""),
189
 
+        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
190
 
+
191
 
+       {STRUCT_FLD(field_name,         "DIFF_VALS"),
192
 
+        STRUCT_FLD(field_length,       MY_INT64_NUM_DECIMAL_DIGITS),
193
 
+        STRUCT_FLD(field_type,         MYSQL_TYPE_LONGLONG),
194
 
+        STRUCT_FLD(value,              0),
195
 
+        STRUCT_FLD(field_flags,        MY_I_S_UNSIGNED),
196
 
+        STRUCT_FLD(old_name,           ""),
197
 
+        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
198
 
+
199
 
+       {STRUCT_FLD(field_name,         "NON_NULL_VALS"),
200
 
+        STRUCT_FLD(field_length,       MY_INT64_NUM_DECIMAL_DIGITS),
201
 
+        STRUCT_FLD(field_type,         MYSQL_TYPE_LONGLONG),
202
 
+        STRUCT_FLD(value,              0),
203
 
+        STRUCT_FLD(field_flags,        MY_I_S_UNSIGNED | MY_I_S_MAYBE_NULL),
204
 
+        STRUCT_FLD(old_name,           ""),
205
 
+        STRUCT_FLD(open_method,        SKIP_OPEN_TABLE)},
206
 
+
207
 
+       END_OF_ST_FIELD_INFO
208
 
+};
209
 
+
210
 
+static
211
 
+int
212
 
+copy_string_field(
213
 
+/*==============*/
214
 
+       TABLE*                  table,
215
 
+       int                     table_field,
216
 
+       const rec_t*            rec,
217
 
+       int                     rec_field)
218
 
+{
219
 
+       int             status;
220
 
+       const byte*     data;
221
 
+       ulint           len;
222
 
+
223
 
+       /*fprintf(stderr, "copy_string_field %d %d\n", table_field, rec_field);*/
224
 
+
225
 
+       data = rec_get_nth_field_old(rec, rec_field, &len);
226
 
+       if (len == UNIV_SQL_NULL) {
227
 
+               table->field[table_field]->set_null();
228
 
+               status = 0; /* success */
229
 
+       } else {
230
 
+               table->field[table_field]->set_notnull();
231
 
+               status = table->field[table_field]->store(
232
 
+                       (char *) data, len, system_charset_info);
233
 
+       }
234
 
+
235
 
+       return status;
236
 
+}
237
 
+
238
 
+static
239
 
+int
240
 
+copy_name_fields(
241
 
+/*=============*/
242
 
+       TABLE*                  table,
243
 
+       int                     table_field_1,
244
 
+       const rec_t*            rec,
245
 
+       int                     rec_field)
246
 
+{
247
 
+       int             status;
248
 
+       const byte*     data;
249
 
+       ulint           len;
250
 
+
251
 
+       data = rec_get_nth_field_old(rec, rec_field, &len);
252
 
+       if (len == UNIV_SQL_NULL) {
253
 
+               table->field[table_field_1]->set_null();
254
 
+               table->field[table_field_1 + 1]->set_null();
255
 
+               status = 0; /* success */
256
 
+       } else {
257
 
+               char    buf[NAME_LEN * 2 + 2];
258
 
+               char*   ptr;
259
 
+
260
 
+               if (len > NAME_LEN * 2 + 1) {
261
 
+                       table->field[table_field_1]->set_null();
262
 
+                       status = field_store_string(table->field[table_field_1 + 1],
263
 
+                                                   "###TOO LONG NAME###");
264
 
+                       goto end_func;
265
 
+               }
266
 
+
267
 
+               strncpy(buf, (char*)data, len);
268
 
+               buf[len] = '\0';
269
 
+               ptr = strchr(buf, '/');
270
 
+               if (ptr) {
271
 
+                       *ptr = '\0';
272
 
+                       ++ptr;
273
 
+
274
 
+                       status = field_store_string(table->field[table_field_1], buf);
275
 
+                       status |= field_store_string(table->field[table_field_1 + 1], ptr);
276
 
+               } else {
277
 
+                       table->field[table_field_1]->set_null();
278
 
+                       status = field_store_string(table->field[table_field_1 + 1], buf);
279
 
+               }
280
 
+       }
281
 
+
282
 
+end_func:
283
 
+       return status;
284
 
+}
285
 
+
286
 
+static
287
 
+int
288
 
+copy_int_field(
289
 
+/*===========*/
290
 
+       TABLE*                  table,
291
 
+       int                     table_field,
292
 
+       const rec_t*            rec,
293
 
+       int                     rec_field)
294
 
+{
295
 
+       int             status;
296
 
+       const byte*     data;
297
 
+       ulint           len;
298
 
+
299
 
+       /*fprintf(stderr, "copy_int_field %d %d\n", table_field, rec_field);*/
300
 
+
301
 
+       data = rec_get_nth_field_old(rec, rec_field, &len);
302
 
+       if (len == UNIV_SQL_NULL) {
303
 
+               table->field[table_field]->set_null();
304
 
+               status = 0; /* success */
305
 
+       } else {
306
 
+               table->field[table_field]->set_notnull();
307
 
+               status = table->field[table_field]->store(
308
 
+                       mach_read_from_4(data), true);
309
 
+       }
310
 
+
311
 
+       return status;
312
 
+}
313
 
+
314
 
+static
315
 
+int
316
 
+copy_id_field(
317
 
+/*==========*/
318
 
+       TABLE*                  table,
319
 
+       int                     table_field,
320
 
+       const rec_t*            rec,
321
 
+       int                     rec_field)
322
 
+{
323
 
+       int             status;
324
 
+       const byte*     data;
325
 
+       ulint           len;
326
 
+
327
 
+       /*fprintf(stderr, "copy_id_field %d %d\n", table_field, rec_field);*/
328
 
+
329
 
+       data = rec_get_nth_field_old(rec, rec_field, &len);
330
 
+       if (len == UNIV_SQL_NULL) {
331
 
+               table->field[table_field]->set_null();
332
 
+               status = 0; /* success */
333
 
+       } else {
334
 
+               table->field[table_field]->set_notnull();
335
 
+               status = table->field[table_field]->store(
336
 
+                       ut_conv_dulint_to_longlong(mach_read_from_8(data)), true);
337
 
+       }
338
 
+
339
 
+       return status;
340
 
+}
341
 
+
342
 
+static
343
 
+int
344
 
+copy_sys_tables_rec(
345
 
+/*================*/
346
 
+       TABLE*                  table,
347
 
+       const dict_index_t*     index,
348
 
+       const rec_t*            rec
349
 
+)
350
 
+{
351
 
+       int     status;
352
 
+       int     field;
353
 
+
354
 
+       /* NAME */
355
 
+       field = dict_index_get_nth_col_pos(index, 0);
356
 
+       status = copy_name_fields(table, 0, rec, field);
357
 
+       if (status) {
358
 
+               return status;
359
 
+       }
360
 
+       /* ID */
361
 
+       field = dict_index_get_nth_col_pos(index, 1);
362
 
+       status = copy_id_field(table, 2, rec, field);
363
 
+       if (status) {
364
 
+               return status;
365
 
+       }
366
 
+       /* N_COLS */
367
 
+       field = dict_index_get_nth_col_pos(index, 2);
368
 
+       status = copy_int_field(table, 3, rec, field);
369
 
+       if (status) {
370
 
+               return status;
371
 
+       }
372
 
+       /* TYPE */
373
 
+       field = dict_index_get_nth_col_pos(index, 3);
374
 
+       status = copy_int_field(table, 4, rec, field);
375
 
+       if (status) {
376
 
+               return status;
377
 
+       }
378
 
+       /* MIX_ID */
379
 
+       field = dict_index_get_nth_col_pos(index, 4);
380
 
+       status = copy_id_field(table, 5, rec, field);
381
 
+       if (status) {
382
 
+               return status;
383
 
+       }
384
 
+       /* MIX_LEN */
385
 
+       field = dict_index_get_nth_col_pos(index, 5);
386
 
+       status = copy_int_field(table, 6, rec, field);
387
 
+       if (status) {
388
 
+               return status;
389
 
+       }
390
 
+       /* CLUSTER_NAME */
391
 
+       field = dict_index_get_nth_col_pos(index, 6);
392
 
+       status = copy_string_field(table, 7, rec, field);
393
 
+       if (status) {
394
 
+               return status;
395
 
+       }
396
 
+       /* SPACE */
397
 
+       field = dict_index_get_nth_col_pos(index, 7);
398
 
+       status = copy_int_field(table, 8, rec, field);
399
 
+       if (status) {
400
 
+               return status;
401
 
+       }
402
 
+
403
 
+       return 0;
404
 
+}
405
 
+
406
 
+static
407
 
+int
408
 
+copy_sys_indexes_rec(
409
 
+/*=================*/
410
 
+       TABLE*                  table,
411
 
+       const dict_index_t*     index,
412
 
+       const rec_t*            rec
413
 
+)
414
 
+{
415
 
+       int     status;
416
 
+       int     field;
417
 
+
418
 
+       /* TABLE_ID */
419
 
+       field = dict_index_get_nth_col_pos(index, 0);
420
 
+       status = copy_id_field(table, 0, rec, field);
421
 
+       if (status) {
422
 
+               return status;
423
 
+       }
424
 
+       /* ID */
425
 
+       field = dict_index_get_nth_col_pos(index, 1);
426
 
+       status = copy_id_field(table, 1, rec, field);
427
 
+       if (status) {
428
 
+               return status;
429
 
+       }
430
 
+       /* NAME */
431
 
+       field = dict_index_get_nth_col_pos(index, 2);
432
 
+       status = copy_string_field(table, 2, rec, field);
433
 
+       if (status) {
434
 
+               return status;
435
 
+       }
436
 
+       /* N_FIELDS */
437
 
+       field = dict_index_get_nth_col_pos(index, 3);
438
 
+       status = copy_int_field(table, 3, rec, field);
439
 
+       if (status) {
440
 
+               return status;
441
 
+       }
442
 
+       /* TYPE */
443
 
+       field = dict_index_get_nth_col_pos(index, 4);
444
 
+       status = copy_int_field(table, 4, rec, field);
445
 
+       if (status) {
446
 
+               return status;
447
 
+       }
448
 
+       /* SPACE */
449
 
+       field = dict_index_get_nth_col_pos(index, 5);
450
 
+       status = copy_int_field(table, 5, rec, field);
451
 
+       if (status) {
452
 
+               return status;
453
 
+       }
454
 
+       /* PAGE_NO */
455
 
+       field = dict_index_get_nth_col_pos(index, 6);
456
 
+       status = copy_int_field(table, 6, rec, field);
457
 
+       if (status) {
458
 
+               return status;
459
 
+       }
460
 
+
461
 
+       return 0;
462
 
+}
463
 
+
464
 
+static
465
 
+int
466
 
+copy_sys_stats_rec(
467
 
+/*===============*/
468
 
+       TABLE*                  table,
469
 
+       const dict_index_t*     index,
470
 
+       const rec_t*            rec
471
 
+)
472
 
+{
473
 
+       int     status;
474
 
+       int     field;
475
 
+       ulint   n_fields;
476
 
+
477
 
+       n_fields = rec_get_n_fields_old(rec);
478
 
+
479
 
+       /* INDEX_ID */
480
 
+       field = dict_index_get_nth_col_pos(index, 0);
481
 
+       status = copy_id_field(table, 0, rec, field);
482
 
+       if (status) {
483
 
+               return status;
484
 
+       }
485
 
+       /* KEY_COLS */
486
 
+       field = dict_index_get_nth_col_pos(index, 1);
487
 
+       status = copy_int_field(table, 1, rec, field);
488
 
+       if (status) {
489
 
+               return status;
490
 
+       }
491
 
+       /* DIFF_VALS */
492
 
+       field = dict_index_get_nth_col_pos(index, 2);
493
 
+       status = copy_id_field(table, 2, rec, field);
494
 
+       if (status) {
495
 
+               return status;
496
 
+       }
497
 
+       /* NON_NULL_VALS */
498
 
+       if (n_fields < 6) {
499
 
+               table->field[3]->set_null();
500
 
+       } else {
501
 
+               field = dict_index_get_nth_col_pos(index, 3);
502
 
+               status = copy_id_field(table, 3, rec, field);
503
 
+               if (status) {
504
 
+                       return status;
505
 
+               }
506
 
+       }
507
 
+
508
 
+       return 0;
509
 
+}
510
 
+
511
 
+static
512
 
+int
513
 
+i_s_innodb_schema_table_fill(
514
 
+/*=========================*/
515
 
+       THD*            thd,
516
 
+       TABLE_LIST*     tables,
517
 
+       COND*           cond)
518
 
+{
519
 
+       int             status  = 0;
520
 
+       TABLE*          table   = (TABLE *) tables->table;
521
 
+       const char*     table_name = tables->schema_table_name;
522
 
+       dict_table_t*   innodb_table;
523
 
+       dict_index_t*   index;
524
 
+       btr_pcur_t      pcur;
525
 
+       const rec_t*    rec;
526
 
+       mtr_t           mtr;
527
 
+       int             id;
528
 
+
529
 
+       DBUG_ENTER("i_s_innodb_schema_table_fill");
530
 
+
531
 
+       /* deny access to non-superusers */
532
 
+       if (check_global_access(thd, PROCESS_ACL)) {
533
 
+               DBUG_RETURN(0);
534
 
+       }
535
 
+
536
 
+       if (innobase_strcasecmp(table_name, "innodb_sys_tables") == 0) {
537
 
+               id = 0;
538
 
+       } else if (innobase_strcasecmp(table_name, "innodb_sys_indexes") == 0) {
539
 
+               id = 1;
540
 
+       } else if (innobase_strcasecmp(table_name, "innodb_sys_stats") == 0) {
541
 
+               id = 2;
542
 
+       } else {
543
 
+               DBUG_RETURN(1);
544
 
+       }
545
 
+
546
 
+
547
 
+       RETURN_IF_INNODB_NOT_STARTED(tables->schema_table_name);
548
 
+
549
 
+       mutex_enter(&(dict_sys->mutex));
550
 
+
551
 
+       mtr_start(&mtr);
552
 
+
553
 
+       if (id == 0) {
554
 
+               innodb_table = dict_table_get_low("SYS_TABLES");
555
 
+       } else if (id == 1) {
556
 
+               innodb_table = dict_table_get_low("SYS_INDEXES");
557
 
+       } else {
558
 
+               innodb_table = dict_table_get_low("SYS_STATS");
559
 
+       }
560
 
+       index = UT_LIST_GET_FIRST(innodb_table->indexes);
561
 
+
562
 
+       btr_pcur_open_at_index_side(TRUE, index, BTR_SEARCH_LEAF, &pcur,
563
 
+                                   TRUE, &mtr);
564
 
+       for (;;) {
565
 
+               btr_pcur_move_to_next_user_rec(&pcur, &mtr);
566
 
+
567
 
+               rec = btr_pcur_get_rec(&pcur);
568
 
+               if (!btr_pcur_is_on_user_rec(&pcur)) {
569
 
+                       /* end of index */
570
 
+                       break;
571
 
+               }
572
 
+
573
 
+               btr_pcur_store_position(&pcur, &mtr);
574
 
+
575
 
+               if (rec_get_deleted_flag(rec, 0)) {
576
 
+                       /* record marked as deleted */
577
 
+                       goto next_record;
578
 
+               }
579
 
+
580
 
+               if (id == 0) {
581
 
+                       status = copy_sys_tables_rec(table, index, rec);
582
 
+               } else if (id == 1) {
583
 
+                       status = copy_sys_indexes_rec(table, index, rec);
584
 
+               } else {
585
 
+                       status = copy_sys_stats_rec(table, index, rec);
586
 
+               }
587
 
+               if (status) {
588
 
+                       break;
589
 
+               }
590
 
+
591
 
+               status = schema_table_store_record(thd, table);
592
 
+               if (status) {
593
 
+                       break;
594
 
+               }
595
 
+next_record:
596
 
+               mtr_commit(&mtr);
597
 
+
598
 
+               mtr_start(&mtr);
599
 
+               btr_pcur_restore_position(BTR_SEARCH_LEAF, &pcur, &mtr);
600
 
+       }
601
 
+
602
 
+       btr_pcur_close(&pcur);
603
 
+       mtr_commit(&mtr);
604
 
+
605
 
+       mutex_exit(&(dict_sys->mutex));
606
 
+
607
 
+       DBUG_RETURN(status);
608
 
+}
609
 
+
610
 
+static
611
 
+int
612
 
+i_s_innodb_sys_tables_init(
613
 
+/*=======================*/
614
 
+       void*   p)
615
 
+{
616
 
+       DBUG_ENTER("i_s_innodb_sys_tables_init");
617
 
+       ST_SCHEMA_TABLE* schema = (ST_SCHEMA_TABLE*) p;
618
 
+
619
 
+       schema->fields_info = i_s_innodb_sys_tables_info;
620
 
+       schema->fill_table = i_s_innodb_schema_table_fill;
621
 
+
622
 
+       DBUG_RETURN(0);
623
 
+}
624
 
+
625
 
+static
626
 
+int
627
 
+i_s_innodb_sys_indexes_init(
628
 
+/*========================*/
629
 
+       void*   p)
630
 
+{
631
 
+       DBUG_ENTER("i_s_innodb_sys_indexes_init");
632
 
+       ST_SCHEMA_TABLE* schema = (ST_SCHEMA_TABLE*) p;
633
 
+
634
 
+       schema->fields_info = i_s_innodb_sys_indexes_info;
635
 
+       schema->fill_table = i_s_innodb_schema_table_fill;
636
 
+
637
 
+       DBUG_RETURN(0);
638
 
+}
639
 
+
640
 
+static
641
 
+int
642
 
+i_s_innodb_sys_stats_init(
643
 
+/*======================*/
644
 
+       void*   p)
645
 
+{
646
 
+       DBUG_ENTER("i_s_innodb_sys_stats_init");
647
 
+       ST_SCHEMA_TABLE* schema = (ST_SCHEMA_TABLE*) p;
648
 
+
649
 
+       schema->fields_info = i_s_innodb_sys_stats_info;
650
 
+       schema->fill_table = i_s_innodb_schema_table_fill;
651
 
+
652
 
+       DBUG_RETURN(0);
653
 
+}
654
 
+
655
 
+UNIV_INTERN struct st_mysql_plugin   i_s_innodb_sys_tables =
656
 
+{
657
 
+       STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
658
 
+       STRUCT_FLD(info, &i_s_info),
659
 
+       STRUCT_FLD(name, "INNODB_SYS_TABLES"),
660
 
+       STRUCT_FLD(author, "Percona"),
661
 
+       STRUCT_FLD(descr, "InnoDB SYS_TABLES table"),
662
 
+       STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
663
 
+       STRUCT_FLD(init, i_s_innodb_sys_tables_init),
664
 
+       STRUCT_FLD(deinit, i_s_common_deinit),
665
 
+       STRUCT_FLD(version, 0x0100 /* 1.0 */),
666
 
+       STRUCT_FLD(status_vars, NULL),
667
 
+       STRUCT_FLD(system_vars, NULL),
668
 
+       STRUCT_FLD(__reserved1, NULL)
669
 
+};
670
 
+
671
 
+UNIV_INTERN struct st_mysql_plugin   i_s_innodb_sys_indexes =
672
 
+{
673
 
+       STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
674
 
+       STRUCT_FLD(info, &i_s_info),
675
 
+       STRUCT_FLD(name, "INNODB_SYS_INDEXES"),
676
 
+       STRUCT_FLD(author, "Percona"),
677
 
+       STRUCT_FLD(descr, "InnoDB SYS_INDEXES table"),
678
 
+       STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
679
 
+       STRUCT_FLD(init, i_s_innodb_sys_indexes_init),
680
 
+       STRUCT_FLD(deinit, i_s_common_deinit),
681
 
+       STRUCT_FLD(version, 0x0100 /* 1.0 */),
682
 
+       STRUCT_FLD(status_vars, NULL),
683
 
+       STRUCT_FLD(system_vars, NULL),
684
 
+       STRUCT_FLD(__reserved1, NULL)
685
 
+};
686
 
+
687
 
+UNIV_INTERN struct st_mysql_plugin   i_s_innodb_sys_stats =
688
 
+{
689
 
+       STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
690
 
+       STRUCT_FLD(info, &i_s_info),
691
 
+       STRUCT_FLD(name, "INNODB_SYS_STATS"),
692
 
+       STRUCT_FLD(author, "Percona"),
693
 
+       STRUCT_FLD(descr, "InnoDB SYS_STATS table"),
694
 
+       STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
695
 
+       STRUCT_FLD(init, i_s_innodb_sys_stats_init),
696
 
+       STRUCT_FLD(deinit, i_s_common_deinit),
697
 
+       STRUCT_FLD(version, 0x0100 /* 1.0 */),
698
 
+       STRUCT_FLD(status_vars, NULL),
699
 
+       STRUCT_FLD(system_vars, NULL),
700
 
+       STRUCT_FLD(__reserved1, NULL)
701
 
+};
702
 
--- a/storage/innodb_plugin/handler/i_s.h
703
 
+++ b/storage/innodb_plugin/handler/i_s.h
704
 
@@ -41,5 +41,8 @@
705
 
 extern struct st_mysql_plugin  i_s_innodb_table_stats;
706
 
 extern struct st_mysql_plugin  i_s_innodb_index_stats;
707
 
 extern struct st_mysql_plugin  i_s_innodb_admin_command;
708
 
+extern struct st_mysql_plugin   i_s_innodb_sys_tables;
709
 
+extern struct st_mysql_plugin   i_s_innodb_sys_indexes;
710
 
+extern struct st_mysql_plugin  i_s_innodb_sys_stats;
711
 
 
712
 
 #endif /* i_s_h */
713
 
--- a/storage/innodb_plugin/handler/innodb_patch_info.h
714
 
+++ b/storage/innodb_plugin/handler/innodb_patch_info.h
715
 
@@ -46,5 +46,6 @@
716
 
 {"innodb_pass_corrupt_table","Treat tables as corrupt instead of crash, when meet corrupt blocks","","http://www.percona.com/docs/wiki/percona-xtradb"},
717
 
 {"innodb_fast_checksum","Using the checksum on 32bit-unit calculation","incompatible for unpatched ver.","http://www.percona.com/docs/wiki/percona-xtradb"},
718
 
 {"innodb_files_extend","allow >4GB transaction log files, and can vary universal page size of datafiles","incompatible for unpatched ver.","http://www.percona.com/docs/wiki/percona-xtradb"},
719
 
+{"innodb_sys_tables_sys_indexes","Expose InnoDB SYS_TABLES and SYS_INDEXES schema tables","","http://www.percona.com/docs/wiki/percona-xtradb"},
720
 
 {NULL, NULL, NULL, NULL}
721
 
 };
722
 
--- /dev/null
723
 
+++ b/mysql-test/r/percona_innodb_use_sys_stats_table.result
724
 
@@ -0,0 +1,3 @@
725
 
+show variables like 'innodb_use_sys_stats%';
726
 
+Variable_name  Value
727
 
+innodb_use_sys_stats_table     ON
728
 
--- /dev/null
729
 
+++ b/mysql-test/t/percona_innodb_use_sys_stats_table-master.opt
730
 
@@ -0,0 +1 @@
731
 
+--innodb_use_sys_stats_table
732
 
--- /dev/null
733
 
+++ b/mysql-test/t/percona_innodb_use_sys_stats_table.test
734
 
@@ -0,0 +1,2 @@
735
 
+--source include/have_innodb.inc
736
 
+show variables like 'innodb_use_sys_stats%';