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

Selectivity of a multiple equality with an earlier table is never applied

    XMLWordPrintable

Details

    • Task
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • 10.11.19
    • 10.11
    • Optimizer
    • None
    • EITs unused in non-indexed join conditions.

    Description

      During optimization, when a table is joined onto the tables already in the
      plan, table_multi_eq_cond_selectivity() is meant to account for the
      multiple equalities tying its columns to theirs that the chosen access
      method does not already use: for each such equality, the largest
      avg_frequency/rows over its fields on the earlier tables, multiplied
      together across equalities.

      It never did. The accumulator starts at 1.0 and is only ever raised:

      double eq_fld_sel= 1.0;
      ...
      if (curr_eq_fld_sel < 1.0)
      set_if_bigger(eq_fld_sel, curr_eq_fld_sel);

      Every candidate is below 1.0, so eq_fld_sel stays 1.0 and the function returns 1.0 for every table in every plan. This has been so since the function was added (fc1c8ffdadf, the MWL#253 pilot patch).

      SET optimizer_use_condition_selectivity= 4;
      SET use_stat_tables= PREFERABLY;
      SET join_cache_level= 2;
       
      CREATE TABLE dim (d_id INT PRIMARY KEY, d_name VARCHAR(20)) ENGINE=InnoDB;
      INSERT INTO dim SELECT seq, CONCAT('name', seq) FROM seq_1_to_20;
       
      # fact.d_id has no index, so the join to dim can only be a BNL join
      CREATE TABLE fact (f_id INT PRIMARY KEY, d_id INT NOT NULL, val INT) ENGINE=InnoDB;
      INSERT INTO fact SELECT seq, seq % 20 + 1, seq FROM seq_1_to_2000;
       
      CREATE TABLE detail (f_id INT PRIMARY KEY, extra INT) ENGINE=InnoDB;
      INSERT INTO detail SELECT seq, seq * 2 FROM seq_1_to_2000;
       
      ANALYZE TABLE dim, fact, detail PERSISTENT FOR ALL;
       
      # one of 20 dim rows survives, so one twentieth of fact joins it and detail is looked up 100 times
      EXPLAIN EXTENDED
      SELECT STRAIGHT_JOIN COUNT(*) FROM dim, fact, detail
      WHERE fact.d_id = dim.d_id AND detail.f_id = fact.f_id AND dim.d_name = 'name7';
       
      --source include/analyze-format.inc
      ANALYZE FORMAT=JSON
      SELECT STRAIGHT_JOIN COUNT(*) FROM dim, fact, detail
      WHERE fact.d_id = dim.d_id AND detail.f_id = fact.f_id AND dim.d_name = 'name7';
       
      DROP TABLE dim, fact, detail;
      

      Attachments

        Activity

          People

            Johnston Rex Johnston
            Johnston Rex Johnston
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Time Tracking

                Estimated:
                Original Estimate - 1d
                1d
                Remaining:
                Remaining Estimate - 1d
                1d
                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.