MyCATApache/Mycat-Server · error
ER_PARSE_ERROR
ER_PARSE_ERROR
Error message
msg == null ? e.getClass().getSimpleName() : msg
What it means
ExplainHandler.getRouteResultset() runs EXPLAIN statements through the router service and converts any exception into an ER_PARSE_ERROR error packet written to the manager/client connection, using e.getMessage() or the exception class simple name when null. It tells the developer that Mycat could not route the statement being explained.
Solutions
- Inspect the server log line '... <stmt> error: <exception>' for the underlying cause and stack trace.
- Fix the explained SQL or the corresponding schema/rule configuration so route() succeeds.
- If the message is a bare class name, locate the NPE/IAE in the stack trace and fix the missing configuration it points to.
Example fix
// before
EXPLAIN INSERT INTO t_seq VALUES (NEXT VALUE FOR MYCATSEQ_GLOBAL); // malformed sequence usage -> router exception
// after
// configure the sequence in sequence_conf.properties / rule.xml, then:
EXPLAIN INSERT INTO t_seq (name) VALUES ('a'); Defensive patterns
Strategy: try-catch
Validate before calling
// verify target table is routable before issuing EXPLAIN
String table = resolveTableName(stmt);
if (!mycatSchemaTables.contains(table)) {
System.err.println("cannot EXPLAIN: table missing from schema.xml: " + table);
} Try / catch
try (Statement st = conn.createStatement()) {
st.execute("EXPLAIN " + sql);
} catch (SQLException e) {
if (e.getErrorCode() == 1064) {
// Mycat router rejected the explained statement; read server.log 'error:' line
LOGGER.error("EXPLAIN routing failed for: " + sql, e);
} else {
throw e;
}
} Prevention
- Use EXPLAIN only on tables already declared in schema.xml.
- Simplify the explained SQL first; complex subqueries/hints may be unparseable by the router.
- Read the manager/server log line '... error: <exception>' for the true cause.
- Keep Mycat sequence configuration valid when explaining statements using NEXT VALUE FOR.
When it happens
Trigger: Any Exception from MycatServer.getInstance().getRouterservice().route(...) while processing an EXPLAIN statement: unsupported syntax, missing schema/table routing config, router internal errors; null-message exceptions yield just the class name in the error packet.
Common situations: Using EXPLAIN to debug sharding of a table that is missing from schema.xml; EXPLAIN of SQL the Druid-based parser cannot parse; sequence (isMycatSeq) or hint handling throwing on malformed input.
Understand the failure class
Background: "query failed", "%w: SQL error" — wrapped database query errors in Go libraries explained — this error's family across 3 libraries.
Related errors
- ER_PARSE_ERROR
- schema: ,table: ,sql: is not allowed,because table is…
- can't find hint datanode
- can't find hint schema
- Multi statements is not supported,use single statement…
AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11).
Data as JSON: /api/errors/d3c09b37335c8f03.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/io/mycat/server/handler/ExplainHandler.java:156
c.writeErrMessage(ErrorCode.ER_BAD_DB_ERROR, "Unknown database '"
+ db + "'");
return null;
}
try {
if(ServerParse.INSERT==sqlType&&isMycatSeq(stmt, schema))
{
c.writeErrMessage(ErrorCode.ER_PARSE_ERROR, "insert sql using mycat seq,you must provide primaryKey value for explain");
return null;
}
SystemConfig system = MycatServer.getInstance().getConfig().getSystem();
return MycatServer.getInstance().getRouterservice()
.route(system,schema, sqlType, stmt, c.getCharset(), c);
} catch (Exception e) {
StringBuilder s = new StringBuilder();
logger.warn(s.append(c).append(stmt).toString()+" error:"+ e);
String msg = e.getMessage();
c.writeErrMessage(ErrorCode.ER_PARSE_ERROR, msg == null ? e
.getClass().getSimpleName() : msg);
return null;
}
}
private static boolean isMycatSeq(String stmt, SchemaConfig schema)
{
if(pattern.matcher(stmt).find()) {
return true;
}
SQLStatementParser parser =new MySqlStatementParser(stmt);
MySqlInsertStatement statement = (MySqlInsertStatement) parser.parseStatement();
String tableName= statement.getTableName().getSimpleName();
TableConfig tableConfig= schema.getTables().get(tableName.toUpperCase());
if(tableConfig==null) {
return false;
}
if(tableConfig.isAutoIncrement())View on GitHub (pinned to 65f8d8beb7)