这里的第一个计时器。我有一个MySQL查询,只要它是两个表,就会在6秒内运行。
sitedata is 4000 records, 10 fields.
clientdata is 2000 records, 8 fields.
下面的查询在6秒内运行通过添加第三个表,我得到400秒。
该表是可整合的,400条记录,12个字段。
任何建议都将不胜感激。
SELECT sitedata.geozone AS geo, sitedata.week AS schweek, sitedata.PMcycle AS cycle,
sitedata.sitenotes1 AS sitenotes1, sitedata.sitenotes2 AS sitenotes2, sitedata.sitezip AS sitezip,
sitedata.sitecity AS sitecity, sitedata.sitestate AS sitestate,
sitedata.siteaddress AS siteaddress, sitedata.clientsite1 AS ClientSite,
clientdata.prefix AS prefix,
consolidatortable.calldate AS indate, consolidatortable.duedate AS promisedate,
consolidatortable.nte AS callnte,
consolidatortable.description AS calldescription,
consolidatortable.tracking AS POnumber
FROM ((sitedata INNER JOIN
clientdata
ON sitedata.clientname = clientdata.clientname COLLATE utf8_unicode_ci
) INNER JOIN
consolidatortable
ON sitedata.portalname1 = consolidatortable.site COLLATE utf8_unicode_ci);
答案 0 :(得分:0)
首先,学习更简单地编写查询:
SELECT sd.geozone AS geo, sd.week AS schweek, sd.PMcycle AS cycle,
sd.sitenotes1 AS sitenotes1, sd.sitenotes2 AS sitenotes2, sd.sitezip AS sitezip,
sd.sitecity AS sitecity, sd.sitestate AS sitestate,
sd.siteaddress AS siteaddress, sd.clientsite1 AS ClientSite,
cd.prefix AS prefix,
ct.calldate AS indate, ct.duedate AS promisedate,
ct.nte AS callnte,
ct.description AS calldescription,
ct.tracking AS POnumber
FROM sitedata sd INNER JOIN
clientdata cd
ON sd.clientname = cd.clientname COLLATE utf8_unicode_ci INNER JOIN
consolidatortable ct
ON sd.portalname1 = ct.site COLLATE utf8_unicode_ci;
FROM
子句建议您在clientdata(clientname)
和consolidatortable(site)
上设置索引。
但是,COLLATE
可能会排除使用任何索引。这可能是导致性能问题的根本原因。我建议您修复表,以便它们都使用相同的排序规则。然后从查询中删除COLLATE
。