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

Join order optimizer hints inconsistently resolve table names

    XMLWordPrintable

Details

    Description

      --source include/have_sequence.inc
      create table t1 (a int, b int, key idx_a(a));
      insert into t1 select seq, seq from seq_1_to_10;
      create table t2 as select * from t1;
       
      set optimizer_switch='derived_merge=on';
       
      --echo # Default join order is t2, t1
      explain select * from
        (select /*+ qb_name(qb1)*/ t1.* from t1, t2 where t1.a = t2.a and t1.a < 100) as DT1;
       
      --echo # Hint applied
      explain select /*+ join_order(t1@qb1,t2@qb1)*/ * from
        (select /*+ qb_name(qb1)*/ t1.* from t1, t2 where t1.a = t2.a and t1.a < 100) as DT1;
       
      --echo # Variation of the same hint but now it is ignored without a warning
      explain select /*+ join_order(@qb1 t1, t2)*/ * from
        (select /*+ qb_name(qb1)*/ t1.* from t1, t2 where t1.a = t2.a and t1.a < 100) as DT1;
       
      --echo # Hint is applied although tables are inside another query block
      explain select /*+ join_order(t1, t2)*/ * from
        (select t1.* from t1, t2 where t1.a = t2.a and t1.a < 100) as DT1;
       
      --echo # Run the same statements with derived merging turned off
      set optimizer_switch='derived_merge=off';
       
      --echo # Warning is generated and the hint is ignored despite correct syntax
      explain select /*+ join_order(t1@qb1,t2@qb1)*/ * from
        (select /*+ qb_name(qb1)*/ t1.* from t1, t2 where t1.a = t2.a and t1.a < 100) as DT1;
       
      --echo # Hint is applied, everything is correct
      explain select /*+ join_order(@qb1 t1, t2)*/ * from
        (select /*+ qb_name(qb1)*/ t1.* from t1, t2 where t1.a = t2.a and t1.a < 100) as DT1;
       
      --echo # Warning is generated, it is correct
      explain select /*+ join_order(t1, t2)*/ * from
        (select t1.* from t1, t2 where t1.a = t2.a and t1.a < 100) as DT1;
      

      Attachments

        Issue Links

          Activity

            People

              oleg.smirnov Oleg Smirnov
              oleg.smirnov Oleg Smirnov
              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.