<?xml version="1.0" encoding="utf-8"?>
<launchpad-bug id="903169">
  <date_last_updated>2012-03-21 15:42:00.424495+00:00</date_last_updated>
  <api_links>
    <bug_api_link>https://api.launchpad.net/1.0/bugs/903169</bug_api_link>
    <bug_owner_link>https://api.launchpad.net/1.0/~sergefp</bug_owner_link>
    <milestone_link>https://api.launchpad.net/1.0/maria/+milestone/5.3</milestone_link>
    <linked_branches_collection_link>https://api.launchpad.net/1.0/bugs/903169/linked_branches</linked_branches_collection_link>
    <activity_link>https://api.launchpad.net/1.0/bugs/903169/activity</activity_link>
  </api_links>
  <bug_web_link>https://bugs.launchpad.net/bugs/903169</bug_web_link>
  <owner>Sergey Petrunia</owner>
  <assignee>Michael Widenius</assignee>
  <milestone_title>Maria 5.3</milestone_title>
  <duplicate_link></duplicate_link>
  <duplicate_bug_id></duplicate_bug_id>
  <title>Created_tmp_tables is incremented with derived_merge=ON</title>
  <status>New</status>
  <importance>Low</importance>
  <created>2011-12-12 12:18:29.468799+00:00</created>
  <description>
<![CDATA[Created_tmp_tables is incremented even when derived_merge=ON, when temp.tables should not be created.
One can observe this as follows:

create table t1 (a int);
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
alter table t1 add b int;
create table t2 as select * from t1;

set optimizer_switch='derived_merge=off';
explain select * from (select t1.a, t2.b from t1, t2) T;
+----+-------------+------------+------+---------------+------+---------+------+------+------------------------------------+
| id | select_type | table      | type | possible_keys | key  | key_len | ref  | rows | Extra                              |
+----+-------------+------------+------+---------------+------+---------+------+------+------------------------------------+
|  1 | PRIMARY     | <derived2> | ALL  | NULL          | NULL | NULL    | NULL |  100 |                                    |
|  2 | DERIVED     | t1         | ALL  | NULL          | NULL | NULL    | NULL |   10 |                                    |
|  2 | DERIVED     | t2         | ALL  | NULL          | NULL | NULL    | NULL |   10 | Using join buffer (flat, BNL join) |
+----+-------------+------------+------+---------------+------+---------+------+------+------------------------------------+
3 rows in set (0.01 sec)

flush status;
select * from (select t1.a, t2.b from t1, t2) T;
show status like 'created%';
+-------------------------+-------+
| Variable_name           | Value |
+-------------------------+-------+
| Created_tmp_disk_tables | 0     |
| Created_tmp_files       | 0     |
| Created_tmp_tables      | 1     |
+-------------------------+-------+
3 rows in set (0.00 sec)

set optimizer_switch='derived_merge=on';
explain select * from (select t1.a, t2.b from t1, t2) T;
+----+-------------+-------+------+---------------+------+---------+------+------+------------------------------------+
| id | select_type | table | type | possible_keys | key  | key_len | ref  | rows | Extra                              |
+----+-------------+-------+------+---------------+------+---------+------+------+------------------------------------+
|  1 | SIMPLE      | t1    | ALL  | NULL          | NULL | NULL    | NULL |   10 |                                    |
|  1 | SIMPLE      | t2    | ALL  | NULL          | NULL | NULL    | NULL |   10 | Using join buffer (flat, BNL join) |
+----+-------------+-------+------+---------------+------+---------+------+------+------------------------------------+
2 rows in set (0.00 sec)
flush status;
select * from (select t1.a, t2.b from t1, t2) T;
show status like 'created%';
+-------------------------+-------+
| Variable_name           | Value |
+-------------------------+-------+
| Created_tmp_disk_tables | 0     |
| Created_tmp_files       | 0     |
| Created_tmp_tables      | 1     |
+-------------------------+-------+
3 rows in set (0.00 sec)]]>  </description>
  <activities>
    <activity datechanged="2011-12-12T12:18:29.468799+00:00">
      <oldvalue>
<![CDATA[]]>      </oldvalue>
      <newvalue>
<![CDATA[]]>      </newvalue>
      <whatchanged>bug</whatchanged>
      <person>Sergey Petrunia</person>
      <message>added bug</message>
    </activity>
    <activity datechanged="2011-12-12T12:28:02.272364+00:00">
      <oldvalue>
<![CDATA[]]>      </oldvalue>
      <newvalue>
<![CDATA[5.2]]>      </newvalue>
      <whatchanged>maria: milestone</whatchanged>
      <person>Sergey Petrunia</person>
      <message></message>
    </activity>
    <activity datechanged="2011-12-12T12:28:04.369250+00:00">
      <oldvalue>
<![CDATA[5.2]]>      </oldvalue>
      <newvalue>
<![CDATA[5.3]]>      </newvalue>
      <whatchanged>maria: milestone</whatchanged>
      <person>Sergey Petrunia</person>
      <message></message>
    </activity>
    <activity datechanged="2011-12-12T12:28:19.667505+00:00">
      <oldvalue>
<![CDATA[]]>      </oldvalue>
      <newvalue>
<![CDATA[Igor Babaev (igorb-seattle)]]>      </newvalue>
      <whatchanged>maria: assignee</whatchanged>
      <person>Sergey Petrunia</person>
      <message></message>
    </activity>
    <activity datechanged="2011-12-18T15:54:50.255069+00:00">
      <oldvalue>
<![CDATA[Undecided]]>      </oldvalue>
      <newvalue>
<![CDATA[Low]]>      </newvalue>
      <whatchanged>maria: importance</whatchanged>
      <person>Sergey Petrunia</person>
      <message></message>
    </activity>
    <activity datechanged="2012-03-21T15:41:59.208626+00:00">
      <oldvalue>
<![CDATA[Igor Babaev (igorb-seattle)]]>      </oldvalue>
      <newvalue>
<![CDATA[Michael Widenius (monty)]]>      </newvalue>
      <whatchanged>maria: assignee</whatchanged>
      <person>Michael Widenius</person>
      <message></message>
    </activity>
  </activities>
  <comments>
    <comment commentlink="https://api.launchpad.net/1.0/maria/+bug/903169/comments/1" datecreated="2011-12-12T12:19:46.100885+00:00">
      <person>Sergey Petrunia</person>
      <subject>
<![CDATA[Re: Created_tmp_tables is incremented with derived_merge=ON]]>      </subject>
      <content>
<![CDATA[The user will see Created_tmp_tables=1 in both cases, which is mispresentation of what has happened.]]>      </content>
    </comment>
    <comment commentlink="https://api.launchpad.net/1.0/maria/+bug/903169/comments/2" datecreated="2011-12-12T12:27:53.689160+00:00">
      <person>Sergey Petrunia</person>
      <subject>
<![CDATA[Re: Created_tmp_tables is incremented with derived_merge=ON]]>      </subject>
      <content>
<![CDATA[Ok, Created_tmp_tables  is incremented at the start of create_tmp_table().  

When derived_merge=ON,  we still get calls like this:

create_tmp_table (thd=0x9ed6fa8, param=0x9f3d6a0, fields=..., group=0x0, distinct=false, save_sum_fields=true, select_options=2416204288, rows_limit=18446744073709551615, table_alias=0x9f3d1d0 "T", do_not_open=true) 

note that  do_not_open==TRUE.  I think such calls should not be counted.]]>      </content>
    </comment>
  </comments>
</launchpad-bug>
