[MDEV-29106] The information of the table in INFORMATION_SCHEMA is inconsistent with the actual! Created: 2022-07-15  Updated: 2022-07-15  Resolved: 2022-07-15

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

Type: Bug Priority: Critical
Reporter: fengwei Assignee: Unassigned
Resolution: Not a Bug Votes: 0
Labels: None
Environment:

MariaDB Server version: 10.0.20-MariaDB
MariaDB Server version: 10.9.1-MariaDB-1:10.9.1+maria~jammy

OS :
Linux 4.4.38-1.el7.elrepo.x86_64 #1 SMP Sat Dec 10 18:16:05 EST 2016 x86_64 x86_64 x86_64 GNU/Linux



 Description   

There is no primary key when the table is created, but INFORMATION_SCHEMA shows that there is a primary key.

When querying, FORCE INDEX(`PRIMARY`) cannot be used!

I want "INFORMATION_SCHEMA" and "FORCE INDEX" to be consistent!

CREATE TABLE `test` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `user` varchar(50) DEFAULT NULL,
  `create_time` timestamp NULL DEFAULT current_timestamp(),
 UNIQUE KEY `id` (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4;
 
insert into test values(1, "tony", now());
insert into test values(2, "jack", now());
 
SELECT COLUMN_NAME, IS_NULLABLE, DATA_TYPE, COLUMN_KEY, EXTRA FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA="test" AND TABLE_NAME="test" ORDER BY ORDINAL_POSITION\G;
*************************** 1. row ***************************
COLUMN_NAME: id
IS_NULLABLE: NO
  DATA_TYPE: int
COLUMN_KEY: PRI
 EXTRA: auto_increment
*************************** 2. row ***************************
COLUMN_NAME: user
IS_NULLABLE: YES
  DATA_TYPE: varchar
 COLUMN_KEY:
      EXTRA:
*************************** 3. row ***************************
COLUMN_NAME: create_time
IS_NULLABLE: YES
  DATA_TYPE: timestamp
 COLUMN_KEY:
      EXTRA:
 
 
MariaDB [test]> select id from test1  FORCE INDEX(`PRIMARY`)  where id=2;
ERROR 1146 (42S02): Table 'test.test1' doesn't exist
 



 Comments   
Comment by Elena Stepanova [ 2022-07-15 ]

In the absence of a primary key, a non-nullable unique index serves as such and is indicated as such. This is intentional and documented behavior. See MariaDB KB and MySQL manual.

A UNIQUE index may be displayed as PRI if it cannot contain NULL values and there is no PRIMARY KEY in the table

If you need constraint names, use information_schema.table_constraints instead.

Comment by fengwei [ 2022-07-15 ]

Since this is intentional, why is FORCE INDEX(`PRIMARY`) not allowed?
Isn't this behavior inconsistent?

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