How should I create an index for this table?

Source: Internet
Author: User
How should I create an index for this table?
-- TABLE structure 'group _ member' -- create table 'group _ member' ('Member _ id' int (10) unsigned not null auto_increment COMMENT 'Member ID ', 'group _ id' int (10) unsigned not null comment 'group ID', 'Add _ time' int (10) unsigned not null comment' add time ', primary key ('Member _ id') ENGINE = MyISAM default charset = gbk AUTO_INCREMENT = 1; -- export the table data 'group _ member '--


This is a group member table with unique members and groups.
The frequently-involved query requirement is to query all users in the group by group id.

You need to create a unique index for the group id and member id, or check the index in the add interface; do not create this index.
The index will result in a waste of data, which slows down the update and deletion rate, but there are not many queries between the two. the function of creating this composite index is only to ensure the correctness of the data.

You can use the leftmost prefix for a composite index. it is still necessary to create an index for the group_id. After a composite index is created, you can still use group_id in front of it.

It would be better to build it. thank you for giving me more advice ..


Reply to discussion (solution)

The frequently-involved query requirement is to query all users in the group by group id.
Create an index on group_id

Agree to the upstairs, one of the index creation rules: the index should be built on a highly selective field

Reference http://wenku.baidu.com/view/b67041ef172ded630b1cb6b9.html for details

Memberid is the primary key. it is good to create a group as the index ~

Memberid is the primary key. it is good to create a group as the index ~

It seems that I want to save the unique index and can only query it once on the interface.

After you set up a group as an index, the effect is as follows: "The function of creating this composite index is only to ensure data correctness .", Because the primary key id is associated with the 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.