Skip to content

Commit c96b224

Browse files
yizhang82inikep
authored andcommitted
Return stats from storage engine directly without table open
Summary: In 8.0 query from i_s.tables are *much* slower (~5x) most likely due to table open/close are much slower - profiling data showed that 74% time spent on opening tables and 19.71% time spent on reading histograms, only 2.41% spent on the actual stats inside MyRocks. 8.0 provides a new callback get_table_statistics and get_index_column_cardinality that when "overridden", signal MySQL to go call those functions to fill in stats directly, which should be much faster, with some caveats: * Our stats code path need to work without table open - this fix updates our stat code path to strictly use Rdb_tbl_def and Rdb_key_def. One catch is that we won't be able to update the auto_inc value correctly because we won't know if the table actually has AUTO_INCREMENT without opening it, so there are some corner cases the value might be NULL (such as immediately after creating a table with AUTO_INCREMENT). This actually aligns with ROCKSDB_DDL table behavior and InnoDB behavior as well. Once you open the table, the cached Rdb_tbl_def::m_auto_inc_val should be updated properly. * We also need to make sure the lifetime / locking works properly with regarding to DDL and special cases like drop cf. Fortunately the table_stats code path does take MDL_EXPLICIT lock with the db_name.table_name, so correctness should be straight-forward. One special case if DROP TABLE is running at the same time, the MDL_EXPLICIT lock may succeed *after* drop table succeed, and Rdbl_ddl_manager::find would return null, and we would give default values in the columns and with a error message saying table cannot be found. Note this version only overrides get_table_statistics (and it updates SQL layer to treat them separately) and we can add get_index_column_cardinality in the future if there is a need - right now there is little evidence that we are querying information_schema.statistics much (if not at all). Reviewed By: hermanlee Differential Revision: D26624028
1 parent 12dffe9 commit c96b224

File tree

10 files changed

+393
-220
lines changed

10 files changed

+393
-220
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
set @old_debug = @@global.debug;
2+
drop table if exists t1;
3+
set @@global.debug = '+d,rocksdb_before_delete_table';
4+
create table t1 (
5+
id1 int(10) unsigned not null default '0',
6+
primary key (id1) comment 'cf_primary_key'
7+
) engine=rocksdb;
8+
Warnings:
9+
Warning 1681 Integer display width is deprecated and will be removed in a future release.
10+
drop table t1;
11+
set debug_sync = "now wait_for ready_to_mark_cf_dropped_before_delete_table";
12+
SHOW TABLE STATUS LIKE 't1';
13+
set debug_sync = "now signal mark_cf_dropped_done_before_delete_table";
14+
show tables;
15+
Tables_in_test
16+
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
17+
t1 ROCKSDB 10 Fixed 4294967295 0 0 0 0 0 NULL # # NULL # NULL No such table: 'Table is missing'
18+
Warnings:
19+
Warning 155 No such table: 'Table is missing'
20+
set @@global.debug = @old_debug;
21+
set @@global.debug = '+d,rocksdb_after_delete_table';
22+
create table t1 (
23+
id1 int(10) unsigned not null default '0',
24+
primary key (id1) comment 'cf_primary_key'
25+
) engine=rocksdb;
26+
Warnings:
27+
Warning 1681 Integer display width is deprecated and will be removed in a future release.
28+
drop table t1;
29+
set debug_sync = "now wait_for ready_to_mark_cf_dropped_after_delete_table";
30+
SHOW TABLE STATUS LIKE 't1';
31+
set debug_sync = "now signal mark_cf_dropped_done_after_delete_table";
32+
show tables;
33+
Tables_in_test
34+
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
35+
t1 ROCKSDB 10 Fixed 4294967295 0 0 0 0 0 NULL # # NULL # NULL No such table: 'Table is missing'
36+
Warnings:
37+
Warning 155 No such table: 'Table is missing'
38+
set @@global.debug = @old_debug;

mysql-test/suite/rocksdb/r/truncate_table.result

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ DROP TABLE t1;
99
CREATE TABLE t1 (a INT KEY AUTO_INCREMENT, c CHAR(8)) ENGINE=RocksDB CHARSET=latin1;
1010
SHOW TABLE STATUS LIKE 't1';
1111
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
12+
t1 ROCKSDB 10 Fixed # # # 0 0 0 NULL # # NULL latin1_swedish_ci NULL
13+
SELECT COUNT(*) FROM t1;
14+
COUNT(*)
15+
0
16+
SHOW TABLE STATUS LIKE 't1';
17+
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
1218
t1 ROCKSDB 10 Fixed # # # 0 0 0 1 # # NULL latin1_swedish_ci NULL
1319
INSERT INTO t1 (c) VALUES ('a'),('b'),('c');
1420
SHOW TABLE STATUS LIKE 't1';
@@ -17,6 +23,12 @@ t1 ROCKSDB 10 Fixed # # # 0 0 0 4 # # NULL latin1_swedish_ci NULL
1723
TRUNCATE TABLE t1;
1824
SHOW TABLE STATUS LIKE 't1';
1925
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
26+
t1 ROCKSDB 10 Fixed # # # 0 0 0 NULL # # NULL latin1_swedish_ci NULL
27+
SELECT COUNT(*) FROM t1;
28+
COUNT(*)
29+
0
30+
SHOW TABLE STATUS LIKE 't1';
31+
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
2032
t1 ROCKSDB 10 Fixed # # # 0 0 0 1 # # NULL latin1_swedish_ci NULL
2133
INSERT INTO t1 (c) VALUES ('d');
2234
SHOW TABLE STATUS LIKE 't1';
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
--source include/have_debug.inc
2+
--source include/have_debug_sync.inc
3+
--source include/have_rocksdb.inc
4+
--source include/count_sessions.inc
5+
6+
--disable_query_log
7+
#call mtr.add_suppression("Cannot mark Column family.*because it is in use");
8+
--enable_query_log
9+
10+
set @old_debug = @@global.debug;
11+
12+
--disable_warnings
13+
drop table if exists t1;
14+
--enable_warnings
15+
16+
connect (conn1,localhost,root,,);
17+
connect (conn2,localhost,root,,);
18+
connect (conn3,localhost,root,,);
19+
20+
## test1 ##
21+
--connection conn1
22+
set @@global.debug = '+d,rocksdb_before_delete_table';
23+
create table t1 (
24+
id1 int(10) unsigned not null default '0',
25+
primary key (id1) comment 'cf_primary_key'
26+
) engine=rocksdb;
27+
28+
send drop table t1;
29+
30+
--connection conn2
31+
set debug_sync = "now wait_for ready_to_mark_cf_dropped_before_delete_table";
32+
33+
# replace_column is in reap
34+
send SHOW TABLE STATUS LIKE 't1';
35+
36+
--connection conn3
37+
let $wait_condition= SELECT count(*) = 1 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE State = 'Waiting for table metadata lock';
38+
--source include/wait_condition.inc
39+
set debug_sync = "now signal mark_cf_dropped_done_before_delete_table";
40+
41+
--connection conn1
42+
reap;
43+
show tables;
44+
45+
--connection conn2
46+
--replace_column 12 # 13 # 15 #
47+
reap;
48+
49+
set @@global.debug = @old_debug;
50+
51+
## test2 ##
52+
--connection conn1
53+
54+
set @@global.debug = '+d,rocksdb_after_delete_table';
55+
create table t1 (
56+
id1 int(10) unsigned not null default '0',
57+
primary key (id1) comment 'cf_primary_key'
58+
) engine=rocksdb;
59+
60+
send drop table t1;
61+
62+
--connection conn2
63+
set debug_sync = "now wait_for ready_to_mark_cf_dropped_after_delete_table";
64+
65+
# replace_column is in reap
66+
send SHOW TABLE STATUS LIKE 't1';
67+
68+
--connection conn3
69+
let $wait_condition= SELECT count(*) = 1 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE State = 'Waiting for table metadata lock';
70+
--source include/wait_condition.inc
71+
72+
set debug_sync = "now signal mark_cf_dropped_done_after_delete_table";
73+
74+
--connection conn1
75+
reap;
76+
show tables;
77+
78+
--connection conn2
79+
--replace_column 12 # 13 # 15 #
80+
reap;
81+
82+
set @@global.debug = @old_debug;
83+
84+
--connection default
85+
--disconnect conn1
86+
--disconnect conn2
87+
--disconnect conn3
88+
--source include/wait_until_count_sessions.inc

mysql-test/suite/rocksdb/t/truncate_table.test

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ DROP TABLE t1;
2828

2929
CREATE TABLE t1 (a INT KEY AUTO_INCREMENT, c CHAR(8)) ENGINE=RocksDB CHARSET=latin1;
3030

31+
# NOTE: Before table open AUTO_INCREMENT will be NULL as table open updates it
32+
#--replace_column 2 # 3 # 4 # 5 # 6 # 7 # 8 # 9 # 10 # 12 # 13 # 14 # 15 # 16 # 17 # 18 #
33+
--replace_column 5 # 6 # 7 # 12 # 13 #
34+
SHOW TABLE STATUS LIKE 't1';
35+
36+
# Force open the table to update autoinc number
37+
SELECT COUNT(*) FROM t1;
38+
3139
#--replace_column 2 # 3 # 4 # 5 # 6 # 7 # 8 # 9 # 10 # 12 # 13 # 14 # 15 # 16 # 17 # 18 #
3240
--replace_column 5 # 6 # 7 # 12 # 13 #
3341
SHOW TABLE STATUS LIKE 't1';
@@ -38,6 +46,15 @@ INSERT INTO t1 (c) VALUES ('a'),('b'),('c');
3846
SHOW TABLE STATUS LIKE 't1';
3947

4048
TRUNCATE TABLE t1;
49+
50+
# NOTE: Before table open AUTO_INCREMENT will be NULL as table open updates it
51+
#--replace_column 2 # 3 # 4 # 5 # 6 # 7 # 8 # 9 # 10 # 12 # 13 # 14 # 15 # 16 # 17 # 18 #
52+
--replace_column 5 # 6 # 7 # 12 # 13 #
53+
54+
SHOW TABLE STATUS LIKE 't1';
55+
# Force open the table to update autoinc number
56+
SELECT COUNT(*) FROM t1;
57+
4158
#--replace_column 2 # 3 # 4 # 5 # 6 # 7 # 8 # 9 # 10 # 12 # 13 # 14 # 15 # 16 # 17 # 18 #
4259
--replace_column 5 # 6 # 7 # 12 # 13 #
4360
SHOW TABLE STATUS LIKE 't1';
@@ -71,4 +88,3 @@ HANDLER h2 READ FIRST;
7188
--enable_testcase
7289

7390
DROP TABLE t1;
74-

sql/dd/info_schema/table_stats.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,9 +491,15 @@ ulonglong Table_statistics::read_stat(
491491
plugin_ref tmp_plugin = ha_resolve_by_name_raw(
492492
thd, lex_cstring_handle(dd::String_type(engine_name_ptr.ptr())));
493493
handlerton *hton = nullptr;
494-
const bool hton_implements_get_statistics =
495-
(tmp_plugin && (hton = plugin_data<handlerton *>(tmp_plugin)) &&
496-
hton->get_index_column_cardinality && hton->get_table_statistics);
494+
bool hton_implements_get_statistics = false;
495+
if (tmp_plugin && (hton = plugin_data<handlerton *>(tmp_plugin))) {
496+
if (stype == enum_table_stats_type::INDEX_COLUMN_CARDINALITY) {
497+
hton_implements_get_statistics =
498+
hton->get_index_column_cardinality != nullptr;
499+
} else {
500+
hton_implements_get_statistics = hton->get_table_statistics != nullptr;
501+
}
502+
}
497503

498504
// Try to get statistics without opening the table.
499505
if (!partition_name && hton_implements_get_statistics)

0 commit comments

Comments
 (0)