1
/*****************************************************************************
3
Copyright (c) 2007, 2009, Innobase Oy. All Rights Reserved.
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.
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.
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., 59 Temple
15
Place, Suite 330, Boston, MA 02111-1307 USA
17
*****************************************************************************/
19
/******************************************************
20
InnoDB INFORMATION SCHEMA tables interface to MySQL.
22
Created July 18, 2007 Vasil Dimov
23
*******************************************************/
25
#include <drizzled/server_includes.h>
26
#include <drizzled/error.h>
27
#include <mystrings/m_ctype.h>
28
#include <mysys/my_sys.h>
29
#include <mysys/hash.h>
30
#include <mysys/mysys_err.h>
31
#include <drizzled/plugin.h>
32
#include <drizzled/field.h>
33
#include <drizzled/table.h>
34
#include <drizzled/plugin/info_schema_table.h>
41
#include "trx0trx.h" /* for TRX_QUE_STATE_STR_MAX_LEN */
42
#include "buf0buddy.h" /* for i_s_cmpmem */
43
#include "buf0buf.h" /* for buf_pool and PAGE_ZIP_MIN_SIZE */
44
#include "ha_prototypes.h" /* for innobase_convert_name() */
45
#include "srv0start.h" /* for srv_was_started */
47
#include "handler0vars.h"
49
static const char plugin_author[] = "Innobase Oy";
56
#define RETURN_IF_INNODB_NOT_STARTED(plugin_name) \
58
if (!srv_was_started) { \
59
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN, \
60
ER_CANT_FIND_SYSTEM_REC, \
61
"InnoDB: SELECTing from " \
62
"INFORMATION_SCHEMA.%s but " \
63
"the InnoDB storage engine " \
64
"is not installed", plugin_name); \
69
#define STRUCT_FLD(name, value) value
71
drizzled::plugin::InfoSchemaTable *innodb_trx_schema_table= NULL;
72
drizzled::plugin::InfoSchemaTable *innodb_locks_schema_table= NULL;
73
drizzled::plugin::InfoSchemaTable *innodb_lock_waits_schema_table= NULL;
74
drizzled::plugin::InfoSchemaTable *innodb_cmp_schema_table= NULL;
75
drizzled::plugin::InfoSchemaTable *innodb_cmp_reset_schema_table= NULL;
76
drizzled::plugin::InfoSchemaTable *innodb_cmpmem_schema_table= NULL;
77
drizzled::plugin::InfoSchemaTable *innodb_cmpmem_reset_schema_table= NULL;
79
static TrxISMethods trx_methods;
80
static CmpISMethods cmp_methods;
81
static CmpResetISMethods cmp_reset_methods;
82
static CmpmemISMethods cmpmem_methods;
83
static CmpmemResetISMethods cmpmem_reset_methods;
86
Use the following types mapping:
88
C type ST_FIELD_INFO::field_type
89
---------------------------------
90
long DRIZZLE_TYPE_LONGLONG
91
(field_length=MY_INT64_NUM_DECIMAL_DIGITS)
93
long unsigned DRIZZLE_TYPE_LONGLONG
94
(field_length=MY_INT64_NUM_DECIMAL_DIGITS, field_flags=MY_I_S_UNSIGNED)
96
char* DRIZZLE_TYPE_STRING
99
float DRIZZLE_TYPE_FLOAT
100
(field_length=0 is ignored)
102
void* DRIZZLE_TYPE_LONGLONG
103
(field_length=MY_INT64_NUM_DECIMAL_DIGITS, field_flags=MY_I_S_UNSIGNED)
105
boolean (if else) DRIZZLE_TYPE_LONG
108
time_t DRIZZLE_TYPE_DATETIME
109
(field_length=0 ignored)
110
---------------------------------
113
/* XXX these are defined in mysql_priv.h inside #ifdef DRIZZLE_SERVER */
114
bool schema_table_store_record(Session *session, Table *table);
115
void localtime_to_TIME(DRIZZLE_TIME *to, struct tm *from);
117
/***********************************************************************
118
Unbind a dynamic INFORMATION_SCHEMA table. */
120
/***********************************************************************
121
Auxiliary function to store time_t value in DRIZZLE_TYPE_DATETIME
127
/* out: 0 on success */
128
Field* field, /* in/out: target field for storage */
129
time_t time) /* in: value to store */
131
DRIZZLE_TIME my_time;
135
/* use this if you are sure that `variables' and `time_zone'
136
are always initialized */
137
session->variables.time_zone->gmt_sec_to_TIME(
138
&my_time, (time_t) time);
140
localtime_r(&time, &tm_time);
141
localtime_to_TIME(&my_time, &tm_time);
142
my_time.time_type = DRIZZLE_TIMESTAMP_DATETIME;
145
return(field->store_time(&my_time, DRIZZLE_TIMESTAMP_DATETIME));
148
/***********************************************************************
149
Auxiliary function to store char* value in DRIZZLE_TYPE_STRING field. */
154
/* out: 0 on success */
155
Field* field, /* in/out: target field for storage */
156
const char* str) /* in: NUL-terminated utf-8 string,
163
ret = field->store(str, strlen(str),
164
system_charset_info);
165
field->set_notnull();
168
ret = 0; /* success */
175
/***********************************************************************
176
Auxiliary function to store ulint value in DRIZZLE_TYPE_LONGLONG field.
177
If the value is ULINT_UNDEFINED then the field it set to NULL. */
182
/* out: 0 on success */
183
Field* field, /* in/out: target field for storage */
184
ulint n) /* in: value to store */
188
if (n != ULINT_UNDEFINED) {
190
ret = field->store(n);
191
field->set_notnull();
194
ret = 0; /* success */
201
/* Fields of the dynamic table INFORMATION_SCHEMA.innodb_trx */
202
static drizzled::plugin::ColumnInfo innodb_trx_fields_info[] =
205
drizzled::plugin::ColumnInfo("trx_id",
207
DRIZZLE_TYPE_VARCHAR,
213
#define IDX_TRX_STATE 1
214
drizzled::plugin::ColumnInfo("trx_state",
215
TRX_QUE_STATE_STR_MAX_LEN + 1,
216
DRIZZLE_TYPE_VARCHAR,
222
#define IDX_TRX_STARTED 2
223
drizzled::plugin::ColumnInfo("trx_started",
225
DRIZZLE_TYPE_DATETIME,
231
#define IDX_TRX_REQUESTED_LOCK_ID 3
232
drizzled::plugin::ColumnInfo("trx_requested_lock_id",
233
TRX_I_S_LOCK_ID_MAX_LEN + 1,
234
DRIZZLE_TYPE_VARCHAR,
240
#define IDX_TRX_WAIT_STARTED 4
241
drizzled::plugin::ColumnInfo("trx_wait_started",
243
DRIZZLE_TYPE_DATETIME,
249
#define IDX_TRX_WEIGHT 5
250
drizzled::plugin::ColumnInfo("trx_weight",
251
MY_INT64_NUM_DECIMAL_DIGITS,
252
DRIZZLE_TYPE_LONGLONG,
258
#define IDX_TRX_DRIZZLE_THREAD_ID 6
259
drizzled::plugin::ColumnInfo("trx_mysql_thread_id",
260
MY_INT64_NUM_DECIMAL_DIGITS,
261
DRIZZLE_TYPE_LONGLONG,
267
#define IDX_TRX_QUERY 7
268
drizzled::plugin::ColumnInfo("trx_query",
269
TRX_I_S_TRX_QUERY_MAX_LEN,
270
DRIZZLE_TYPE_VARCHAR,
276
drizzled::plugin::ColumnInfo()
279
/***********************************************************************
280
Read data from cache buffer and fill the INFORMATION_SCHEMA.innodb_trx
284
fill_innodb_trx_from_cache(
285
/*=======================*/
286
/* out: 0 on success */
287
trx_i_s_cache_t* cache, /* in: cache to read from */
288
Session* session, /* in: used to call
289
schema_table_store_record() */
290
Table* table) /* in/out: fill this table */
294
char lock_id[TRX_I_S_LOCK_ID_MAX_LEN + 1];
297
fields = table->field;
299
rows_num = trx_i_s_cache_get_rows_used(cache,
302
for (i = 0; i < rows_num; i++) {
305
char trx_id[TRX_ID_MAX_LEN + 1];
307
row = (i_s_trx_row_t*)
308
trx_i_s_cache_get_nth_row(
309
cache, I_S_INNODB_TRX, i);
312
ut_snprintf(trx_id, sizeof(trx_id), TRX_ID_FMT, row->trx_id);
313
OK(field_store_string(fields[IDX_TRX_ID], trx_id));
316
OK(field_store_string(fields[IDX_TRX_STATE],
320
OK(field_store_time_t(fields[IDX_TRX_STARTED],
321
(time_t) row->trx_started));
323
/* trx_requested_lock_id */
324
/* trx_wait_started */
325
if (row->trx_wait_started != 0) {
327
OK(field_store_string(
328
fields[IDX_TRX_REQUESTED_LOCK_ID],
329
trx_i_s_create_lock_id(
330
row->requested_lock_row,
331
lock_id, sizeof(lock_id))));
332
/* field_store_string() sets it no notnull */
334
OK(field_store_time_t(
335
fields[IDX_TRX_WAIT_STARTED],
336
(time_t) row->trx_wait_started));
337
fields[IDX_TRX_WAIT_STARTED]->set_notnull();
340
fields[IDX_TRX_REQUESTED_LOCK_ID]->set_null();
341
fields[IDX_TRX_WAIT_STARTED]->set_null();
345
OK(fields[IDX_TRX_WEIGHT]->store((int64_t) row->trx_weight,
348
/* trx_mysql_thread_id */
349
OK(fields[IDX_TRX_DRIZZLE_THREAD_ID]->store(
350
row->trx_mysql_thread_id));
353
OK(field_store_string(fields[IDX_TRX_QUERY],
356
OK(schema_table_store_record(session, table));
362
/***********************************************************************
363
Bind the dynamic table INFORMATION_SCHEMA.innodb_trx */
367
/* out: 0 on success */
368
) /* in/out: table schema object */
370
if ((innodb_trx_schema_table= new drizzled::plugin::InfoSchemaTable("INNODB_TRX")) == NULL)
373
innodb_trx_schema_table->setColumnInfo(innodb_trx_fields_info);
374
innodb_trx_schema_table->setInfoSchemaMethods(&trx_methods);
380
/* Fields of the dynamic table INFORMATION_SCHEMA.innodb_locks */
381
static drizzled::plugin::ColumnInfo innodb_locks_fields_info[] =
383
#define IDX_LOCK_ID 0
384
drizzled::plugin::ColumnInfo("lock_id",
385
TRX_I_S_LOCK_ID_MAX_LEN + 1,
386
DRIZZLE_TYPE_VARCHAR,
392
#define IDX_LOCK_TRX_ID 1
393
drizzled::plugin::ColumnInfo("lock_trx_id",
395
DRIZZLE_TYPE_VARCHAR,
401
#define IDX_LOCK_MODE 2
402
drizzled::plugin::ColumnInfo("lock_mode",
403
/* S[,GAP] X[,GAP] IS[,GAP] IX[,GAP] AUTO_INC UNKNOWN */
405
DRIZZLE_TYPE_VARCHAR,
411
#define IDX_LOCK_TYPE 3
412
drizzled::plugin::ColumnInfo("lock_type",
413
32, /* RECORD|TABLE|UNKNOWN */
414
DRIZZLE_TYPE_VARCHAR,
420
#define IDX_LOCK_TABLE 4
421
drizzled::plugin::ColumnInfo("lock_table",
423
DRIZZLE_TYPE_VARCHAR,
429
#define IDX_LOCK_INDEX 5
430
drizzled::plugin::ColumnInfo("lock_index",
432
DRIZZLE_TYPE_VARCHAR,
438
#define IDX_LOCK_SPACE 6
439
drizzled::plugin::ColumnInfo("lock_space",
440
MY_INT64_NUM_DECIMAL_DIGITS,
441
DRIZZLE_TYPE_LONGLONG,
443
MY_I_S_UNSIGNED | MY_I_S_MAYBE_NULL,
447
#define IDX_LOCK_PAGE 7
448
drizzled::plugin::ColumnInfo("lock_page",
449
MY_INT64_NUM_DECIMAL_DIGITS,
450
DRIZZLE_TYPE_LONGLONG,
452
MY_I_S_UNSIGNED | MY_I_S_MAYBE_NULL,
456
#define IDX_LOCK_REC 8
457
drizzled::plugin::ColumnInfo("lock_rec",
458
MY_INT64_NUM_DECIMAL_DIGITS,
459
DRIZZLE_TYPE_LONGLONG,
461
MY_I_S_UNSIGNED | MY_I_S_MAYBE_NULL,
465
#define IDX_LOCK_DATA 9
466
drizzled::plugin::ColumnInfo("lock_data",
467
TRX_I_S_LOCK_DATA_MAX_LEN,
468
DRIZZLE_TYPE_VARCHAR,
474
drizzled::plugin::ColumnInfo()
477
/***********************************************************************
478
Read data from cache buffer and fill the INFORMATION_SCHEMA.innodb_locks
482
fill_innodb_locks_from_cache(
483
/*=========================*/
484
/* out: 0 on success */
485
trx_i_s_cache_t* cache, /* in: cache to read from */
486
Session* session, /* in: MySQL client connection */
487
Table* table) /* in/out: fill this table */
491
char lock_id[TRX_I_S_LOCK_ID_MAX_LEN + 1];
494
fields = table->field;
496
rows_num = trx_i_s_cache_get_rows_used(cache,
499
for (i = 0; i < rows_num; i++) {
501
i_s_locks_row_t* row;
503
/* note that the decoded database or table name is
504
never expected to be longer than NAME_LEN;
505
NAME_LEN for database name
506
2 for surrounding quotes around database name
507
NAME_LEN for table name
508
2 for surrounding quotes around table name
509
1 for the separating dot (.)
510
9 for the #mysql50# prefix */
511
char buf[2 * NAME_LEN + 14];
514
char lock_trx_id[TRX_ID_MAX_LEN + 1];
516
row = (i_s_locks_row_t*)
517
trx_i_s_cache_get_nth_row(
518
cache, I_S_INNODB_LOCKS, i);
521
trx_i_s_create_lock_id(row, lock_id, sizeof(lock_id));
522
OK(field_store_string(fields[IDX_LOCK_ID],
526
ut_snprintf(lock_trx_id, sizeof(lock_trx_id),
527
TRX_ID_FMT, row->lock_trx_id);
528
OK(field_store_string(fields[IDX_LOCK_TRX_ID], lock_trx_id));
531
OK(field_store_string(fields[IDX_LOCK_MODE],
535
OK(field_store_string(fields[IDX_LOCK_TYPE],
539
bufend = innobase_convert_name(buf, sizeof(buf),
541
strlen(row->lock_table),
543
OK(fields[IDX_LOCK_TABLE]->store(buf, bufend - buf,
544
system_charset_info));
547
if (row->lock_index != NULL) {
549
bufend = innobase_convert_name(buf, sizeof(buf),
551
strlen(row->lock_index),
553
OK(fields[IDX_LOCK_INDEX]->store(buf, bufend - buf,
554
system_charset_info));
555
fields[IDX_LOCK_INDEX]->set_notnull();
558
fields[IDX_LOCK_INDEX]->set_null();
562
OK(field_store_ulint(fields[IDX_LOCK_SPACE],
566
OK(field_store_ulint(fields[IDX_LOCK_PAGE],
570
OK(field_store_ulint(fields[IDX_LOCK_REC],
574
OK(field_store_string(fields[IDX_LOCK_DATA],
577
OK(schema_table_store_record(session, table));
583
/***********************************************************************
584
Bind the dynamic table INFORMATION_SCHEMA.innodb_locks */
588
/* out: 0 on success */
589
) /* in/out: table schema object */
592
if ((innodb_locks_schema_table= new drizzled::plugin::InfoSchemaTable("INNODB_LOCKS")) == NULL)
595
innodb_locks_schema_table->setColumnInfo(innodb_locks_fields_info);
596
innodb_locks_schema_table->setInfoSchemaMethods(&trx_methods);
601
/* Fields of the dynamic table INFORMATION_SCHEMA.innodb_lock_waits */
602
static drizzled::plugin::ColumnInfo innodb_lock_waits_fields_info[] =
604
#define IDX_REQUESTING_TRX_ID 0
605
drizzled::plugin::ColumnInfo("requesting_trx_id",
607
DRIZZLE_TYPE_VARCHAR,
613
#define IDX_REQUESTED_LOCK_ID 1
614
drizzled::plugin::ColumnInfo("requested_lock_id",
615
TRX_I_S_LOCK_ID_MAX_LEN + 1,
616
DRIZZLE_TYPE_VARCHAR,
622
#define IDX_BLOCKING_TRX_ID 2
623
drizzled::plugin::ColumnInfo("blocking_trx_id",
625
DRIZZLE_TYPE_VARCHAR,
631
#define IDX_BLOCKING_LOCK_ID 3
632
drizzled::plugin::ColumnInfo("blocking_lock_id",
633
TRX_I_S_LOCK_ID_MAX_LEN + 1,
634
DRIZZLE_TYPE_VARCHAR,
640
drizzled::plugin::ColumnInfo()
643
/***********************************************************************
644
Read data from cache buffer and fill the
645
INFORMATION_SCHEMA.innodb_lock_waits table with it. */
648
fill_innodb_lock_waits_from_cache(
649
/*==============================*/
650
/* out: 0 on success */
651
trx_i_s_cache_t* cache, /* in: cache to read from */
652
Session* session, /* in: used to call
653
schema_table_store_record() */
654
Table* table) /* in/out: fill this table */
658
char requested_lock_id[TRX_I_S_LOCK_ID_MAX_LEN + 1];
659
char blocking_lock_id[TRX_I_S_LOCK_ID_MAX_LEN + 1];
662
fields = table->field;
664
rows_num = trx_i_s_cache_get_rows_used(cache,
665
I_S_INNODB_LOCK_WAITS);
667
for (i = 0; i < rows_num; i++) {
669
i_s_lock_waits_row_t* row;
671
char requesting_trx_id[TRX_ID_MAX_LEN + 1];
672
char blocking_trx_id[TRX_ID_MAX_LEN + 1];
674
row = (i_s_lock_waits_row_t*)
675
trx_i_s_cache_get_nth_row(
676
cache, I_S_INNODB_LOCK_WAITS, i);
678
/* requesting_trx_id */
679
ut_snprintf(requesting_trx_id, sizeof(requesting_trx_id),
680
TRX_ID_FMT, row->requested_lock_row->lock_trx_id);
681
OK(field_store_string(fields[IDX_REQUESTING_TRX_ID],
684
/* requested_lock_id */
685
OK(field_store_string(
686
fields[IDX_REQUESTED_LOCK_ID],
687
trx_i_s_create_lock_id(
688
row->requested_lock_row,
690
sizeof(requested_lock_id))));
692
/* blocking_trx_id */
693
ut_snprintf(blocking_trx_id, sizeof(blocking_trx_id),
694
TRX_ID_FMT, row->blocking_lock_row->lock_trx_id);
695
OK(field_store_string(fields[IDX_BLOCKING_TRX_ID],
698
/* blocking_lock_id */
699
OK(field_store_string(
700
fields[IDX_BLOCKING_LOCK_ID],
701
trx_i_s_create_lock_id(
702
row->blocking_lock_row,
704
sizeof(blocking_lock_id))));
706
OK(schema_table_store_record(session, table));
712
/***********************************************************************
713
Bind the dynamic table INFORMATION_SCHEMA.innodb_lock_waits */
715
innodb_lock_waits_init(
716
/*===================*/
717
/* out: 0 on success */
721
if ((innodb_lock_waits_schema_table= new drizzled::plugin::InfoSchemaTable("INNODB_LOCK_WAITS")) == NULL)
724
innodb_lock_waits_schema_table->setColumnInfo(innodb_lock_waits_fields_info);
725
innodb_lock_waits_schema_table->setInfoSchemaMethods(&trx_methods);
732
/***********************************************************************
733
Common function to fill any of the dynamic tables:
734
INFORMATION_SCHEMA.innodb_trx
735
INFORMATION_SCHEMA.innodb_locks
736
INFORMATION_SCHEMA.innodb_lock_waits */
738
TrxISMethods::fillTable(
739
/*======================*/
740
/* out: 0 on success */
741
Session* session, /* in: thread */
742
TableList* tables, /* in/out: tables to fill */
743
COND* ) /* in: condition (not used) */
745
const char* table_name;
747
trx_i_s_cache_t* cache;
749
/* minimize the number of places where global variables are
751
cache = trx_i_s_cache;
753
/* which table we have to fill? */
754
table_name = tables->schema_table_name;
755
/* or table_name = tables->schema_table->table_name; */
757
RETURN_IF_INNODB_NOT_STARTED(table_name);
759
/* update the cache */
760
trx_i_s_cache_start_write(cache);
761
trx_i_s_possibly_fetch_data_into_cache(cache);
762
trx_i_s_cache_end_write(cache);
764
if (trx_i_s_cache_is_truncated(cache)) {
766
/* XXX show warning to user if possible */
767
fprintf(stderr, "Warning: data in %s truncated due to "
768
"memory limit of %d bytes\n", table_name,
774
trx_i_s_cache_start_read(cache);
776
if (innobase_strcasecmp(table_name, "innodb_trx") == 0) {
778
if (fill_innodb_trx_from_cache(
779
cache, session, tables->table) != 0) {
784
} else if (innobase_strcasecmp(table_name, "innodb_locks") == 0) {
786
if (fill_innodb_locks_from_cache(
787
cache, session, tables->table) != 0) {
792
} else if (innobase_strcasecmp(table_name, "innodb_lock_waits") == 0) {
794
if (fill_innodb_lock_waits_from_cache(
795
cache, session, tables->table) != 0) {
802
/* huh! what happened!? */
804
"InnoDB: trx_i_s_common_fill_table() was "
805
"called to fill unknown table: %s.\n"
806
"This function only knows how to fill "
807
"innodb_trx, innodb_locks and "
808
"innodb_lock_waits tables.\n", table_name);
813
trx_i_s_cache_end_read(cache);
818
/* if this function returns something else than 0 then a
819
deadlock occurs between the mysqld server and mysql client,
820
see http://bugs.mysql.com/29900 ; when that bug is resolved
821
we can enable the return(ret) above */
826
/* Fields of the dynamic table information_schema.innodb_cmp. */
827
static drizzled::plugin::ColumnInfo i_s_cmp_fields_info[] =
829
drizzled::plugin::ColumnInfo("page_size",
834
"Compressed Page Size",
837
drizzled::plugin::ColumnInfo("compress_ops",
838
MY_INT32_NUM_DECIMAL_DIGITS,
842
"Total Number of Compressions",
845
drizzled::plugin::ColumnInfo("compress_ops_ok",
846
MY_INT32_NUM_DECIMAL_DIGITS,
850
"Total Number of Successful Compressions",
853
drizzled::plugin::ColumnInfo("compress_time",
854
MY_INT32_NUM_DECIMAL_DIGITS,
858
"Total Duration of Compressions in Seconds",
861
drizzled::plugin::ColumnInfo("uncompress_ops",
862
MY_INT32_NUM_DECIMAL_DIGITS,
866
"Total Number of Decompressions",
869
drizzled::plugin::ColumnInfo("uncompress_time",
870
MY_INT32_NUM_DECIMAL_DIGITS,
874
"Total Duration of Decompressions in Seconds",
877
drizzled::plugin::ColumnInfo()
881
/***********************************************************************
882
Fill the dynamic table information_schema.innodb_cmp or
888
/* out: 0 on success, 1 on failure */
889
Session* session, /* in: thread */
890
TableList* tables, /* in/out: tables to fill */
891
COND* , /* in: condition (ignored) */
892
ibool reset) /* in: TRUE=reset cumulated counts */
894
Table* table = (Table *) tables->table;
898
RETURN_IF_INNODB_NOT_STARTED(tables->schema_table_name);
900
for (uint i = 0; i < PAGE_ZIP_NUM_SSIZE - 1; i++) {
901
page_zip_stat_t* zip_stat = &page_zip_stat[i];
903
table->field[0]->store(PAGE_ZIP_MIN_SIZE << i);
905
/* The cumulated counts are not protected by any
906
mutex. Thus, some operation in page0zip.c could
907
increment a counter between the time we read it and
908
clear it. We could introduce mutex protection, but it
909
could cause a measureable performance hit in
911
table->field[1]->store(zip_stat->compressed);
912
table->field[2]->store(zip_stat->compressed_ok);
913
table->field[3]->store(
914
(ulong) (zip_stat->compressed_usec / 1000000));
915
table->field[4]->store(zip_stat->decompressed);
916
table->field[5]->store(
917
(ulong) (zip_stat->decompressed_usec / 1000000));
920
memset(zip_stat, 0, sizeof *zip_stat);
923
if (schema_table_store_record(session, table)) {
932
/***********************************************************************
933
Fill the dynamic table information_schema.innodb_cmp. */
935
CmpISMethods::fillTable(
937
/* out: 0 on success, 1 on failure */
938
Session* session, /* in: thread */
939
TableList* tables, /* in/out: tables to fill */
940
COND* cond) /* in: condition (ignored) */
942
return(i_s_cmp_fill_low(session, tables, cond, FALSE));
945
/***********************************************************************
946
Fill the dynamic table information_schema.innodb_cmp_reset. */
948
CmpResetISMethods::fillTable(
950
/* out: 0 on success, 1 on failure */
951
Session* session, /* in: thread */
952
TableList* tables, /* in/out: tables to fill */
953
COND* cond) /* in: condition (ignored) */
955
return(i_s_cmp_fill_low(session, tables, cond, TRUE));
959
/***********************************************************************
960
Bind the dynamic table information_schema.innodb_cmp. */
964
/* out: 0 on success */
968
if ((innodb_cmp_schema_table= new drizzled::plugin::InfoSchemaTable("INNODB_CMP")) == NULL)
971
innodb_cmp_schema_table->setColumnInfo(i_s_cmp_fields_info);
972
innodb_cmp_schema_table->setInfoSchemaMethods(&cmp_methods);
977
/***********************************************************************
978
Bind the dynamic table information_schema.innodb_cmp_reset. */
982
/* out: 0 on success */
983
) /* in/out: table schema object */
986
if ((innodb_cmp_reset_schema_table= new drizzled::plugin::InfoSchemaTable("INNODB_CMP_RESET")) == NULL)
989
innodb_cmp_reset_schema_table->setColumnInfo(i_s_cmp_fields_info);
990
innodb_cmp_reset_schema_table->setInfoSchemaMethods(&cmp_reset_methods);
997
/* Fields of the dynamic table information_schema.innodb_cmpmem. */
998
static drizzled::plugin::ColumnInfo i_s_cmpmem_fields_info[] =
1000
drizzled::plugin::ColumnInfo("page_size",
1008
drizzled::plugin::ColumnInfo("pages_used",
1009
MY_INT32_NUM_DECIMAL_DIGITS,
1016
drizzled::plugin::ColumnInfo("pages_free",
1017
MY_INT32_NUM_DECIMAL_DIGITS,
1021
"Currently Available",
1024
drizzled::plugin::ColumnInfo("relocation_ops",
1025
MY_INT64_NUM_DECIMAL_DIGITS,
1026
DRIZZLE_TYPE_LONGLONG,
1029
"Total Number of Relocations",
1032
drizzled::plugin::ColumnInfo("relocation_time",
1033
MY_INT32_NUM_DECIMAL_DIGITS,
1037
"Total Duration of Relocations, in Seconds",
1040
drizzled::plugin::ColumnInfo()
1043
/***********************************************************************
1044
Fill the dynamic table information_schema.innodb_cmpmem or
1045
innodb_cmpmem_reset. */
1048
i_s_cmpmem_fill_low(
1049
/*================*/
1050
/* out: 0 on success, 1 on failure */
1051
Session* session, /* in: thread */
1052
TableList* tables, /* in/out: tables to fill */
1053
COND* , /* in: condition (ignored) */
1054
ibool reset) /* in: TRUE=reset cumulated counts */
1056
Table* table = (Table *) tables->table;
1059
RETURN_IF_INNODB_NOT_STARTED(tables->schema_table_name);
1061
buf_pool_mutex_enter();
1063
for (uint x = 0; x <= BUF_BUDDY_SIZES; x++) {
1064
buf_buddy_stat_t* buddy_stat = &buf_buddy_stat[x];
1066
table->field[0]->store(BUF_BUDDY_LOW << x);
1067
table->field[1]->store(buddy_stat->used);
1068
table->field[2]->store(UNIV_LIKELY(x < BUF_BUDDY_SIZES)
1069
? UT_LIST_GET_LEN(buf_pool->zip_free[x])
1071
table->field[3]->store((int64_t) buddy_stat->relocated, true);
1072
table->field[4]->store(
1073
(ulong) (buddy_stat->relocated_usec / 1000000));
1076
/* This is protected by buf_pool_mutex. */
1077
buddy_stat->relocated = 0;
1078
buddy_stat->relocated_usec = 0;
1081
if (schema_table_store_record(session, table)) {
1087
buf_pool_mutex_exit();
1091
/***********************************************************************
1092
Fill the dynamic table information_schema.innodb_cmpmem. */
1094
CmpmemISMethods::fillTable(
1096
/* out: 0 on success, 1 on failure */
1097
Session* session, /* in: thread */
1098
TableList* tables, /* in/out: tables to fill */
1099
COND* cond) /* in: condition (ignored) */
1101
return(i_s_cmpmem_fill_low(session, tables, cond, FALSE));
1104
/***********************************************************************
1105
Fill the dynamic table information_schema.innodb_cmpmem_reset. */
1107
CmpmemResetISMethods::fillTable(
1108
/*==================*/
1109
/* out: 0 on success, 1 on failure */
1110
Session* session, /* in: thread */
1111
TableList* tables, /* in/out: tables to fill */
1112
COND* cond) /* in: condition (ignored) */
1114
return(i_s_cmpmem_fill_low(session, tables, cond, TRUE));
1117
/***********************************************************************
1118
Bind the dynamic table information_schema.innodb_cmpmem. */
1122
/* out: 0 on success */
1126
if ((innodb_cmpmem_schema_table= new drizzled::plugin::InfoSchemaTable("INNODB_CMPMEM")) == NULL)
1129
innodb_cmpmem_schema_table->setColumnInfo(i_s_cmpmem_fields_info);
1130
innodb_cmpmem_schema_table->setInfoSchemaMethods(&cmpmem_methods);
1135
/***********************************************************************
1136
Bind the dynamic table information_schema.innodb_cmpmem_reset. */
1138
i_s_cmpmem_reset_init(
1139
/*==================*/
1140
/* out: 0 on success */
1143
if ((innodb_cmpmem_reset_schema_table= new drizzled::plugin::InfoSchemaTable("INNODB_CMPMEM_RESET")) == NULL)
1146
innodb_cmpmem_reset_schema_table->setColumnInfo(i_s_cmpmem_fields_info);
1147
innodb_cmpmem_reset_schema_table->setInfoSchemaMethods(&cmpmem_reset_methods);
1152
/***********************************************************************
1153
Unbind a dynamic INFORMATION_SCHEMA table. */
1157
/* out: 0 on success */
1158
drizzled::plugin::Registry ®istry) /* in/out: table schema object */
1160
registry.remove(innodb_trx_schema_table);
1161
registry.remove(innodb_locks_schema_table);
1162
registry.remove(innodb_lock_waits_schema_table);
1163
registry.remove(innodb_cmp_schema_table);
1164
registry.remove(innodb_cmp_reset_schema_table);
1165
registry.remove(innodb_cmpmem_schema_table);
1166
registry.remove(innodb_cmpmem_reset_schema_table);
1168
delete innodb_trx_schema_table;
1169
delete innodb_locks_schema_table;
1170
delete innodb_lock_waits_schema_table;
1171
delete innodb_cmp_schema_table;
1172
delete innodb_cmp_reset_schema_table;
1173
delete innodb_cmpmem_schema_table;
1174
delete innodb_cmpmem_reset_schema_table;