Application of MySQL prefix index

Source: Internet
Author: User

In MySQL, sometimes the columns that need to be indexed are very long, and if you apply the index directly it can cause problems with indexing too large. So we can take some of the fields to do the indexing, for example:

Add index: ALTER TABLE * Add key (field (3)); field index fields, number of 3 index characters

But how do we determine how long the number of characters to take the most reasonable index length:

By: Select count (Field)/count (*) from table, statement gets selection rate,

Then: SELECT COUNT (distinct left (field, N))/count (*) from table

Use this statement to fit the most reasonable n.

Application of MySQL prefix index

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.