Php+mysql Query Optimization Simple instance _php tutorial

Source: Internet
Author: User
Tags mysql query mysql query optimization

Php+mysql Query Optimization Simple instance


This article mainly introduces the simple example of Php+mysql query optimization, analyzes the techniques of SQL statement optimization query in Php+mysql program design, and has some reference value for improving the query efficiency, the friends who need can refer to

In this paper, the method of Php+mysql query optimization is analyzed. Share to everyone for your reference. The specific analysis is as follows:

Php+mysql is one of the most frequently used gold partners, both of which are used to perform the best performance and, of course, even more perfect if used with Apache.

Therefore, you need to do a good job of MySQL query optimization, following a simple example, to show the impact of different SQL statements on query speed.

There is a table test that has a self-increment ID as the primary index, and now you want to query the record with the ID number in a range, you can use the following SQL statement:

The code is as follows:

SELECT *
From ' Test '
ORDER BY ID ASC
Limit 208888,50


This SQL statement means that the record from the ID number 208888 starts to fetch 50 records, test in a database of 300,000 records, when the primary index has been established, the time to execute this statement is 40-50 seconds, then there is no faster SQL statement to execute it? Obviously, look at the following SQL statement:

The code is as follows:

SELECT *
From ' Test '
WHERE ID
Between 208838
and 208888


This statement uses a condition to filter, and the actual test execution time is approximately 0.06 seconds.

The reason is because although the id attribute is already indexed, but the order is still a very expensive operation, to use caution, and the second statement, you can let MySQL make full use of the database has been established B + Tree index, so the search speed is very fast, is hundreds of times times the original.

This shows that the site developers in the use of SQL statements, must be cautious, because a careless SQL statement, may make your website access speed down sharply, the background database is under great pressure, and quickly into the predicament of unable to open the page.

It is hoped that this article is helpful to everyone's php+mysql program design.

http://www.bkjia.com/PHPjc/971925.html www.bkjia.com true http://www.bkjia.com/PHPjc/971925.html techarticle Php+mysql Simple example of query optimization This article mainly introduces the simple example of Php+mysql query optimization, analyzes the techniques of SQL statement optimization query in Php+mysql program design, and improves the query ...

  • 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.