How to Fix MySQL Error 3128 (ER_UNRESOLVED_HINT_NAME)

Published
Length
3 min read

Luis Felipe Dias

All posts

You get mysql error 3128 when a query hint uses a name that does not exist. You fix it by matching the hint name to a valid table, alias, or index. MySQL logs this condition with the symbol ER_UNRESOLVED_HINT_NAME and the SQLSTATE code HY000. The engine returns a message stating that there is an unresolved name for your hint. Despite the word error, the database engine treats this event as a query optimizer warning. Your query still runs, but the optimizer ignores the broken hint and picks anot

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You get mysql error 3128 when a query hint uses a name that does not exist. You fix it by matching the hint name to a valid table, alias, or index.

MySQL logs this condition with the symbol ER_UNRESOLVED_HINT_NAME and the SQLSTATE code HY000. The engine returns a message stating that there is an unresolved name for your hint. Despite the word error, the database engine treats this event as a query optimizer warning. Your query still runs, but the optimizer ignores the broken hint and picks another plan.

Root causes of mysql error 3128 in your database

The MySQL optimizer reads query hints to change how it joins tables or scans indexes. Every table hint or index hint must point to an object in the query. If the target name is missing, the parser raises ER_UNRESOLVED_HINT_NAME during query planning.

Table aliases cause this problem more than any other factor in daily database work. Once you give a table an alias in a query, the hint must use it. If your hint uses the base table name instead, MySQL cannot match the two names. The engine drops the hint and logs the warning for that specific statement.

Schema changes also trigger this warning across your production databases. A developer might drop an old index during a routine cleanup task. If an app query still asks the optimizer to use that dropped index, the hint fails. The query does not crash, so your team might miss the sudden drop in speed. Instead of using a fast index lookup, the database might scan the whole table.

Subqueries and query block names add another layer where names can go wrong. Developers can name query blocks to aim hints at specific parts of a big query. A simple typo in the block name or table reference breaks the link right away. Case rules for table names on your host operating system can also cause mismatches.

How to find and fix broken hints in production

Finding the root cause requires checking the warning log after the slow query runs. Do not grant broad admin roles to developers just to check live production schemas. Instead, give users read-only permissions to view table definitions and run query plan checks. This setup keeps production data safe while your team inspects the query structure.

MySQL Access Governance + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Start by capturing the exact query text that triggers the 3128 warning code. Compare every name inside the hint comment against the tables in the query block. Check if any table uses an alias in the main clause or join clause. Update the hint so it uses the exact alias instead of the raw table name.

Next, check that all index names in the hint exist on the target table. You can view the current table indexes using standard schema metadata views. If an index was renamed or dropped, update the app code to match the live schema. Test the updated query in a staging database before you push changes to production.

Preventing hint failures during schema updates

You can stop hint warnings before they hit production by checking queries during code reviews. Keep a list of queries that rely on optimizer hints in your app codebase. When your team plans to drop or rename an index, check that list first. This simple step keeps your query plans stable when schemas change over time.

When engineers inspect query plans on live databases, protect sensitive fields in the output. Data masking rewrites matched fields like emails, phone numbers, card numbers, and national IDs in results. This rule lets engineers test real queries while keeping private customer records safe. Combine scoped read roles with query logging so teams can spot hint warnings early.

Check MySQL queries and results on the wire

MySQL grants control who logs in. They do not check single queries or mask sensitive columns once a session starts. With hoop.dev, you run an open-source proxy, a sidecar for your MySQL, inline in the MySQL wire protocol. On every query an AI agent or human runs against production MySQL, RDS, or Aurora, hoop.dev decides to pass, mask, block, or hold it for review.

Multi-statement batches and prepared queries are split and checked one by one by hoop.dev guardrails, which refuse banned queries with a native MySQL error or hold risky ones for approval. On the response path, hoop.dev data masking rewrites string values in returned rows in memory, and every decision is logged. See the MIT-licensed project on GitHub.

Frequently asked questions

Does mysql error 3128 stop my query from running?

No, the database engine treats code 3128 as a warning rather than a hard stop. MySQL ignores the invalid hint and runs the query using its normal cost plan. Still, the query may run much slower if it misses an important index.

Why does my hint fail when the table name is spelled right?

Your query likely gives that table an alias in the main table list. When a table has an alias, the optimizer only knows the table by that short name. Change the hint to use the alias, and the warning will go away.

How can we catch ER_UNRESOLVED_HINT_NAME warnings in our app?

Have your test suite check the database warning count after running key app queries. You can also inspect the database slow query log and performance schema tables for warnings. Fixing broken hints during testing stops slow query plans from reaching your live servers.

The query runs. The emails stay hidden.