How to Fix MySQL Error 3126 (ER_WARN_CONFLICTING_HINT)
You get mysql error 3126 when a query contains duplicate or opposing optimizer hints. You can fix this issue by removing the extra or clashing hints from your statement. When the database engine reads your query, it checks all special instructions inside comment blocks. If two instructions fight each other, the database cannot follow both rules at once. It keeps the first valid instruction and drops the second one. Then it raises a warning with the symbol ER_WARN_CONFLICTING_HINT and SQLSTATE H
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 3126 when a query contains duplicate or opposing optimizer hints. You can fix this issue by removing the extra or clashing hints from your statement.
When the database engine reads your query, it checks all special instructions inside comment blocks. If two instructions fight each other, the database cannot follow both rules at once. It keeps the first valid instruction and drops the second one. Then it raises a warning with the symbol ER_WARN_CONFLICTING_HINT and SQLSTATE HY000. The query still runs, but it might pick a slow path.
Why mysql error 3126 happens in your database
The official message for this warning says that a hint is ignored as conflicting or duplicated. The query planner reads your statement from left to right. It builds a list of rules for how to join tables and read indexes. If you pass the exact same rule twice for one table, the planner flags the duplicate.
Conflicts also happen when two different rules ask for opposite actions on the same table. For example, one hint might tell the planner to use a specific index. A second hint in the same block might tell the planner to skip that exact index. The engine cannot obey both commands during the same run. It drops the later hint and logs code 3126 to alert your team.
Code generators and object mappers often cause this problem in large apps. A base query builder might attach a default index rule to a table read. Later in the code path, a custom filter might append another rule to the same query. When the app sends the final text to the server, both hints sit in the statement. Subqueries and merged views can also bring clashing hints together when the planner flattens them.
How to find and fix conflicting hints in live apps
To find the bad query, check your database warning logs right after the query runs. The warning message will name the exact hint that the engine ignored. Match this message back to the query text in your app code or slow query log.
Once you find the statement, read all comment blocks that hold planner rules. Look for repeated table names or index names inside those blocks. Keep only the single rule that gives you the best run time. Delete any extra copies or opposing rules from the statement text.
MySQL Access Governance + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
If a query builder creates the statement, check how your app joins query parts. Make sure child modules clear old hints before they add new ones. If you use database views, inspect the view definitions for hidden planner rules. A rule inside a view can clash with a rule in the outer query.
Test the cleaned query in a staging setup before you change live code. Run an execution plan check to see how the engine reads the tables now. Make sure the warning count stays at zero after the query finishes.
How to prevent hint conflicts across your team
Teams often add planner hints during a late night outage to fix a slow page. Over time, schema changes make those old rules useless or harmful. Set up a code review rule that flags any new query hints in pull requests.
Ask developers to document why a hint is needed before they merge the code. When you add or drop an index, search your app repo for hints on that table. Removing stale rules keeps your queries clean and stops code 3126 from filling your logs. It also lets the database planner use new indexes without old rules blocking the way.
Inspect every MySQL query and response in flight
Static grants and network rules block bad logins. They cannot pause a risky query for review or mask emails in a result set. By design, hoop.dev sits inline in the MySQL protocol as a sidecar for your MySQL. For every plain query, prepared statement, or cursor an agent or human runs in production, hoop.dev decides to pass, mask, block, or hold it for review.
First, hoop.dev guardrails block banned actions before MySQL runs them, and an AI Analyzer you configure can score intent or escalate for approval. Next, hoop.dev data masking rewrites sensitive string columns in results in memory, and every verdict goes to the audit trail. Find the open-source binary on GitHub.
Frequently asked questions
Does mysql error 3126 stop my query from running?
No, code 3126 is a warning and not a hard stop error. The database drops the conflicting hint and runs the query with the remaining rules.
Which hint wins when two hints conflict in a query?
The database engine reads hints in the order they appear in the query text. It applies the first valid hint and ignores the later conflicting hint.
Can views cause ER_WARN_CONFLICTING_HINT in a query?
Yes, a view definition can hold its own planner hints. Those inner hints can clash with hints written in the outer query.
Related guides
In this post