以下SQL语句执行正确,但是效率上让我有点担心。我想请教,这样的一条SQL语句能不能承受得了1万以内的数据啊。O(∩_∩)O哈哈~。郁闷呢。SELECT items.id AS id, items.typeid AS tid, items.title AS title, trip.days AS days, trip.price AS price, trip.ctdate AS ctdate, trip.zctdate AS zctdate, enum.ename AS departussre, denum.ename AS destinaddtion
FROM tp_archives AS items
LEFT JOIN tp_addontrip AS trip ON trip.aid = items.id
LEFT JOIN tp_sys_enum AS enum ON trip.departure = enum.evalue
AND enum.egroup = "departure"
LEFT JOIN tp_sys_enum AS denum ON trip.destination = denum.evalue
AND denum.egroup = "destination"
LIMIT 0 , 30
FROM tp_archives AS items
LEFT JOIN tp_addontrip AS trip ON trip.aid = items.id
LEFT JOIN tp_sys_enum AS enum ON trip.departure = enum.evalue
AND enum.egroup = "departure"
LEFT JOIN tp_sys_enum AS denum ON trip.destination = denum.evalue
AND denum.egroup = "destination"
LIMIT 0 , 30
EXPLAIN 你的 SQL 指令从结果中可以看出你的 SQL 指令是否可以优化
FROM tp_archives AS items
LEFT JOIN tp_addontrip AS trip ON trip.aid = items.id
LEFT JOIN tp_sys_enum AS enum ON trip.departure = enum.evalue
WHERE enum.egroup = "departure" or enum.egroup = "destination"
LIMIT 0 , 30实际执行一下吧。主要还得看各表数据在大小,索引是怎么建的
2、分别在别名为 items、enum、denum 的连接键上做索引
边做边测,直到 type 列没有或最后一个是 all 为止