Skip to content

Conversation

@dr-m
Copy link
Contributor

@dr-m dr-m commented Jan 2, 2026

  • The Jira issue number for this PR is: MDEV-37070

Description

This is based on work by @montywi. Some InnoDB changes will be needed, as noted in MDEV-37070.

Release Notes

TBD

How can this PR be tested?

mysql-test/mtr innodb.index_ahi_option

Basing the PR against the correct MariaDB version

  • This is a new feature or a refactoring, and the PR is based against the main branch.
  • This is a bug fix, and the PR is based against the earliest maintained branch in which the bug can be reproduced.

PR quality check

  • I checked the CODING_STANDARDS.md file and my PR conforms to this where appropriate.
  • For any trivial modifications to the PR, I am ok with the reviewer making the changes themselves.

vuvova and others added 5 commits December 17, 2025 18:40
just like table attributes, field and index attributes must
be parsed using the underlying engine, not ha_partition.
Added ADAPTIVE_HASH_INDEX=YES|NO table and index option to InnoDB.
The table and index options only have an effect if InnoDB adaptive hash
index feature is enabled.

- Having the ADAPTIVE_HASH_INDEX TABLE option set to NO will disable
  adaptive hash index for all indexes in the table that does not have
  the index option adaptive_hash_index=yes.
- Having the ADAPTIVE_HASH_INDEX TABLE option set to YES will enable the
  adaptive hash index for all indexes in the table that does not have
  the index option adaptive_hash_index=no.
- Using adaptive_hash_index=default deletes the old setting.
- One can also use OFF/ON as the options. This is to make it work similar
  as other existing options.
- innodb.adaptive_hash_index has been changed from a bool to an enum with
  values OFF, ON and IF_SPECIFIED.  If IF_SPECIFIED is used, adaptive
  hash index are only used for tables and indexes that specifies
  adaptive_hash_index=on.
- The following new options can be used for further optimize adaptive hash
  index for an index:
   - complete_fields (default 0):
     - 0 to the number of columns the key is defined on
   - bytes_from_incomplete_fields (default 0):
     - This is only usable for memcmp() comparable index fields, such as
       VARBINARY or INT. For example, a 3-byte prefix on an INT will
       return an identical hash value for 0‥255, another one for 256‥511,
       and so on.
   - for_equal_hash_point_to_last_record (default 0)
     -  Default is the first record, known as left_side in the code.
        Example: we have an INT column with the values 1,4,10 and bytes=3,
        will that hash value point to the record 1 or the record 10?
        Note: all values will necessarily have the same hash value
        computed on the big endian byte prefix 0x800000, for all of the
        values 0x80000001, 0x80000004, 0x8000000a. InnoDB inverts the
        sign bit in order to have memcmp() compatible comparison

Example:
CREATE TABLE t1 (a int primary key, b varchar(100), c int,
index (b) adaptive_hash_index=no, index (c))
engine=innodb, adaptive_hash_index=yes;

Notable changes in InnoDB
- btr_search.enabled was changed from a bool to a ulong to be
  able to handle options OFF, ON as IF_ENABLED. ulong is needed
  to compile with MariaDB enum variables.
- To be able to find all instances where btr_search.enabled was used
  I changed all code to use btr_search.get_enabled() when accessing
  the value and used btr_search.is_enabled(index) to test if AHI is
  enabled for the index.
- btr_search.enabled() was changed to always take two parameters,
  resize and value of enabled. This was needed as enabled can now
  have values 0, 1, and 2.

Visible user changes:
- select @@global.adaptive_hash_index will now return a string instead
  of 0 or 1.

Other things (for Marko)
- Check in buf0buff.cc buf_pool_t::resize(). The first call to
  btr_search.enable will enver happen as ahi_disabled is always 0
  here.
FIXME: Correctly implement the per-index parameters and adjust the test
@dr-m dr-m self-assigned this Jan 2, 2026
@CLAassistant
Copy link

CLAassistant commented Jan 2, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
0 out of 3 committers have signed the CLA.

❌ dr-m
❌ montywi
❌ vuvova
You have signed the CLA already but the status is still pending? Let us recheck it.

dr-m added 2 commits January 5, 2026 09:44
innodb_ahi_enable(): Apply the adative_hash_index table and index options
to the InnoDB table and index.

FIXME: The value 2, which the logic makes use of, is never being used.
Cover SET GLOBAL innodb_adaptive_hash_index=if_specified.
TODO: Only distinct 2 values of the table option
adaptive_hash_index are still being observed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

5 participants