MySQL index using notes

Source: Internet
Author: User
Tags mysql index

1. Use the Explain statement to view performance mysql> explain select product_id from Orders where order_id in (123, 312, 223,, 224) \g

2. Why create a composite index? If there is only one index, the 2 query criteria will first go to the index to query a condition, and then MySQL will go to the table on the disk to query another condition. If you have a combined index, MySQL can take 2 query conditions completely from the index, and the speed will naturally be fast.

3. The first field of the combined index must appear in the query group sentence, and the index will not be used; it doesn't matter if it appears in select rather than in where, but it has to be; the order in the where statement does not matter, because it automatically adjusts to the matching index order

4. When executing a query in MySQL, only one index can be used, and if we are building multiple indexes on the where condition, MySQL chooses the most stringent index to get the least number of result set records when executing the query.

5. When creating a multicolumn index, the most frequently used column in the WHERE clause is placed on the far left, depending on the business requirements

6. The fields in the order by must be indexed in the order of the SQL statements;

7. The sort order of the fields in the order by must remain, otherwise the index is invalid.
8. Building an index is not necessarily effective, check with the actual SQL.

Profile: http://www.cnblogs.com/sunss/archive/2010/09/14/1826112.html

MySQL index using notes

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.