Database Structure Design and how to maximize the use of indexes and database Indexes

Source: Internet
Author: User

Database Structure Design and how to maximize the use of indexes and database Indexes

For example, a message table

The structure is as follows: Id (auto-incrementing primary key) Content (Content) UserId (speaker Id) IsWonderful (whether it is a brilliant speech) Top (whether it is set to the Top) IsBarrage (whether it is a bullet screen)

When the table data in this structure is small, it is faster to set the top comments and bullet screens for frequent speeches.

However, when there are more than 0.3 million data records, you can find the data.

Find frequently spoken items in pieces of data

Time: 4.753 seconds

Although the data can be searched for 0.1 seconds after the index is added, the write speed of each index is slowed down. After the index is set to the top of the screen, it is not necessary to add the index. writing is very slow, especially in this case. when tables are frequently written, the design of this table is very problematic.

In this case, when creating a table, the structure is

Id Primary Key

Type 1-brilliant speech 2-top, 3-bullet Screen

ChatMessageId: Id of the message table

 

Next it's time to verify with facts.

Next let's take a look at the analysis

Perfect use of existing primary key indexes

 

It took only 0.0001 seconds to find the frequently spoken data in pieces of data, and no new indexes were added. How can I see this?

Do not add new indexes when designing databases in the future (unless there are few writes or changes). Try to use the built-in primary key 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.