MySQL incorrect key file for tmp table when making multiple joins

后端 未结 11 1269
轻奢々
轻奢々 2020-11-27 17:01

I don\'t come here for help often but I am pretty frustrated by this and I am hoping someone has encountered it before.

Whenever I try to fetch records from a table

11条回答
  •  青春惊慌失措
    2020-11-27 17:30

    I had this problem with a query on a table that had 500K+ records. It was giving me the same exact type of error, pointing to a .MYI file in the /tmp directory that was rarely there upon checking. I had already increased the heap and temp file sizes in the /etc/my.cnf file.

    The problem with the query was the it did indeed contain a ORDER clause at the end, omitting it made the query work without error. It also had a LIMIT. I was trying to look at the most recent 5 records in the table. With the ORDER clause included it choked and gave the error.

    What was happening was the mysqld was creating an internal temp table with ALL the records from the giant table to apply the ORDER.

    The way that I got around this is to apply an additional WHERE condition, limiting the records from the giant table to some smaller set. I conveniently had a datetime field to do the filtering from.

    I hope that helps someone.

提交回复
热议问题