patternsqlMajor
"Copying to tmp table" extremely slow
Viewed 0 times
tmpextremelyslowcopyingtable
Problem
This is my example of query:
Explain of that select:
```
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE guilds_has_users ref fk_guilds_has_users_users1,act
SELECT
nickname,
CASE class_id
WHEN 1 THEN 'Druid'
WHEN 2 THEN 'Necromancer'
WHEN 3 THEN 'Mage'
WHEN 4 THEN 'Priest'
WHEN 5 THEN 'Warrior'
WHEN 6 THEN 'Stalker'
WHEN 7 THEN 'Paladin'
WHEN 8 THEN 'Psionic'
END class_name,
ROUND(AVG(level),2) level,
ROUND(AVG(tabard_id),2) tabard,
CASE rank_id
WHEN 1 THEN 'Leader'
WHEN 2 THEN 'Officer'
WHEN 3 THEN 'Veteran'
WHEN 4 THEN 'HonoryMember'
WHEN 5 THEN 'OrdinaryMember'
WHEN 6 THEN 'Alt'
WHEN 7 THEN 'Apprentice'
WHEN 8 THEN 'Penalty'
END rank_name,
ROUND(AVG(loyality),2) loyality,
ROUND((MAX(authority)-MIN(authority))/AVG(tabard_id)) authority_effective,
MAX(authority)-MIN(authority) authority_delta,
MIN(authority) authority_begin,
MAX(authority) authority_end
FROM users
LEFT JOIN level_history ON level_history.users_id = users.id
LEFT JOIN tabard_history ON tabard_history.users_id = users.id
LEFT JOIN rank_history ON rank_history.users_id = users.id
LEFT JOIN loyality_history ON loyality_history.users_id = users.id
LEFT JOIN authority_history ON authority_history.users_id = users.id
LEFT JOIN guilds_has_users ON guilds_has_users.users_id = users.id
LEFT JOIN report ON report.id = authority_history.report_id
AND report.id = level_history.report_id
AND report.id = loyality_history.report_id
AND report.id = rank_history.report_id
AND report.id = tabard_history.report_id
WHERE report.date BETWEEN '2011-10-24 00:00:00' AND '2011-10-30 23:59:59'
AND guilds_has_users.active = 1
GROUP BY users.id;Explain of that select:
```
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE guilds_has_users ref fk_guilds_has_users_users1,act
Solution
You may need to try setting certain variables within your session
These particular values may be too small for your DB Connection to fulfill the query efficiently. These can be set within as follows:
Please consult the MySQL Documentation on Temp Table Usage
If you cannot set these values within your own session, contact your hosting provider to dynamically set them in your my.cnf.
Give it a Try !!!
- tmp_table_size
- max_heap_table_size
These particular values may be too small for your DB Connection to fulfill the query efficiently. These can be set within as follows:
- To see what values these settings have currently do the following:
SHOW VARIABLES LIKE 'max_heap_table_size';
SHOW VARIABLES LIKE 'tmp_table_size';
- To set max_heap_table_size to 64M do the following:
SET max_heap_table_size = 1024 1024 64;
- To set tmp_table_size to 32M do the following:
SET tmp_table_size = 1024 1024 32;
Please consult the MySQL Documentation on Temp Table Usage
If you cannot set these values within your own session, contact your hosting provider to dynamically set them in your my.cnf.
Give it a Try !!!
Context
StackExchange Database Administrators Q#7806, answer score: 23
Revisions (0)
No revisions yet.