search

Home  >  Q&A  >  body text

MYSQL creates a unique index on the primary key

I just came to work in this company. I checked their database and found that they actually created a unique index on the primary key. What is going on? Is it a clever way of writing or a very rubbish way of writing? I feel very sad. baffling?

I looked at it and found that many watches are like this

CREATE TABLE `tbl_nvhl_order` (
  `UUID` varchar(32) NOT NULL COMMENT '订单号。',
  `CHANNEL_ORDER_ID` varchar(50) DEFAULT '' COMMENT '渠道订单号',
  
   ...

  `ISGROUP` varchar(10) DEFAULT NULL COMMENT '团单标识',
  PRIMARY KEY (`UUID`),
  UNIQUE KEY `PK_TBL_NVHL_ORDER` (`UUID`) USING BTREE,
  KEY `index_name` (`CHANNEL_ORDER_ID`,`SOURCE`) USING BTREE,
  KEY `idx_creator` (`CREATOR`) USING BTREE,
  KEY `productcode` (`PRODUCTCODE`),
  KEY `index_app_id` (`APP_ID`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=''

in

PRIMARY KEY (`UUID`),
UNIQUE KEY `PK_TBL_NVHL_ORDER` (`UUID`) USING BTREE,

Seek the guidance of the great God!

学习ing学习ing2735 days ago1135

reply all(3)I'll reply

  • 过去多啦不再A梦

    过去多啦不再A梦2017-06-30 09:57:11

    It’s definitely the latter.

    High-performance mysql specifically points out this situation, which is a duplicate index. When performing an update operation, two indexes need to be maintained, which increases the performance overhead.

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-06-30 09:57:11

    It must be redundant, and using uuid as the primary key is also a pitfall. This is self-developed, right?

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-06-30 09:57:11

    It’s not very good. It’s best not to use this method if you can.

    reply
    0
  • Cancelreply