By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE test (
id INT PRIMARY KEY,
id2 INT, UNIQUE (id2),
id3 INT, INDEX (id3)
);
INSERT INTO test VALUES
(1,2,5),
(2,4,3),
(3,6,1),
(4,1,6),
(5,3,4),
(6,5,2);
SELECT * FROM test;
SHOW CREATE TABLE test;
Records: 6 Duplicates: 0 Warnings: 0
id | id2 | id3 |
---|---|---|
1 | 2 | 5 |
2 | 4 | 3 |
3 | 6 | 1 |
4 | 1 | 6 |
5 | 3 | 4 |
6 | 5 | 2 |
Table | Create Table |
---|---|
test | CREATE TABLE `test` ( `id` int NOT NULL, `id2` int DEFAULT NULL, `id3` int DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `id2` (`id2`), KEY `id3` (`id3`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
SELECT id FROM test LIMIT 3;
SELECT id FROM test USE INDEX (PRIMARY) LIMIT 3;
SELECT id FROM test USE INDEX (id2) LIMIT 3;
SELECT id FROM test USE INDEX (id3) LIMIT 3;
id |
---|
4 |
1 |
5 |
id |
---|
1 |
2 |
3 |
id |
---|
4 |
1 |
5 |
id |
---|
3 |
6 |
2 |