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