Processing mysql subquery with the in keyword 1317 Error 1317 mysql query execution interrupted message content: query execution interrupted (database directly suspended) 1. symptom: (1) Mysql automatically suspends by using subquery statements in the PHP program, that is, the database is "stuck" and the program cannot run properly (2) execute the subquery statement in the mysql command line. Mysql needs to wait for a long time, and the following message is displayed: "Error 1317 mysql query execution interrupted" 2. there are two solutions: the number of records in the 006_kh table is 24256. The total number of records in the uzone_27020.kh table is 52327. Original SQL statement (subquery): [html] SELECT count (kh_id) FROM '006 _ kh' WHERE kh_id in (select khbh from uzone_2701_kh whe Re uzbh = '000000' and jgm = '000000') use the desc command for analysis. The result is as follows: [html] mysql> desc SELECT count (kh_id) FROM '006 _ kh' WHERE kh_id in (select khbh from uzone_2701_kh where uzbh = '000000' and jgm = '000000 '); + ---- + -------------------- + --------------- + ------- + ------------- + --------- + ------ + ------- + certificate + | id | select_type | table | type | possible_keys | key | key_len | re F | rows | Extra | + ---- + -------------------- + --------------- + ------- + ------------- + --------- + ------ + ------- + keys + | 1 | PRIMARY | 006_kh | index | NULL | PRIMARY | 4 | NULL | 89394 | Using where; using index | 2 | dependent subquery | uzone_2701_kh | ALL | NULL | 24256 | Using where | + ---- + ------------------ + --------------- + ------- + ----- ---------- + --------- + ------ + ------- + -------------------------- + 2 rows in set (0.00 sec) (1) Method 1: SQL script [html] select count (kh_id) FROM '006 _ kh' where kh_id in (select khbh from uzone_27020.kh where uzbh = '000000' and jgm = '000000') as khid_array) use the desc command for analysis, results: [html] mysql> desc select count (kh_id) FROM '006 _ kh' where kh_id in (select khbh from uzone_2 701_kh where uzbh = '000000' and jgm = '000000') as khid_array ); + ---- + keys + --------------- + ------- + ------------- + --------- + ------ + ------- + keys + | id | select_type | table | type | possible_keys | key | key_len | ref | rows | extra | + ---- + ------------------ + --------------- + ------- + --------------- + --------- + ------ + ------- + ----------------- --------- + | 1 | PRIMARY | 006_kh | index | NULL | PRIMARY | 4 | NULL | 96767 | Using where; using index | 2 | dependent subquery | <derived3> | ALL | NULL | 24099 | Using where | 3 | DERIVED | uzone_2701_kh | ALL | NULL | NULL | 24256 | Using where | + ---- + -------------------- + --------------- + ------- + --------------- + --------- + ------ + ------- ------------------- + 3 rows in set (0.02 sec) (2) Method 2: SQL Script: [html] select count (. kh_id) from 011_kh a inner join uzone_2701_kh B on. kh_id = B. khbh where B. uzbh = '000000' and B. jgm = '000000' use the desc command for analysis. The results are as follows: [html] mysql> desc select count (. kh_id) from 011_kh a inner join uzone_2701_kh B on. kh_id = B. khbh where B. uzbh = '000000' and B. jgm = '000000'; + ---- + ------------- + ------- -+ --------------- + --------- + Hour + ------- + ------------- + | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | + ---- + ------------- + ------- + -------- + --------------- + --------- + -------------------- + ------- + ------------- + | 1 | SIMPLE | B | ALL | NULL | 24256 | Using where | 1 | SIMPLE | a | eq_ref | PRIMARY | PRIMARY | 4 | keys | 1 | Using index | + ---- + ------------- + ------- + -------- + --------------- + --------- + ------------------ + ------- + ------------- + 2 rows in set (0.00 sec) my test conclusion: the query using JOIN statements is not necessarily faster than that using subqueries. Based on my own test results and DESC analysis results, the JOIN statement is faster, high efficiency. Therefore, when the in keyword is used for subqueries, the second type is strongly recommended!