MySQL 8.4Lab-verified · 2026-11-30

MySQL ERROR 1176 (42000): Key 'idx_cust' doesn't exist in table 'orders'

An index hint names an index that the table doesn't have.

MySQL 8.4.13
1176 (42000): Key 'idx_cust' doesn't exist in table 'orders'

Jump to a cause

  1. 01Typo in the index name in FORCE INDEX
  2. 02The index was dropped or replaced, but the query still has the old hint
  3. 03A column name used instead of the index name (primary key is PRIMARY)

Lab-verifiedReproduced and fixed on MySQL 8.4.13 · 2026-11-30 · container image mysql:8.4

ERROR 1176 comes from index hints such as FORCE INDEX (...) and USE INDEX (...). MySQL checks the name in the hint against the table's index names and stops the query if there is no match.

The quickest check is the list of index names in information_schema.statistics. Below are three cases reproduced on MySQL 8.4.

01Typo in the index name in FORCE INDEX

The query asked for FORCE INDEX (idx_cust), but the index on cust_id is called idx_orders_cust.

Setup
Setuprun as lab_a
CREATE TABLE orders (order_id INT PRIMARY KEY, cust_id INT, created_at DATE, KEY idx_orders_cust (cust_id));
INSERT INTO orders VALUES (1, 10, '2026-11-01'), (2, 20, '2026-11-02'), (3, 10, '2026-11-03');
OUTPUT
Query OK, 0 rows affected (0.02 sec)

Query OK, 3 rows affected (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 0
Reproducerun as lab_a
SELECT order_id FROM orders FORCE INDEX (idx_cust) WHERE cust_id = 10;
✕ ERROR
ERROR 1176 (42000): Key 'idx_cust' doesn't exist in table 'orders'
Check the causerun as lab_a
SELECT index_name, column_name FROM information_schema.statistics
 WHERE table_schema = DATABASE() AND table_name = 'orders'
 ORDER BY index_name, seq_in_index;
OUTPUT
+-----------------+-------------+
| INDEX_NAME      | COLUMN_NAME |
+-----------------+-------------+
| idx_orders_cust | cust_id     |
| PRIMARY         | order_id    |
+-----------------+-------------+
2 rows in set (0.00 sec)

The table has only idx_orders_cust (on cust_id) and PRIMARY. There is no idx_cust.

Checkrun as lab_a
EXPLAIN FORMAT=TREE SELECT order_id FROM orders FORCE INDEX (idx_orders_cust) WHERE cust_id = 10\G
OUTPUT
*************************** 1. row ***************************
EXPLAIN: -> Covering index lookup on orders using idx_orders_cust (cust_id=10)  (cost=0.35 rows=1)

1 row in set (0.00 sec)

With the real name, EXPLAIN shows Covering index lookup on orders using idx_orders_cust, and the query returns orders 1 and 3.

After the fixrun as lab_a
SELECT order_id FROM orders FORCE INDEX (idx_orders_cust) WHERE cust_id = 10;
✓ SUCCESS
+----------+
| order_id |
+----------+
|        1 |
|        3 |
+----------+
2 rows in set (0.00 sec)

02The index was dropped or replaced, but the query still has the old hint

idx_orders_cust was replaced by a composite index ix_cust_created (cust_id, created_at). The application query still says USE INDEX (idx_orders_cust), so it fails right after the index change.

Setup
Setuprun as lab_a
CREATE TABLE orders (order_id INT PRIMARY KEY, cust_id INT, created_at DATE, KEY idx_orders_cust (cust_id));
INSERT INTO orders VALUES (1, 10, '2026-11-01'), (2, 20, '2026-11-02'), (3, 10, '2026-11-03');
ALTER TABLE orders DROP INDEX idx_orders_cust, ADD INDEX ix_cust_created (cust_id, created_at);
OUTPUT
Query OK, 0 rows affected (0.02 sec)

Query OK, 3 rows affected (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 0

Query OK, 0 rows affected (0.02 sec)
Records: 0  Duplicates: 0  Warnings: 0
Reproducerun as lab_a
SELECT order_id FROM orders USE INDEX (idx_orders_cust) WHERE cust_id = 10 ORDER BY created_at;
✕ ERROR
ERROR 1176 (42000): Key 'idx_orders_cust' doesn't exist in table 'orders'
Check the causerun as lab_a
SELECT index_name, column_name FROM information_schema.statistics
 WHERE table_schema = DATABASE() AND table_name = 'orders'
 ORDER BY index_name, seq_in_index;
OUTPUT
+-----------------+-------------+
| INDEX_NAME      | COLUMN_NAME |
+-----------------+-------------+
| ix_cust_created | cust_id     |
| ix_cust_created | created_at  |
| PRIMARY         | order_id    |
+-----------------+-------------+
3 rows in set (0.00 sec)

idx_orders_cust is gone; ix_cust_created covers cust_id and created_at.

Checkrun as lab_a
EXPLAIN FORMAT=TREE SELECT order_id FROM orders WHERE cust_id = 10 ORDER BY created_at\G
OUTPUT
*************************** 1. row ***************************
EXPLAIN: -> Covering index lookup on orders using ix_cust_created (cust_id=10)  (cost=0.45 rows=2)

1 row in set (0.00 sec)

Removing the hint was enough: EXPLAIN shows the optimizer picks ix_cust_created by itself. You could also change the hint to the new name.

After the fixrun as lab_a
SELECT order_id FROM orders WHERE cust_id = 10 ORDER BY created_at;
✓ SUCCESS
+----------+
| order_id |
+----------+
|        1 |
|        3 |
+----------+
2 rows in set (0.00 sec)

03A column name used instead of the index name (primary key is PRIMARY)

FORCE INDEX (order_id) uses the column name. Hints take index names, and the primary key index is always named PRIMARY.

Setup
Setuprun as lab_a
CREATE TABLE orders (order_id INT PRIMARY KEY, cust_id INT, created_at DATE, KEY idx_orders_cust (cust_id));
INSERT INTO orders VALUES (1, 10, '2026-11-01'), (2, 20, '2026-11-02'), (3, 10, '2026-11-03');
OUTPUT
Query OK, 0 rows affected (0.02 sec)

Query OK, 3 rows affected (0.01 sec)
Records: 3  Duplicates: 0  Warnings: 0
Reproducerun as lab_a
SELECT order_id, cust_id FROM orders FORCE INDEX (order_id) WHERE order_id BETWEEN 1 AND 2;
✕ ERROR
ERROR 1176 (42000): Key 'order_id' doesn't exist in table 'orders'
Check the causerun as lab_a
SELECT index_name, column_name FROM information_schema.statistics
 WHERE table_schema = DATABASE() AND table_name = 'orders'
 ORDER BY index_name, seq_in_index;
OUTPUT
+-----------------+-------------+
| INDEX_NAME      | COLUMN_NAME |
+-----------------+-------------+
| idx_orders_cust | cust_id     |
| PRIMARY         | order_id    |
+-----------------+-------------+
2 rows in set (0.00 sec)

The index on order_id is named PRIMARY, not order_id.

Checkrun as lab_a
EXPLAIN FORMAT=TREE SELECT order_id, cust_id FROM orders FORCE INDEX (PRIMARY) WHERE order_id BETWEEN 1 AND 2\G
OUTPUT
*************************** 1. row ***************************
EXPLAIN: -> Filter: (orders.order_id between 1 and 2)  (cost=0.46 rows=1)
    -> Index range scan on orders using PRIMARY over (1 <= order_id <= 2)  (cost=0.46 rows=1)

1 row in set (0.00 sec)

FORCE INDEX (PRIMARY) works; EXPLAIN shows Index range scan on orders using PRIMARY.

After the fixrun as lab_a
SELECT order_id, cust_id FROM orders FORCE INDEX (PRIMARY) WHERE order_id BETWEEN 1 AND 2;
✓ SUCCESS
+----------+---------+
| order_id | cust_id |
+----------+---------+
|        1 |      10 |
|        2 |      20 |
+----------+---------+
2 rows in set (0.00 sec)

FAQ

How do I list index names to fix ERROR 1176?

Query information_schema.statistics for the table (index_name, column_name), or use SHOW INDEX FROM orders. Use exactly one of those names in the hint.

What is the index name of the primary key in MySQL?

PRIMARY. Write FORCE INDEX (PRIMARY), not the column name.

Do I need the index hint at all?

Often not. In the replaced-index case, removing the hint let the optimizer choose the new index on its own (checked with EXPLAIN FORMAT=TREE).

How we verify

Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.

lab_a and lab_b are ordinary users created for the test, each with full rights on a database of the same name (its default database); root is the administrator. MySQL 8.4.13