Common SQL Errors

MySQL Error 3127: ER_WARN_UNKNOWN_QB_NAME - How to Fix and Prevent

Galaxy Team
August 8, 2025

The optimizer hint references a query block alias that does not exist in the current SQL statement.

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is MySQL error 3127 ER_WARN_UNKNOWN_QB_NAME?

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.

Error Highlights

Typical Error Message

ER_WARN_UNKNOWN_QB_NAME

Error Type

Optimizer Hint Warning

Language

MySQL

Symbol

ER_WARN_UNKNOWN_QB_NAME was added in 5.7.7.

Error Code

3127

SQL State

HY000

Explanation

Table of Contents

What does the MySQL ER_WARN_UNKNOWN_QB_NAME warning mean?

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.

What Causes This Error?

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.

How to Fix ER_WARN_UNKNOWN_QB_NAME

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.

Common Scenarios and Solutions

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.

Best Practices to Avoid This Error

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.

Related Errors and Solutions

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.

Common Causes

Misspelled alias in the hint

A single character typo causes the alias in the hint to differ from the declared alias, triggering the warning.

Removed subquery or derived table

Refactoring that deletes a query block but leaves its hint behind results in an unknown alias.

Alias defined after the hint

Placing a hint before the corresponding subquery definition prevents the parser from associating the names.

Forgotten alias declaration

Using an optimizer hint on an inline view that lacks an alias declaration produces the warning.

Related Errors

ER_WARN_INDEX_NOT_APPLICABLE

Index hint provided cannot be used for the chosen access path.

ER_WARN_HINT_UNSUPPORTED_VERSION

Optimizer hint is not supported in the running MySQL version.

ER_WARN_DEPRECATED_SYNTAX

SQL statement uses syntax that is deprecated and might be removed in future releases.

FAQs

Is ER_WARN_UNKNOWN_QB_NAME fatal?

No. It is a warning, not an error. The query still executes, but the hint is ignored.

Can I suppress the warning?

You can disable warnings globally with SQL_WARNINGS, but fixing the hint is safer.

Does the warning affect performance?

Yes. Because the optimizer ignores the hint, the execution plan may be slower than expected.

How does Galaxy help?

Galaxy highlights unresolved hint aliases during editing, letting you correct them before running the query.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo