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

LP:940652 - Non-semi-join materialization creates too many temp. tables

    Details

    • Type: Bug
    • Status: Closed
    • Resolution: Not a Bug
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:

      Description

      Non-semi-join materialization strategy creates too many temp. tables:

      CREATE TABLE t1(a int);
      INSERT INTO t1 values(1),(2);
      CREATE TABLE t2(a int);
      INSERT INTO t2 values(1),(2);
      set optimizer_switch='semijoin=off';
      flush status;
      SELECT * FROM t1 WHERE a IN (SELECT * FROM t2 GROUP BY a HAVING a > 1);
      SHOW STATUS LIKE 'Created_tmp_tables';
      ------------------------------+

      Variable_name Value

      ------------------------------+

      Created_tmp_disk_tables 0
      Created_tmp_files 0
      Created_tmp_tables 3

      ------------------------------+

      The query creates 3 temporary tables. Note that with default settings (semijoin=on) it will create two:

      • one for group by
      • another for doing subquery materialization.
        one could argue that even two tables are too many for this example since they have identical data and keys. In general case, two tables may be required. However, creating three tables is a bug.

        Gliffy Diagrams

          Attachments

            Activity

            Hide
            psergey Sergei Petrunia added a comment -

            Re: Non-semi-join materialization creates too many temp. tables
            EXPLAIN:

            MariaDB [j16]> explain SELECT * FROM t1 WHERE a IN (SELECT * FROM t2 GROUP BY a HAVING a > 1);
            ------------------------------------------------------------------------+

            id select_type table type possible_keys key key_len ref rows Extra

            ------------------------------------------------------------------------+

            1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where
            2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 Using temporary

            ------------------------------------------------------------------------+
            2 rows in set (2.59 sec)

            Show
            psergey Sergei Petrunia added a comment - Re: Non-semi-join materialization creates too many temp. tables EXPLAIN: MariaDB [j16] > explain SELECT * FROM t1 WHERE a IN (SELECT * FROM t2 GROUP BY a HAVING a > 1); --- ------------ ----- ---- ------------- ---- ------- ---- ---- ----------------+ id select_type table type possible_keys key key_len ref rows Extra --- ------------ ----- ---- ------------- ---- ------- ---- ---- ----------------+ 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where 2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 Using temporary --- ------------ ----- ---- ------------- ---- ------- ---- ---- ----------------+ 2 rows in set (2.59 sec)
            Hide
            psergey Sergei Petrunia added a comment -

            Re: Non-semi-join materialization creates too many temp. tables
            Figured out that the 3rd temp table is created by expression cache.

            Show
            psergey Sergei Petrunia added a comment - Re: Non-semi-join materialization creates too many temp. tables Figured out that the 3rd temp table is created by expression cache.
            Hide
            ratzpo Rasmus Johansson added a comment -

            Launchpad bug id: 940652

            Show
            ratzpo Rasmus Johansson added a comment - Launchpad bug id: 940652

              People

              • Assignee:
                Unassigned
                Reporter:
                psergey Sergei Petrunia
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: