所以最初这个查询正在使8 minutes
返回1400行。我注释掉原始查询中导致滞后的部分。 EXPLAIN sql显示lien_objet_contact table
没有索引。我不能简单地创建一个索引,因为这是为了工作而需要迁移。我相信如果我可以编写带有 TXT_POSTE_CONTACT 作为子查询的查询,我可以加快速度。
以下方法的问题在于它引入了所有联系人。我只想要基于下面的 WHERE 子句的联系人。所以他们必须附加到poste.strreference
。基本上这是一个充满工作和候选人的数据库。每个工作都有一个联系人,您可以称之为招聘经理。我认为这更像是一个方法问题。我可能完全不在下面的尝试。如果是这样,我愿意接受建议。提前致谢。
SELECT DISTINCT poste.pkposte
AS
`COLONNE_NON_AFFICHEE`,
poste.strreference
AS `TXT_REFERENCE`,
lib_poste.strlangue1
AS `TXT_INTITULE`,
Group_concat(DISTINCT Concat(lib_u.strprenom, ' ',
lib_u.strnom)) AS
`TXT_POSTE_CHARGE_RECRUTEMENT`,
(SELECT Group_concat(DISTINCT Concat(lib_contact.strprenom, ' ', lib_contact.strnom))
FROM poste p
LEFT JOIN lien_objet_contact lib_loc
ON p.pkposte = lib_loc.fkobjet
LEFT JOIN contact lib_contact
ON lib_loc.fkcontact = lib_contact.pkcontact) AS `TXT_POSTE_CONTACT`,
-- Group_concat(DISTINCT Concat(lib_contact.strprenom, ' ',
-- lib_contact.strnom)) AS
-- `TXT_POSTE_CONTACT`,
lib_country.strlangue1
AS `TXT_PAYS`,
lib_state.strlangue1
AS `TXT_REGION`,
lib_city.strlangue1
AS `TXT_DEPARTEMENT_GEO`,
Concat(c.strprenom, ' ', c.strnom)
AS `Candidate`,
CASE
WHEN c.imobiliteinterne = 1 THEN "yes"
WHEN c.imobiliteinterne = 0 THEN "no"
end
AS `Internal_Candidate`,
Max(Date_format(sa_hired_date.dtdateaction, "%c/%e/%y"))
AS `TXT_EMBAUCHER`,
Date_format(hireInfo.dtdebut, "%c/%e/%y")
AS StartDate,
Source.strlangue1
AS TXT_PARTENAIRE_SOURCE
FROM poste
INNER JOIN r_texte_court lib_poste
ON poste.fklibintitule = lib_poste.pktextecourt
LEFT JOIN lien_utilisateur_objet lib_luo
ON poste.pkposte = lib_luo.fkobjet
AND lib_luo.itypeobjet = 2
LEFT JOIN utilisateur lib_u
ON lib_luo.fkutilisateur = lib_u.pkutilisateur
-- LEFT JOIN lien_objet_contact lib_loc
-- ON poste.pkposte = lib_loc.fkobjet
-- AND lib_loc.itypeobjet = 2
-- AND lib_loc.strcontexte = 'descriptif/contact'
-- LEFT JOIN contact lib_contact
-- ON lib_loc.fkcontact = lib_contact.pkcontact
LEFT JOIN affectation aff
ON aff.fkposte = poste.pkposte
AND aff.isuppr = 0
LEFT JOIN candidat c
ON c.pkcandidat = aff.fkcandidat
LEFT JOIN lien_objet_ref_1 lor1a
ON lor1a.fkobjet = poste.pkposte
AND lor1a.itypeobjet = 2
AND lor1a.strcontexte = 'descriptif/pays'
LEFT JOIN r_referentiel rr_country
ON lor1a.fkreferentiel = rr_country.pkreferentiel
LEFT JOIN r_libelle_ref lib_country
ON rr_country.fklib1 = lib_country.pklibelleref
LEFT JOIN lien_objet_ref_2 lor2a
ON lor2a.fkobjet = poste.pkposte
AND lor2a.itypeobjet = 2
AND lor2a.strcontexte = 'descriptif/region'
LEFT JOIN r_referentiel rr_state
ON lor2a.fkreferentiel = rr_state.pkreferentiel
LEFT JOIN r_libelle_ref lib_state
ON rr_state.fklib1 = lib_state.pklibelleref
LEFT JOIN lien_objet_ref_3 lor3a
ON lor3a.fkobjet = poste.pkposte
AND lor3a.itypeobjet = 2
AND lor3a.strcontexte = 'descriptif/departement_geo'
LEFT JOIN r_referentiel rr_city
ON lor3a.fkreferentiel = rr_city.pkreferentiel
LEFT JOIN r_libelle_ref lib_city
ON rr_city.fklib1 = lib_city.pklibelleref
LEFT JOIN historique_candidat sa_hired_date
ON c.pkcandidat = sa_hired_date.fkcandidat
LEFT JOIN embauche hireInfo
ON aff.pkaffectation = hireInfo.fkaffectation
INNER JOIN embauche hireInfoFilter
ON aff.pkaffectation = hireInfoFilter.fkaffectation
LEFT JOIN candidature cand
ON c.pkcandidat = cand.fkcandidat
LEFT JOIN partenaire pnaire
ON cand.fkpartenairesource = pnaire.pkpartenaire
LEFT JOIN r_texte_court Source
ON Source.pktextecourt = pnaire.fklibnom
WHERE poste.isuppr <> 1
AND poste.pkposte <> 1
AND hireInfo.iembauche = 1
GROUP BY `txt_reference`,
`pkcandidat`