{"record":{"id":"d3c09b37335c8f03","repo":"MyCATApache/Mycat-Server","slug":"er-parse-error-d3c09b","errorCode":"ER_PARSE_ERROR","errorMessage":"msg == null ? e.getClass().getSimpleName() : msg","messagePattern":"msg == null \\? e\\.getClass\\(\\)\\.getSimpleName\\(\\) : msg","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/server/handler/ExplainHandler.java","lineNumber":156,"sourceCode":"\t\t\tc.writeErrMessage(ErrorCode.ER_BAD_DB_ERROR, \"Unknown database '\"\n\t\t\t\t\t+ db + \"'\");\n\t\t\treturn null;\n\t\t}\n\t\ttry {\n\n            if(ServerParse.INSERT==sqlType&&isMycatSeq(stmt, schema))\n            {\n                c.writeErrMessage(ErrorCode.ER_PARSE_ERROR, \"insert sql using mycat seq,you must provide primaryKey value for explain\");\n                return null;\n            }\n            SystemConfig system = MycatServer.getInstance().getConfig().getSystem();\n            return MycatServer.getInstance().getRouterservice()\n\t\t\t\t\t.route(system,schema, sqlType, stmt, c.getCharset(), c);\n\t\t} catch (Exception e) {\n\t\t\tStringBuilder s = new StringBuilder();\n\t\t\tlogger.warn(s.append(c).append(stmt).toString()+\" error:\"+ e);\n\t\t\tString msg = e.getMessage();\n\t\t\tc.writeErrMessage(ErrorCode.ER_PARSE_ERROR, msg == null ? e\n\t\t\t\t\t.getClass().getSimpleName() : msg);\n\t\t\treturn null;\n\t\t}\n\t}\n\n    private static boolean isMycatSeq(String stmt, SchemaConfig schema)\n    {\n        if(pattern.matcher(stmt).find()) {\n\t\t\treturn true;\n\t\t}\n        SQLStatementParser parser =new MySqlStatementParser(stmt);\n        MySqlInsertStatement statement = (MySqlInsertStatement) parser.parseStatement();\n        String tableName=   statement.getTableName().getSimpleName();\n        TableConfig tableConfig= schema.getTables().get(tableName.toUpperCase());\n        if(tableConfig==null) {\n\t\t\treturn false;\n\t\t}\n        if(tableConfig.isAutoIncrement())","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/server/handler/ExplainHandler.java#L138-L174","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nEXPLAIN INSERT INTO t_seq VALUES (NEXT VALUE FOR MYCATSEQ_GLOBAL); // malformed sequence usage -> router exception\n// after\n// configure the sequence in sequence_conf.properties / rule.xml, then:\nEXPLAIN INSERT INTO t_seq (name) VALUES ('a');","handlingStrategy":"try-catch","validationCode":"// verify target table is routable before issuing EXPLAIN\nString table = resolveTableName(stmt);\nif (!mycatSchemaTables.contains(table)) {\n    System.err.println(\"cannot EXPLAIN: table missing from schema.xml: \" + table);\n}","typeGuard":null,"tryCatchPattern":"try (Statement st = conn.createStatement()) {\n    st.execute(\"EXPLAIN \" + sql);\n} catch (SQLException e) {\n    if (e.getErrorCode() == 1064) {\n        // Mycat router rejected the explained statement; read server.log 'error:' line\n        LOGGER.error(\"EXPLAIN routing failed for: \" + sql, e);\n    } else {\n        throw e;\n    }\n}","preventionTips":["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."],"tags":["sql","explain","routing","mysql"],"backgroundTag":"sql-query-failed","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}