I had a similar situation where I was trying to figure out if I just needed to have TEXT
or BLOB
in the table for a forced temporary table on disk, when MySQL should create a temporary table or that it is also based on whether this column is in the query ( SELECT
or WHERE
).
It was a request ( posts.body
is of type TEXT
)
SELECT * FROM posts p LEFT JOIN user u ON p.user_id = u.id LEFT JOIN setting s ON u.id = s.user_id WHERE (p.title LIKE '%search%' AND (p.status = 'PUBLISH' AND p.date <= 1368441957)) GROUP BY u.id LIMIT 5
I saw that doing this increases the value of the Created_tmp_disk_tables
variable. So I changed the request to
SELECT p.id FROM posts p LEFT JOIN user u ON p.user_id = u.id LEFT JOIN setting s ON u.id = s.user_id WHERE (p.title LIKE '%search%' AND (p.status = 'PUBLISH' AND p.date <= 1368441957)) GROUP BY u.id LIMIT 5
And it is interesting that the counter has not increased. However, the following is mentioned in the MySQL documentation, which is different from my output.
Some conditions do not allow the use of a temporary table in memory, in which case the server uses the table on disk:
The presence of a BLOB or TEXT column in the table
...
source share