MySQL index prefix index and index selectivity

Source: Internet
Author: User
Tags mysql index

Sometimes you need to index a long character column, which makes the index larger and slower. One strategy is to emulate a hash index. But sometimes it's not good enough, then?

You can usually index the beginning of several characters, rather than all values, to save space and get good performance. This makes the index less space required, but it also reduces selectivity. Index selectivity is the ratio of non-repeating index values to all rows in the table. A highly selective index is good because it allows MySQL to wave off more rows when looking for matches. The selection rate for a unique index is 1, which is the best value.

If you index blogs and text columns, or long varchar columns, you must define a prefix index because MySQL does not allow indexing of their full culture.

You can calculate for many different prefix lengths in the same query, choosing a good choice. "Linux commune http://www.linuxidc.com"

(with left function, left (city,4))

Add prefix Index

Mysql>alter table Test.test add key (city (7));

The prefix index is a good way to reduce the size and speed of the index, but MySQL cannot use the prefix index in the order by and group by queries, nor do they use the index to overwrite them.

Sometimes a suffix index can be useful, for example, to find all e-mail addresses for a domain name. MySQL does not support reverse indexing, but it can save the inverse string and index its prefix. This index can be maintained with triggers.

MySQL index prefix index and index selectivity

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.