IPB

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> [mysql]避免使用count()语法, 加快查询速度
猫猫草
post 2018-03-21 15:16:17, Wed
Post #1


猫猫猫
***

Group: Power Cat
Posts: 626
Joined: 2006-12-8
Member No.: 2



查询时使用 count() 函数,操作上会将所有匹配的行读取一遍,而且与原本的结果集不能同时输出

改用 SQL_CALC_FOUND_ROWS 配合 FOUND_ROWS() 函数会快得多

举例
代码
SELECT * FROM T1 WHERE C1='V1' LIMIT 10;
SELECT COUNT(*) FROM T1 WHERE C1='V1';


改为
代码
SELECT SQL_CALC_FOUND_ROWS * FROM T1 WHERE C1='V1' LIMIT 10;
SELECT FOUND_ROWS();
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



Lo-Fi Version Time is now: 2024-10-31 19:35