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

Find null complement without a full scan

    XMLWordPrintable

Details

    Description

      A FULL JOIN returning one result row might read every row of its right side unnecessarily.

      CREATE TABLE s1 (a INT, b INT, KEY(a));
      CREATE TABLE s2 (a INT, b INT, KEY(a));
      INSERT INTO s1 SELECT seq, seq FROM seq_1_to_10;
      INSERT INTO s2 SELECT seq, seq FROM seq_1_to_10000;
      ANALYZE TABLE s1, s2 PERSISTENT FOR ALL;
       
      -- Q1
      SELECT * FROM s1 FULL JOIN s2 ON s1.a = s2.a WHERE COALESCE(s1.a, s2.a) = 107;
      

      The row Q1 returns comes from the second pass, which returns the right side null complement rows. run_fj_null_complement_pass (sql/opt_full_join.cc:2406) replaces the access the first pass used. It sets read_first_record to join_init_read_record at line 2427, clears join_tab->select at line 2428 and disables the pushed rowid filter at line 2430. The second pass therefore reads all of the right side for every query, regardless of the access type that the first pass used.

      Give the second pass an access of its own, chosen from the WHERE conjuncts with NULL in place of the left side's columns, and use the full scan only when no such access exists. The match record is the set of right side rowids in full_join_duplicate_filter, which the second pass tests for each row it reads. The cost term of ticket 1 would then cost this access rather than a full scan.

      Attachments

        Activity

          People

            Gosselin Dave Gosselin
            Gosselin Dave Gosselin
            Dave Gosselin Dave Gosselin
            Sergei Petrunia Sergei Petrunia
            Votes:
            0 Vote for this issue
            Watchers:
            1 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.