Mysql Query Optimization Index application of the detailed _mysql

Source: Internet
Author: User

Poor SQL query statements can have a serious impact on the operation of the entire application, not only consuming more database time, but also impacting other application components.

As with other disciplines, optimizing query performance largely depends on the developer's intuition. Fortunately, databases like MySQL have a few help tools on their own. This article briefly discusses the three kinds of tools: Using indexes, using explain to analyze queries, and adjusting the internal configuration of MySQL.

MySQL allows you to index database tables so that you can quickly find records without having to scan the entire table in the first place, thereby dramatically speeding up the query. Each table can have up to 16 indexes, and MySQL also supports multiple-column indexes and Full-text searches.

Adding an index to a table is very simple, just call a CREATE INDEX command and specify its domain for the index.
List A gives an example:

Copy Code code as follows:

Mysql> CREATE INDEX idx_username on users (username);

Here, the username domain of the users table is indexed to make sure that the SELECT query statement referencing this field in the WHERE or HAVING clause runs faster than if no index was added. The show index command lets you see that the index has been created (List B).

It's worth noting that the index is like a double-edged sword. Indexing each field in a table is often unnecessary and is likely to slow down because MySQL has to index the extra work each time it inserts or modifies data into the table. On the other hand, it is also not a good idea to avoid indexing each field in a table, because the query operation slows down when you increase the speed at which you insert records. This requires finding a balance, for example, when designing an indexing system, it is a wise choice to consider the main function of the table (data repair and editing).

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.