source include/have_innodb.inc;
source include/have_debug.inc;
source include/not_embedded.inc;

--echo #
--echo # BUG#20080942 - ADAPTIVE_HASH_SEARCHES_BTREE NOT UPDATED
--echo #

# To make sure that the change buffer is empty
SET GLOBAL innodb_fast_shutdown=0;
--source include/restart_mysqld.inc

SET GLOBAL innodb_stats_persistent = OFF;
SET GLOBAL innodb_stats_auto_recalc = OFF;
SET GLOBAL innodb_purge_stop_now = ON;

CREATE TABLE t1(a INT PRIMARY KEY, b BLOB) STATS_PERSISTENT=0;

let $start=`SELECT COUNT FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME LIKE
'adaptive_hash_searches_btree' ORDER BY NAME`;

INSERT INTO t1 VALUES(1, 'abc');
INSERT INTO t1 VALUES(2, 'def');
INSERT INTO t1 VALUES(3, 'ghi');
SELECT * FROM t1;

let $end=`SELECT COUNT FROM INFORMATION_SCHEMA.INNODB_METRICS WHERE NAME LIKE
'adaptive_hash_searches_btree' ORDER BY NAME`;

let $diff=`SELECT $end-$start`;

if ($diff != 3) {
	echo "Unexpected count: $diff";
}

DROP TABLE t1;

SET GLOBAL innodb_stats_persistent = default;
SET GLOBAL innodb_stats_auto_recalc = default;
SET GLOBAL innodb_purge_run_now = ON;
