以下sql语句执行时间比较长,我想可能我是的sql语句需要改进一下,请高手们指点指点,谢谢啊
SELECT s.itemid,s.`subject`,s.subjectimage,sm.price,sm.picuture_s
FROM supe_productitems s,supe_productmessage sm
where FIND_IN_SET(s.catid,getChildList('2')) and sm.itemid=s.itemid ORDER BY RAND() LIMIT 3
SELECT s.itemid,s.`subject`,s.subjectimage,sm.price,sm.picuture_s
FROM supe_productitems s,supe_productmessage sm
where FIND_IN_SET(s.catid,getChildList('2')) and sm.itemid=s.itemid ORDER BY RAND() LIMIT 3
另外你这个查询的结果不加limit的情况下一般多少记录?
-----------------
如果中间产生的符合条件的结果很多,用这个排序,将是一个大瓶颈
FIND_IN_SET(s.catid,getChildList('2')) 本身无索引可用。getChildList 这个函数是什么?效率如何?
还有就是order by rand() 也是用不上索引的导致全表扫描。
FROM supe_productitems s inner join supe_productmessage sm on sm.itemid=s.itemid
where FIND_IN_SET(s.catid,getChildList('2')) and ORDER BY RAND() LIMIT 3sm.itemid 和 s.itemid 如果不是主键的话,建上索引。
不过,这个sql的效率主要影响在 FIND_IN_SET 函数上了。