下面这一段sql代码运行超时优化一下:SELECT infoInfoId infoInfoTypeId AS Title AS Summary AS Image AS Source AS Tags infoUpdateTime infoWeight AS Content infoEnabled infoaddTime infobLocked infoUser
可以尝试以下优化:
-
添加索引:在info表的Enabled字段和infotype表的SiteId字段上添加索引,可以提高查询效率。
-
对查询字段进行优化:将查询字段中的空字符串替换为NULL,可以节省一定的存储空间和查询时间。
修改后的代码如下:
SELECT info.InfoId, info.InfoTypeId, NULL AS Title, NULL AS Summary, NULL AS Image, NULL AS Source, NULL AS Tags, info.UpdateTime, info.Weight, NULL AS Content, info.Enabled, info.addTime, info.bLocked, info.UserId FROM info LEFT OUTER JOIN infotype ON info.InfoTypeId = infotype.InfoTypeId WHERE info.Enabled = 0 AND infotype.SiteId = 9 ORDER BY info.InfoId LIMIT 0,10000
原文地址: http://www.cveoy.top/t/topic/disl 著作权归作者所有。请勿转载和采集!