~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/handler/data_dictionary.cc

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
2
 
 
3
 
Copyright (c) 2007, 2009, Innobase Oy. All Rights Reserved.
4
 
 
5
 
This program is free software; you can redistribute it and/or modify it under
6
 
the terms of the GNU General Public License as published by the Free Software
7
 
Foundation; version 2 of the License.
8
 
 
9
 
This program is distributed in the hope that it will be useful, but WITHOUT
10
 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
 
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
 
 
13
 
You should have received a copy of the GNU General Public License along with
14
 
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15
 
St, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
*****************************************************************************/
18
 
 
19
 
#include "config.h"
20
 
 
21
 
#include "data_dictionary.h"
22
 
 
23
 
#include "drizzled/current_session.h"
24
 
 
25
 
extern "C" {
26
 
#include "trx0i_s.h"
27
 
#include "trx0trx.h" /* for TRX_QUE_STATE_STR_MAX_LEN */
28
 
#include "buf0buddy.h" /* for i_s_cmpmem */
29
 
#include "buf0buf.h" /* for buf_pool and PAGE_ZIP_MIN_SIZE */
30
 
#include "ha_prototypes.h" /* for innobase_convert_name() */
31
 
#include "srv0start.h" /* for srv_was_started */
32
 
#include "btr0pcur.h"   /* for file sys_tables related info. */
33
 
#include "btr0types.h"
34
 
#include "dict0load.h"  /* for file sys_tables related info. */
35
 
#include "dict0mem.h"
36
 
#include "dict0types.h"
37
 
}
38
 
#include "handler0vars.h"
39
 
 
40
 
using namespace drizzled;
41
 
 
42
 
InnodbSysTablesTool::InnodbSysTablesTool() :
43
 
  plugin::TableFunction("DATA_DICTIONARY", "INNODB_SYS_TABLES")
44
 
{
45
 
  add_field("TABLE_ID", plugin::TableFunction::NUMBER, 0, false);
46
 
  add_field("NAME", plugin::TableFunction::STRING, NAME_LEN + 1, false);
47
 
  add_field("FLAG", plugin::TableFunction::NUMBER, 0, false);
48
 
  add_field("N_COLS", plugin::TableFunction::NUMBER, 0, false);
49
 
  add_field("SPACE", plugin::TableFunction::NUMBER, 0, false);
50
 
}
51
 
 
52
 
InnodbSysTablesTool::Generator::Generator(Field **arg) :
53
 
  plugin::TableFunction::Generator(arg)
54
 
{
55
 
  heap= NULL;
56
 
}
57
 
 
58
 
bool InnodbSysTablesTool::Generator::populate()
59
 
{
60
 
  if (heap == NULL)
61
 
  {
62
 
    heap = mem_heap_create(1000);
63
 
    mutex_enter(&(dict_sys->mutex));
64
 
    mtr_start(&mtr);
65
 
 
66
 
    rec = dict_startscan_system(&pcur, &mtr, SYS_TABLES);
67
 
  }
68
 
  else
69
 
  {
70
 
    /* Get the next record */
71
 
    mutex_enter(&dict_sys->mutex);
72
 
    mtr_start(&mtr);
73
 
    rec = dict_getnext_system(&pcur, &mtr);
74
 
  }
75
 
 
76
 
  if (! rec)
77
 
  {
78
 
    mtr_commit(&mtr);
79
 
    mutex_exit(&dict_sys->mutex);
80
 
    mem_heap_free(heap);
81
 
    return false;
82
 
  }
83
 
 
84
 
  const char*   err_msg;
85
 
  dict_table_t* table_rec;
86
 
 
87
 
  /* Create and populate a dict_table_t structure with
88
 
     information from SYS_TABLES row */
89
 
  err_msg = dict_process_sys_tables_rec(heap, rec, &table_rec,
90
 
                                        DICT_TABLE_LOAD_FROM_RECORD);
91
 
 
92
 
  mtr_commit(&mtr);
93
 
  mutex_exit(&dict_sys->mutex);
94
 
 
95
 
  if (!err_msg) {
96
 
    push(table_rec->id);
97
 
    push(table_rec->name);
98
 
    push(static_cast<uint64_t>(table_rec->flags));
99
 
    push(static_cast<uint64_t>(table_rec->n_cols));
100
 
    push(static_cast<uint64_t>(table_rec->space));
101
 
  } else {
102
 
/*    push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
103
 
                        ER_CANT_FIND_SYSTEM_REC,
104
 
                        err_msg);
105
 
*/  }
106
 
 
107
 
  /* Since dict_process_sys_tables_rec() is called with
108
 
     DICT_TABLE_LOAD_FROM_RECORD, the table_rec is created in
109
 
     dict_process_sys_tables_rec(), we will need to free it */
110
 
  if (table_rec) {
111
 
    dict_mem_table_free(table_rec);
112
 
  }
113
 
 
114
 
  mem_heap_empty(heap);
115
 
 
116
 
  return true;
117
 
}
118
 
 
119
 
InnodbSysTableStatsTool::InnodbSysTableStatsTool() :
120
 
  plugin::TableFunction("DATA_DICTIONARY", "INNODB_SYS_TABLESTATS")
121
 
{
122
 
  add_field("TABLE_ID", plugin::TableFunction::NUMBER, 0, false);
123
 
  add_field("NAME", plugin::TableFunction::STRING, NAME_LEN + 1, false);
124
 
  add_field("STATS_INITIALIZED", plugin::TableFunction::STRING, NAME_LEN + 1, false);
125
 
  add_field("NUM_ROWS", plugin::TableFunction::NUMBER, 0, false);
126
 
  add_field("CLUST_INDEX_SIZE", plugin::TableFunction::NUMBER, 0, false);
127
 
  add_field("OTHER_INDEX_SIZE", plugin::TableFunction::NUMBER, 0, false);
128
 
  add_field("MODIFIED_COUNTER", plugin::TableFunction::NUMBER, 0, false);
129
 
  add_field("AUTOINC", plugin::TableFunction::NUMBER, 0, false);
130
 
  add_field("HANDLES_OPENED", plugin::TableFunction::NUMBER, 0, false);
131
 
}
132
 
 
133
 
InnodbSysTableStatsTool::Generator::Generator(Field **arg) :
134
 
  plugin::TableFunction::Generator(arg)
135
 
{
136
 
  heap= NULL;
137
 
}
138
 
 
139
 
bool InnodbSysTableStatsTool::Generator::populate()
140
 
{
141
 
  if (heap == NULL)
142
 
  {
143
 
    heap = mem_heap_create(1000);
144
 
    mutex_enter(&dict_sys->mutex);
145
 
    mtr_start(&mtr);
146
 
    rec = dict_startscan_system(&pcur, &mtr, SYS_TABLES);
147
 
  }
148
 
  else
149
 
  {
150
 
    /* Get the next record */
151
 
    mutex_enter(&dict_sys->mutex);
152
 
    mtr_start(&mtr);
153
 
    rec = dict_getnext_system(&pcur, &mtr);
154
 
  }
155
 
 
156
 
  if (!rec)
157
 
  {
158
 
    mtr_commit(&mtr);
159
 
    mutex_exit(&dict_sys->mutex);
160
 
    mem_heap_free(heap);
161
 
    return false;
162
 
  }
163
 
 
164
 
  const char*   err_msg;
165
 
  dict_table_t* table_rec;
166
 
 
167
 
  /* Fetch the dict_table_t structure corresponding to
168
 
     this SYS_TABLES record */
169
 
  err_msg = dict_process_sys_tables_rec(heap, rec, &table_rec,
170
 
                                        DICT_TABLE_LOAD_FROM_CACHE);
171
 
 
172
 
  mtr_commit(&mtr);
173
 
  mutex_exit(&dict_sys->mutex);
174
 
 
175
 
  if (!err_msg) {
176
 
    push(table_rec->id);
177
 
    push(table_rec->name);
178
 
    if (table_rec->stat_initialized)
179
 
      push("Initialized");
180
 
    else
181
 
      push("Uninitialized");
182
 
    push(table_rec->stat_n_rows);
183
 
    push(static_cast<uint64_t>(table_rec->stat_clustered_index_size));
184
 
    push(static_cast<uint64_t>(table_rec->stat_sum_of_other_index_sizes));
185
 
    push(static_cast<uint64_t>(table_rec->stat_modified_counter));
186
 
    push(table_rec->autoinc);
187
 
    push(static_cast<uint64_t>(table_rec->n_mysql_handles_opened));
188
 
  } else {
189
 
    /*    push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
190
 
                        ER_CANT_FIND_SYSTEM_REC,
191
 
                        err_msg);*/
192
 
  }
193
 
 
194
 
  mem_heap_empty(heap);
195
 
 
196
 
  return true;
197
 
}
198
 
 
199
 
InnodbSysIndexesTool::InnodbSysIndexesTool() :
200
 
  plugin::TableFunction("DATA_DICTIONARY", "INNODB_SYS_INDEXES")
201
 
{
202
 
  add_field("INDEX_ID", plugin::TableFunction::NUMBER, 0, false);
203
 
  add_field("NAME", plugin::TableFunction::STRING, NAME_LEN + 1, false);
204
 
  add_field("TABLE_ID", plugin::TableFunction::NUMBER, 0, false);
205
 
  add_field("TYPE", plugin::TableFunction::NUMBER, 0, false);
206
 
  add_field("N_FIELDS", plugin::TableFunction::NUMBER, 0, false);
207
 
  add_field("PAGE_NO", plugin::TableFunction::NUMBER, 0, false);
208
 
  add_field("SPACE", plugin::TableFunction::NUMBER, 0, false);
209
 
}
210
 
 
211
 
InnodbSysIndexesTool::Generator::Generator(Field **arg) :
212
 
  plugin::TableFunction::Generator(arg)
213
 
{
214
 
  heap= NULL;
215
 
}
216
 
 
217
 
bool InnodbSysIndexesTool::Generator::populate()
218
 
{
219
 
  if (heap == NULL)
220
 
  {
221
 
    heap = mem_heap_create(1000);
222
 
    mutex_enter(&dict_sys->mutex);
223
 
    mtr_start(&mtr);
224
 
 
225
 
    /* Start scan the SYS_INDEXES table */
226
 
    rec = dict_startscan_system(&pcur, &mtr, SYS_INDEXES);
227
 
  }
228
 
  else
229
 
  {
230
 
    /* Get the next record */
231
 
    mutex_enter(&dict_sys->mutex);
232
 
    mtr_start(&mtr);
233
 
    rec = dict_getnext_system(&pcur, &mtr);
234
 
  }
235
 
 
236
 
  if (! rec)
237
 
  {
238
 
    mtr_commit(&mtr);
239
 
    mutex_exit(&dict_sys->mutex);
240
 
    mem_heap_free(heap);
241
 
    return false;
242
 
  }
243
 
 
244
 
  const char*   err_msg;;
245
 
  table_id_t    table_id;
246
 
  dict_index_t  index_rec;
247
 
 
248
 
  /* Populate a dict_index_t structure with information from
249
 
     a SYS_INDEXES row */
250
 
  err_msg = dict_process_sys_indexes_rec(heap, rec, &index_rec,
251
 
                                         &table_id);
252
 
 
253
 
  mtr_commit(&mtr);
254
 
  mutex_exit(&dict_sys->mutex);
255
 
  if (!err_msg) {
256
 
    push(index_rec.id);
257
 
    push(index_rec.name);
258
 
    push(static_cast<uint64_t>(table_id));
259
 
    push(static_cast<uint64_t>(index_rec.type));
260
 
    push(static_cast<uint64_t>(index_rec.n_fields));
261
 
    push(static_cast<uint64_t>(index_rec.page));
262
 
    push(static_cast<uint64_t>(index_rec.space));
263
 
  } else {
264
 
/*    push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
265
 
                        ER_CANT_FIND_SYSTEM_REC,
266
 
                        err_msg);*/
267
 
  }
268
 
 
269
 
  mem_heap_empty(heap);
270
 
 
271
 
  if (!rec)
272
 
  {
273
 
    mtr_commit(&mtr);
274
 
    mutex_exit(&dict_sys->mutex);
275
 
    mem_heap_free(heap);
276
 
    return false;
277
 
  }
278
 
 
279
 
  return true;
280
 
}
281
 
 
282
 
InnodbSysColumnsTool::InnodbSysColumnsTool() :
283
 
  plugin::TableFunction("DATA_DICTIONARY", "INNODB_SYS_COLUMNS")
284
 
{
285
 
  add_field("TABLE_ID", plugin::TableFunction::NUMBER, 0, false);
286
 
  add_field("NAME", plugin::TableFunction::STRING, NAME_LEN + 1, false);
287
 
  add_field("POS", plugin::TableFunction::NUMBER, 0, false);
288
 
  add_field("MTYPE", plugin::TableFunction::NUMBER, 0, false);
289
 
  add_field("PRTYPE", plugin::TableFunction::NUMBER, 0, false);
290
 
  add_field("LEN", plugin::TableFunction::NUMBER, 0, false);
291
 
}
292
 
 
293
 
InnodbSysColumnsTool::Generator::Generator(Field **arg) :
294
 
  plugin::TableFunction::Generator(arg)
295
 
{
296
 
  heap= NULL;
297
 
}
298
 
 
299
 
bool InnodbSysColumnsTool::Generator::populate()
300
 
{
301
 
  if (heap == NULL)
302
 
  {
303
 
    heap = mem_heap_create(1000);
304
 
    mutex_enter(&dict_sys->mutex);
305
 
    mtr_start(&mtr);
306
 
    rec = dict_startscan_system(&pcur, &mtr, SYS_COLUMNS);
307
 
  }
308
 
  else
309
 
  {
310
 
    /* Get the next record */
311
 
    mutex_enter(&dict_sys->mutex);
312
 
    mtr_start(&mtr);
313
 
    rec = dict_getnext_system(&pcur, &mtr);
314
 
  }
315
 
 
316
 
  if (! rec)
317
 
  {
318
 
    mtr_commit(&mtr);
319
 
    mutex_exit(&dict_sys->mutex);
320
 
    mem_heap_free(heap);
321
 
    return false;
322
 
  }
323
 
 
324
 
  const char*   err_msg;
325
 
  dict_col_t    column_rec;
326
 
  table_id_t    table_id;
327
 
  const char*   col_name;
328
 
 
329
 
  /* populate a dict_col_t structure with information from
330
 
     a SYS_COLUMNS row */
331
 
  err_msg = dict_process_sys_columns_rec(heap, rec, &column_rec,
332
 
                                                       &table_id, &col_name);
333
 
 
334
 
  mtr_commit(&mtr);
335
 
  mutex_exit(&dict_sys->mutex);
336
 
 
337
 
  if (!err_msg) {
338
 
    push(table_id);
339
 
    push(col_name);
340
 
    push(static_cast<uint64_t>(column_rec.ind));
341
 
    push(static_cast<uint64_t>(column_rec.mtype));
342
 
    push(static_cast<uint64_t>(column_rec.prtype));
343
 
    push(static_cast<uint64_t>(column_rec.len));
344
 
  } else {
345
 
/*    push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
346
 
                        ER_CANT_FIND_SYSTEM_REC,
347
 
                        err_msg);*/
348
 
  }
349
 
 
350
 
  mem_heap_empty(heap);
351
 
 
352
 
  return true;
353
 
}
354
 
 
355
 
InnodbSysFieldsTool::InnodbSysFieldsTool() :
356
 
  plugin::TableFunction("DATA_DICTIONARY", "INNODB_SYS_FIELDS")
357
 
{
358
 
  add_field("INDEX_ID", plugin::TableFunction::NUMBER, 0, false);
359
 
  add_field("NAME", plugin::TableFunction::STRING, NAME_LEN + 1, false);
360
 
  add_field("POS", plugin::TableFunction::NUMBER, 0, false);
361
 
}
362
 
 
363
 
InnodbSysFieldsTool::Generator::Generator(Field **arg) :
364
 
  plugin::TableFunction::Generator(arg)
365
 
{
366
 
  heap= NULL;
367
 
}
368
 
 
369
 
bool InnodbSysFieldsTool::Generator::populate()
370
 
{
371
 
  if (heap == NULL)
372
 
  {
373
 
    heap = mem_heap_create(1000);
374
 
    mutex_enter(&dict_sys->mutex);
375
 
    mtr_start(&mtr);
376
 
 
377
 
    /* will save last index id so that we know whether we move to
378
 
       the next index. This is used to calculate prefix length */
379
 
    last_id = 0;
380
 
 
381
 
    rec = dict_startscan_system(&pcur, &mtr, SYS_FIELDS);
382
 
  }
383
 
  else
384
 
  {
385
 
    /* Get the next record */
386
 
    mutex_enter(&dict_sys->mutex);
387
 
    mtr_start(&mtr);
388
 
    rec = dict_getnext_system(&pcur, &mtr);
389
 
  }
390
 
 
391
 
  if (! rec)
392
 
  {
393
 
    mtr_commit(&mtr);
394
 
    mutex_exit(&dict_sys->mutex);
395
 
    mem_heap_free(heap);
396
 
 
397
 
    return false;
398
 
  }
399
 
 
400
 
  ulint         pos;
401
 
  const char*   err_msg;
402
 
  index_id_t    index_id;
403
 
  dict_field_t  field_rec;
404
 
 
405
 
  /* Populate a dict_field_t structure with information from
406
 
     a SYS_FIELDS row */
407
 
  err_msg = dict_process_sys_fields_rec(heap, rec, &field_rec,
408
 
                                        &pos, &index_id, last_id);
409
 
 
410
 
  mtr_commit(&mtr);
411
 
  mutex_exit(&dict_sys->mutex);
412
 
 
413
 
  if (!err_msg) {
414
 
    push(index_id);
415
 
    push(field_rec.name);
416
 
    push(static_cast<uint64_t>(pos));
417
 
 
418
 
    last_id = index_id;
419
 
  } else {
420
 
/*    push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
421
 
                        ER_CANT_FIND_SYSTEM_REC,
422
 
                        err_msg);*/
423
 
  }
424
 
 
425
 
  mem_heap_empty(heap);
426
 
 
427
 
  return true;
428
 
}
429
 
 
430
 
InnodbSysForeignTool::InnodbSysForeignTool() :
431
 
  plugin::TableFunction("DATA_DICTIONARY", "INNODB_SYS_FOREIGN")
432
 
{
433
 
  add_field("ID", plugin::TableFunction::STRING, NAME_LEN + 1, false);
434
 
  add_field("FOR_NAME", plugin::TableFunction::STRING, NAME_LEN + 1, false);
435
 
  add_field("REF_NAME", plugin::TableFunction::STRING, NAME_LEN + 1, false);
436
 
  add_field("N_COLS", plugin::TableFunction::NUMBER, 0, false);
437
 
  add_field("TYPE", plugin::TableFunction::NUMBER, 0, false);
438
 
}
439
 
 
440
 
InnodbSysForeignTool::Generator::Generator(Field **arg) :
441
 
  plugin::TableFunction::Generator(arg)
442
 
{
443
 
  heap= NULL;
444
 
}
445
 
 
446
 
bool InnodbSysForeignTool::Generator::populate()
447
 
{
448
 
  if (heap == NULL)
449
 
  {
450
 
    heap = mem_heap_create(1000);
451
 
    mutex_enter(&dict_sys->mutex);
452
 
    mtr_start(&mtr);
453
 
 
454
 
    rec = dict_startscan_system(&pcur, &mtr, SYS_FOREIGN);
455
 
  }
456
 
  else
457
 
  {
458
 
    /* Get the next record */
459
 
    mtr_start(&mtr);
460
 
    mutex_enter(&dict_sys->mutex);
461
 
    rec = dict_getnext_system(&pcur, &mtr);
462
 
  }
463
 
 
464
 
  if (! rec)
465
 
  {
466
 
    mtr_commit(&mtr);
467
 
    mutex_exit(&dict_sys->mutex);
468
 
    mem_heap_free(heap);
469
 
    return false;
470
 
  }
471
 
 
472
 
  const char*   err_msg;
473
 
  dict_foreign_t        foreign_rec;
474
 
 
475
 
  /* Populate a dict_foreign_t structure with information from
476
 
     a SYS_FOREIGN row */
477
 
  err_msg = dict_process_sys_foreign_rec(heap, rec, &foreign_rec);
478
 
 
479
 
  mtr_commit(&mtr);
480
 
  mutex_exit(&dict_sys->mutex);
481
 
 
482
 
  if (!err_msg) {
483
 
    push(foreign_rec.id);
484
 
    push(foreign_rec.foreign_table_name);
485
 
    push(foreign_rec.referenced_table_name);
486
 
    push(static_cast<uint64_t>(foreign_rec.n_fields));
487
 
    push(static_cast<uint64_t>(foreign_rec.type));
488
 
  } else {
489
 
/*    push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
490
 
                        ER_CANT_FIND_SYSTEM_REC,
491
 
                        err_msg);
492
 
*/  }
493
 
 
494
 
  mem_heap_empty(heap);
495
 
 
496
 
  return true;
497
 
}
498
 
 
499
 
InnodbSysForeignColsTool::InnodbSysForeignColsTool() :
500
 
  plugin::TableFunction("DATA_DICTIONARY", "INNODB_SYS_FOREIGN_COLS")
501
 
{
502
 
  add_field("ID", plugin::TableFunction::STRING, NAME_LEN + 1, false);
503
 
  add_field("FOR_COL_NAME", plugin::TableFunction::STRING, NAME_LEN + 1, false);
504
 
  add_field("REF_COL_NAME", plugin::TableFunction::STRING, NAME_LEN + 1, false);
505
 
  add_field("POS", plugin::TableFunction::NUMBER, 0, false);
506
 
}
507
 
 
508
 
InnodbSysForeignColsTool::Generator::Generator(Field **arg) :
509
 
  plugin::TableFunction::Generator(arg)
510
 
{
511
 
  heap= NULL;
512
 
}
513
 
 
514
 
bool InnodbSysForeignColsTool::Generator::populate()
515
 
{
516
 
  if (heap == NULL)
517
 
  {
518
 
    heap = mem_heap_create(1000);
519
 
    mutex_enter(&dict_sys->mutex);
520
 
    mtr_start(&mtr);
521
 
 
522
 
    rec = dict_startscan_system(&pcur, &mtr, SYS_FOREIGN_COLS);
523
 
  }
524
 
  else
525
 
  {
526
 
    /* Get the next record */
527
 
    mutex_enter(&dict_sys->mutex);
528
 
    mtr_start(&mtr);
529
 
    rec = dict_getnext_system(&pcur, &mtr);
530
 
  }
531
 
 
532
 
  if (! rec)
533
 
  {
534
 
    mtr_commit(&mtr);
535
 
    mutex_exit(&dict_sys->mutex);
536
 
    mem_heap_free(heap);
537
 
 
538
 
    return false;
539
 
  }
540
 
 
541
 
  const char*   err_msg;
542
 
  const char*   name;
543
 
  const char*   for_col_name;
544
 
  const char*   ref_col_name;
545
 
  ulint         pos;
546
 
 
547
 
  /* Extract necessary information from a SYS_FOREIGN_COLS row */
548
 
  err_msg = dict_process_sys_foreign_col_rec(heap, rec, &name, &for_col_name,
549
 
                                             &ref_col_name, &pos);
550
 
 
551
 
  mtr_commit(&mtr);
552
 
  mutex_exit(&dict_sys->mutex);
553
 
 
554
 
  if (!err_msg) {
555
 
    push(name);
556
 
    push(for_col_name);
557
 
    push(ref_col_name);
558
 
    push(static_cast<uint64_t>(pos));
559
 
  } else {
560
 
/*    push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
561
 
                        ER_CANT_FIND_SYSTEM_REC,
562
 
                        err_msg);
563
 
*/
564
 
  }
565
 
 
566
 
  mem_heap_empty(heap);
567
 
 
568
 
  return true;
569
 
}
570
 
 
571
 
/*
572
 
 * Fill the dynamic table data_dictionary.INNODB_CMP and INNODB_CMP_RESET
573
 
 *
574
 
 */
575
 
CmpTool::CmpTool(bool in_reset) :
576
 
  plugin::TableFunction("DATA_DICTIONARY", in_reset ? "INNODB_CMP_RESET" : "INNODB_CMP"),
577
 
  outer_reset(in_reset)
578
 
{
579
 
  add_field("PAGE_SIZE", plugin::TableFunction::NUMBER, 0, false);
580
 
  add_field("COMPRESS_OPS", plugin::TableFunction::NUMBER, 0, false);
581
 
  add_field("COMPRESS_OPS_OK", plugin::TableFunction::NUMBER, 0, false);
582
 
  add_field("COMPRESS_TIME", plugin::TableFunction::NUMBER, 0, false);
583
 
  add_field("UNCOMPRESS_OPS", plugin::TableFunction::NUMBER, 0, false);
584
 
  add_field("UNCOMPRESS_TIME", plugin::TableFunction::NUMBER, 0, false);
585
 
}
586
 
 
587
 
CmpTool::Generator::Generator(Field **arg, bool in_reset) :
588
 
  plugin::TableFunction::Generator(arg),
589
 
  record_number(0),
590
 
  inner_reset(in_reset)
591
 
{
592
 
}
593
 
 
594
 
bool CmpTool::Generator::populate()
595
 
{
596
 
  if (record_number == (PAGE_ZIP_NUM_SSIZE - 1))
597
 
  {
598
 
    return false;
599
 
  }
600
 
 
601
 
  page_zip_stat_t*        zip_stat = &page_zip_stat[record_number];
602
 
 
603
 
  push(static_cast<uint64_t>(PAGE_ZIP_MIN_SIZE << record_number));
604
 
 
605
 
  /* The cumulated counts are not protected by any
606
 
     mutex.  Thus, some operation in page0zip.c could
607
 
     increment a counter between the time we read it and
608
 
     clear it.  We could introduce mutex protection, but it
609
 
     could cause a measureable performance hit in
610
 
     page0zip.c. */
611
 
  push(static_cast<uint64_t>(zip_stat->compressed));
612
 
  push(static_cast<uint64_t>(zip_stat->compressed_ok));
613
 
  push(zip_stat->compressed_usec / 1000000);
614
 
  push(static_cast<uint64_t>(zip_stat->decompressed));
615
 
  push(zip_stat->decompressed_usec / 1000000);
616
 
 
617
 
  if (inner_reset)
618
 
  {
619
 
    memset(zip_stat, 0, sizeof *zip_stat);
620
 
  }
621
 
 
622
 
  record_number++;
623
 
 
624
 
  return true;
625
 
}
626
 
 
627
 
/*
628
 
 * Fill the dynamic table data_dictionary.INNODB_CMPMEM and INNODB_CMPMEM_RESET
629
 
 *
630
 
 */
631
 
CmpmemTool::CmpmemTool(bool in_reset) :
632
 
  plugin::TableFunction("DATA_DICTIONARY", in_reset ? "INNODB_CMPMEM_RESET" : "INNODB_CMPMEM"),
633
 
  outer_reset(in_reset)
634
 
{
635
 
  add_field("BUF_POOL", plugin::TableFunction::NUMBER, 0, false);
636
 
  add_field("PAGE_SIZE", plugin::TableFunction::NUMBER, 0, false);
637
 
  add_field("PAGES_USED", plugin::TableFunction::NUMBER, 0, false);
638
 
  add_field("PAGES_FREE", plugin::TableFunction::NUMBER, 0, false);
639
 
  add_field("RELOCATION_OPS", plugin::TableFunction::NUMBER, 0, false);
640
 
  add_field("RELOCATION_TIME", plugin::TableFunction::NUMBER, 0, false);
641
 
}
642
 
 
643
 
CmpmemTool::Generator::Generator(Field **arg, bool in_reset) :
644
 
  plugin::TableFunction::Generator(arg),
645
 
  record_number(0),
646
 
  inner_reset(in_reset)
647
 
{
648
 
}
649
 
 
650
 
CmpmemTool::Generator::~Generator()
651
 
{
652
 
}
653
 
 
654
 
bool CmpmemTool::Generator::populate()
655
 
{
656
 
  if (record_number >= (BUF_BUDDY_SIZES+1)*srv_buf_pool_instances)
657
 
  {
658
 
    return false;
659
 
  }
660
 
 
661
 
  uint32_t buddy_nr= record_number % (BUF_BUDDY_SIZES+1);
662
 
  uint32_t buf_pool_nr= (record_number/(BUF_BUDDY_SIZES+1));
663
 
 
664
 
  buf_pool_t *buf_pool= buf_pool_from_array(buf_pool_nr);
665
 
 
666
 
  buf_pool_mutex_enter(buf_pool);
667
 
 
668
 
  buf_buddy_stat_t* buddy_stat = &buf_pool->buddy_stat[buddy_nr];
669
 
 
670
 
 
671
 
  push(static_cast<uint64_t>(buf_pool_nr));
672
 
  push(static_cast<uint64_t>(BUF_BUDDY_LOW << buddy_nr));
673
 
  push(static_cast<uint64_t>(buddy_stat->used));
674
 
 
675
 
 
676
 
  uint64_t pages_free= (UNIV_LIKELY(buddy_nr < BUF_BUDDY_SIZES) ? UT_LIST_GET_LEN(buf_pool->zip_free[buddy_nr]) : 0);
677
 
  push(pages_free);
678
 
 
679
 
  push(buddy_stat->relocated);
680
 
  push(buddy_stat->relocated_usec / 1000000);
681
 
 
682
 
 
683
 
  if (inner_reset)
684
 
  {
685
 
    buddy_stat->relocated = 0;
686
 
    buddy_stat->relocated_usec = 0;
687
 
  }
688
 
 
689
 
  buf_pool_mutex_exit(buf_pool);
690
 
  record_number++;
691
 
 
692
 
  return true;
693
 
}
694
 
 
695
 
/*
696
 
 * Fill the dynamic table data_dictionary.INNODB_TRX INNODB_LOCKS INNODB_LOCK_WAITS
697
 
 *
698
 
 */
699
 
InnodbTrxTool::InnodbTrxTool(const char* in_table_name) :
700
 
  plugin::TableFunction("DATA_DICTIONARY", in_table_name),
701
 
  table_name(in_table_name)
702
 
{
703
 
  if (innobase_strcasecmp(table_name, "INNODB_TRX") == 0)
704
 
  {
705
 
    add_field("TRX_ID");
706
 
    add_field("TRX_STATE");
707
 
    add_field("TRX_STARTED", plugin::TableFunction::NUMBER, 0, false);
708
 
    add_field("TRX_REQUESTED_LOCK_ID");
709
 
    add_field("TRX_WAIT_STARTED", plugin::TableFunction::NUMBER, 0, false);
710
 
    add_field("TRX_WEIGHT", plugin::TableFunction::NUMBER, 0, false);
711
 
    add_field("TRX_DRIZZLE_THREAD_ID", plugin::TableFunction::NUMBER, 0, false);
712
 
    add_field("TRX_QUERY", plugin::TableFunction::STRING, TRX_I_S_TRX_QUERY_MAX_LEN, true);
713
 
    add_field("TRX_OPERATION_STATE", plugin::TableFunction::STRING, TRX_I_S_TRX_OP_STATE_MAX_LEN, true);
714
 
//    add_field("TRX_TABLES_IN_USE", plugin::TableFunction::NUMBER, 0, false);
715
 
    add_field("TRX_TABLES_LOCKED", plugin::TableFunction::NUMBER, 0, false);
716
 
    add_field("TRX_LOCK_STRUCTS", plugin::TableFunction::NUMBER, 0, false);
717
 
    add_field("TRX_LOCK_MEMORY_BYTES", plugin::TableFunction::NUMBER, 0, false);
718
 
    add_field("TRX_ROWS_LOCKED", plugin::TableFunction::NUMBER, 0, false);
719
 
    add_field("TRX_ROWS_MODIFIED", plugin::TableFunction::NUMBER, 0, false);
720
 
    add_field("TRX_CONCURRENCY_TICKETS", plugin::TableFunction::NUMBER, 0, false);
721
 
    add_field("TRX_ISOLATION_LEVEL", plugin::TableFunction::STRING, TRX_I_S_TRX_ISOLATION_LEVEL_MAX_LEN, false);
722
 
    add_field("TRX_UNIQUE_CHECKS", plugin::TableFunction::NUMBER, 0, false);
723
 
    add_field("TRX_FOREIGN_KEY_CHECKS", plugin::TableFunction::NUMBER, 0, false);
724
 
    add_field("TRX_LAST_FOREIGN_KEY_ERROR", plugin::TableFunction::STRING,
725
 
              TRX_I_S_TRX_FK_ERROR_MAX_LEN, true);
726
 
    add_field("TRX_ADAPTIVE_HASH_LATCHED", plugin::TableFunction::NUMBER, 0, false);
727
 
    add_field("TRX_ADAPTIVE_HASH_TIMEOUT", plugin::TableFunction::NUMBER, 0, false);
728
 
  }
729
 
  else if (innobase_strcasecmp(table_name, "INNODB_LOCKS") == 0)
730
 
  {
731
 
    add_field("LOCK_ID");
732
 
    add_field("LOCK_TRX_ID");
733
 
    add_field("LOCK_MODE");
734
 
    add_field("LOCK_TYPE");
735
 
    add_field("LOCK_TABLE");
736
 
    add_field("LOCK_INDEX");
737
 
    add_field("LOCK_SPACE", plugin::TableFunction::NUMBER, 0, false);
738
 
    add_field("LOCK_PAGE", plugin::TableFunction::NUMBER, 0, false);
739
 
    add_field("LOCK_REC", plugin::TableFunction::NUMBER, 0, false);
740
 
    add_field("LOCK_DATA");
741
 
  }
742
 
  else if (innobase_strcasecmp(table_name, "INNODB_LOCK_WAITS") == 0)
743
 
  {
744
 
    add_field("REQUESTING_TRX_ID");  
745
 
    add_field("REQUESTED_LOCK_ID");
746
 
    add_field("BLOCKING_TRX_ID");
747
 
    add_field("BLOCKING_LOCK_ID");
748
 
  } 
749
 
}
750
 
 
751
 
InnodbTrxTool::Generator::Generator(Field **arg, const char* in_table_name) :
752
 
  plugin::TableFunction::Generator(arg),
753
 
  table_name(in_table_name)
754
 
{
755
 
  /* update the cache */
756
 
  trx_i_s_cache_start_write(trx_i_s_cache);
757
 
  trx_i_s_possibly_fetch_data_into_cache(trx_i_s_cache);
758
 
  trx_i_s_cache_end_write(trx_i_s_cache);
759
 
 
760
 
  if (trx_i_s_cache_is_truncated(trx_i_s_cache))
761
 
  {
762
 
    errmsg_printf(ERRMSG_LVL_ERROR, _("Warning: data in %s truncated due to memory limit of %d bytes\n"), 
763
 
                  table_name, TRX_I_S_MEM_LIMIT);
764
 
  } 
765
 
 
766
 
  trx_i_s_cache_start_read(trx_i_s_cache);
767
 
 
768
 
  if (innobase_strcasecmp(table_name, "INNODB_TRX") == 0)
769
 
    number_rows= trx_i_s_cache_get_rows_used(trx_i_s_cache, I_S_INNODB_TRX);
770
 
  else if (innobase_strcasecmp(table_name, "INNODB_LOCKS") == 0)
771
 
    number_rows= trx_i_s_cache_get_rows_used(trx_i_s_cache, I_S_INNODB_LOCKS);
772
 
  else if (innobase_strcasecmp(table_name, "INNODB_LOCK_WAITS") == 0)
773
 
    number_rows= trx_i_s_cache_get_rows_used(trx_i_s_cache, I_S_INNODB_LOCK_WAITS);
774
 
 
775
 
  record_number= 0;
776
 
}
777
 
 
778
 
InnodbTrxTool::Generator::~Generator()
779
 
{
780
 
  trx_i_s_cache_end_read(trx_i_s_cache);
781
 
}
782
 
 
783
 
bool InnodbTrxTool::Generator::populate()
784
 
{
785
 
  if (record_number == number_rows)
786
 
  {
787
 
    return false;
788
 
  }
789
 
 
790
 
  if (innobase_strcasecmp(table_name, "INNODB_TRX") == 0)
791
 
  {
792
 
    populate_innodb_trx();
793
 
  }
794
 
  else if (innobase_strcasecmp(table_name, "INNODB_LOCKS") == 0)
795
 
  {
796
 
    populate_innodb_locks();
797
 
  }
798
 
  else if (innobase_strcasecmp(table_name, "INNODB_LOCK_WAITS") == 0)
799
 
  {
800
 
    populate_innodb_lock_waits();
801
 
  }
802
 
  else 
803
 
  {
804
 
    return false;
805
 
  }
806
 
  record_number++;
807
 
 
808
 
  return true;
809
 
}
810
 
 
811
 
void InnodbTrxTool::Generator::populate_innodb_locks()
812
 
{
813
 
 
814
 
  char lock_id[TRX_I_S_LOCK_ID_MAX_LEN + 1];
815
 
  i_s_locks_row_t* row;
816
 
 
817
 
  /* note that the decoded database or table name is
818
 
     never expected to be longer than NAME_LEN;
819
 
     NAME_LEN for database name
820
 
     2 for surrounding quotes around database name
821
 
     NAME_LEN for table name
822
 
     2 for surrounding quotes around table name
823
 
     1 for the separating dot (.)
824
 
     9 for the #mysql50# prefix 
825
 
  */
826
 
 
827
 
   char buf[2 * NAME_LEN + 14];
828
 
   const char* bufend;
829
 
 
830
 
   char lock_trx_id[TRX_ID_MAX_LEN + 1];
831
 
 
832
 
   row = (i_s_locks_row_t*)
833
 
          trx_i_s_cache_get_nth_row(
834
 
          trx_i_s_cache, I_S_INNODB_LOCKS, record_number);
835
 
 
836
 
 
837
 
   trx_i_s_create_lock_id(row, lock_id, sizeof(lock_id));
838
 
   push(lock_id);
839
 
 
840
 
   ut_snprintf(lock_trx_id, sizeof(lock_trx_id),
841
 
               TRX_ID_FMT, row->lock_trx_id);
842
 
   push(lock_trx_id);
843
 
 
844
 
   push(row->lock_mode);
845
 
   push(row->lock_type);
846
 
 
847
 
   bufend = innobase_convert_name(buf, sizeof(buf),
848
 
                                  row->lock_table,
849
 
                                  strlen(row->lock_table),
850
 
                                  current_session, TRUE);
851
 
   push(bufend);
852
 
 
853
 
   if (row->lock_index != NULL)
854
 
   {
855
 
     bufend = innobase_convert_name(buf, sizeof(buf),
856
 
                                    row->lock_index,
857
 
                                    strlen(row->lock_index),
858
 
                                    current_session, FALSE);
859
 
     push(bufend);     
860
 
   }
861
 
   else 
862
 
   {
863
 
     push("");
864
 
   }   
865
 
 
866
 
   push(static_cast<uint64_t>(row->lock_space));
867
 
   push(static_cast<uint64_t>(row->lock_page)); 
868
 
   push(static_cast<uint64_t>(row->lock_rec));
869
 
   push(row->lock_data);
870
 
}
871
 
 
872
 
void InnodbTrxTool::Generator::populate_innodb_trx()
873
 
{
874
 
    char lock_id[TRX_I_S_LOCK_ID_MAX_LEN + 1];
875
 
    i_s_trx_row_t* row;
876
 
    char trx_id[TRX_ID_MAX_LEN + 1];
877
 
    row = (i_s_trx_row_t*) trx_i_s_cache_get_nth_row(trx_i_s_cache, I_S_INNODB_TRX, record_number);
878
 
 
879
 
    /* trx_id */
880
 
    ut_snprintf(trx_id, sizeof(trx_id), TRX_ID_FMT, row->trx_id);
881
 
 
882
 
    push(trx_id);
883
 
    push(row->trx_state);
884
 
    push(static_cast<uint64_t>(row->trx_started));
885
 
 
886
 
    if (row->trx_wait_started != 0)
887
 
    {
888
 
      push(trx_i_s_create_lock_id(row->requested_lock_row, lock_id, sizeof(lock_id)));
889
 
      push(static_cast<uint64_t>(row->trx_wait_started));
890
 
    }
891
 
    else
892
 
    {
893
 
      push(static_cast<uint64_t>(0));
894
 
      push(static_cast<uint64_t>(0));
895
 
    }
896
 
 
897
 
    push(static_cast<int64_t>(row->trx_weight));
898
 
    push(static_cast<uint64_t>(row->trx_mysql_thread_id));
899
 
    if (row->trx_query)
900
 
      push(row->trx_query);
901
 
    else
902
 
      push();
903
 
 
904
 
    if (row->trx_operation_state)
905
 
      push(row->trx_operation_state);
906
 
    else
907
 
      push();
908
 
 
909
 
//    push(row->trx_tables_in_use);
910
 
    push(static_cast<uint64_t>(row->trx_tables_locked));
911
 
    push(static_cast<uint64_t>(row->trx_lock_structs));
912
 
    push(static_cast<uint64_t>(row->trx_lock_memory_bytes));
913
 
    push(static_cast<uint64_t>(row->trx_rows_locked));
914
 
    push(static_cast<uint64_t>(row->trx_rows_modified));
915
 
    push(static_cast<uint64_t>(row->trx_concurrency_tickets));
916
 
    push(row->trx_isolation_level);
917
 
    push(static_cast<uint64_t>(row->trx_unique_checks));
918
 
    push(static_cast<uint64_t>(row->trx_foreign_key_checks));
919
 
    if (row->trx_foreign_key_error)
920
 
      push(row->trx_foreign_key_error);
921
 
    else
922
 
      push();
923
 
 
924
 
    push(static_cast<uint64_t>(row->trx_has_search_latch));
925
 
    push(static_cast<uint64_t>(row->trx_search_latch_timeout));
926
 
}
927
 
 
928
 
void InnodbTrxTool::Generator::populate_innodb_lock_waits()
929
 
{
930
 
  char requested_lock_id[TRX_I_S_LOCK_ID_MAX_LEN + 1];
931
 
  char blocking_lock_id[TRX_I_S_LOCK_ID_MAX_LEN + 1];
932
 
 
933
 
  i_s_lock_waits_row_t* row;
934
 
 
935
 
  char requesting_trx_id[TRX_ID_MAX_LEN + 1];
936
 
  char blocking_trx_id[TRX_ID_MAX_LEN + 1];
937
 
 
938
 
  row = (i_s_lock_waits_row_t*)
939
 
         trx_i_s_cache_get_nth_row(
940
 
         trx_i_s_cache, I_S_INNODB_LOCK_WAITS, record_number);
941
 
 
942
 
  ut_snprintf(requesting_trx_id, sizeof(requesting_trx_id),
943
 
              TRX_ID_FMT, row->requested_lock_row->lock_trx_id);
944
 
  push(requesting_trx_id);
945
 
 
946
 
  push(trx_i_s_create_lock_id(row->requested_lock_row, requested_lock_id, 
947
 
       sizeof(requested_lock_id)));
948
 
 
949
 
  ut_snprintf(blocking_trx_id, sizeof(blocking_trx_id),
950
 
              TRX_ID_FMT, row->blocking_lock_row->lock_trx_id);
951
 
  push(blocking_trx_id);
952
 
 
953
 
  push(trx_i_s_create_lock_id(row->blocking_lock_row, blocking_lock_id, 
954
 
       sizeof(blocking_lock_id)));
955
 
}