[MDEV-22868] DESC Table incorrectly shows some unique keys as primary. Created: 2020-06-10  Updated: 2020-08-25  Resolved: 2020-06-15

Status: Closed
Project: MariaDB Server
Component/s: Storage Engine - InnoDB
Affects Version/s: 10.4.8
Fix Version/s: N/A

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

CentOS 7



 Description   

MariaDB [test]> CREATE TABLE `B2C_S_USER` (
    ->   `ROW_ID` varchar(15) NOT NULL,
    ->   `LOGIN` varchar(50) NOT NULL,
    ->   `CDC_INSERT_TIME` datetime DEFAULT sysdate(),
    ->   `CDC_UPDATE_TIME` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
    ->   `op_ts` datetime DEFAULT NULL,
    ->   UNIQUE KEY `B2C_S_USER_P1` (`ROW_ID`),
    ->   KEY `B2C_S_USER_M1` (`LOGIN`)
    -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
Query OK, 0 rows affected (0.042 sec)
 
MariaDB [test]> select
    ->     tbl.table_schema,
    ->     tbl.table_name
    -> from information_schema.tables tbl
    -> left join information_schema.key_column_usage as col
    -> on tbl.table_name = col.table_name
    ->    and col.constraint_schema = tbl.table_schema
    ->    and col.constraint_name = 'PRIMARY'
    -> where
    ->     tbl.table_schema <> 'information_schema'
    -> and tbl.table_schema <> 'performance_schema'
    -> and tbl.table_schema <> 'mysql'
    -> and col.constraint_name is NULL;
+--------------+------------+
| table_schema | table_name |
+--------------+------------+
| test         | B2C_S_USER |
+--------------+------------+
1 row in set (0.052 sec)
 
MariaDB [test]> desc B2C_S_USER;
+-----------------+-------------+------+-----+---------------------+-------------------------------+
| Field           | Type        | Null | Key | Default             | Extra                         |
+-----------------+-------------+------+-----+---------------------+-------------------------------+
| ROW_ID          | varchar(15) | NO   | PRI | NULL                |                               |
| LOGIN           | varchar(50) | NO   | MUL | NULL                |                               |
| CDC_INSERT_TIME | datetime    | YES  |     | sysdate()           |                               |
| CDC_UPDATE_TIME | timestamp   | NO   |     | current_timestamp() | on update current_timestamp() |
| op_ts           | datetime    | YES  |     | NULL                |                               |
+-----------------+-------------+------+-----+---------------------+-------------------------------+
5 rows in set (0.001 sec)



 Comments   
Comment by Alice Sherepa [ 2020-06-15 ]

According to KB: "A UNIQUE index may be displayed as PRI if it cannot contain NULL values and there is no PRIMARY KEY in the table."
https://mariadb.com/kb/en/show-columns/

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