How to Fix MySQL Error 3515 (ER_WARN_UNSUPPORTED_HINT)

Published
Length
3 min read

Luis Felipe Dias

All posts

You see mysql error 3515 when a query uses an optimizer hint in the wrong place. You can fix it by moving the hint to a valid query block or removing it. MySQL logs this issue with symbol ER_WARN_UNSUPPORTED_HINT and SQLSTATE HY000. The server sends the message that hints are not supported in the target context. Your query still runs, but the database ignores the hint you wrote. This can cause slow queries in your live app if the planner picks a bad path. What causes mysql error 3515 in your

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 see mysql error 3515 when a query uses an optimizer hint in the wrong place. You can fix it by moving the hint to a valid query block or removing it.

MySQL logs this issue with symbol ER_WARN_UNSUPPORTED_HINT and SQLSTATE HY000. The server sends the message that hints are not supported in the target context. Your query still runs, but the database ignores the hint you wrote. This can cause slow queries in your live app if the planner picks a bad path.

What causes mysql error 3515 in your database

The database planner reads special comments that guide how it joins tables or uses indexes. These comments are optimizer hints. Still, the engine only allows hints in specific statement types and clauses. When an app or user puts a hint inside an unsupported statement, error 3515 fires.

Common triggers include placing hints inside stored routines or DDL statements that cannot use them. You might also trigger ER_WARN_UNSUPPORTED_HINT by placing a hint after the wrong keyword in a query. In some cases, an ORM tool adds hints to every query by mistake. When that happens, your warning logs fill up fast.

Database upgrades can also surface this warning. A query that ran without complaints in an older setup might now raise SQLSTATE HY000. The parser checks hint locations strictly and flags any block it cannot optimize with hints.

How to find and fix the warning in production

First, you need to find the exact query that triggers the warning. Check your database warning logs or query audit trail to see the full statement text. Look for optimizer hint comments inside that text. Note the exact statement type shown in the warning message.

Do not give developers broad production rights just to debug query plans. Instead, run your checks through a controlled workflow with read-only permissions. If the query touches customer tables, make sure data masking rewrites emails and phone numbers in results. This lets your team inspect query output and warnings without exposing private records.

Customer Support Access to Production + MySQL Access Governance: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Once you locate the bad hint, check if the statement type supports optimizer hints at all. MySQL supports hints at the start of select, insert, replace, update, and delete statements. If your hint sits inside another command, delete the hint comment from your code.

If the statement is a valid query type, check the hint placement. The hint block must sit right after the first keyword of the query block. Move the comment to that exact spot and test the query plan again. Verify that the warning disappears and the engine picks the right index.

How to prevent bad hints from reaching production

You can stop mysql error 3515 before code reaches your live database. Add a step in your test pipeline that checks SQL warnings after every test run. Most apps ignore warnings because the query still returns rows. Treating optimizer warnings as test failures catches misplaced hints early.

You should also review ad-hoc queries before they run against live data. When an engineer needs to tune a slow query by hand, use a peer review flow. A second pair of eyes can spot a misplaced hint right away. Plus, central query logs help you track which app or user sent the bad syntax.

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 3515 stop my query from running?

No, ER_WARN_UNSUPPORTED_HINT is a warning, not a fatal error. MySQL ignores the invalid hint and runs the rest of your statement using its normal plan.

Why does my ORM trigger ER_WARN_UNSUPPORTED_HINT?

Some query builders attach hints to outer wrappers or unsupported commands by mistake. Check the raw SQL in your logs and update the builder settings to remove the hint.

How can developers test query hints safely on live data?

Use a database proxy that enforces read-only roles and approvals for tuning sessions. Masking rules can also rewrite card numbers and national IDs in results during the test.

The query runs. The emails stay hidden.