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

The optimizer thinks subquery is correlated while it is not

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • 10.2, 10.3, 10.4, 10.5, 10.6, 10.7
    • 10.4, 10.5, 10.6
    • Optimizer
    • None

    Description

      This issue was exposed by fix for MDEV-25636.

      Take this testcase from subselect4.result:

      #
      # LP BUG#680038 bool close_thread_table(THD*, TABLE**):
      #               Assertion `table->key_read == 0' failed in EXPLAIN
      #
      CREATE TABLE t1 (f1 int,f3 int,f4 int) ;
      INSERT IGNORE INTO t1 VALUES (NULL,1,0);
      CREATE TABLE t2 (f2 int,f4 int,f5 int) ;
      INSERT IGNORE INTO t2 VALUES (8,0,0),(5,0,0);
      CREATE TABLE t3 (f4 int,KEY (f4)) ;
      INSERT IGNORE INTO t3 VALUES (0),(0);
      set @@optimizer_switch='semijoin=off';
      

      EXPLAIN
      SELECT * FROM t1 WHERE
      (SELECT f2 FROM t2
      WHERE f4 <= ALL
      (SELECT max(SQ1_t1.f4)
      FROM t3 AS SQ1_t1 JOIN t3 AS SQ1_t3 ON SQ1_t3.f4
      GROUP BY SQ1_t1.f4));
      id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
      1	PRIMARY	t1	system	NULL	NULL	NULL	NULL	1	
      2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	2	Using where
      3	SUBQUERY	SQ1_t1	index	NULL	f4	5	NULL	2	Using index; Using temporary
      3	SUBQUERY	SQ1_t3	index	f4	f4	5	NULL	2	Using where; Using index; Using join buffer (flat, BNL join)
      

      Here, select with id=2 should have SUBQUERY, not DEPENDENT SUBQUERY.

      The details of why/how this happens are described here:

      https://jira.mariadb.org/browse/MDEV-25636?focusedCommentId=190180&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-190180

      Attachments

        Issue Links

          Activity

            People

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