A simple query method for MySQL database

Source: Internet
Author: User

Create a data table of this structure and insert 1.1 million random records for query performance testing.

After inserting 1.1 million random records, the size of the datasheet is 102MB.

Now use phpMyAdmin's own SQL query to perform profiling.

The following is a query test with indexed mode:

A. Random character field full-match query, spents 0.0005 (S)

B. Random primary key query, spents 0.0005 (S)

C. Random use of character function queries, spents 0.4482 (S)

D. Use like mode one query, spents 0.0007 (S)

E. Using the like mode two query, spents 0.7361 (S)

The following is a test that deletes an index:

A. Random character field full-match query, spents 0.3439 (S)

B. Random primary key query, spents 0.0004 (S)

C. Random use of character function queries, spents 0.4882 (S)

D. Use like mode one query, spents 0.3487 (S)

E. Using the like mode two query, spents 0.7339 (S)

Conclusion:

In the case of a simple query on a field, if the field is indexed, the query speed is much faster than if no index was built. Queries that use the MySQL function still have the same speed as if they were indexed. When using the like xxx% mode, the index is much faster than the index, but the%xxx% mode is indexed and not indexed.

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.