MySQL uses limit 1 to improve query efficiency

Source: Internet
Author: User
Tags timestamp to date mysql index

In the process of web development with a large amount of data, you must carefully think about whether there is a better way to improve the efficiency of program execution. Next we will share a method that is frequently used but easily overlooked in actual work to optimize MySQL query efficiency and use limit 1 rationally.

Currently, there is a table (User table) as follows ):

create table member( id int primary key auto_increment, username varchar(40), password varchar(40) );

The login operations in development are often written as follows:

SELECT * FROM member WHERE `username`='www.phpernote.com';

Or:

SELECT * FROM member WHERE `username`='www.phpernote.com' LIMIT 1;

These two query methods are common, but do you know their actual differences? The results obtained from the author's test with 1 million pieces of data:

The first query statement takes 0.56 s

The second query statement that uses LIMIT 1 takes 0.28 s

It can be seen from the above that in the case of a large amount of data, the appropriate use of LIMIT 1 to optimize the query operation is quite obvious.

Note: If the username in the preceding table fields is set as an index, LIMIT 1 does not have a significant effect on the query speed.

Articles you may be interested in
  • Improves the query speed of millions of data records for MySQL
  • MySQL limit Query Optimization
  • Mysql converts unix timestamp to date format, and MySQL queries the current time
  • Summary of the causes and solutions for slow mysql Server Query
  • MySQL index Operation Command (create index, re-index, query index, delete index) Summary
  • How to query data of mysql today, yesterday, last 7 days, last 30 days, last month, and last month
  • 30 methods for optimizing SQL statement query in mysql
  • Navicat for mysql remote connection to the mySql database prompt 10061,1045 error Solution

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.