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

Unexpected result with firstmatch=off,loosescan=off

    XMLWordPrintable

Details

    • Bug
    • Status: In Progress (View Workflow)
    • Major
    • Resolution: Unresolved
    • 11.4
    • 11.4
    • Optimizer
    • None
    • Q4/2026 Server Maintenance

    Description

      Start the server with the option --memory.optimizer_row_copy_cost=0

      Then run the following scenario. Notice the optimizer_switch settings.

      create table t1 (a int primary key);
      insert into t1 values (1),(2),(3);
      create table t2 (b int primary key);
      insert into t2 values (1),(2),(3),(4);
      create table t3 (c int, d int);
      insert into t3 values (1,1),(2,2),(3,3),(4,4),(5,5),
      (6,6),(7,7),(8,8),(9,9),(10,10);
      insert into t3 select c+10, d+10 from t3;
      insert into t3 select c+20, d+20 from t3;
      insert into t3 select c+40, d+40 from t3;
       
      set optimizer_switch='firstmatch=off,loosescan=off';
      set optimizer_where_cost=0;
       
      select t1.a x, t2.b y 
      from 
        t1 left join t2 on t1.a=t2.b
      where 
        t1.a=1 and t2.b=1 and 
        t1.a in (select c from t3) and rand() < 0;
      

      The SELECT generates the following result, which is incorrect, and instead should generate the empty set.

      +---+---+
      | x | y |
      +---+---+
      | 1 | 1 |
      +---+---+
      1 row in set (0.002 sec)
      

      Attachments

        Issue Links

          Activity

            People

              Gosselin Dave Gosselin
              Gosselin Dave Gosselin
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

                  Estimated:
                  Original Estimate - 7h 13m Original Estimate - 7h 13m
                  7h 13m
                  Remaining:
                  Time Spent - 1d 3.25h Remaining Estimate - 0.5h
                  0.5h
                  Logged:
                  Time Spent - 1d 3.25h Remaining Estimate - 0.5h
                  1d 3.25h

                  Git Integration

                    Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.