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

Join performance on composite secondary index lookup with inequality

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Not a Bug
    • 10.1, 10.1.38, 10.3.13, 10.2, 10.3
    • N/A
    • Optimizer
    • None

    Description

      Joins with ids and dates are very common especially with temporal tables.
      Looks like MariaDB optimizer only uses the id and not the date for the lookup leading to poor join performance when the date is discriminant.
      Here is the test case.

      create table t(
      id int not null auto_increment primary key,
      id2 int not null, 
      valid_to datetime(6) not null,
      index id2_valid_to (id2, valid_to)
      ) engine=InnoDB;
       
      truncate table t;
       
      insert into t(id2, valid_to) values(rand()*1000, date_add(now(), interval - rand()*1000 day));
      insert into t(id2, valid_to) values(rand()*1000, date_add(now(), interval - rand()*1000 day));
      insert into t(id2, valid_to) values(rand()*1000, date_add(now(), interval - rand()*1000 day));
      insert into t(id2, valid_to) values(rand()*1000, date_add(now(), interval - rand()*1000 day));
      replace into t(id2, valid_to) select rand()*1000, date_add(now(), interval - rand()*1000 day) from t t1, t t2, t t3, t t4, t t5, t t6, t t7, t t8, t t9;
      drop temporary table if exists t_max;
      create temporary table t_max as select max(id) id from t group by id2;
      update t, t_max set t.valid_to='9999-12-31' where t.id = t_max.id;
      commit;
      analyze table t;
      select count(*) from t join t t2 on t.id2 = t2.id2 and t2.valid_to >='9999-12-31';
      

      MySQL 8.0 is fast, MariaDB 10.1.29, 10.1.38, 10.3.13 are slow.

      select count(*) from t join t t2 on t.id2 = t2.id2 and t2.valid_to ='9999-12-31'; 
      

      is fast

      Attachments

        1. DOUBLE_PREC_AFTER_9999.png
          DOUBLE_PREC_AFTER_9999.png
          56 kB
        2. DOUBLE_PREC.png
          DOUBLE_PREC.png
          36 kB
        3. SINGLE_PREC_AFTER_9999.png
          SINGLE_PREC_AFTER_9999.png
          58 kB
        4. SINGLE_PREC.png
          SINGLE_PREC.png
          65 kB

        Activity

          People

            igor Igor Babaev
            aadant Arnaud Adant
            Votes:
            1 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

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