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
/**************************************************//**
21
InnoDB INFORMATION SCHEMA tables interface to MySQL.
23
Created July 18, 2007 Vasil Dimov
24
*******************************************************/
26
#include <drizzled/server_includes.h>
27
#include <drizzled/error.h>
28
#include <mystrings/m_ctype.h>
29
#include <mysys/my_sys.h>
30
#include <mysys/hash.h>
31
#include <mysys/mysys_err.h>
32
#include <drizzled/plugin.h>
33
#include <drizzled/field.h>
34
#include <drizzled/table.h>
35
#include <drizzled/plugin/info_schema_table.h>
42
#include "trx0trx.h" /* for TRX_QUE_STATE_STR_MAX_LEN */
43
#include "buf0buddy.h" /* for i_s_cmpmem */
44
#include "buf0buf.h" /* for buf_pool and PAGE_ZIP_MIN_SIZE */
45
#include "ha_prototypes.h" /* for innobase_convert_name() */
46
#include "srv0start.h" /* for srv_was_started */
48
#include "handler0vars.h"
50
static const char plugin_author[] = "Innobase Oy";
57
#define RETURN_IF_INNODB_NOT_STARTED(plugin_name) \
59
if (!srv_was_started) { \
60
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN, \
61
ER_CANT_FIND_SYSTEM_REC, \
62
"InnoDB: SELECTing from " \
63
"INFORMATION_SCHEMA.%s but " \
64
"the InnoDB storage engine " \
65
"is not installed", plugin_name); \
70
#define STRUCT_FLD(name, value) value
72
drizzled::plugin::InfoSchemaTable *innodb_trx_schema_table= NULL;
73
drizzled::plugin::InfoSchemaTable *innodb_locks_schema_table= NULL;
74
drizzled::plugin::InfoSchemaTable *innodb_lock_waits_schema_table= NULL;
75
drizzled::plugin::InfoSchemaTable *innodb_cmp_schema_table= NULL;
76
drizzled::plugin::InfoSchemaTable *innodb_cmp_reset_schema_table= NULL;
77
drizzled::plugin::InfoSchemaTable *innodb_cmpmem_schema_table= NULL;
78
drizzled::plugin::InfoSchemaTable *innodb_cmpmem_reset_schema_table= NULL;
80
static TrxISMethods trx_methods;
81
static CmpISMethods cmp_methods;
82
static CmpResetISMethods cmp_reset_methods;
83
static CmpmemISMethods cmpmem_methods;
84
static CmpmemResetISMethods cmpmem_reset_methods;
87
Use the following types mapping:
89
C type ST_FIELD_INFO::field_type
90
---------------------------------
91
long DRIZZLE_TYPE_LONGLONG
92
(field_length=MY_INT64_NUM_DECIMAL_DIGITS)
94
long unsigned DRIZZLE_TYPE_LONGLONG
95
(field_length=MY_INT64_NUM_DECIMAL_DIGITS, field_flags=MY_I_S_UNSIGNED)
97
char* DRIZZLE_TYPE_STRING
100
float DRIZZLE_TYPE_FLOAT
101
(field_length=0 is ignored)
103
void* DRIZZLE_TYPE_LONGLONG
104
(field_length=MY_INT64_NUM_DECIMAL_DIGITS, field_flags=MY_I_S_UNSIGNED)
106
boolean (if else) DRIZZLE_TYPE_LONG
109
time_t DRIZZLE_TYPE_DATETIME
110
(field_length=0 ignored)
111
---------------------------------
114
/* XXX these are defined in mysql_priv.h inside #ifdef DRIZZLE_SERVER */
115
void localtime_to_TIME(DRIZZLE_TIME *to, struct tm *from);
117
/*******************************************************************//**
118
Auxiliary function to store time_t value in MYSQL_TYPE_DATETIME
120
@return 0 on success */
125
Field* field, /*!< in/out: target field for storage */
126
time_t time) /*!< in: value to store */
128
DRIZZLE_TIME my_time;
132
/* use this if you are sure that `variables' and `time_zone'
133
are always initialized */
134
session->variables.time_zone->gmt_sec_to_TIME(
135
&my_time, (time_t) time);
137
localtime_r(&time, &tm_time);
138
localtime_to_TIME(&my_time, &tm_time);
139
my_time.time_type = DRIZZLE_TIMESTAMP_DATETIME;
142
return(field->store_time(&my_time, DRIZZLE_TIMESTAMP_DATETIME));
145
/*******************************************************************//**
146
Auxiliary function to store char* value in MYSQL_TYPE_STRING field.
147
@return 0 on success */
152
Field* field, /*!< in/out: target field for storage */
153
const char* str) /*!< in: NUL-terminated utf-8 string,
160
ret = field->store(str, strlen(str),
161
system_charset_info);
162
field->set_notnull();
165
ret = 0; /* success */
172
/*******************************************************************//**
173
Auxiliary function to store ulint value in DRIZZLE_TYPE_LONGLONG field.
174
If the value is ULINT_UNDEFINED then the field it set to NULL.
175
@return 0 on success */
180
Field* field, /*!< in/out: target field for storage */
181
ulint n) /*!< in: value to store */
185
if (n != ULINT_UNDEFINED) {
187
ret = field->store(n);
188
field->set_notnull();
191
ret = 0; /* success */
198
/* Fields of the dynamic table INFORMATION_SCHEMA.innodb_trx */
199
static drizzled::plugin::ColumnInfo innodb_trx_fields_info[] =
202
drizzled::plugin::ColumnInfo("trx_id",
204
DRIZZLE_TYPE_VARCHAR,
209
#define IDX_TRX_STATE 1
210
drizzled::plugin::ColumnInfo("trx_state",
211
TRX_QUE_STATE_STR_MAX_LEN + 1,
212
DRIZZLE_TYPE_VARCHAR,
217
#define IDX_TRX_STARTED 2
218
drizzled::plugin::ColumnInfo("trx_started",
220
DRIZZLE_TYPE_DATETIME,
225
#define IDX_TRX_REQUESTED_LOCK_ID 3
226
drizzled::plugin::ColumnInfo("trx_requested_lock_id",
227
TRX_I_S_LOCK_ID_MAX_LEN + 1,
228
DRIZZLE_TYPE_VARCHAR,
233
#define IDX_TRX_WAIT_STARTED 4
234
drizzled::plugin::ColumnInfo("trx_wait_started",
236
DRIZZLE_TYPE_DATETIME,
241
#define IDX_TRX_WEIGHT 5
242
drizzled::plugin::ColumnInfo("trx_weight",
243
MY_INT64_NUM_DECIMAL_DIGITS,
244
DRIZZLE_TYPE_LONGLONG,
249
#define IDX_TRX_DRIZZLE_THREAD_ID 6
250
drizzled::plugin::ColumnInfo("trx_mysql_thread_id",
251
MY_INT64_NUM_DECIMAL_DIGITS,
252
DRIZZLE_TYPE_LONGLONG,
257
#define IDX_TRX_QUERY 7
258
drizzled::plugin::ColumnInfo("trx_query",
259
TRX_I_S_TRX_QUERY_MAX_LEN,
260
DRIZZLE_TYPE_VARCHAR,
265
drizzled::plugin::ColumnInfo()
268
/*******************************************************************//**
269
Read data from cache buffer and fill the INFORMATION_SCHEMA.innodb_trx
271
@return 0 on success */
274
fill_innodb_trx_from_cache(
275
/*=======================*/
276
trx_i_s_cache_t* cache, /*!< in: cache to read from */
277
Table* table, /*!< in/out: fill this table */
278
drizzled::plugin::InfoSchemaTable *schema_table)
282
char lock_id[TRX_I_S_LOCK_ID_MAX_LEN + 1];
285
fields = table->field;
287
rows_num = trx_i_s_cache_get_rows_used(cache,
290
for (i = 0; i < rows_num; i++) {
293
char trx_id[TRX_ID_MAX_LEN + 1];
295
row = (i_s_trx_row_t*)
296
trx_i_s_cache_get_nth_row(
297
cache, I_S_INNODB_TRX, i);
300
ut_snprintf(trx_id, sizeof(trx_id), TRX_ID_FMT, row->trx_id);
301
OK(field_store_string(fields[IDX_TRX_ID], trx_id));
304
OK(field_store_string(fields[IDX_TRX_STATE],
308
OK(field_store_time_t(fields[IDX_TRX_STARTED],
309
(time_t) row->trx_started));
311
/* trx_requested_lock_id */
312
/* trx_wait_started */
313
if (row->trx_wait_started != 0) {
315
OK(field_store_string(
316
fields[IDX_TRX_REQUESTED_LOCK_ID],
317
trx_i_s_create_lock_id(
318
row->requested_lock_row,
319
lock_id, sizeof(lock_id))));
320
/* field_store_string() sets it no notnull */
322
OK(field_store_time_t(
323
fields[IDX_TRX_WAIT_STARTED],
324
(time_t) row->trx_wait_started));
325
fields[IDX_TRX_WAIT_STARTED]->set_notnull();
328
fields[IDX_TRX_REQUESTED_LOCK_ID]->set_null();
329
fields[IDX_TRX_WAIT_STARTED]->set_null();
333
OK(fields[IDX_TRX_WEIGHT]->store((int64_t) row->trx_weight,
336
/* trx_mysql_thread_id */
337
OK(fields[IDX_TRX_DRIZZLE_THREAD_ID]->store(
338
row->trx_mysql_thread_id));
341
OK(field_store_string(fields[IDX_TRX_QUERY],
344
schema_table->addRow(table->record[0],
345
table->s->reclength);
351
/*******************************************************************//**
352
Bind the dynamic table INFORMATION_SCHEMA.innodb_trx
353
@return 0 on success */
358
if ((innodb_trx_schema_table= new drizzled::plugin::InfoSchemaTable("INNODB_TRX")) == NULL)
361
innodb_trx_schema_table->setColumnInfo(innodb_trx_fields_info);
362
innodb_trx_schema_table->setInfoSchemaMethods(&trx_methods);
368
/* Fields of the dynamic table INFORMATION_SCHEMA.innodb_locks */
369
static drizzled::plugin::ColumnInfo innodb_locks_fields_info[] =
371
#define IDX_LOCK_ID 0
372
drizzled::plugin::ColumnInfo("lock_id",
373
TRX_I_S_LOCK_ID_MAX_LEN + 1,
374
DRIZZLE_TYPE_VARCHAR,
379
#define IDX_LOCK_TRX_ID 1
380
drizzled::plugin::ColumnInfo("lock_trx_id",
382
DRIZZLE_TYPE_VARCHAR,
387
#define IDX_LOCK_MODE 2
388
drizzled::plugin::ColumnInfo("lock_mode",
389
/* S[,GAP] X[,GAP] IS[,GAP] IX[,GAP] AUTO_INC UNKNOWN */
391
DRIZZLE_TYPE_VARCHAR,
396
#define IDX_LOCK_TYPE 3
397
drizzled::plugin::ColumnInfo("lock_type",
398
32, /* RECORD|TABLE|UNKNOWN */
399
DRIZZLE_TYPE_VARCHAR,
404
#define IDX_LOCK_TABLE 4
405
drizzled::plugin::ColumnInfo("lock_table",
407
DRIZZLE_TYPE_VARCHAR,
412
#define IDX_LOCK_INDEX 5
413
drizzled::plugin::ColumnInfo("lock_index",
415
DRIZZLE_TYPE_VARCHAR,
420
#define IDX_LOCK_SPACE 6
421
drizzled::plugin::ColumnInfo("lock_space",
422
MY_INT64_NUM_DECIMAL_DIGITS,
423
DRIZZLE_TYPE_LONGLONG,
425
MY_I_S_UNSIGNED | MY_I_S_MAYBE_NULL,
428
#define IDX_LOCK_PAGE 7
429
drizzled::plugin::ColumnInfo("lock_page",
430
MY_INT64_NUM_DECIMAL_DIGITS,
431
DRIZZLE_TYPE_LONGLONG,
433
MY_I_S_UNSIGNED | MY_I_S_MAYBE_NULL,
436
#define IDX_LOCK_REC 8
437
drizzled::plugin::ColumnInfo("lock_rec",
438
MY_INT64_NUM_DECIMAL_DIGITS,
439
DRIZZLE_TYPE_LONGLONG,
441
MY_I_S_UNSIGNED | MY_I_S_MAYBE_NULL,
444
#define IDX_LOCK_DATA 9
445
drizzled::plugin::ColumnInfo("lock_data",
446
TRX_I_S_LOCK_DATA_MAX_LEN,
447
DRIZZLE_TYPE_VARCHAR,
452
drizzled::plugin::ColumnInfo()
455
/*******************************************************************//**
456
Read data from cache buffer and fill the INFORMATION_SCHEMA.innodb_locks
458
@return 0 on success */
461
fill_innodb_locks_from_cache(
462
/*=========================*/
463
trx_i_s_cache_t* cache, /*!< in: cache to read from */
464
Session* session,/*!< in: MySQL client connection */
465
Table* table, /*!< in/out: fill this table */
466
drizzled::plugin::InfoSchemaTable *schema_table)
470
char lock_id[TRX_I_S_LOCK_ID_MAX_LEN + 1];
473
fields = table->field;
475
rows_num = trx_i_s_cache_get_rows_used(cache,
478
for (i = 0; i < rows_num; i++) {
480
i_s_locks_row_t* row;
482
/* note that the decoded database or table name is
483
never expected to be longer than NAME_LEN;
484
NAME_LEN for database name
485
2 for surrounding quotes around database name
486
NAME_LEN for table name
487
2 for surrounding quotes around table name
488
1 for the separating dot (.)
489
9 for the #mysql50# prefix */
490
char buf[2 * NAME_LEN + 14];
493
char lock_trx_id[TRX_ID_MAX_LEN + 1];
495
row = (i_s_locks_row_t*)
496
trx_i_s_cache_get_nth_row(
497
cache, I_S_INNODB_LOCKS, i);
500
trx_i_s_create_lock_id(row, lock_id, sizeof(lock_id));
501
OK(field_store_string(fields[IDX_LOCK_ID],
505
ut_snprintf(lock_trx_id, sizeof(lock_trx_id),
506
TRX_ID_FMT, row->lock_trx_id);
507
OK(field_store_string(fields[IDX_LOCK_TRX_ID], lock_trx_id));
510
OK(field_store_string(fields[IDX_LOCK_MODE],
514
OK(field_store_string(fields[IDX_LOCK_TYPE],
518
bufend = innobase_convert_name(buf, sizeof(buf),
520
strlen(row->lock_table),
522
OK(fields[IDX_LOCK_TABLE]->store(buf, bufend - buf,
523
system_charset_info));
526
if (row->lock_index != NULL) {
528
bufend = innobase_convert_name(buf, sizeof(buf),
530
strlen(row->lock_index),
532
OK(fields[IDX_LOCK_INDEX]->store(buf, bufend - buf,
533
system_charset_info));
534
fields[IDX_LOCK_INDEX]->set_notnull();
537
fields[IDX_LOCK_INDEX]->set_null();
541
OK(field_store_ulint(fields[IDX_LOCK_SPACE],
545
OK(field_store_ulint(fields[IDX_LOCK_PAGE],
549
OK(field_store_ulint(fields[IDX_LOCK_REC],
553
OK(field_store_string(fields[IDX_LOCK_DATA],
556
schema_table->addRow(table->record[0],
557
table->s->reclength);
563
/*******************************************************************//**
564
Bind the dynamic table INFORMATION_SCHEMA.innodb_locks
565
@return 0 on success */
571
if ((innodb_locks_schema_table= new drizzled::plugin::InfoSchemaTable("INNODB_LOCKS")) == NULL)
574
innodb_locks_schema_table->setColumnInfo(innodb_locks_fields_info);
575
innodb_locks_schema_table->setInfoSchemaMethods(&trx_methods);
580
/* Fields of the dynamic table INFORMATION_SCHEMA.innodb_lock_waits */
581
static drizzled::plugin::ColumnInfo innodb_lock_waits_fields_info[] =
583
#define IDX_REQUESTING_TRX_ID 0
584
drizzled::plugin::ColumnInfo("requesting_trx_id",
586
DRIZZLE_TYPE_VARCHAR,
591
#define IDX_REQUESTED_LOCK_ID 1
592
drizzled::plugin::ColumnInfo("requested_lock_id",
593
TRX_I_S_LOCK_ID_MAX_LEN + 1,
594
DRIZZLE_TYPE_VARCHAR,
599
#define IDX_BLOCKING_TRX_ID 2
600
drizzled::plugin::ColumnInfo("blocking_trx_id",
602
DRIZZLE_TYPE_VARCHAR,
607
#define IDX_BLOCKING_LOCK_ID 3
608
drizzled::plugin::ColumnInfo("blocking_lock_id",
609
TRX_I_S_LOCK_ID_MAX_LEN + 1,
610
DRIZZLE_TYPE_VARCHAR,
615
drizzled::plugin::ColumnInfo()
618
/*******************************************************************//**
619
Read data from cache buffer and fill the
620
INFORMATION_SCHEMA.innodb_lock_waits table with it.
621
@return 0 on success */
624
fill_innodb_lock_waits_from_cache(
625
/*==============================*/
626
trx_i_s_cache_t* cache, /*!< in: cache to read from */
627
Table* table, /*!< in/out: fill this table */
628
drizzled::plugin::InfoSchemaTable *schema_table)
632
char requested_lock_id[TRX_I_S_LOCK_ID_MAX_LEN + 1];
633
char blocking_lock_id[TRX_I_S_LOCK_ID_MAX_LEN + 1];
636
fields = table->field;
638
rows_num = trx_i_s_cache_get_rows_used(cache,
639
I_S_INNODB_LOCK_WAITS);
641
for (i = 0; i < rows_num; i++) {
643
i_s_lock_waits_row_t* row;
645
char requesting_trx_id[TRX_ID_MAX_LEN + 1];
646
char blocking_trx_id[TRX_ID_MAX_LEN + 1];
648
row = (i_s_lock_waits_row_t*)
649
trx_i_s_cache_get_nth_row(
650
cache, I_S_INNODB_LOCK_WAITS, i);
652
/* requesting_trx_id */
653
ut_snprintf(requesting_trx_id, sizeof(requesting_trx_id),
654
TRX_ID_FMT, row->requested_lock_row->lock_trx_id);
655
OK(field_store_string(fields[IDX_REQUESTING_TRX_ID],
658
/* requested_lock_id */
659
OK(field_store_string(
660
fields[IDX_REQUESTED_LOCK_ID],
661
trx_i_s_create_lock_id(
662
row->requested_lock_row,
664
sizeof(requested_lock_id))));
666
/* blocking_trx_id */
667
ut_snprintf(blocking_trx_id, sizeof(blocking_trx_id),
668
TRX_ID_FMT, row->blocking_lock_row->lock_trx_id);
669
OK(field_store_string(fields[IDX_BLOCKING_TRX_ID],
672
/* blocking_lock_id */
673
OK(field_store_string(
674
fields[IDX_BLOCKING_LOCK_ID],
675
trx_i_s_create_lock_id(
676
row->blocking_lock_row,
678
sizeof(blocking_lock_id))));
680
schema_table->addRow(table->record[0],
681
table->s->reclength);
687
/*******************************************************************//**
688
Bind the dynamic table INFORMATION_SCHEMA.innodb_lock_waits
689
@return 0 on success */
691
innodb_lock_waits_init()
692
/*===================*/
695
if ((innodb_lock_waits_schema_table= new drizzled::plugin::InfoSchemaTable("INNODB_LOCK_WAITS")) == NULL)
698
innodb_lock_waits_schema_table->setColumnInfo(innodb_lock_waits_fields_info);
699
innodb_lock_waits_schema_table->setInfoSchemaMethods(&trx_methods);
706
/*******************************************************************//**
707
Common function to fill any of the dynamic tables:
708
INFORMATION_SCHEMA.innodb_trx
709
INFORMATION_SCHEMA.innodb_locks
710
INFORMATION_SCHEMA.innodb_lock_waits
711
@return 0 on success */
713
TrxISMethods::fillTable(
714
/*======================*/
715
Session* session,/*!< in: thread */
716
Table* table, /*!< in/out: tables to fill */
717
drizzled::plugin::InfoSchemaTable *schema_table)
719
const char* table_name;
721
trx_i_s_cache_t* cache;
723
/* minimize the number of places where global variables are
725
cache = trx_i_s_cache;
727
/* which table we have to fill? */
728
table_name = schema_table->getName().c_str();
729
/* or table_name = tables->schema_table->table_name; */
731
RETURN_IF_INNODB_NOT_STARTED(table_name);
733
/* update the cache */
734
trx_i_s_cache_start_write(cache);
735
trx_i_s_possibly_fetch_data_into_cache(cache);
736
trx_i_s_cache_end_write(cache);
738
if (trx_i_s_cache_is_truncated(cache)) {
740
/* XXX show warning to user if possible */
741
fprintf(stderr, "Warning: data in %s truncated due to "
742
"memory limit of %d bytes\n", table_name,
748
trx_i_s_cache_start_read(cache);
750
if (innobase_strcasecmp(table_name, "innodb_trx") == 0) {
752
if (fill_innodb_trx_from_cache(
753
cache, table, schema_table) != 0) {
758
} else if (innobase_strcasecmp(table_name, "innodb_locks") == 0) {
760
if (fill_innodb_locks_from_cache(
761
cache, session, table, schema_table) != 0) {
766
} else if (innobase_strcasecmp(table_name, "innodb_lock_waits") == 0) {
768
if (fill_innodb_lock_waits_from_cache(
769
cache, table, schema_table) != 0) {
776
/* huh! what happened!? */
778
"InnoDB: trx_i_s_common_fill_table() was "
779
"called to fill unknown table: %s.\n"
780
"This function only knows how to fill "
781
"innodb_trx, innodb_locks and "
782
"innodb_lock_waits tables.\n", table_name);
787
trx_i_s_cache_end_read(cache);
792
/* if this function returns something else than 0 then a
793
deadlock occurs between the mysqld server and mysql client,
794
see http://bugs.mysql.com/29900 ; when that bug is resolved
795
we can enable the return(ret) above */
800
/* Fields of the dynamic table information_schema.innodb_cmp. */
801
static drizzled::plugin::ColumnInfo i_s_cmp_fields_info[] =
803
drizzled::plugin::ColumnInfo("page_size",
808
"Compressed Page Size"),
810
drizzled::plugin::ColumnInfo("compress_ops",
811
MY_INT32_NUM_DECIMAL_DIGITS,
815
"Total Number of Compressions"),
817
drizzled::plugin::ColumnInfo("compress_ops_ok",
818
MY_INT32_NUM_DECIMAL_DIGITS,
822
"Total Number of Successful Compressions"),
824
drizzled::plugin::ColumnInfo("compress_time",
825
MY_INT32_NUM_DECIMAL_DIGITS,
829
"Total Duration of Compressions in Seconds"),
831
drizzled::plugin::ColumnInfo("uncompress_ops",
832
MY_INT32_NUM_DECIMAL_DIGITS,
836
"Total Number of Decompressions"),
838
drizzled::plugin::ColumnInfo("uncompress_time",
839
MY_INT32_NUM_DECIMAL_DIGITS,
843
"Total Duration of Decompressions in Seconds"),
845
drizzled::plugin::ColumnInfo()
849
/*******************************************************************//**
850
Fill the dynamic table information_schema.innodb_cmp or
852
@return 0 on success, 1 on failure */
857
Session* session,/*!< in: thread */
858
Table* table, /*!< in/out: tables to fill */
859
drizzled::plugin::InfoSchemaTable *schema_table,
860
ibool reset) /*!< in: TRUE=reset cumulated counts */
865
RETURN_IF_INNODB_NOT_STARTED(schema_table->getName().c_str());
867
for (uint i = 0; i < PAGE_ZIP_NUM_SSIZE - 1; i++) {
868
page_zip_stat_t* zip_stat = &page_zip_stat[i];
870
table->field[0]->store(PAGE_ZIP_MIN_SIZE << i);
872
/* The cumulated counts are not protected by any
873
mutex. Thus, some operation in page0zip.c could
874
increment a counter between the time we read it and
875
clear it. We could introduce mutex protection, but it
876
could cause a measureable performance hit in
878
table->field[1]->store(zip_stat->compressed);
879
table->field[2]->store(zip_stat->compressed_ok);
880
table->field[3]->store(
881
(ulong) (zip_stat->compressed_usec / 1000000));
882
table->field[4]->store(zip_stat->decompressed);
883
table->field[5]->store(
884
(ulong) (zip_stat->decompressed_usec / 1000000));
887
memset(zip_stat, 0, sizeof *zip_stat);
890
schema_table->addRow(table->record[0],
891
table->s->reclength);
897
/*******************************************************************//**
898
Fill the dynamic table information_schema.innodb_cmp.
899
@return 0 on success, 1 on failure */
901
CmpISMethods::fillTable(
903
Session* session,/*!< in: thread */
904
Table* table, /*!< in/out: tables to fill */
905
drizzled::plugin::InfoSchemaTable *schema_table)
907
return(i_s_cmp_fill_low(session, table, schema_table, FALSE));
910
/*******************************************************************//**
911
Fill the dynamic table information_schema.innodb_cmp_reset.
912
@return 0 on success, 1 on failure */
914
CmpResetISMethods::fillTable(
916
Session* session,/*!< in: thread */
917
Table* table, /*!< in/out: tables to fill */
918
drizzled::plugin::InfoSchemaTable *schema_table)
920
return(i_s_cmp_fill_low(session, table, schema_table, TRUE));
923
/*******************************************************************//**
924
Bind the dynamic table information_schema.innodb_cmp.
925
@return 0 on success */
931
if ((innodb_cmp_schema_table= new drizzled::plugin::InfoSchemaTable("INNODB_CMP")) == NULL)
934
innodb_cmp_schema_table->setColumnInfo(i_s_cmp_fields_info);
935
innodb_cmp_schema_table->setInfoSchemaMethods(&cmp_methods);
940
/*******************************************************************//**
941
Bind the dynamic table information_schema.innodb_cmp_reset.
942
@return 0 on success */
948
if ((innodb_cmp_reset_schema_table= new drizzled::plugin::InfoSchemaTable("INNODB_CMP_RESET")) == NULL)
951
innodb_cmp_reset_schema_table->setColumnInfo(i_s_cmp_fields_info);
952
innodb_cmp_reset_schema_table->setInfoSchemaMethods(&cmp_reset_methods);
959
/* Fields of the dynamic table information_schema.innodb_cmpmem. */
960
static drizzled::plugin::ColumnInfo i_s_cmpmem_fields_info[] =
962
drizzled::plugin::ColumnInfo("page_size",
969
drizzled::plugin::ColumnInfo("pages_used",
970
MY_INT32_NUM_DECIMAL_DIGITS,
976
drizzled::plugin::ColumnInfo("pages_free",
977
MY_INT32_NUM_DECIMAL_DIGITS,
981
"Currently Available"),
983
drizzled::plugin::ColumnInfo("relocation_ops",
984
MY_INT64_NUM_DECIMAL_DIGITS,
985
DRIZZLE_TYPE_LONGLONG,
988
"Total Number of Relocations"),
990
drizzled::plugin::ColumnInfo("relocation_time",
991
MY_INT32_NUM_DECIMAL_DIGITS,
995
"Total Duration of Relocations, in Seconds"),
997
drizzled::plugin::ColumnInfo()
1000
/*******************************************************************//**
1001
Fill the dynamic table information_schema.innodb_cmpmem or
1002
innodb_cmpmem_reset.
1003
@return 0 on success, 1 on failure */
1006
i_s_cmpmem_fill_low(
1007
/*================*/
1008
Session* session,/*!< in: thread */
1009
Table* table, /*!< in/out: tables to fill */
1010
drizzled::plugin::InfoSchemaTable *schema_table,
1011
ibool reset) /*!< in: TRUE=reset cumulated counts */
1015
RETURN_IF_INNODB_NOT_STARTED(schema_table->getName().c_str());
1017
buf_pool_mutex_enter();
1019
for (uint x = 0; x <= BUF_BUDDY_SIZES; x++) {
1020
buf_buddy_stat_t* buddy_stat = &buf_buddy_stat[x];
1022
table->field[0]->store(BUF_BUDDY_LOW << x);
1023
table->field[1]->store(buddy_stat->used);
1024
table->field[2]->store(UNIV_LIKELY(x < BUF_BUDDY_SIZES)
1025
? UT_LIST_GET_LEN(buf_pool->zip_free[x])
1027
table->field[3]->store((int64_t) buddy_stat->relocated, true);
1028
table->field[4]->store(
1029
(ulong) (buddy_stat->relocated_usec / 1000000));
1032
/* This is protected by buf_pool_mutex. */
1033
buddy_stat->relocated = 0;
1034
buddy_stat->relocated_usec = 0;
1037
schema_table->addRow(table->record[0],
1038
table->s->reclength);
1041
buf_pool_mutex_exit();
1045
/*******************************************************************//**
1046
Fill the dynamic table information_schema.innodb_cmpmem.
1047
@return 0 on success, 1 on failure */
1049
CmpmemISMethods::fillTable(
1051
Session* session,/*!< in: thread */
1052
Table* table, /*!< in/out: tables to fill */
1053
drizzled::plugin::InfoSchemaTable *schema_table)
1055
return(i_s_cmpmem_fill_low(session, table, schema_table, FALSE));
1058
/*******************************************************************//**
1059
Fill the dynamic table information_schema.innodb_cmpmem_reset.
1060
@return 0 on success, 1 on failure */
1062
CmpmemResetISMethods::fillTable(
1063
/*==================*/
1064
Session* session,/*!< in: thread */
1065
Table* table, /*!< in/out: tables to fill */
1066
drizzled::plugin::InfoSchemaTable *schema_table)
1068
return(i_s_cmpmem_fill_low(session, table, schema_table, TRUE));
1071
/*******************************************************************//**
1072
Bind the dynamic table information_schema.innodb_cmpmem.
1073
@return 0 on success */
1079
if ((innodb_cmpmem_schema_table= new drizzled::plugin::InfoSchemaTable("INNODB_CMPMEM")) == NULL)
1082
innodb_cmpmem_schema_table->setColumnInfo(i_s_cmpmem_fields_info);
1083
innodb_cmpmem_schema_table->setInfoSchemaMethods(&cmpmem_methods);
1088
/*******************************************************************//**
1089
Bind the dynamic table information_schema.innodb_cmpmem_reset.
1090
@return 0 on success */
1092
i_s_cmpmem_reset_init()
1093
/*==================*/
1095
if ((innodb_cmpmem_reset_schema_table= new drizzled::plugin::InfoSchemaTable("INNODB_CMPMEM_RESET")) == NULL)
1098
innodb_cmpmem_reset_schema_table->setColumnInfo(i_s_cmpmem_fields_info);
1099
innodb_cmpmem_reset_schema_table->setInfoSchemaMethods(&cmpmem_reset_methods);
1104
/*******************************************************************//**
1105
Unbind a dynamic INFORMATION_SCHEMA table.
1106
@return 0 on success */
1110
drizzled::plugin::Registry ®istry) /*!< in/out: table schema object */
1112
registry.remove(innodb_trx_schema_table);
1113
registry.remove(innodb_locks_schema_table);
1114
registry.remove(innodb_lock_waits_schema_table);
1115
registry.remove(innodb_cmp_schema_table);
1116
registry.remove(innodb_cmp_reset_schema_table);
1117
registry.remove(innodb_cmpmem_schema_table);
1118
registry.remove(innodb_cmpmem_reset_schema_table);
1120
delete innodb_trx_schema_table;
1121
delete innodb_locks_schema_table;
1122
delete innodb_lock_waits_schema_table;
1123
delete innodb_cmp_schema_table;
1124
delete innodb_cmp_reset_schema_table;
1125
delete innodb_cmpmem_schema_table;
1126
delete innodb_cmpmem_reset_schema_table;