开发者

Can this SQL query be made to run any faster?

I'm using mySQL InnoDB tables. The query is simple but it just takes too long to run. Its bound to run even slower once I upload it to a server (not to mention that these two tables 开发者_JAVA百科will keep growing in size).

The 'author' table size is 3,045 records. The 'book' table size is 5,278 records.

SELECT author.*, count( auth_id ) AS author_count
FROM author
LEFT JOIN book ON author.id = book.auth_id
GROUP BY author.id

I'm wondering if there is some trick I can employ to make the query run at least twice as fast as it is now (it currently takes about 10.5 seconds to run - an eternity when displaying web content!)


1) Is this returning what you want?

2) You should list in the GROUP BY clause all the fields from the SELECT clause that are not in an agregate function (like COUNT in this case, but also could be AVG or SUM).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜