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

Wrong result with InnoDB when index merge is forced

    XMLWordPrintable

Details

    Description

      When using dbt3_s001 (see mysql-test/main/dbt3_s001.inc) with InnoDB engine one gets:

      MariaDB [dbt3_s001]> SELECT COUNT(*) FROM lineitem WHERE l_receiptDATE < '1994-09-10' AND l_suppkey = 3 OR l_linenumber < 6 AND l_receiptDATE <> '1993-03-17' AND l_receiptDATE <> '1995-11-24' OR l_orderkey = 816;        
      +----------+
      | COUNT(*) |
      +----------+
      |     5375 |
      +----------+
      1 row in set (0.054 sec)
       
      MariaDB [dbt3_s001]> SELECT COUNT(*) FROM lineitem  FORCE INDEX (i_l_receiptdate, i_l_orderkey) WHERE l_receiptDATE < '1994-09-10' AND l_suppkey = 3 OR l_linenumber < 6 AND l_receiptDATE <> '1993-03-17' AND l_receiptDATE <> '1995-11-24' OR l_orderkey = 816;       +----------+
      | COUNT(*) |
      +----------+
      |     2994 |
      +----------+
      1 row in set (0.072 sec)
      

      The second result is incorrect.
      The following execution plans are used:

      MariaDB [dbt3_s001]> EXPLAIN SELECT COUNT(*) FROM lineitem WHERE l_receiptDATE < '1994-09-10' AND l_suppkey = 3 OR l_linenumber < 6 AND l_receiptDATE <> '1993-03-17' AND l_receiptDATE <> '1995-11-24' OR l_orderkey = 816;                                            
      +------+-------------+----------+------+------------------------------------------------------------------------+------+---------+------+------+-------------+
      | id   | select_type | table    | type | possible_keys                                                          | key  | key_len | ref  | rows | Extra       |
      +------+-------------+----------+------+------------------------------------------------------------------------+------+---------+------+------+-------------+
      |    1 | SIMPLE      | lineitem | ALL  | PRIMARY,i_l_suppkey,i_l_receiptdate,i_l_orderkey,i_l_orderkey_quantity | NULL | NULL    | NULL | 5871 | Using where |
      +------+-------------+----------+------+------------------------------------------------------------------------+------+---------+------+------+-------------+
      1 row in set (0.006 sec)
       
      MariaDB [dbt3_s001]> EXPLAIN SELECT COUNT(*) FROM lineitem  FORCE INDEX (i_l_receiptdate, i_l_orderkey) WHERE l_receiptDATE < '1994-09-10' AND l_suppkey = 3 OR l_linenumber < 6 AND l_receiptDATE <> '1993-03-17' AND l_receiptDATE <> '1995-11-24' OR l_orderkey = 816;
      +------+-------------+----------+-------------+------------------------------+------------------------------+---------+------+------+-------------------------------------------------------------+
      | id   | select_type | table    | type        | possible_keys                | key                          | key_len | ref  | rows | Extra                                                       |
      +------+-------------+----------+-------------+------------------------------+------------------------------+---------+------+------+-------------------------------------------------------------+
      |    1 | SIMPLE      | lineitem | index_merge | i_l_receiptdate,i_l_orderkey | i_l_receiptdate,i_l_orderkey | 4,4     | NULL | 3336 | Using sort_union(i_l_receiptdate,i_l_orderkey); Using where |
      +------+-------------+----------+-------------+------------------------------+------------------------------+---------+------+------+-------------------------------------------------------------+
      

      It does not matter what settings are used for 'use_stat_tables' and 'optimizer_use_condition_selectivity'.
      The same database with MyISAM returns correct results with the same plans as for InnoDB.
      Later versions most probably are affected as well

      Attachments

        Activity

          People

            igor Igor Babaev
            igor Igor Babaev
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

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