Details
Description
When derived tables or VIEWs are resolved with subquery merge, they still
increment Created_tmp_tables status variable and CREATED_TMP_TABLES in
performance_schema.events_statements_* tables.
Example:
create table t2 (a int); insert into t2 values (1),(2),(3); create view v2 as select a from t2;
flush status; select * from v2; show status like '%Created_tmp%'; +-------------------------+-------+ | Variable_name | Value | +-------------------------+-------+ | Created_tmp_disk_tables | 0 | | Created_tmp_files | 0 | | Created_tmp_tables | 1 | +-------------------------+-------+
To be sure it's merged, let's check the query plan:
explain select * from v2; +------+-------------+-------+------+---------------+------+---------+------+------+-------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +------+-------------+-------+------+---------------+------+---------+------+------+-------+ | 1 | SIMPLE | t2 | ALL | NULL | NULL | NULL | NULL | 3 | | +------+-------------+-------+------+---------------+------+---------+------+------+-------+
The same thing happens when using a derived table:
select * from (select * from t2) T1;
Gliffy Diagrams
Attachments
Issue Links
Activity
- All
- Comments
- Work Log
- History
- Activity
- Transitions
Code-wise the problem happens when create_tmp_table() is called with the parameter do_not_open=true. We create a temporary but we don't open it. The problems with this are