Common SQL Errors

MySQL Error 3123: ER_WARN_OPTIMIZER_HINT_SYNTAX_ERROR - Diagnose, Fix, and Prevent

Galaxy Team
August 8, 2025

MySQL raises warning 3123 when an optimizer hint is misspelled, misplaced, or uses unsupported syntax.

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 3123 (ER_WARN_OPTIMIZER_HINT_SYNTAX_ERROR)?

ER_WARN_OPTIMIZER_HINT_SYNTAX_ERROR (MySQL error 3123) means your optimizer hint is malformed or unsupported. Correct the hint keyword, placement, or remove it entirely to clear the warning and let the query run with the intended execution plan.

Error Highlights

Typical Error Message

ER_WARN_OPTIMIZER_HINT_SYNTAX_ERROR

Error Type

Syntax Warning

Language

MySQL

Symbol

ER_WARN_OPTIMIZER_HINT_SYNTAX_ERROR was added in 5.7.7.

Error Code

3123

SQL State

HY000

Explanation

Table of Contents

What is MySQL error 3123 (ER_WARN_OPTIMIZER_HINT_SYNTAX_ERROR)?

Error 3123 is a non-fatal warning thrown by MySQL when the parser encounters an optimizer hint that it cannot understand. MySQL continues executing the statement but ignores the problematic hint, which may lead to a sub-optimal execution plan.

The error was introduced in MySQL 5.7.7 alongside the initial optimizer hint feature set. It still appears in current 8.x releases whenever hint syntax deviates from documented rules.

What causes this error?

The warning surfaces when a hint keyword is misspelled, contains wrong casing, or is not supported in the running server version. It also triggers if the hint is placed outside the valid comment form /*+ ... */ or when its inner parameters are malformed.

Using multiple hints separated by commas without proper spacing, nesting hints incorrectly, or passing an incorrect schema.table reference will also cause the parser to flag the hint.

How to fix ER_WARN_OPTIMIZER_HINT_SYNTAX_ERROR

Locate the faulty hint, cross-check the syntax against the official manual for your server version, and correct the spelling, parameter list, and placement. If the hint is unnecessary, simply remove it to silence the warning.

After editing, run EXPLAIN to verify that the modified hint is accepted and that the desired plan is chosen.

Common scenarios and solutions

Developers often copy hints written for Oracle or older MySQL versions, leading to unsupported keywords. Another scenario is automated query generators injecting hints that break when table aliases change. Refactoring queries to use proper aliases resolves this quickly.

In migration projects, temporarily disable all hints, benchmark the native plan, then add only the minimal set of validated hints back.

Best practices to avoid this error

Keep documentation for accepted hints handy, test each new hint with EXPLAIN before committing, and gate database upgrades with integration tests that include hinted queries. In Galaxy, you can save validated hint templates in a shared Collection to prevent team-wide syntax drift.

Related errors and solutions

Warnings 3163 (ER_WARN_HINT_UNSUPPORTED_LEVEL) and 3170 (ER_DUP_SIGNED_KEY) often appear with badly placed hints. Correcting the hint block or downgrading to a version that supports the hint clears them.

Common Causes

Misspelled or unsupported hint keyword

Typos like IDX_MERGE instead of INDEX_MERGE or using hints introduced in later MySQL versions will trigger the warning.

Incorrect comment wrapper

Hints must live inside a standard comment that starts with /*+ and ends with */. Any deviation, such as extra dashes, breaks parsing.

Malformed parameter list

Passing invalid table aliases, column names, or forgetting parentheses inside the hint results in error 3123.

Related Errors

ER_WARN_HINT_UNSUPPORTED_LEVEL (3163)

Appears when the scope level of a hint is not recognized. Use session or statement scope only.

ER_OPTION_PREVENTS_STATEMENT (1290)

Occurs when the sql_mode or server option disallows a hinted feature. Adjust configuration or drop the hint.

ER_PARSE_ERROR (1064)

A generic syntax error that can be thrown if the hint breaks the overall statement structure, not just the hint area.

FAQs

Does error 3123 stop my query from running?

No - MySQL treats it as a warning, ignores the faulty hint, and executes the statement.

Can I force MySQL to fail on hint errors?

You cannot turn this warning into a fatal error, but you can check it in application code using SHOW WARNINGS and abort if present.

Do hints hurt performance if written wrong?

The hint is skipped, so performance may degrade if the optimizer chooses a slower plan than intended.

How does Galaxy help avoid hint mistakes?

Galaxy’s AI copilot autocompletes valid hint keywords and flags syntax errors in real time, reducing the chance of pushing broken hints.

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