Skip to content

Commit 0a4817f

Browse files
AliSQLAliSQL
authored andcommitted
[Feature] Issue#29: ADD INFORMATION_SCHEMA.INNODB_RSEG TABLE TO DISPLAY
THE ROLLBACK INFORMATION Description: ------------ This feature introduced one system table "information_schema.innodb_rseg" to show the status of each of the rollback segments information.
1 parent e6abc82 commit 0a4817f

File tree

6 files changed

+280
-34
lines changed

6 files changed

+280
-34
lines changed

mysql-test/r/mysqlshow.result

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -110,34 +110,35 @@ Database: information_schema
110110
| TRIGGERS |
111111
| USER_PRIVILEGES |
112112
| VIEWS |
113-
| INNODB_LOCKS |
114-
| INNODB_TRX |
113+
| INNODB_CMP_RESET |
114+
| INNODB_RSEG |
115115
| INNODB_SYS_DATAFILES |
116-
| INNODB_LOCK_WAITS |
116+
| INNODB_TRX |
117117
| INNODB_SYS_TABLESTATS |
118-
| INNODB_CMP |
119-
| INNODB_METRICS |
120-
| INNODB_CMP_RESET |
118+
| INNODB_FT_CONFIG |
119+
| INNODB_FT_BEING_DELETED |
120+
| INNODB_LOCKS |
121121
| INNODB_CMP_PER_INDEX |
122-
| INNODB_CMPMEM_RESET |
123-
| INNODB_FT_DELETED |
124122
| INNODB_BUFFER_PAGE_LRU |
125-
| INNODB_SYS_FOREIGN |
126-
| INNODB_SYS_COLUMNS |
123+
| INNODB_FT_DELETED |
124+
| INNODB_CMPMEM_RESET |
125+
| INNODB_LOCK_WAITS |
126+
| INNODB_CMP |
127127
| INNODB_SYS_INDEXES |
128-
| INNODB_FT_DEFAULT_STOPWORD |
128+
| INNODB_SYS_TABLES |
129129
| INNODB_SYS_FIELDS |
130130
| INNODB_CMP_PER_INDEX_RESET |
131131
| INNODB_BUFFER_PAGE |
132-
| INNODB_CMPMEM |
132+
| INNODB_FT_DEFAULT_STOPWORD |
133133
| INNODB_FT_INDEX_TABLE |
134-
| INNODB_FT_BEING_DELETED |
135-
| INNODB_SYS_TABLESPACES |
136134
| INNODB_FT_INDEX_CACHE |
135+
| INNODB_SYS_TABLESPACES |
136+
| INNODB_METRICS |
137137
| INNODB_SYS_FOREIGN_COLS |
138-
| INNODB_SYS_TABLES |
138+
| INNODB_CMPMEM |
139139
| INNODB_BUFFER_POOL_STATS |
140-
| INNODB_FT_CONFIG |
140+
| INNODB_SYS_COLUMNS |
141+
| INNODB_SYS_FOREIGN |
141142
+---------------------------------------+
142143
Database: INFORMATION_SCHEMA
143144
+---------------------------------------+
@@ -174,34 +175,35 @@ Database: INFORMATION_SCHEMA
174175
| TRIGGERS |
175176
| USER_PRIVILEGES |
176177
| VIEWS |
177-
| INNODB_LOCKS |
178-
| INNODB_TRX |
178+
| INNODB_CMP_RESET |
179+
| INNODB_RSEG |
179180
| INNODB_SYS_DATAFILES |
180-
| INNODB_LOCK_WAITS |
181+
| INNODB_TRX |
181182
| INNODB_SYS_TABLESTATS |
182-
| INNODB_CMP |
183-
| INNODB_METRICS |
184-
| INNODB_CMP_RESET |
183+
| INNODB_FT_CONFIG |
184+
| INNODB_FT_BEING_DELETED |
185+
| INNODB_LOCKS |
185186
| INNODB_CMP_PER_INDEX |
186-
| INNODB_CMPMEM_RESET |
187-
| INNODB_FT_DELETED |
188187
| INNODB_BUFFER_PAGE_LRU |
189-
| INNODB_SYS_FOREIGN |
190-
| INNODB_SYS_COLUMNS |
188+
| INNODB_FT_DELETED |
189+
| INNODB_CMPMEM_RESET |
190+
| INNODB_LOCK_WAITS |
191+
| INNODB_CMP |
191192
| INNODB_SYS_INDEXES |
192-
| INNODB_FT_DEFAULT_STOPWORD |
193+
| INNODB_SYS_TABLES |
193194
| INNODB_SYS_FIELDS |
194195
| INNODB_CMP_PER_INDEX_RESET |
195196
| INNODB_BUFFER_PAGE |
196-
| INNODB_CMPMEM |
197+
| INNODB_FT_DEFAULT_STOPWORD |
197198
| INNODB_FT_INDEX_TABLE |
198-
| INNODB_FT_BEING_DELETED |
199-
| INNODB_SYS_TABLESPACES |
200199
| INNODB_FT_INDEX_CACHE |
200+
| INNODB_SYS_TABLESPACES |
201+
| INNODB_METRICS |
201202
| INNODB_SYS_FOREIGN_COLS |
202-
| INNODB_SYS_TABLES |
203+
| INNODB_CMPMEM |
203204
| INNODB_BUFFER_POOL_STATS |
204-
| INNODB_FT_CONFIG |
205+
| INNODB_SYS_COLUMNS |
206+
| INNODB_SYS_FOREIGN |
205207
+---------------------------------------+
206208
Wildcard: inf_rmation_schema
207209
+--------------------+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
show create table information_schema.innodb_rseg;
2+
Table Create Table
3+
INNODB_RSEG CREATE TEMPORARY TABLE `INNODB_RSEG` (
4+
`rseg_id` bigint(21) unsigned NOT NULL DEFAULT '0',
5+
`space_id` bigint(21) unsigned NOT NULL DEFAULT '0',
6+
`zip_size` bigint(21) unsigned NOT NULL DEFAULT '0',
7+
`page_no` bigint(21) unsigned NOT NULL DEFAULT '0',
8+
`max_size` bigint(21) unsigned NOT NULL DEFAULT '0',
9+
`curr_size` bigint(21) unsigned NOT NULL DEFAULT '0'
10+
) ENGINE=MEMORY DEFAULT CHARSET=utf8
11+
create database t_db;
12+
grant select on t_db.* to c@'%';
13+
use t_db;
14+
create table t_rseg(id int primary key auto_increment, col1 varchar(1000))engine=innodb;
15+
insert into t_rseg values(1, repeat('test', 100));
16+
insert into t_rseg(col1) select col1 from t_rseg;
17+
insert into t_rseg(col1) select col1 from t_rseg;
18+
insert into t_rseg(col1) select col1 from t_rseg;
19+
insert into t_rseg(col1) select col1 from t_rseg;
20+
insert into t_rseg(col1) select col1 from t_rseg;
21+
select count(*) from t_rseg;
22+
count(*)
23+
32
24+
commit;
25+
select count(*) from information_schema.innodb_rseg;
26+
count(*)
27+
128
28+
select count(*) from information_schema.innodb_rseg;
29+
ERROR 42000: Access denied; you need (at least one of) the PROCESS privilege(s) for this operation
30+
drop table t_rseg;
31+
drop database t_db;
32+
drop user c@'%';
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
connection default;
2+
show create table information_schema.innodb_rseg;
3+
4+
create database t_db;
5+
grant select on t_db.* to c@'%';
6+
7+
8+
use t_db;
9+
create table t_rseg(id int primary key auto_increment, col1 varchar(1000))engine=innodb;
10+
11+
insert into t_rseg values(1, repeat('test', 100));
12+
13+
let $count = 5;
14+
15+
while ($count) {
16+
eval insert into t_rseg(col1) select col1 from t_rseg;
17+
dec $count;
18+
}
19+
20+
select count(*) from t_rseg;
21+
commit;
22+
23+
select count(*) from information_schema.innodb_rseg;
24+
25+
26+
connect (con1, localhost, c,,);
27+
connection con1;
28+
--error ER_SPECIFIC_ACCESS_DENIED_ERROR
29+
select count(*) from information_schema.innodb_rseg;
30+
31+
connection default;
32+
33+
drop table t_rseg;
34+
drop database t_db;
35+
drop user c@'%';

storage/innobase/handler/ha_innodb.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16941,6 +16941,7 @@ mysql_declare_plugin(innobase)
1694116941
NULL, /* reserved */
1694216942
0, /* flags */
1694316943
},
16944+
i_s_innodb_rseg,
1694416945
i_s_innodb_trx,
1694516946
i_s_innodb_locks,
1694616947
i_s_innodb_lock_waits,

storage/innobase/handler/i_s.cc

Lines changed: 177 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ Created July 18, 2007 Vasil Dimov
5656
#include "fts0priv.h"
5757
#include "btr0btr.h"
5858
#include "page0zip.h"
59+
#include "trx0rseg.h"
5960

6061
/** structure associates a name string with a file page type and/or buffer
6162
page state. */
@@ -620,14 +621,13 @@ fill_innodb_trx_from_cache(
620621
/* trx_requested_lock_id */
621622
/* trx_wait_started */
622623
if (row->trx_wait_started != 0) {
623-
624624
OK(field_store_string(
625625
fields[IDX_TRX_REQUESTED_LOCK_ID],
626626
trx_i_s_create_lock_id(
627627
row->requested_lock_row,
628628
lock_id, sizeof(lock_id))));
629-
/* field_store_string() sets it no notnull */
630629

630+
/* field_store_string() sets it no notnull */
631631
OK(field_store_time_t(
632632
fields[IDX_TRX_WAIT_STARTED],
633633
(time_t) row->trx_wait_started));
@@ -756,6 +756,181 @@ static struct st_mysql_information_schema i_s_info =
756756
MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION
757757
};
758758

759+
/* Fields of the dynamic table information_schema.innodb_rseg. */
760+
static ST_FIELD_INFO i_s_innodb_rseg_fields_info[] =
761+
{
762+
{STRUCT_FLD(field_name, "rseg_id"),
763+
STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
764+
STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
765+
STRUCT_FLD(value, 0),
766+
STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
767+
STRUCT_FLD(old_name, ""),
768+
STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
769+
770+
{STRUCT_FLD(field_name, "space_id"),
771+
STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
772+
STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
773+
STRUCT_FLD(value, 0),
774+
STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
775+
STRUCT_FLD(old_name, ""),
776+
STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
777+
778+
{STRUCT_FLD(field_name, "zip_size"),
779+
STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
780+
STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
781+
STRUCT_FLD(value, 0),
782+
STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
783+
STRUCT_FLD(old_name, ""),
784+
STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
785+
786+
{STRUCT_FLD(field_name, "page_no"),
787+
STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
788+
STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
789+
STRUCT_FLD(value, 0),
790+
STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
791+
STRUCT_FLD(old_name, ""),
792+
STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
793+
794+
{STRUCT_FLD(field_name, "max_size"),
795+
STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
796+
STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
797+
STRUCT_FLD(value, 0),
798+
STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
799+
STRUCT_FLD(old_name, ""),
800+
STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
801+
802+
{STRUCT_FLD(field_name, "curr_size"),
803+
STRUCT_FLD(field_length, MY_INT64_NUM_DECIMAL_DIGITS),
804+
STRUCT_FLD(field_type, MYSQL_TYPE_LONGLONG),
805+
STRUCT_FLD(value, 0),
806+
STRUCT_FLD(field_flags, MY_I_S_UNSIGNED),
807+
STRUCT_FLD(old_name, ""),
808+
STRUCT_FLD(open_method, SKIP_OPEN_TABLE)},
809+
810+
END_OF_ST_FIELD_INFO
811+
};
812+
813+
/*******************************************************************//**
814+
Fill the dynamic table INFORMATION_SCHEMA.innodb_rseg
815+
@return 0 on success */
816+
static
817+
int
818+
i_s_innodb_rseg_fill(
819+
/*=================*/
820+
THD* thd, /*!< in: thread */
821+
TABLE_LIST* tables, /*!< in/out: tables to fill */
822+
Item* cond)
823+
{
824+
TABLE *table;
825+
int status;
826+
827+
status = 0;
828+
table = (TABLE *) tables->table;
829+
DBUG_ENTER("i_s_innodb_rseg_fill");
830+
831+
/* Deny access to user without PROCESS_ACL privilege */
832+
if (check_global_access(thd, PROCESS_ACL)) {
833+
DBUG_RETURN(0);
834+
}
835+
836+
RETURN_IF_INNODB_NOT_STARTED(tables->schema_table_name);
837+
/* Since rseg_array is a static array, so we don't need trx_sys->mutex.
838+
And we only estimate the size of rseg, also avoid rseg->mutex contention.
839+
*/
840+
for (ulint i = 0; i < TRX_SYS_N_RSEGS; ++i) {
841+
const trx_rseg_t* rseg = trx_sys->rseg_array[i];
842+
843+
if (rseg != NULL) {
844+
table->field[0]->store(rseg->id);
845+
table->field[1]->store(rseg->space);
846+
table->field[2]->store(rseg->zip_size);
847+
table->field[3]->store(rseg->page_no);
848+
table->field[4]->store(rseg->max_size);
849+
table->field[5]->store(rseg->curr_size);
850+
851+
if (schema_table_store_record(thd, table)) {
852+
status = 1; // no cover line.
853+
break;
854+
}
855+
}
856+
}
857+
858+
DBUG_RETURN(status);
859+
}
860+
861+
862+
/*******************************************************************//**
863+
Bind the dynamic table INFORMATION_SCHEMA.innodb_rseg
864+
@return 0 on success */
865+
static
866+
int
867+
innodb_rseg_init(
868+
/*=============*/
869+
void* p) /*!< in/out: table schema object */
870+
{
871+
ST_SCHEMA_TABLE* schema;
872+
DBUG_ENTER("innodb_rseg_init");
873+
874+
schema= (ST_SCHEMA_TABLE*) p;
875+
876+
schema->fields_info= i_s_innodb_rseg_fields_info;
877+
schema->fill_table= i_s_innodb_rseg_fill;
878+
879+
DBUG_RETURN(0);
880+
}
881+
882+
UNIV_INTERN struct st_mysql_plugin i_s_innodb_rseg =
883+
{
884+
/* the plugin type (a MYSQL_XXX_PLUGIN value) */
885+
/* int */
886+
STRUCT_FLD(type, MYSQL_INFORMATION_SCHEMA_PLUGIN),
887+
888+
/* pointer to type-specific plugin descriptor */
889+
/* void* */
890+
STRUCT_FLD(info, &i_s_info),
891+
892+
/* plugin name */
893+
/* const char* */
894+
STRUCT_FLD(name, "INNODB_RSEG"),
895+
896+
/* plugin author (for SHOW PLUGINS) */
897+
/* const char* */
898+
STRUCT_FLD(author, "Aliyun"),
899+
900+
/* general descriptive text (for SHOW PLUGINS) */
901+
/* const char* */
902+
STRUCT_FLD(descr, "InnoDB rollback segment information"),
903+
904+
/* the plugin license (PLUGIN_LICENSE_XXX) */
905+
/* int */
906+
STRUCT_FLD(license, PLUGIN_LICENSE_GPL),
907+
908+
/* the function to invoke when plugin is loaded */
909+
/* int (*)(void*); */
910+
STRUCT_FLD(init, innodb_rseg_init),
911+
912+
/* the function to invoke when plugin is unloaded */
913+
/* int (*)(void*); */
914+
STRUCT_FLD(deinit, i_s_common_deinit),
915+
916+
/* plugin version (for SHOW PLUGINS) */
917+
/* unsigned int */
918+
STRUCT_FLD(version, INNODB_VERSION_SHORT),
919+
920+
/* struct st_mysql_show_var* */
921+
STRUCT_FLD(status_vars, NULL),
922+
923+
/* struct st_mysql_sys_var** */
924+
STRUCT_FLD(system_vars, NULL),
925+
926+
/* reserved for dependency checking */
927+
STRUCT_FLD(__reserved1, NULL),
928+
929+
/* plugin flags */
930+
/* unsigned long */
931+
STRUCT_FLD(flags, 0UL),
932+
};
933+
759934
UNIV_INTERN struct st_mysql_plugin i_s_innodb_trx =
760935
{
761936
/* the plugin type (a MYSQL_XXX_PLUGIN value) */

storage/innobase/handler/i_s.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Created July 18, 2007 Vasil Dimov
2828

2929
const char plugin_author[] = "Oracle Corporation";
3030

31+
extern struct st_mysql_plugin i_s_innodb_rseg;
3132
extern struct st_mysql_plugin i_s_innodb_trx;
3233
extern struct st_mysql_plugin i_s_innodb_locks;
3334
extern struct st_mysql_plugin i_s_innodb_lock_waits;

0 commit comments

Comments
 (0)