[MDEV-26752] Two indexes are being created when using serial + primary key Created: 2021-10-03  Updated: 2021-10-06  Resolved: 2021-10-06

Status: Closed
Project: MariaDB Server
Component/s: Data Definition - Create Table
Affects Version/s: None
Fix Version/s: N/A

Type: Bug Priority: Minor
Reporter: s13k Assignee: Unassigned
Resolution: Not a Bug Votes: 0
Labels: None

Attachments: PNG File Screenshot 2021-10-03 at 15.02.37.png    

 Description   

When issuing a statement like this:

CREATE TABLE `db`.`table` (`id` serial, PRIMARY KEY (id));

Two indexes are being created instead of one.



 Comments   
Comment by Alice Sherepa [ 2021-10-05 ]

SERIAL is an alias for BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE, so this works as expected:

MariaDB [test]> CREATE TABLE `table` (`id` serial, PRIMARY KEY (id));
Query OK, 0 rows affected (0.052 sec)
 
MariaDB [test]> show create table `table`;
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                     |
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| table | CREATE TABLE `table` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`id`),
  UNIQUE KEY `id` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.004 sec)

Generated at Thu Feb 08 09:47:40 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.