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