MySQL uses limit 1 to improve sql query efficiency

In the process of web development with a large amount of data, in any step of program development, it is necessary to seriously consider whether there is a better way to improve the execution efficiency of the program. Let's share a method for optimizing the efficiency of mysql

query that is often used in practical work but is easily overlooked , and use limit 1 reasonably. Currently there is the following table (user table): create table member( id int primary key auto_increment, username varchar(40), password varchar(40) ); Our login operations in development are often written like this: SELECT * FROM member WHERE `username`='www.kubiji.cn'; or: SELECT * FROM member WHERE `username`='www.kubiji.cn' LIMIT 1; These two query methods are very common, but do you know the actual difference between them ? The author tested 1 million pieces of data and obtained the result: the first query statement took 0.56 s , and the second query statement after using LIMIT 1 took 0.28 s . It can be seen from the above that in the case of a large amount of data, appropriate The optimization effect of using LIMIT 1 on query operations is quite obvious. Note: If the username in the above table field is set as an index, using LIMIT 1 at this time has no obvious effect on the query speed.




























Go to: http://www.kubiji.cn/topic-id755.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326430921&siteId=291194637