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

Join optimizer prunes good join orders

    XMLWordPrintable

Details

    • Bug
    • Status: Confirmed (View Workflow)
    • Major
    • Resolution: Unresolved
    • 10.6, 10.11, 11.4, 11.8, 12.1
    • 10.11
    • Optimizer
    • None

    Description

      Probably affect lower versions too. Split from MDEV-36055 (see https://jira.mariadb.org/browse/MDEV-36055?focusedCommentId=309780&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-309780)

      With the following setup:

      --source include/have_sequence.inc
      create table t1 (a int);
      insert into t1 select seq from seq_1_to_10000;
       
      create table t2 (
        a int,
        b int,
        index(a)
      );
      insert into t2
      select
        A.seq,
        B.seq
      from
        seq_1_to_10000 A,
        seq_1_to_100 B;
       
      create table t3 (
        a int,
        b int,
        index(a)
      );
      insert into t3
      select
        A.seq,
        B.seq
      from
        seq_1_to_10000 A,
        seq_1_to_10 B;
       
      analyze table t1,t2,t3;
      

      We get bad join order with suboptimal costs:

      explain format=json
      select *
      from
      t1
      join t3 on t3.a=t1.a and t3.b in (1,2,3,4)
      join t2 on t2.a=t1.a and t2.b in (1,2,3,4);
      EXPLAIN
      {
        "query_block": {
          "select_id": 1,
          "cost": 5090.535084,
      ...
      explain format=json
      select *
      from
      t1
      join t2 on t2.a=t1.a and t2.b in (1,2,3,4)
      join t3 on t3.a=t1.a and t3.b in (1,2,3,4);
      EXPLAIN
      {
        "query_block": {
          "select_id": 1,
          "cost": 5090.535084,
      ...
      explain format=json
      select straight_join *   # set optimizer_prune_level=0 also works
      from
      t1
      join t2 on t2.a=t1.a and t2.b in (1,2,3,4)
      join t3 on t3.a=t1.a and t3.b in (1,2,3,4);
      EXPLAIN
      {
        "query_block": {
          "select_id": 1,
          "cost": 1759.088784,
      

      See also https://jira.mariadb.org/browse/MDEV-36055?focusedCommentId=309781&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-309781 about similarities to MDEV-36331.

      Attachments

        Issue Links

          Activity

            People

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