开发者

Is it the same efficiency when I am using LIMIT clause in millions records and thousands records in MySQL?

开发者 https://www.devze.com 2023-02-14 22:01 出处:网络
E.g: I am going to using JQuery ui autocomplet plugin.The suggestionsdata should be extracted from MySQL databse,and my sql query is:

E.g:

I am going to using JQuery ui autocomplet plugin.The suggestions data should be extracted from MySQL databse,and my sql query is:

SELECT `keywords`,`record_count`  FROM `suggestion_words`WHERE `keywords` LIKE '%'.$suggestio开发者_运维百科ns .'%' ORDER BY `search_count` LIMIT 0,10

As every one said,the LIKE is more slower.So,I just wonder,if I only return 10 records at every query,should it be the same efficiency in millions records and thousands records!?

Thank you very much!!


No, MySql will still need to scan the entire table, so the more rows it needs to scan, the more time it will take.

Becouse MySql will only stop the sorting as soon as it finds 10 rows, if you only need 10 random records, you should think about doing the sorting in a outer subquery, so MySql can stop looking once 10 rows are found.

Read http://dev.mysql.com/doc/refman/5.0/en/limit-optimization.html

0

精彩评论

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