The optimizer hint references a query block alias that does not exist in the current SQL statement.
ER_WARN_UNKNOWN_QB_NAME appears when a MySQL optimizer hint names a query block alias that the parser cannot find. Correct the alias or remove the hint to clear the warning and ensure the optimizer follows your intended plan.
ER_WARN_UNKNOWN_QB_NAME
MySQL raises the ER_WARN_UNKNOWN_QB_NAME warning when the optimizer processes a hint like USE_INDEX, JOIN_ORDER, or STRAIGHT_JOIN that names a query block alias not present in the statement. Because the alias cannot be resolved, the hint is ignored and a warning is returned instead of an error.
The code was introduced in MySQL 5.7.7 to help users detect typos and outdated hints during query tuning. Although it is only a warning, it signals that the intended execution plan directive will not take effect, which can lead to slower queries.
The warning occurs when the query text includes an optimizer hint that references a block alias that is misspelled, removed, or never declared. It also appears if you forget to label the subquery with the alias required by the hint.
First, list all query block aliases used in the statement. Next, compare them to the aliases named in each optimizer hint. Finally, rename or remove any hint that does not match an existing alias. Once the aliases align, rerun the statement; the warning disappears.
Developers often copy hints from older versions of a query after refactoring joins or removing subqueries, leaving the old alias behind. Revalidating aliases during code reviews or using a modern SQL editor like Galaxy helps catch these mismatches before deployment.
Always declare explicit aliases for subqueries you intend to reference in hints. Keep hint names adjacent to the related query block in your code, and automate testing that runs EXPLAIN to surface warnings. Galaxy’s inline linting flags unresolved aliases in real time.
Warnings such as ER_WARN_INDEX_NOT_APPLICABLE, ER_WARN_DEPRECATED_SYNTAX, and ER_WARN_HINT_UNSUPPORTED_VERSION also inform you when optimizer directives are ineffective. Fix them promptly to ensure predictable performance.
A single character typo causes the alias in the hint to differ from the declared alias, triggering the warning.
Refactoring that deletes a query block but leaves its hint behind results in an unknown alias.
Placing a hint before the corresponding subquery definition prevents the parser from associating the names.
Using an optimizer hint on an inline view that lacks an alias declaration produces the warning.
Index hint provided cannot be used for the chosen access path.
Optimizer hint is not supported in the running MySQL version.
SQL statement uses syntax that is deprecated and might be removed in future releases.
No. It is a warning, not an error. The query still executes, but the hint is ignored.
You can disable warnings globally with SQL_WARNINGS, but fixing the hint is safer.
Yes. Because the optimizer ignores the hint, the execution plan may be slower than expected.
Galaxy highlights unresolved hint aliases during editing, letting you correct them before running the query.