{"record":{"id":"300f0fc24ff214c1","repo":"MyCATApache/Mycat-Server","slug":"s-er","errorCode":null,"errorMessage":"%s包含不是ER分片的表","messagePattern":"(.+?)包含不是ER分片的表","errorType":"exception","errorClass":"java.sql.SQLNonTransientException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/route/util/RouterUtil.java","lineNumber":2039,"sourceCode":"\t\t\t\t\t\tif(processedInsert==false){\r\n\t\t\t\t\t\t\tRouteResultset executeRrs = RouterUtil.routeToSingleNode(rrs, result, origSQL);\r\n\t\t\t\t\t\t\tsc.getSession2().execute(executeRrs, ServerParse.INSERT);\r\n\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\t@Override\r\n\t\t\t\t\tpublic void onFailure(Throwable t) {\r\n\t\t\t\t\t\tStringBuilder s = new StringBuilder();\r\n\t\t\t\t\t\tLOGGER.warn(s.append(sc.getSession2()).append(origSQL).toString() +\r\n\t\t\t\t\t\t\t\t\" err:\" + t.getMessage());\r\n\t\t\t\t\t\tsc.writeErrMessage(ErrorCode.ER_PARSE_ERROR, t.getMessage() + \" \" + s.toString());\r\n\t\t\t\t\t}\r\n\t\t\t\t}, MycatServer.getInstance().\r\n\t\t\t\t\t\tgetListeningExecutorService());\r\n\r\n\t\t\t} else if(erFlag) {\r\n\t\t\t\tthrow new SQLNonTransientException(String.format(\"%s包含不是ER分片的表\", origSQL));\r\n\t\t\t}\r\n\t\t}\r\n\r\n\r\n\t\treturn erFlag;\r\n\t}\r\n\r\n\t/**\r\n\t * 寻找joinKey的索引\r\n\t *\r\n\t * @param columns\r\n\t * @param joinKey\r\n\t * @return -1表示没找到，>=0表示找到了\r\n\t */\r\n\tprivate static int getJoinKeyIndex(List<SQLExpr> columns, String joinKey) {\r\n\t\tfor (int i = 0; i < columns.size(); i++) {\r\n\t\t\tString col = StringUtil.removeBackquote(columns.get(i).toString()).toUpperCase();\r\n\t\t\tif (col.equals(joinKey)) {\r","sourceCodeStart":2021,"sourceCodeEnd":2057,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/route/util/RouterUtil.java#L2021-L2057","documentation":"In the ER batch-insert routing flow, erFlag is set when the statement mix looks like an ER (global/ER-consistency) insert, but validation finds that the statement set includes tables that are not part of any ER relationship. Mycat cannot guarantee cross-shard consistency for such a mix, so it aborts with SQLNonTransientException '%s包含不是ER分片的表' ('%s contains tables that are not ER-sharded').","triggerScenarios":"routeByER returns true for erFlag, yet one or more tables in the multi-table/batch statement are ordinary (non-childTable, non-ER-group) tables in schema.xml; the check after the per-statement loop throws.","commonSituations":"Mixed multi-statement batches inserting into both ER and non-ER tables; schema.xml where only some joined tables are declared as childTable; renaming/adding a table to an ER group without updating all related tables; sending several INSERTs in one packet assuming Mycat handles them transactionally as ER.","solutions":["Separate statements touching non-ER tables from the ER batch and send them individually","Declare all related tables in schema.xml as part of the ER relationship (childTable with parentKey/joinKey) if they belong together","Remove the non-ER table from the batched statement set","Review how erFlag is set — ensure only genuine ER inserts go through this routing path"],"exampleFix":"// before (one batch, mixed tables)\nINSERT INTO orders(...) VALUES(...); INSERT INTO t_global(...) VALUES(...);\n// after: send ER insert alone\nINSERT INTO orders(...) VALUES(...);  // then separately\nINSERT INTO t_global(...) VALUES(...);","handlingStrategy":"validation","validationCode":"// Before batching statements, verify every target table is part of an ER relationship\nfor (String t : targetTables) {\n    if (!erTables.contains(t)) throw new IllegalStateException(\"non-ER table \" + t + \" cannot be in an ER batch\");\n}","typeGuard":null,"tryCatchPattern":"catch (SQLNonTransientException e) { if (e.getMessage().endsWith(\"包含不是ER分片的表\")) { /* split batch by ER membership and resend */ } throw e; }","preventionTips":["Keep ER groups complete in schema.xml — declare every related table as childTable","Group outbound statements by ER membership before batching","After schema changes, re-verify which tables participate in ER routing"],"tags":["er-table","batch","mixed-tables","routing","consistency"],"backgroundTag":"unsupported-operation","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"}