When mysql data tables are many-to-many relationships, will it be faster to add an’ id’ primary key to the intermediate table than not to add a primary key?

  mysql, question

For example, the commodity table and the attribute table have a commodity attribute intermediate table because of the many-to-many relationship.
CREATE TABLE IF NOT EXISTSdslxs_goods_attr(
goods_idMedical (8) unsigned not null comment ‘id of commodity’,
attr_idMediumint (8) unsigned not null comment ‘id of attribute’,
Keygoods_id(goods_id),
Keyattr_id(attr_id)
) engine = innodb defaultcharset = utf8comment =’ intermediate table of commodity attributes’;
If you add one to this tableIdMedical (8) unsigned not null auto _ increment and set to PRIMARY KEY (Id)。 This will not be quick, there is no big data can not be tested, which experienced please let me know. .

The so-called KEY is only an alias of the index, and the index is the key to improve the query speed of your mapping table, and you have already set the index of these two words. What may need to be done now is to add a foreign key to improve the stability of the table and the entire database, and so on. Adding a unique key will slightly increase the insertion burden, and there will definitely be no queries based on this unique key, and there may be deletions based on this key (the possibility is very small, if it is necessary to speed up, add a joint index of the two, the insertion will be slower, and the index file will become larger).

This is roughly the case. To jump out of the misconception that all tables require a unique increment key.