Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-42423

Per-partition ADAPTIVE_HASH_INDEX option is accepted but has no effect

    XMLWordPrintable

Details

    • Can result in unexpected behaviour

    Description

      Problem

      The server accepts engine-defined table options for each partition (MDEV-5271). So the ADAPTIVE_HASH_INDEX table option of MDEV-37070 is accepted on a partition, and SHOW CREATE TABLE shows it. But InnoDB does not use the value of the partition. The first open of the table replaces it with the table-level value.

      How to repeat

      The test below gives ahi_used 0 for the partition value, also after FLUSH TABLES. The same option at table level gives 1. Tested on main (392818112aa), Debug build.

      --source include/have_innodb.inc
      --source include/have_partition.inc
      --source include/have_sequence.inc
       
      SET @save_ahi= @@GLOBAL.innodb_adaptive_hash_index;
      SET GLOBAL innodb_adaptive_hash_index= if_specified;
      SET GLOBAL innodb_monitor_enable= module_adaptive_hash;
       
      CREATE TABLE t_part (id INT PRIMARY KEY, c INT) ENGINE=InnoDB
      PARTITION BY RANGE (id)
      (PARTITION p0 VALUES LESS THAN MAXVALUE ADAPTIVE_HASH_INDEX=YES);
      CREATE TABLE t_table (id INT PRIMARY KEY, c INT) ENGINE=InnoDB
      ADAPTIVE_HASH_INDEX=YES
      PARTITION BY RANGE (id)
      (PARTITION p0 VALUES LESS THAN MAXVALUE);
      SHOW CREATE TABLE t_part;
      INSERT INTO t_part SELECT seq, seq FROM seq_1_to_100;
      INSERT INTO t_table SELECT seq, seq FROM seq_1_to_100;
       
      SELECT count INTO @start FROM information_schema.innodb_metrics
      WHERE name = 'adaptive_hash_searches';
      SELECT SUM(t.c) FROM seq_1_to_2000 s JOIN t_part t ON t.id = 1 + s.seq % 100;
      SELECT count > @start AS ahi_used FROM information_schema.innodb_metrics
      WHERE name = 'adaptive_hash_searches';
      # ahi_used: 0, expected 1
       
      SELECT count INTO @start FROM information_schema.innodb_metrics
      WHERE name = 'adaptive_hash_searches';
      SELECT SUM(t.c) FROM seq_1_to_2000 s JOIN t_table t ON t.id = 1 + s.seq % 100;
      SELECT count > @start AS ahi_used FROM information_schema.innodb_metrics
      WHERE name = 'adaptive_hash_searches';
      # ahi_used: 1
       
      FLUSH TABLES;
      SELECT count INTO @start FROM information_schema.innodb_metrics
      WHERE name = 'adaptive_hash_searches';
      SELECT SUM(t.c) FROM seq_1_to_2000 s JOIN t_part t ON t.id = 1 + s.seq % 100;
      SELECT count > @start AS ahi_used FROM information_schema.innodb_metrics
      WHERE name = 'adaptive_hash_searches';
      # ahi_used: 0, expected 1
       
      DROP TABLE t_part, t_table;
      SET GLOBAL innodb_monitor_disable= module_adaptive_hash;
      --disable_warnings
      SET GLOBAL innodb_monitor_disable= default;
      SET GLOBAL innodb_monitor_enable= default;
      --enable_warnings
      SET GLOBAL innodb_adaptive_hash_index= @save_ahi;
      

      Cause

      innodb_ahi_enable() gets the table options from two different sources:

      • At CREATE TABLE: innobase_copy_frm_flags_from_create_info() passes create_info->option_struct. ha_partition sets it to the options of the partition (partition_element::option_struct_part, ha_partition.cc:2790). This value is correct.
      • At each open: innobase_copy_frm_flags_from_table() passes table_share->option_struct_table, the table-level value. It ignores handler::option_struct, which ha_partition sets to the options of the partition (ha_partition.cc:9230). The INSERT after CREATE TABLE already opens the table, so the partition value is never used.

      The commit of an in-place ALTER TABLE has the same problem, by code reading (not tested). ha_partition::commit_inplace_alter_table() calls InnoDB once, and InnoDB commits all partitions in one group commit. commit_inplace_alter_table() then calls innobase_copy_frm_flags_from_table(..., altered_table) for each partition (handler0alter.cc:11675, 11751), with the table-level options. ha_partition gives the options of each partition only to check_if_supported_inplace_alter() and prepare_inplace_alter_table().

      Suggested fix

      Either apply the value of the partition, or reject a per-partition ADAPTIVE_HASH_INDEX. To apply it:

      • At open, pass handler::option_struct to innodb_ahi_enable(). For a table that is not partitioned, it is the same as table_share->option_struct_table.
      • At an in-place ALTER TABLE, store the options of each partition in its ha_innobase_inplace_ctx in prepare_inplace_alter_table(), and use them at commit.

      The fix of the open path also serves MDEV-40052 (PINNED). Its design supports a per-partition table option and uses the same open path. A table option for MDEV-42372 (page fill factor) would use the same path. So this fix should come first.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              alessandro.vetere Alessandro Vetere
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

                  Estimated:
                  Original Estimate - 3d
                  3d
                  Remaining:
                  Remaining Estimate - 3d
                  3d
                  Logged:
                  Time Spent - Not Specified
                  Not Specified

                  Git Integration

                    Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.