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!
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.
It must be redundant, and using uuid as the primary key is also a pitfall. This is self-developed, right?
It’s not very good. It’s best not to use this method if you can.