我有一个大查询(MYSQL)来连接几个表:
SELECT * FROM
`AuthLogTable`,
`AppTable`,
`Company`,
`LicenseUserTable`,
`LicenseTable`,
`LicenseUserPool`,
`PoolTable`
WHERE
`LicenseUserPool`.`UserID`=`LicenseUserTable`.`UserID` and
`LicenseUserTable`.`License`=`LicenseTable`.`License` and
LEFT(RIGHT(`AuthLogTable`.`User`, 17), 16)=`LicenseUserPool`.`UserID` and
`LicenseUserPool`.`PoolID`=`PoolTable`.`id` and
`Company`.`id`=`LicenseTable`.`CompanyID` and
`AuthLogTable`.`License` = `LicenseTable`.`License` and
`AppTable`.`AppID` = `AuthLogTable`.`AppID` AND
`PoolTable`.`id` IN (-1,1,2,4,15,16,17,5,18,19,43,20,3,6,8,10,29,30,7,11,12,24,25,26,27,28,21,23,22,31,32,33,34,35,36,37,38,39,40,41,42,-1)
ORDER BY
`AuthLogTable`.`AuthDate` DESC,
`AuthLogTable`.`AuthTime` DESC
LIMIT 0,20
我使用explain,它给出了以下内容:
如何使它更快?在一张大桌子上要花几秒钟。
“显示第0-19行(共20行,查询用时3.5825秒)”
据我所知,查询中使用的字段在每个表中都有索引。
为AuthLogTable设置了索引
您可以尝试在数据上不使用“ order by”子句的情况下运行此查询,以查看它是否有所不同(也可以运行“ explain”)。如果是这样,您可以考虑在排序依据的字段上添加索引。Using temporary; using filesort;
表示创建临时表然后对其进行排序,而无需花费时间的索引。
据我所知,联接样式没有任何区别,因为无论如何查询都被解析为另一种形式。但是您仍然可能要使用ANSI连接语法(另请参见ANSI连接与“ where子句” join的问题)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句