我的查询需要10秒以上, 最庞大的表是requetes,其中的子句取决于filter:
SELECT SQL_CALC_FOUND_ROWS
requetes.id AS thread_id,
requetes.id AS thread_id2,
CONCAT_WS("/", SUBSTR(requetes.id, 5, 2), SUBSTR(requetes.id, 3, 2), SUBSTR(requetes.id, 1, 2)) AS thread_create_date,
DATE_FORMAT(create_date, "%d/%m/%Y %H:%i") AS create_date,
IF(UNIX_TIMESTAMP(requetes.date_objectif_requete) = 0, NULL, DATE_FORMAT(requetes.date_objectif_requete, "%d/%m/%Y %H:%i:%S")) AS thread_target_date,
IF(UNIX_TIMESTAMP(requetes.date_objectif_requete) = 0, NULL, DATE_FORMAT(requetes.date_objectif_requete, "%Y%m%d")) AS int_thread_target_date,
requetes.prenom AS customer_first_name,
requetes.nom AS customer_last_name,
requetes.subject AS subject_action,
requetes.ident_e AS code_customer,
CONCAT_WS(" ", UPPER(requetes.nom), requetes.prenom, requetes.pseudo) AS complete_customer_name,
requetes.type_rs AS type_rs,
themes_sous.id AS thread_type_id,
requetes.cp AS zip_code,
requetes.libelle_pc_origine AS libelle_pc_origine,
themes_sous.libelle AS thread_type_label,
themes_sous.action_page AS thread_type_target_url,
agents.prenom AS user_first_name,
agents.nom AS user_last_name,
req_agent.id_agent AS code_user,
CONCAT_WS(" ", UPPER(agents.nom), agents.prenom) AS complete_user_name,
(1 - statut_inverse) AS done,
archive AS archived,
num_messages,
themes.libelle AS libelle_categ
FROM requetes
LEFT OUTER JOIN themes_sous
ON requetes.id_ss_theme = themes_sous.id
LEFT OUTER JOIN req_agent
ON requetes.id = req_agent.id_requete
LEFT OUTER JOIN agents
ON req_agent.id_agent = agents.id
LEFT OUTER JOIN themes
ON themes.id = themes_sous.id_theme
WHERE requetes.client_identifier=4
AND themes_sous.client_identifier=4
AND requetes.statut_inverse = 1 AND DATE_FORMAT(requetes.date_objectif_requete, "%Y%m%d") <> 20171215 AND NOT (DATE_FORMAT(requetes.date_objectif_requete, "%Y%m%d") > 20171215) AND ( req_agent.id_agent_origine = "5087050" ) AND requetes.date_objectif_requete IS NOT NULL AND requetes.date_objectif_requete <> "0000-00-00 00:00:00"
ORDER BY requetes.id LIMIT 0, 25;
此查询的解释是: explain of the query
config of the most bulky table
感谢您的帮助