Wir haben mehrere MySql-Abfragen, die gut funktionieren, wenn eine kleinere Anzahl von Datensätzen ausgewählt werden, d. H. Begrenzen 0,100.Mysql nimmt lange für größere Grenzen
Die Abfrage dauerte fast 10X bis 50X mehr Zeit, wenn wir den Grenzwert von 100 auf 1000 erhöhen, d. H. 0,1000 begrenzen.
BEARBEITET Wie können wir das optimieren? Explain Plan unten geben,
QUERY
Select
concat(floor(TIMESTAMPDIFF(MINUTE,x.msgCreatedOn, NOW())/60),':',floor(TIMESTAMPDIFF(MINUTE,x.msgCreatedOn, NOW())%60)) as aging,
x.`actionStartDate`,
concat(floor(TIMESTAMPDIFF(MINUTE,x.`actionStartDate`, NOW())/60),':',floor(TIMESTAMPDIFF(MINUTE,x.`actionStartDate`, NOW())%60)) as workflowAging
from
(
Select
*
from
t_wk_dtls d left
join t_s_dtls s on (d.id = s.`work_parentId` or d.`parentId` = s.`work_parentId`) and d.`currentlyActive` = true
left join t_w b on b.basketId=d.toBasketId
left join t_u u on d.toUserId= u.userId
left join t_s_m sch on d.sourceId=sch.schMsgId
left join t_l_s_a a on a.orgId='1002'
AND ((((a.`type`='TWITTER' and d.channel in (1,34))
or (a.`type`='FACEBOOK' and d.channel in (6,7))
or (a.`type`='GOOGLEPLUS' and d.channel in (5,25))
or (a.`type`='LINKEDIN' and d.channel =30)
or (a.`type`='GOOGLEPLUS' and d.channel=36)
or ((a.`type`='YOUTUBE' or a.`type`='GOOGLEPLUS') and d.channel=27)
or (a.`type`='TUMBLR' and d.channel in (29,31))
or (a.`type`='INSTAGRAM' and d.channel=35)) AND d.userChannelId=a.socialId) OR (a.`type`='BLOG' and d.channel in (9,11,15,21) AND d.msgId=a.socialId))
left join t_l l on l.leadId=a.leadId and l.orgId='1002'
where
d.currentlyActive = true
and d.dataSource ='SOLR'
and d.profileId = '148' AND msgCreatedOn BETWEEN '2016-03-14 18:30:00' AND '2016-03-31 18:29:59'
order by d.msgCreatedOn desc limit 0,100000) as x
Indizes ........ –
Beachten Sie, dass viel mehr Daten übertragen. – jarlh
könnten Sie die Abfrage zur Frage hinzufügen? Es könnte Cross Join oder etwas anderes sein, das die Abfrage mit höheren Limits verlangsamt. – Jester