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

EITS: Incorrect filtered% value for single-table select with range access

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 10.0.9
    • 10.0.11
    • None

    Description

      filtered% value is incorrect for single-table select and two-keypart key.

      create table ten(a int);
      insert into ten values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
       
      create table t2 (a int, b int, col1 varchar(64), col2 varchar(64), key(a,b));
      insert into t2 select A.a+10*B.a, C.a+10*D.a, 'filler-data1', 'filler-data2' from ten A, ten B, ten C, ten D;
       
      set histogram_size=100;
      set optimizer_use_condition_selectivity=4;
      set use_stat_tables='preferably';
      analyze table t2 persistent for all;

      Then, try this:

      explain extended select * from t2 where a in (1,2,3) and b in (1,2,3);
      +------+-------------+-------+-------+---------------+------+---------+------+------+----------+-----------------------+
      | id   | select_type | table | type  | possible_keys | key  | key_len | ref  | rows | filtered | Extra                 |
      +------+-------------+-------+-------+---------------+------+---------+------+------+----------+-----------------------+
      |    1 | SIMPLE      | t2    | range | a             | a    | 10      | NULL |    9 |     3.37 | Using index condition |
      +------+-------------+-------+-------+---------------+------+---------+------+------+----------+-----------------------+

      The entire WHERE clause is used to construct range access. If we use range access, it will give us 9 rows, and after that 'filtered' should be 100%. Instead, it is 3.37%, and again the optimizer will grossly underestimate #rows.

      Attachments

        Activity

          psergei Sergei Petrunia created issue -
          psergei Sergei Petrunia made changes -
          Field Original Value New Value
          Labels eits
          psergei Sergei Petrunia made changes -
          Assignee Igor Babaev [ igor ]
          psergei Sergei Petrunia made changes -
          Assignee Igor Babaev [ igor ] Sergei Petrunia [ psergey ]
          psergei Sergei Petrunia made changes -
          Status Open [ 1 ] In Progress [ 3 ]

          Analysis

          == calculate_cond_selectivity_for_table() ==

          records_in_column_ranges() is invoked for b.
          It returns:
          (gdb) p rows/ table_records
          $127 = 0.033663366336633659

          We also see a quick select with used_key_parts=2 and
          selectivity 0.000899.

          We multiply these two selectivities (this is wrong) and get:
          (gdb) p table->cond_selectivity
          $132 = 3.0297029702970299e-05

          = table_cond_selectivity() ==
          sees that quick select is used
          removes its selectivity
          The remaining selectivity is:
          (gdb) print sel
          $136 = 0.033663366336633666

          psergei Sergei Petrunia added a comment - Analysis == calculate_cond_selectivity_for_table() == records_in_column_ranges() is invoked for b. It returns: (gdb) p rows/ table_records $127 = 0.033663366336633659 We also see a quick select with used_key_parts=2 and selectivity 0.000899. We multiply these two selectivities (this is wrong) and get: (gdb) p table->cond_selectivity $132 = 3.0297029702970299e-05 = table_cond_selectivity() == sees that quick select is used removes its selectivity The remaining selectivity is: (gdb) print sel $136 = 0.033663366336633666

          Committed a patch.

          psergei Sergei Petrunia added a comment - Committed a patch.
          serg Sergei Golubchik made changes -
          Fix Version/s 10.0.11 [ 15200 ]
          psergei Sergei Petrunia made changes -
          Resolution Fixed [ 1 ]
          Status In Progress [ 3 ] Closed [ 6 ]
          serg Sergei Golubchik made changes -
          Workflow defaullt [ 37806 ] MariaDB v2 [ 42422 ]
          ratzpo Rasmus Johansson (Inactive) made changes -
          Workflow MariaDB v2 [ 42422 ] MariaDB v3 [ 61362 ]
          serg Sergei Golubchik made changes -
          Workflow MariaDB v3 [ 61362 ] MariaDB v4 [ 147722 ]

          People

            psergei Sergei Petrunia
            psergei Sergei Petrunia
            Votes:
            0 Vote for this issue
            Watchers:
            1 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.