diff --git a/mysql-test/main/rowid_filter_innodb,ahi.rdiff b/mysql-test/main/rowid_filter_innodb,ahi.rdiff index 9d0b7fc137c3c..548ac94927287 100644 --- a/mysql-test/main/rowid_filter_innodb,ahi.rdiff +++ b/mysql-test/main/rowid_filter_innodb,ahi.rdiff @@ -9,21 +9,273 @@ DROP DATABASE IF EXISTS dbt3_s001; CREATE DATABASE dbt3_s001; use dbt3_s001; -@@ -2059,7 +2059,7 @@ +@@ -159,7 +159,8 @@ + "cost": "REPLACED", + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", +- "r_engine_stats": REPLACED, ++ "r_engine_stats": REPLACED ++ }, + "filtered": 8.492922783, + "r_total_filtered": 9.742120344, + "index_condition": "lineitem.l_quantity > 47", +@@ -277,7 +278,8 @@ + "cost": "REPLACED", + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", +- "r_engine_stats": REPLACED, ++ "r_engine_stats": REPLACED ++ }, + "filtered": 8.492922783, + "r_total_filtered": 9.742120344, + "index_condition": "lineitem.l_quantity > 47", +@@ -426,7 +428,8 @@ + "cost": "REPLACED", + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", +- "r_engine_stats": REPLACED, ++ "r_engine_stats": REPLACED ++ }, + "filtered": 100, + "r_total_filtered": 100, + "attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-01-31'", +@@ -451,7 +454,8 @@ + "cost": "REPLACED", + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", +- "r_engine_stats": REPLACED, ++ "r_engine_stats": REPLACED ++ }, + "filtered": 4.733333111, + "r_total_filtered": 11.2244898, + "attached_condition": "orders.o_totalprice between 200000 and 230000", +@@ -576,7 +580,8 @@ + "cost": "REPLACED", + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", +- "r_engine_stats": REPLACED, ++ "r_engine_stats": REPLACED ++ }, + "filtered": 100, + "r_total_filtered": 100, + "attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-01-31'", +@@ -601,7 +606,8 @@ + "cost": "REPLACED", + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", +- "r_engine_stats": REPLACED, ++ "r_engine_stats": REPLACED ++ }, + "filtered": 4.733333111, + "r_total_filtered": 11.2244898, + "attached_condition": "orders.o_totalprice between 200000 and 230000", +@@ -754,7 +760,8 @@ + "cost": "REPLACED", + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", +- "r_engine_stats": REPLACED, ++ "r_engine_stats": REPLACED ++ }, + "filtered": 8.492922783, + "r_total_filtered": 9.742120344, + "index_condition": "lineitem.l_quantity > 47", +@@ -779,7 +786,8 @@ + "cost": "REPLACED", + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", +- "r_engine_stats": REPLACED, ++ "r_engine_stats": REPLACED ++ }, + "filtered": 9.600000381, + "r_total_filtered": 26.47058824, + "attached_condition": "orders.o_totalprice between 180000 and 230000", +@@ -903,7 +911,8 @@ + "cost": "REPLACED", + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", +- "r_engine_stats": REPLACED, ++ "r_engine_stats": REPLACED ++ }, + "filtered": 100, + "r_total_filtered": 100, + "attached_condition": "orders.o_totalprice between 180000 and 230000", +@@ -933,7 +942,8 @@ + "cost": "REPLACED", + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", +- "r_engine_stats": REPLACED, ++ "r_engine_stats": REPLACED ++ }, + "filtered": 0.493593663, + "r_total_filtered": 0.943396226, + "attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30' and lineitem.l_quantity > 47", +@@ -1060,7 +1070,8 @@ + "cost": "REPLACED", + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", +- "r_engine_stats": REPLACED, ++ "r_engine_stats": REPLACED ++ }, + "filtered": 100, + "r_total_filtered": 100, + "attached_condition": "orders.o_totalprice between 200000 and 230000", +@@ -1089,7 +1100,8 @@ + "cost": "REPLACED", + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", +- "r_engine_stats": REPLACED, ++ "r_engine_stats": REPLACED ++ }, + "filtered": 8.492922783, + "r_total_filtered": 7.773109244, + "attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'", +@@ -1235,7 +1247,8 @@ + "cost": "REPLACED", + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", +- "r_engine_stats": REPLACED, ++ "r_engine_stats": REPLACED ++ }, + "filtered": 100, + "r_total_filtered": 100, + "attached_condition": "orders.o_totalprice between 200000 and 230000", +@@ -1264,7 +1277,8 @@ + "cost": "REPLACED", + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", +- "r_engine_stats": REPLACED, ++ "r_engine_stats": REPLACED ++ }, + "filtered": 8.492922783, + "r_total_filtered": 7.773109244, + "attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'", +@@ -1433,7 +1447,8 @@ + "cost": "REPLACED", + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", +- "r_engine_stats": REPLACED, ++ "r_engine_stats": REPLACED ++ }, + "filtered": 0.566194832, + "r_total_filtered": 38.88888889, + "index_condition": "lineitem.l_receiptDATE between '1996-10-05' and '1996-10-10'", +@@ -1458,7 +1473,8 @@ + "cost": "REPLACED", + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", +- "r_engine_stats": REPLACED, ++ "r_engine_stats": REPLACED ++ }, + "filtered": 5.666666508, + "r_total_filtered": 14.28571429, + "attached_condition": "orders.o_totalprice between 200000 and 250000", +@@ -1586,7 +1602,8 @@ + "cost": "REPLACED", + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", +- "r_engine_stats": REPLACED, ++ "r_engine_stats": REPLACED ++ }, + "filtered": 0.566194832, + "r_total_filtered": 38.88888889, + "index_condition": "lineitem.l_receiptDATE between '1996-10-05' and '1996-10-10'", +@@ -1611,7 +1628,8 @@ + "cost": "REPLACED", + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", +- "r_engine_stats": REPLACED, ++ "r_engine_stats": REPLACED ++ }, + "filtered": 5.666666508, + "r_total_filtered": 14.28571429, + "attached_condition": "orders.o_totalprice between 200000 and 250000", +@@ -1739,7 +1757,8 @@ + "cost": "REPLACED", + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", +- "r_engine_stats": REPLACED, ++ "r_engine_stats": REPLACED ++ }, + "filtered": 3.333333254, + "r_total_filtered": 2.43902439, + "index_condition": "orders.o_totaldiscount between 18000 and 20000", +@@ -1769,7 +1788,8 @@ + "cost": "REPLACED", + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", +- "r_engine_stats": REPLACED, ++ "r_engine_stats": REPLACED ++ }, + "filtered": 3.047460556, + "r_total_filtered": 66.66666667, + "attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-12-01'", +@@ -1893,7 +1913,8 @@ + "cost": "REPLACED", + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", +- "r_engine_stats": REPLACED, ++ "r_engine_stats": REPLACED ++ }, + "filtered": 3.333333254, + "r_total_filtered": 2.43902439, + "index_condition": "orders.o_totaldiscount between 18000 and 20000", +@@ -1923,7 +1944,8 @@ + "cost": "REPLACED", + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", +- "r_engine_stats": REPLACED, ++ "r_engine_stats": REPLACED ++ }, + "filtered": 3.047460556, + "r_total_filtered": 66.66666667, + "attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-12-01'", +@@ -2061,7 +2083,11 @@ "r_table_time_ms": "REPLACED", "r_other_time_ms": "REPLACED", "r_engine_stats": { - "pages_accessed": 90 -+ "pages_accessed": 51 ++ "pages_accessed": 51, ++ "r_ahi_stats": { ++ "ahi_searches": 39, ++ "ahi_searches_btree": 3 ++ } }, "filtered": "REPLACED", "r_total_filtered": 2.43902439, -@@ -2227,7 +2227,7 @@ +@@ -2093,7 +2119,10 @@ + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "r_engine_stats": { +- "pages_accessed": 4 ++ "pages_accessed": 4, ++ "r_ahi_stats": { ++ "ahi_searches_btree": 1 ++ } + }, + "filtered": "REPLACED", + "r_total_filtered": 66.66666667, +@@ -2229,7 +2258,11 @@ "r_table_time_ms": "REPLACED", "r_other_time_ms": "REPLACED", "r_engine_stats": { - "pages_accessed": 90 -+ "pages_accessed": 49 ++ "pages_accessed": 49, ++ "r_ahi_stats": { ++ "ahi_searches": 41, ++ "ahi_searches_btree": 1 ++ } }, "filtered": "REPLACED", "r_total_filtered": 2.43902439, +@@ -2261,7 +2294,10 @@ + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "r_engine_stats": { +- "pages_accessed": 4 ++ "pages_accessed": 4, ++ "r_ahi_stats": { ++ "ahi_searches_btree": 1 ++ } + }, + "filtered": "REPLACED", + "r_total_filtered": 66.66666667, diff --git a/mysql-test/suite/innodb/include/check_ahi_status.inc b/mysql-test/suite/innodb/include/check_ahi_status.inc new file mode 100644 index 0000000000000..7fea1db7ce4d2 --- /dev/null +++ b/mysql-test/suite/innodb/include/check_ahi_status.inc @@ -0,0 +1,45 @@ +# Include file to execute a query with optional repetition and display +# values of r_ahi_stats on ANALYZE FORMAT=JSON +# +# Parameters: +# $query - The query to execute +# $repeat - Number of times to repeat the query before analyzing +# +# This include file will: +# 1. Execute the query $repeat times to warm up AHI (with logging disabled) +# 2. Execute ANALYZE FORMAT=JSON on the query and display the values + +--disable_query_log +--disable_result_log + +# Repeat the query to warm up AHI +let $i = $repeat; +while ($i > 0) +{ + eval $query; + dec $i; +} + +--enable_result_log +--enable_query_log + +# Execute ANALYZE FORMAT=JSON once and capture output +--echo ANALYZE FORMAT=JSON $query +let $out=`ANALYZE FORMAT=JSON $query`; + +# Parse JSON and extract AHI variables +--disable_query_log +evalp set @js='$out'; +set @ahi_searches = COALESCE(json_extract(@js,'$**.r_engine_stats.r_ahi_stats.ahi_searches'), 0); +set @ahi_searches_btree = COALESCE(json_extract(@js,'$**.r_engine_stats.r_ahi_stats.ahi_searches_btree'), 0); +set @ahi_rows_added = COALESCE(json_extract(@js,'$**.r_engine_stats.r_ahi_stats.ahi_rows_added'), 0); +set @ahi_pages_added = COALESCE(json_extract(@js,'$**.r_engine_stats.r_ahi_stats.ahi_pages_added'), 0); +set @r_rows = json_extract(@js,'$**.table.r_rows'); + +# Display AHI variables +select @ahi_searches as ahi_searches, + @ahi_searches_btree as ahi_searches_btree, + @ahi_rows_added as ahi_rows_added, + @ahi_pages_added as ahi_pages_added, + @r_rows as r_rows; +--enable_query_log diff --git a/mysql-test/suite/innodb/r/ahi_stats.result b/mysql-test/suite/innodb/r/ahi_stats.result new file mode 100644 index 0000000000000..8ebb415602cdb --- /dev/null +++ b/mysql-test/suite/innodb/r/ahi_stats.result @@ -0,0 +1,30 @@ +# +# MDEV 38305 : Expose adaptive hash index statistics in ANALYZE FORMAT=JSON +# +SET @start_global_value= @@global.innodb_adaptive_hash_index; +SET GLOBAL innodb_adaptive_hash_index= ON; +CREATE TABLE t1 ( +id INT PRIMARY KEY, +col1 INT, +col2 INT, +col3 INT, +INDEX idx_1 (col1), +INDEX idx_2 (col2), +INDEX idx_3 (col3) +) ENGINE=InnoDB; +INSERT INTO t1 SELECT seq, seq % 20, seq % 5, seq % 10 FROM seq_0_to_999; +ANALYZE FORMAT=JSON SELECT * FROM t1 FORCE INDEX(idx_1) WHERE col1 = 5 +ahi_searches ahi_searches_btree ahi_rows_added ahi_pages_added r_rows +0 [51] 0 0 [50] +ANALYZE FORMAT=JSON SELECT * FROM t1 FORCE INDEX(idx_2) WHERE col2 = 3 +ahi_searches ahi_searches_btree ahi_rows_added ahi_pages_added r_rows +[129] [72] [797] [2] [200] +ANALYZE FORMAT=JSON SELECT * FROM t1 FORCE INDEX(idx_3) WHERE col3 = 5 +ahi_searches ahi_searches_btree ahi_rows_added ahi_pages_added r_rows +[101] 0 0 0 [100] +SET GLOBAL innodb_adaptive_hash_index = OFF; +ANALYZE FORMAT=JSON SELECT * FROM t1 FORCE INDEX(idx_2) WHERE col2 = 2 +ahi_searches ahi_searches_btree ahi_rows_added ahi_pages_added r_rows +0 0 0 0 [200] +DROP TABLE t1; +SET GLOBAL innodb_adaptive_hash_index= @start_global_value; diff --git a/mysql-test/suite/innodb/t/ahi_stats.test b/mysql-test/suite/innodb/t/ahi_stats.test new file mode 100644 index 0000000000000..c6173f4790154 --- /dev/null +++ b/mysql-test/suite/innodb/t/ahi_stats.test @@ -0,0 +1,78 @@ +--source include/have_innodb.inc +--source include/have_innodb_16k.inc +--source include/have_sequence.inc + +--echo # +--echo # MDEV 38305 : Expose adaptive hash index statistics in ANALYZE FORMAT=JSON +--echo # + +# Test Plan: +# When queries use secondary indexes, InnoDB must lookup clustered index records +# using the primary key reference obtained from the secondary index. These +# clustered index lookups accumulate and trigger AHI building when a threshold +# is reached. This test verifies that AHI statistics are correctly reported in +# ANALYZE FORMAT=JSON output across different scenarios: +# +# Test 1: Access 50 rows (col1=5, 50 matches) - insufficient to build AHI +# Test 2: Access 200 rows (col2=3, 200 matches) - combined with Test 1 (250 total), +# this triggers AHI construction on the clustered index +# Test 3: Access with heavy warmup (100 repetitions) - AHI fully utilized +# Test 4: AHI disabled - verify statistics are zero regardless of access patterns + +SET @start_global_value= @@global.innodb_adaptive_hash_index; +SET GLOBAL innodb_adaptive_hash_index= ON; + +CREATE TABLE t1 ( + id INT PRIMARY KEY, + col1 INT, + col2 INT, + col3 INT, + INDEX idx_1 (col1), + INDEX idx_2 (col2), + INDEX idx_3 (col3) +) ENGINE=InnoDB; + +INSERT INTO t1 SELECT seq, seq % 20, seq % 5, seq % 10 FROM seq_0_to_999; + +# Test 1: Insufficient accesses to build AHI +# Query accesses 50 rows (col1=5 matches 50 out of 1000 rows: 5,25,45,...,985). +# When using idx_1, InnoDB performs 50 clustered index lookups to retrieve the +# full rows. This is insufficient to trigger AHI construction, so AHI statistics +# should show minimal or no AHI activity. +let $query = SELECT * FROM t1 FORCE INDEX(idx_1) WHERE col1 = 5; +let $repeat = 0; +--source suite/innodb/include/check_ahi_status.inc + +# Test 2: Accumulated accesses trigger AHI construction +# Query accesses 200 rows (col2=3 matches 200 out of 1000 rows: 3,8,13,18,...,998). +# Combined with Test 1's 50 clustered index lookups, the accumulated total of 250 +# clustered index searches crosses the threshold to build AHI. This test verifies +# that AHI statistics reflect the construction and initial usage of the hash index. +let $query = SELECT * FROM t1 FORCE INDEX(idx_2) WHERE col2 = 3; +let $repeat = 0; +--source suite/innodb/include/check_ahi_status.inc + +# Test 3: Verify AHI statistics with heavy warmup (AHI fully utilized) +# Query accesses 100 rows (col3=5 matches 100 out of 1000 rows: 5,15,25,...,995). +# With repeat=200, this executes the query 200 times before the ANALYZE, resulting +# in 20,000 clustered index lookups. This heavy access pattern ensures the AHI is +# fully built and actively serving lookups, allowing verification that AHI hit +# statistics are properly reported when the hash index is effectively utilized. +let $query = SELECT * FROM t1 FORCE INDEX(idx_3) WHERE col3 = 5; +let $repeat = 200; +--source suite/innodb/include/check_ahi_status.inc + +# Test 4: Verify AHI statistics when AHI is disabled +# Query accesses 200 rows (col2=2 matches 200 out of 1000 rows: 2,7,12,...,997). +# With repeat=100, this would normally trigger heavy AHI usage (20,000 clustered +# index lookups). However, since innodb_adaptive_hash_index is turned OFF, the AHI +# is not used and all AHI statistics should be zero regardless of query repetition. +SET GLOBAL innodb_adaptive_hash_index = OFF; + +let $query = SELECT * FROM t1 FORCE INDEX(idx_2) WHERE col2 = 2; +let $repeat = 100; +--source suite/innodb/include/check_ahi_status.inc + +# Cleanup +DROP TABLE t1; +SET GLOBAL innodb_adaptive_hash_index= @start_global_value; diff --git a/sql/ha_handler_stats.h b/sql/ha_handler_stats.h index 808b4d401efbc..1ba401cfde828 100644 --- a/sql/ha_handler_stats.h +++ b/sql/ha_handler_stats.h @@ -41,6 +41,11 @@ class ha_handler_stats ulonglong undo_records_read; + ulonglong ahi_searches; /* Successful adaptive hash lookups */ + ulonglong ahi_searches_btree; /* B-tree searches (AHI miss) */ + ulonglong ahi_rows_added; /* Rows added to adaptive hash index */ + ulonglong ahi_pages_added; /* Pages added to adaptive hash index */ + /* Time spent in engine, in timer_tracker_frequency() units */ ulonglong engine_time; diff --git a/sql/sql_explain.cc b/sql/sql_explain.cc index 5332b32d70a51..e57513cfa926a 100644 --- a/sql/sql_explain.cc +++ b/sql/sql_explain.cc @@ -1952,6 +1952,20 @@ static void trace_engine_stats(handler *file, Json_writer *writer) writer->add_member("pages_prefetch_read_count").add_ull(hs->pages_prefetched); if (hs->undo_records_read) writer->add_member("old_rows_read").add_ull(hs->undo_records_read); + if (hs->ahi_searches || hs->ahi_searches_btree || + hs->ahi_rows_added || hs->ahi_pages_added) + { + writer->add_member("r_ahi_stats").start_object(); + if (hs->ahi_searches) + writer->add_member("ahi_searches").add_ull(hs->ahi_searches); + if (hs->ahi_searches_btree) + writer->add_member("ahi_searches_btree").add_ull(hs->ahi_searches_btree); + if (hs->ahi_rows_added) + writer->add_member("ahi_rows_added").add_ull(hs->ahi_rows_added); + if (hs->ahi_pages_added) + writer->add_member("ahi_pages_added").add_ull(hs->ahi_pages_added); + writer->end_object(); + } writer->end_object(); } } diff --git a/storage/innobase/btr/btr0cur.cc b/storage/innobase/btr/btr0cur.cc index e0dbe083fdcbd..9c9b3d67684d6 100644 --- a/storage/innobase/btr/btr0cur.cc +++ b/storage/innobase/btr/btr0cur.cc @@ -1146,11 +1146,17 @@ dberr_t btr_cur_t::search_leaf(const dtuple_t *tuple, page_cur_mode_t mode, ut_ad(up_match != uint16_t(~0U) || mode != PAGE_CUR_LE); ut_ad(low_match != uint16_t(~0U) || mode != PAGE_CUR_LE); ++btr_cur_n_sea; + if (mtr->trx) + btr_ahi_inc_searches(mtr->trx); return DB_SUCCESS; } else + { ++btr_cur_n_non_sea; + if (mtr->trx) + btr_ahi_inc_searches_btree(mtr->trx); + } # endif #endif diff --git a/storage/innobase/btr/btr0sea.cc b/storage/innobase/btr/btr0sea.cc index 05e3d67ae2c7f..a36401ef7dede 100644 --- a/storage/innobase/btr/btr0sea.cc +++ b/storage/innobase/btr/btr0sea.cc @@ -82,6 +82,38 @@ inline ahi_node **btr_sea::hash_chain::search(UnaryPred u) noexcept return prev; } +#ifdef BTR_CUR_HASH_ADAPT +void btr_ahi_inc_searches(trx_t *trx) noexcept +{ + if (ha_handler_stats *stats= trx->active_handler_stats) + stats->ahi_searches++; +} + +void btr_ahi_inc_searches_btree(trx_t *trx) noexcept +{ + if (ha_handler_stats *stats= trx->active_handler_stats) + stats->ahi_searches_btree++; +} + +void btr_ahi_inc_rows_added(ulonglong count) noexcept +{ + MONITOR_INC_VALUE(MONITOR_ADAPTIVE_HASH_ROW_ADDED, count); + if (THD *thd= current_thd) + if (trx_t *trx= thd_to_trx(thd)) + if (ha_handler_stats *stats= trx->active_handler_stats) + stats->ahi_rows_added+= count; +} + +void btr_ahi_inc_pages_added() noexcept +{ + MONITOR_INC(MONITOR_ADAPTIVE_HASH_PAGE_ADDED); + if (THD *thd= current_thd) + if (trx_t *trx= thd_to_trx(thd)) + if (ha_handler_stats *stats= trx->active_handler_stats) + stats->ahi_pages_added++; +} +#endif /* BTR_CUR_HASH_ADAPT */ + inline void btr_sea::partition::init() noexcept { latch.SRW_LOCK_INIT(btr_search_latch_key); @@ -625,7 +657,9 @@ static void btr_search_update_hash_ref(const btr_cur_t &cursor, } part.insert(fold, rec, block); - MONITOR_INC(MONITOR_ADAPTIVE_HASH_ROW_ADDED); +#ifdef BTR_CUR_HASH_ADAPT + btr_ahi_inc_rows_added(); +#endif /* BTR_CUR_HASH_ADAPT */ } else { @@ -1676,7 +1710,9 @@ static void btr_search_build_page_hash_index(dict_index_t *index, part.latch.wr_rd_downgrade(SRW_LOCK_CALL); # endif - MONITOR_INC_VALUE(MONITOR_ADAPTIVE_HASH_ROW_ADDED, n_cached); +#ifdef BTR_CUR_HASH_ADAPT + btr_ahi_inc_rows_added(n_cached); +#endif /* BTR_CUR_HASH_ADAPT */ for (size_t i= 0; i < n_cached; i++) { @@ -1711,7 +1747,9 @@ static void btr_search_build_page_hash_index(dict_index_t *index, goto next_redundant; } - MONITOR_INC(MONITOR_ADAPTIVE_HASH_PAGE_ADDED); +#ifdef BTR_CUR_HASH_ADAPT + btr_ahi_inc_pages_added(); +#endif /* BTR_CUR_HASH_ADAPT */ assert_block_ahi_valid(block); part.latch.rd_unlock(); } @@ -1964,7 +2002,9 @@ void btr_search_update_hash_on_insert(btr_cur_t *cursor, bool reorg) noexcept goto unlock_exit; } part.insert(ins_fold, ins_rec, block); - MONITOR_INC(MONITOR_ADAPTIVE_HASH_ROW_ADDED); +#ifdef BTR_CUR_HASH_ADAPT + btr_ahi_inc_rows_added(); +#endif /* BTR_CUR_HASH_ADAPT */ } } else if (fold != ins_fold) @@ -1979,7 +2019,9 @@ void btr_search_update_hash_on_insert(btr_cur_t *cursor, bool reorg) noexcept if (left_bytes_fields & buf_block_t::LEFT_SIDE) fold= ins_fold, rec= ins_rec; part.insert(fold, rec, block); - MONITOR_INC(MONITOR_ADAPTIVE_HASH_ROW_ADDED); +#ifdef BTR_CUR_HASH_ADAPT + btr_ahi_inc_rows_added(); +#endif /* BTR_CUR_HASH_ADAPT */ } if (next_is_supremum) @@ -1994,7 +2036,9 @@ void btr_search_update_hash_on_insert(btr_cur_t *cursor, bool reorg) noexcept goto rollback; } part.insert(ins_fold, ins_rec, block); - MONITOR_INC(MONITOR_ADAPTIVE_HASH_ROW_ADDED); +#ifdef BTR_CUR_HASH_ADAPT + btr_ahi_inc_rows_added(); +#endif /* BTR_CUR_HASH_ADAPT */ } } else if (ins_fold != next_fold) @@ -2009,7 +2053,9 @@ void btr_search_update_hash_on_insert(btr_cur_t *cursor, bool reorg) noexcept if (!(left_bytes_fields & ~buf_block_t::LEFT_SIDE)) next_fold= ins_fold, next_rec= ins_rec; part.insert(next_fold, next_rec, block); - MONITOR_INC(MONITOR_ADAPTIVE_HASH_ROW_ADDED); +#ifdef BTR_CUR_HASH_ADAPT + btr_ahi_inc_rows_added(); +#endif /* BTR_CUR_HASH_ADAPT */ } ut_ad(!locked || index == block->index); diff --git a/storage/innobase/include/btr0sea.h b/storage/innobase/include/btr0sea.h index 685d9a4feb2b1..da58e74ac1739 100644 --- a/storage/innobase/include/btr0sea.h +++ b/storage/innobase/include/btr0sea.h @@ -91,6 +91,21 @@ void btr_search_update_hash_on_insert(btr_cur_t *cursor, bool reorg) noexcept; @param cursor cursor positioned on the to-be-deleted record */ void btr_search_update_hash_on_delete(btr_cur_t *cursor) noexcept; +#ifdef BTR_CUR_HASH_ADAPT +/** Increment successful adaptive hash index lookups */ +void btr_ahi_inc_searches(trx_t *trx) noexcept; + +/** Increment adaptive hash index misses (B-tree fallback) */ +void btr_ahi_inc_searches_btree(trx_t *trx) noexcept; + +/** Increment rows added to adaptive hash index +@param count number of rows added (default 1) */ +void btr_ahi_inc_rows_added(ulonglong count= 1) noexcept; + +/** Increment pages added to adaptive hash index */ +void btr_ahi_inc_pages_added() noexcept; +#endif /* BTR_CUR_HASH_ADAPT */ + /** Validates the search system. @param thd connection, for checking if CHECK TABLE has been killed @return true if ok */ diff --git a/storage/innobase/unittest/innodb_ahi-t.cc b/storage/innobase/unittest/innodb_ahi-t.cc index cb433099fd41e..a0c123d148ab8 100644 --- a/storage/innobase/unittest/innodb_ahi-t.cc +++ b/storage/innobase/unittest/innodb_ahi-t.cc @@ -42,6 +42,8 @@ void mtr_t::commit() {} void mtr_t::rollback_to_savepoint(ulint, ulint) {} void small_vector_base::grow_by_1(void *, size_t) noexcept {} void buf_inc_get(trx_t*) noexcept {} +THD *_current_thd() { return nullptr; } +trx_t *thd_to_trx(const THD*) noexcept { return nullptr; } void sql_print_error(const char*, ...) {} ulint ut_find_prime(ulint n) { return n; }