MySQL Query Optimization-index application details

Source: Internet
Author: User
Tags mysql query optimization

Bad SQL query statements can have a serious impact on the operation of the entire application. They not only consume more database time, but also affect other application components.

Like other disciplines, optimizing query performance is largely dependent on developers' intuition. Fortunately, databases like MySQL come with some assistance tools. This article briefly discusses the three tools: Using indexes, analyzing queries using EXPLAIN, and adjusting the internal configuration of MySQL.

MySQL allows you to index database tables so that you can quickly search for records without scanning the entire table at the beginning, which significantly speeds up query. Each table can have up to 16 indexes. In addition, MySQL also supports multiple column indexes and full-text searches.

It is very easy to add an INDEX to a table. You only need to call the create index Command and specify its fields for the INDEX.
List A provides an example:
Copy codeThe Code is as follows:
Mysql> create index idx_username ON users (username );

Here, the username field of the users table is indexed to ensure that the SELECT query statements that reference this field in the WHERE or HAVING clause run faster than those that do not have an index added. You can run the show index Command to check whether the INDEX has been created (List B ).

It is worth noting that:Indexing is like a double-edged sword. Indexing each field of a table is usually unnecessary and may slow down the operation because MySQL has to re-create indexes for these additional tasks every time it inserts or modifies data in the table. On the other hand, it is not a good idea to avoid indexing each field of a table, because the query operation slows down when the record insertion speed is increased. This requires a balance. For example, when designing an index system, it is wise to consider the table's main functions (data repair and editing.

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.