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

Explain output difference in possible_keys column

    XMLWordPrintable

Details

    Description

      Issue seen in main.group_min_max_innodb

      Trace output:

      ------------------------
      Capture : trace1.txt
      replay : trace2.txt

      Capture Explain:

      -----------

      +------+-------------+------------+-------+---------------+------+---------+---------+------+-----------------------------------------------------------+
      | id   | select_type | table      | type  | possible_keys | key  | key_len | ref     | rows | Extra                                                     |
      +------+-------------+------------+-------+---------------+------+---------+---------+------+-----------------------------------------------------------+
      |    1 | PRIMARY     | t1         | ALL   | NULL          | NULL | NULL    | NULL    | 4    | Using where                                               |
      |    1 | PRIMARY     | <derived2> | ref   | key0          | key0 | 6       | m8.t1.b | 1    |                                                           |
      |    2 | DERIVED     | t2         | range | a             | a    | 58      | NULL    | 7    | Using index for group-by; Using temporary; Using filesort |
      +------+-------------+------------+-------+---------------+------+---------+---------+------+-----------------------------------------------------------+
      

      Replay Explain:

      ----------------

      +------+-------------+------------+-------+---------------+------+---------+---------+------+-----------------------------------------------------------+
      | id   | select_type | table      | type  | possible_keys | key  | key_len | ref     | rows | Extra                                                     |
      +------+-------------+------------+-------+---------------+------+---------+---------+------+-----------------------------------------------------------+
      |    1 | PRIMARY     | t1         | ALL   | NULL          | NULL | NULL    | NULL    | 4    | Using where                                               |
      |    1 | PRIMARY     | <derived2> | ref   | key0          | key0 | 6       | m8.t1.b | 1    |                                                           |
      |    2 | DERIVED     | t2         | range | NULL          | a    | 58      | NULL    | 1    | Using index for group-by; Using temporary; Using filesort |
      +------+-------------+------------+-------+---------------+------+---------+---------+------+-----------------------------------------------------------+
      
      

      How to repro:

      ----------------

      set optimizer_record_context=ON;
       
      CREATE TABLE t1 (a varchar(35), b varchar(4)) ENGINE=InnoDB CHARSET=latin1;
      INSERT INTO t1 VALUES
      ('Albania','AXA'),('Australia','AUS'),('American Samoa','AMSA'),('Bahamas','BS');
       
      CREATE TABLE t2 (a varchar(4), b varchar(50), PRIMARY KEY (b,a), KEY (a)) ENGINE=InnoDB CHARSET=latin1;
      INSERT INTO t2 VALUES
      ('BERM','African Methodist Episcopal'),('AUS','Anglican'),('BERM','Anglican'),('BS','Anglican'),('BS','Baptist'),('BS','Methodist');
       
      explain SELECT t1.a
      FROM (SELECT a FROM t2 GROUP BY a ORDER BY COUNT(DISTINCT b) LIMIT 1) dt
      JOIN t1 ON dt.a=t1.b;
       
      SELECT context INTO DUMPFILE 'context1.txt' FROM INFORMATION_SCHEMA.OPTIMIZER_CONTEXT;
      source context1.txt
      

      Attachments

        1. trace2.txt
          16 kB
        2. trace1.txt
          19 kB

        Issue Links

          Activity

            People

              bsrikanth Srikanth Bondalapati
              mariadb-pavithrapandith Pavithra Pandith
              Votes:
              0 Vote for this issue
              Watchers:
              1 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.