Skip to content

Commit a7716a9

Browse files
AliSQLAliSQL
authored andcommitted
[Feature] Issue#28 PARTITION BTR_SEARCH_LATCH FOR AHI BY INDEX->ID
Description: ------------ A new variable innodb_adaptive_hash_index_parts was introduced to control the partition number of the latch for AHI, default value is 8, range from 1 to 512.
1 parent 52d8473 commit a7716a9

32 files changed

Lines changed: 715 additions & 232 deletions
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
SELECT @@GLOBAL.innodb_adaptive_hash_index;
2+
@@GLOBAL.innodb_adaptive_hash_index
3+
1
4+
SELECT @@GLOBAL.innodb_adaptive_hash_index_parts;
5+
@@GLOBAL.innodb_adaptive_hash_index_parts
6+
4
7+
SET GLOBAL innodb_monitor_enable=module_adaptive_hash;
8+
CREATE TABLE t1 (a INT PRIMARY KEY, b INT, c CHAR(200), UNIQUE INDEX b(b)) ENGINE=InnoDB;
9+
CREATE TABLE t2 (a INT PRIMARY KEY, b INT, c CHAR(200), UNIQUE INDEX b(b)) ENGINE=InnoDB;
10+
CREATE TABLE t3 (a INT PRIMARY KEY, b INT, c CHAR(200), UNIQUE INDEX b(b)) ENGINE=InnoDB;
11+
Filling tables
12+
Querying
13+
SELECT COUNT >= 6 as should_be_1 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME = 'adaptive_hash_pages_added';
14+
should_be_1
15+
1
16+
SELECT COUNT >= 6 as should_be_1 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME = 'adaptive_hash_rows_added';
17+
should_be_1
18+
1
19+
SELECT COUNT > 0 as should_be_1 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME = 'adaptive_hash_searches';
20+
should_be_1
21+
1
22+
SELECT COUNT(*) > 0 AS should_be_1 FROM INFORMATION_SCHEMA.INNODB_BUFFER_PAGE
23+
WHERE PAGE_STATE LIKE "MEMORY";
24+
should_be_1
25+
1
26+
SELECT COUNT(*) >= 6 AS should_be_1 FROM INFORMATION_SCHEMA.INNODB_BUFFER_PAGE
27+
WHERE IS_HASHED LIKE "YES";
28+
should_be_1
29+
1
30+
SET GLOBAL innodb_monitor_disable=module_adaptive_hash;
31+
DROP TABLE t1, t2, t3;
32+
SET GLOBAL innodb_monitor_enable=default;
33+
SET GLOBAL innodb_monitor_disable=default;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--innodb-adaptive-hash-index-parts=4
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#
2+
# Basic test for InnoDB adaptive hash index partitions.
3+
# TODO: add another testcase that uses DEBUG_SYNC to check the partition locking
4+
#
5+
--source include/have_innodb.inc
6+
7+
# Check setup
8+
SELECT @@GLOBAL.innodb_adaptive_hash_index;
9+
SELECT @@GLOBAL.innodb_adaptive_hash_index_parts;
10+
11+
SET GLOBAL innodb_monitor_enable=module_adaptive_hash;
12+
13+
# 6 index trees across 4 AHI partitions
14+
CREATE TABLE t1 (a INT PRIMARY KEY, b INT, c CHAR(200), UNIQUE INDEX b(b)) ENGINE=InnoDB;
15+
CREATE TABLE t2 (a INT PRIMARY KEY, b INT, c CHAR(200), UNIQUE INDEX b(b)) ENGINE=InnoDB;
16+
CREATE TABLE t3 (a INT PRIMARY KEY, b INT, c CHAR(200), UNIQUE INDEX b(b)) ENGINE=InnoDB;
17+
18+
--echo Filling tables
19+
--disable_query_log
20+
let $i=3;
21+
while ($i)
22+
{
23+
eval INSERT INTO t1 VALUES ($i, $i, REPEAT("a", 200));
24+
eval INSERT INTO t2 VALUES ($i, $i, REPEAT("a", 200));
25+
eval INSERT INTO t3 VALUES ($i, $i, REPEAT("a", 200));
26+
dec $i;
27+
}
28+
29+
--echo Querying
30+
--disable_result_log
31+
let $i=200;
32+
while ($i)
33+
{
34+
SELECT b FROM t1 WHERE a=1;
35+
SELECT a FROM t1 WHERE b=1;
36+
SELECT b FROM t2 WHERE a=2;
37+
SELECT a FROM t2 WHERE b=2;
38+
SELECT b FROM t3 WHERE a=3;
39+
SELECT a FROM t3 WHERE b=3;
40+
dec $i;
41+
}
42+
--enable_result_log
43+
--enable_query_log
44+
45+
# Some buffer pool pages should be hashed
46+
SELECT COUNT >= 6 as should_be_1 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME = 'adaptive_hash_pages_added';
47+
# Some rows should be hashed
48+
SELECT COUNT >= 6 as should_be_1 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME = 'adaptive_hash_rows_added';
49+
# AHI should have been used for queries, but the exact lower bound is hard to determine
50+
SELECT COUNT > 0 as should_be_1 FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME = 'adaptive_hash_searches';
51+
52+
# Buffer pool must contain AHI pages now
53+
SELECT COUNT(*) > 0 AS should_be_1 FROM INFORMATION_SCHEMA.INNODB_BUFFER_PAGE
54+
WHERE PAGE_STATE LIKE "MEMORY";
55+
56+
# Buffer pool must contain no less than the number of index trees hashed pages now
57+
SELECT COUNT(*) >= 6 AS should_be_1 FROM INFORMATION_SCHEMA.INNODB_BUFFER_PAGE
58+
WHERE IS_HASHED LIKE "YES";
59+
60+
SET GLOBAL innodb_monitor_disable=module_adaptive_hash;
61+
62+
DROP TABLE t1, t2, t3;
63+
64+
--disable_warnings
65+
SET GLOBAL innodb_monitor_enable=default;
66+
SET GLOBAL innodb_monitor_disable=default;
67+
--enable_warnings
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
SELECT @@GLOBAL.innodb_adaptive_hash_index_parts;
2+
@@GLOBAL.innodb_adaptive_hash_index_parts
3+
8
4+
SET @@GLOBAL.innodb_adaptive_hash_index_parts=1;
5+
ERROR HY000: Variable 'innodb_adaptive_hash_index_parts' is a read only variable
6+
SELECT @@LOCAL.innodb_adaptive_hash_index_parts;
7+
ERROR HY000: Variable 'innodb_adaptive_hash_index_parts' is a GLOBAL variable
8+
SELECT @@SESSION.innodb_adaptive_hash_index_parts;
9+
ERROR HY000: Variable 'innodb_adaptive_hash_index_parts' is a GLOBAL variable
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# A sys_vars suite test for innodb_adaptive_hash_index_parts.
2+
3+
--source include/have_innodb.inc
4+
5+
SELECT @@GLOBAL.innodb_adaptive_hash_index_parts;
6+
7+
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
8+
SET @@GLOBAL.innodb_adaptive_hash_index_parts=1;
9+
10+
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
11+
SELECT @@LOCAL.innodb_adaptive_hash_index_parts;
12+
13+
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
14+
SELECT @@SESSION.innodb_adaptive_hash_index_parts;

storage/innobase/btr/btr0cur.cc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,9 @@ btr_cur_search_to_nth_level(
486486

487487
# ifdef UNIV_SEARCH_PERF_STAT
488488
info->n_searches++;
489-
# endif
490-
if (rw_lock_get_writer(&btr_search_latch) == RW_LOCK_NOT_LOCKED
489+
#endif
490+
if (rw_lock_get_writer(btr_search_get_latch(cursor->index)) ==
491+
RW_LOCK_NOT_LOCKED
491492
&& latch_mode <= BTR_MODIFY_LEAF
492493
&& info->last_hash_succ
493494
&& !estimate
@@ -523,7 +524,7 @@ btr_cur_search_to_nth_level(
523524

524525
if (has_search_latch) {
525526
/* Release possible search latch to obey latching order */
526-
rw_lock_s_unlock(&btr_search_latch);
527+
rw_lock_s_unlock(btr_search_get_latch(cursor->index));
527528
}
528529

529530
/* Store the position of the tree latch we push to mtr so that we
@@ -819,7 +820,7 @@ btr_cur_search_to_nth_level(
819820

820821
if (has_search_latch) {
821822

822-
rw_lock_s_lock(&btr_search_latch);
823+
rw_lock_s_lock(btr_search_get_latch(cursor->index));
823824
}
824825
}
825826

@@ -2042,13 +2043,13 @@ btr_cur_update_in_place(
20422043
btr_search_update_hash_on_delete(cursor);
20432044
}
20442045

2045-
rw_lock_x_lock(&btr_search_latch);
2046+
rw_lock_x_lock(btr_search_get_latch(cursor->index));
20462047
}
20472048

20482049
row_upd_rec_in_place(rec, index, offsets, update, page_zip);
20492050

20502051
if (is_hashed) {
2051-
rw_lock_x_unlock(&btr_search_latch);
2052+
rw_lock_x_unlock(btr_search_get_latch(cursor->index));
20522053
}
20532054

20542055
btr_cur_update_in_place_log(flags, rec, index, update,

0 commit comments

Comments
 (0)