Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mysql-test/include/analyze-format.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# - r_engine_stats depends on buffer pool state and whether old record versions
# were purged.

--replace_regex /("(r_[a-z_]*_time(_in_progress)?_ms|r_buffer_size|cost|r_partial_match_buffer_size)": )[^, \n]*/\1"REPLACED"/ /("r_engine_stats":) {[^}]*}/\1 REPLACED/
--replace_regex /("(r_[a-z_]*_time(_in_progress)?_ms|r_buffer_size|cost|r_partial_match_buffer_size)": )[^, \n]*/\1"REPLACED"/ /("r_engine_stats":) \{(?:[^{}]|\{[^}]*\})*\}/\1 REPLACED/
40 changes: 36 additions & 4 deletions mysql-test/main/rowid_filter_innodb,ahi.rdiff
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,53 @@
DROP DATABASE IF EXISTS dbt3_s001;
CREATE DATABASE dbt3_s001;
use dbt3_s001;
@@ -2059,7 +2059,7 @@
@@ -2061,7 +2061,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 +2097,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 +2236,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 +2272,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,
45 changes: 45 additions & 0 deletions mysql-test/suite/innodb/include/check_ahi_status.inc
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions mysql-test/suite/innodb/r/ahi_stats.result
Original file line number Diff line number Diff line change
@@ -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]
Comment thread
iMineLink marked this conversation as resolved.
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;
78 changes: 78 additions & 0 deletions mysql-test/suite/innodb/t/ahi_stats.test
Original file line number Diff line number Diff line change
@@ -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;
5 changes: 5 additions & 0 deletions sql/ha_handler_stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Comment on lines +44 to +47
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The new fields in ha_handler_stats should be initialized to zero to prevent reporting garbage values in ANALYZE FORMAT=JSON. Additionally, ensure that these fields are cleared in the ha_handler_stats::reset() method (and initialized in the constructor if applicable) so that statistics do not leak between different queries or table accesses within the same session.

Suggested change
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 */
ulonglong ahi_searches = 0; /* Successful adaptive hash lookups */
ulonglong ahi_searches_btree = 0; /* B-tree searches (AHI miss) */
ulonglong ahi_rows_added = 0; /* Rows added to adaptive hash index */
ulonglong ahi_pages_added = 0; /* Pages added to adaptive hash index */


/* Time spent in engine, in timer_tracker_frequency() units */
ulonglong engine_time;

Expand Down
14 changes: 14 additions & 0 deletions sql/sql_explain.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
6 changes: 6 additions & 0 deletions storage/innobase/btr/btr0cur.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Comment on lines +1149 to +1150
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When would we have !mtr->trx here? Never?


return DB_SUCCESS;
}
else
{
++btr_cur_n_non_sea;
if (mtr->trx)
btr_ahi_inc_searches_btree(mtr->trx);
Comment on lines +1157 to +1158
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you post some stack traces where mtr->trx == nullptr would hold here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(rr) bt
#0  __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at ./nptl/pthread_kill.c:44
#1  0x00007fa6faaa09ff in __pthread_kill_internal (threadid=<optimized out>, signo=6) at ./nptl/pthread_kill.c:89
#2  0x00007fa6faa4bcc2 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#3  0x00007fa6faa344ac in __GI_abort () at ./stdlib/abort.c:77
#4  0x00007fa6faa34420 in __assert_fail_base (fmt=<optimized out>, assertion=<optimized out>, file=<optimized out>, line=1154, function=<optimized out>) at ./assert/assert.c:118
#5  0x00005584052eba16 in btr_cur_t::search_leaf (this=0x77a6dfffe410, tuple=0x77a6dfffe3f0, mode=PAGE_CUR_GE, latch_mode=BTR_SEARCH_LEAF, mtr=0x77a6dfffe4b0) at /home/tafzeel/work/main_13May/storage/innobase/btr/btr0cur.cc:1154
#6  0x0000558404fa4915 in btr_pcur_open (tuple=0x77a6dfffe3f0, mode=PAGE_CUR_GE, latch_mode=BTR_SEARCH_LEAF, cursor=0x77a6dfffe410, mtr=0x77a6dfffe4b0) at /home/tafzeel/work/main_13May/storage/innobase/include/btr0pcur.h:430
#7  0x0000558404fa49e5 in btr_pcur_open_on_user_rec (tuple=0x77a6dfffe3f0, latch_mode=BTR_SEARCH_LEAF, cursor=0x77a6dfffe410, mtr=0x77a6dfffe4b0) at /home/tafzeel/work/main_13May/storage/innobase/include/btr0pcur.h:449
#8  0x000055840538bc3c in dict_load_table_on_id (table_id=18, ignore_err=DICT_ERR_IGNORE_FK_NOKEY) at /home/tafzeel/work/main_13May/storage/innobase/dict/dict0load.cc:2613
#9  0x00005584052682cc in trx_purge_table_open (table_id=18, mdl_context=0x558414c627d8, mdl=0x77a6dfffe938) at /home/tafzeel/work/main_13May/storage/innobase/trx/trx0purge.cc:1145
#10 0x0000558405268922 in trx_purge_attach_undo_recs (trx=0x7fa6ef3ff780, n_work_items=0x77a6dfffea28) at /home/tafzeel/work/main_13May/storage/innobase/trx/trx0purge.cc:1251
#11 0x000055840526924c in trx_purge (trx=0x7fa6ef3ff780, n_tasks=4, history_size=7) at /home/tafzeel/work/main_13May/storage/innobase/trx/trx0purge.cc:1364
#12 0x000055840524d5fd in purge_coordinator_state::do_purge (this=0x558406f98240 <purge_state>, trx=0x7fa6ef3ff780) at /home/tafzeel/work/main_13May/storage/innobase/srv/srv0srv.cc:1431
#13 0x000055840524c3f8 in purge_coordinator_callback () at /home/tafzeel/work/main_13May/storage/innobase/srv/srv0srv.cc:1525
#14 0x000055840548270c in tpool::task_group::execute (this=0x558406f98380 <purge_coordinator_task_group>, t=0x558406f98460 <purge_coordinator_task>) at /home/tafzeel/work/main_13May/tpool/task_group.cc:73
#15 0x0000558405482ac2 in tpool::task::execute (this=0x558406f98460 <purge_coordinator_task>) at /home/tafzeel/work/main_13May/tpool/task.cc:32
#16 0x000055840547aa50 in tpool::thread_pool_generic::worker_main (this=0x558414680c50, thread_var=0x558414ace9f0) at /home/tafzeel/work/main_13May/tpool/tpool_generic.cc:531
#17 0x00005584054824d9 in std::__invoke_impl<void, void (tpool::thread_pool_generic::*)(tpool::worker_data*), tpool::thread_pool_generic*, tpool::worker_data*> (
    __f=@0x7fa6f0003578: (void (tpool::thread_pool_generic::*)(class tpool::thread_pool_generic * const, struct tpool::worker_data *)) 0x55840547a922 <tpool::thread_pool_generic::worker_main(tpool::worker_data*)>, __t=@0x7fa6f0003570: 0x558414680c50)
    at /usr/include/c++/14/bits/invoke.h:74
#18 0x00005584054823fe in std::__invoke<void (tpool::thread_pool_generic::*)(tpool::worker_data*), tpool::thread_pool_generic*, tpool::worker_data*> (
    __fn=@0x7fa6f0003578: (void (tpool::thread_pool_generic::*)(class tpool::thread_pool_generic * const, struct tpool::worker_data *)) 0x55840547a922 <tpool::thread_pool_generic::worker_main(tpool::worker_data*)>) at /usr/include/c++/14/bits/invoke.h:96
#19 0x0000558405482331 in std::thread::_Invoker<std::tuple<void (tpool::thread_pool_generic::*)(tpool::worker_data*), tpool::thread_pool_generic*, tpool::worker_data*> >::_M_invoke<0ul, 1ul, 2ul> (this=0x7fa6f0003568) at /usr/include/c++/14/bits/std_thread.h:301
#20 0x00005584054822ce in std::thread::_Invoker<std::tuple<void (tpool::thread_pool_generic::*)(tpool::worker_data*), tpool::thread_pool_generic*, tpool::worker_data*> >::operator() (this=0x7fa6f0003568) at /usr/include/c++/14/bits/std_thread.h:308
#21 0x00005584054822b2 in std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (tpool::thread_pool_generic::*)(tpool::worker_data*), tpool::thread_pool_generic*, tpool::worker_data*> > >::_M_run (this=0x7fa6f0003560) at /usr/include/c++/14/bits/std_thread.h:253
#22 0x00007fa6face1224 in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
#23 0x00007fa6faa9eb7b in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:448
#24 0x00007fa6fab1c630 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:100
(rr) f 5
#5  0x00005584052eba16 in btr_cur_t::search_leaf (this=0x77a6dfffe410, tuple=0x77a6dfffe3f0, mode=PAGE_CUR_GE, latch_mode=BTR_SEARCH_LEAF, mtr=0x77a6dfffe4b0) at /home/tafzeel/work/main_13May/storage/innobase/btr/btr0cur.cc:1154
1154	    ut_ad(mtr->trx!=nullptr);
(rr) p mtr->trx
$1 = (trx_t * const) 0x0
(rr) list
1149	    ++btr_cur_n_sea;
1150	
1151	    return DB_SUCCESS;
1152	  }
1153	  else {
1154	    ut_ad(mtr->trx!=nullptr);
1155	    ++btr_cur_n_non_sea;
1156	  }
1157	# endif
1158	#endif
(rr) 

}
# endif
#endif

Expand Down
44 changes: 37 additions & 7 deletions storage/innobase/btr/btr0sea.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,36 @@ inline ahi_node **btr_sea::hash_chain::search(UnaryPred u) noexcept
return prev;
}

void btr_ahi_inc_searches(trx_t *trx) noexcept
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small nitpickery (also applicable to btr_ahi_inc_searches_btree() below): you can add __attribute__((nonnull))

{
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++;
}
Comment on lines +85 to +95
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could these simple functions be defined inline?


static void btr_ahi_inc_rows_added(ulonglong count= 1) 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;
}

static 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++;
}

inline void btr_sea::partition::init() noexcept
{
latch.SRW_LOCK_INIT(btr_search_latch_key);
Expand Down Expand Up @@ -625,7 +655,7 @@ static void btr_search_update_hash_ref(const btr_cur_t &cursor,
}

part.insert(fold, rec, block);
MONITOR_INC(MONITOR_ADAPTIVE_HASH_ROW_ADDED);
btr_ahi_inc_rows_added();
Comment on lines -628 to +658
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we pass const mtr_t& to all these functions so that calls to current_thd will be avoided?

}
else
{
Expand Down Expand Up @@ -1676,7 +1706,7 @@ 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);
btr_ahi_inc_rows_added(n_cached);

for (size_t i= 0; i < n_cached; i++)
{
Expand Down Expand Up @@ -1711,7 +1741,7 @@ static void btr_search_build_page_hash_index(dict_index_t *index,
goto next_redundant;
}

MONITOR_INC(MONITOR_ADAPTIVE_HASH_PAGE_ADDED);
btr_ahi_inc_pages_added();
assert_block_ahi_valid(block);
part.latch.rd_unlock();
}
Expand Down Expand Up @@ -1964,7 +1994,7 @@ 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);
btr_ahi_inc_rows_added();
}
}
else if (fold != ins_fold)
Expand All @@ -1979,7 +2009,7 @@ 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);
btr_ahi_inc_rows_added();
}

if (next_is_supremum)
Expand All @@ -1994,7 +2024,7 @@ 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);
btr_ahi_inc_rows_added();
}
}
else if (ins_fold != next_fold)
Expand All @@ -2009,7 +2039,7 @@ 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);
btr_ahi_inc_rows_added();
}

ut_ad(!locked || index == block->index);
Expand Down
8 changes: 8 additions & 0 deletions storage/innobase/include/btr0sea.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ 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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: this can be removed as well, should be already checked on top of the file. Can you please try building with BTR_CUR_HASH_ADAPT undefined, as I've seen there are some stubs at the end of the file? Should be controllable by setting to OFF with CMake OPTION(WITH_INNODB_AHI "Include innodb_adaptive_hash_index" ON). Thanks.

/** 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;
#endif /* BTR_CUR_HASH_ADAPT */

/** Validates the search system.
@param thd connection, for checking if CHECK TABLE has been killed
@return true if ok */
Expand Down
2 changes: 2 additions & 0 deletions storage/innobase/unittest/innodb_ahi-t.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
Loading