Incorrect key file for table '/tmp/#sql_18b4_0.MYI'; try to repair it

匿名 (未验证) 提交于 2019-12-03 02:33:02

问题:

I got a query from our developers that is not executing on server and giving below error-

Incorrect key file for table '/tmp/#sql_18b4_0.MYI'; try to repair it 

I have checked all tables individually and their index, everything seems file. Even I have checked all these tables in some other query join which is fetching more data than this query and working fine.

Even these tables hardly keep less than 1000 records per table.

Query is:

SELECT `PsMasterSubject`.`id`, `PsMasterSubject`.`name`, `PsProgram`.`name`, `PsStreamLevel`.`id`  FROM `misdb`.`ps_master_subjects` AS `PsMasterSubject`  LEFT JOIN `misdb`.`ps_programs` AS `PsProgram` ON (`PsMasterSubject`.`ps_program_id` = `PsProgram`.`id`)  LEFT JOIN `misdb`.`ps_stream_levels` AS `PsStreamLevel` ON (`PsStreamLevel`.`id` AND `PsProgram`.`ps_stream_level_id`)  LEFT JOIN `misdb`.`ps_program_levels` AS `PsProgramLevel` ON (`PsProgramLevel`.`id` AND `PsStreamLevel`.`ps_program_level_id`)  WHERE 1 = 1  ORDER BY `PsMasterSubject`.`id` DESC LIMIT 10; 

I am getting some issues same like this but I have checked that my table is not currupt.

Any quick help will be highly appreciated.

回答1:

Oh shit this was a silly mistake from my developer end, After 30 minutes brain storming to design this query in different way I got this issue that developer was using join in wrong way, due to this mysql was not able to proper join tables data and consuming all space in /tmp directory and throwing this error. Correct query is here-

SELECT `PsMasterSubject`.`id`, `PsMasterSubject`.`name`, `PsProgram`.`name`, `PsStreamLevel`.`id`  FROM `misdb`.`ps_master_subjects` AS `PsMasterSubject`  LEFT JOIN `misdb`.`ps_programs` AS `PsProgram` ON (`PsMasterSubject`.`ps_program_id` = `PsProgram`.`id`)  LEFT JOIN `misdb`.`ps_stream_levels` AS `PsStreamLevel` ON (`PsStreamLevel`.`id` = `PsProgram`.`ps_stream_level_id`)  LEFT JOIN `misdb`.`ps_program_levels` AS `PsProgramLevel` ON (`PsProgramLevel`.`id` = `PsStreamLevel`.`ps_program_level_id`)  WHERE 1 = 1  ORDER BY `PsMasterSubject`.`id` DESC LIMIT 10; 

Now question is here that is this a mysql bug as mysql should throw wrong syntax error but here mysql is trying to create a temporary table for temp data.

I will be very thankful if anyone can clear this to me.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!