The design of database structure and how to make maximum use of index

Source: Internet
Author: User

For example, a list of messages

Structure such as the Id (self-increment primary key) content UserId (speaker Id) iswonderful (whether it is a good speech) Top (whether it is pinned) isbarrage (whether it is a barrage)

When the table data of this structure is still young learn to speak on the top of the speaker and the barrage speed faster

But when data is more than 30多万条, finding data

Find frequent speeches in 37w data

spents 4.753 seconds

Although the index can be found after 0.1 seconds to find the data, but each additional index write speed slowed down a little behind, and also to find the top of the screen is not to be indexed so write very slow especially when the table is frequently written, it is more important that the design of this table has a lot of problems

At this time in the construction of a table structure is

ID PRIMARY Key

Type 1-Wonderful speeches 2-top, 3-barrage

Chatmessageid Message table ID

And then it's time to prove it.

Next we look at the analysis

The perfect use of the existing primary key index

It took only 0.0001 seconds to find regular speeches in 37w data, and no new indexes were added. How do you see this is thoughtful?

When you design your database later, don't think about adding new indexes (unless you write and change very rarely) try to take advantage of your own primary key index

The design of database structure and how to make maximum use of 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.