I don’t often come here for help, but I’m very upset about this, and I hope someone has come across it before.
Whenever I try to retrieve records from a table using more than one join, I get this error:
#126 - Incorrect key file for table '/tmp/#sql_64d_0.MYI'; try to repair it
Thus, this query will result in an error:
SELECT * FROM `core_username` INNER JOIN `core_person` ON (`core_username`.`person_id` = `core_person`.`id`) INNER JOIN `core_site` ON (`core_username`.`site_id` = `core_site`.`id`) ORDER BY `core_username`.`name` ASC LIMIT 1
But this will not be:
SELECT * FROM `core_username` INNER JOIN `core_person` ON (`core_username`.`person_id` = `core_person`.`id`) ORDER BY `core_username`.`name` ASC LIMIT 1
And this will not be:
SELECT * FROM `core_username` INNER JOIN `core_site` ON (`core_username`.`site_id` = `core_site`.`id`) ORDER BY `core_username`.`name` ASC LIMIT 1
What could be the reason for this? I really don't know how to repair a tmp table, but I really don't think the problem is that it is a new tmp table every time. The username table is quite large (233,718 entries right now), but I doubt this has anything to do with it.
Any help would be greatly appreciated.
UPDATE After some additional testing, it seems that the error only occurs when trying to streamline the results. That is, this query will give me what I expect:
SELECT * FROM `core_username` INNER JOIN `core_person` ON (`core_username`.`person_id` = `core_person`.`id`) INNER JOIN `core_site` ON (`core_username`.`site_id` = `core_site`.`id`) LIMIT 1
But if I add:
ORDER BY `core_username`.`name` ASC
The error is triggered. This only happens on the specific web server that I am currently using. If I load the database and try the same on my localhost as well as on other servers, it works fine. MySQL Version 5.0.77.
Knowing this, I'm pretty sure that the tmp table being created is too large, and MySQL is throttling as described in this blog post . I'm still not sure what the solution will be, though ...