{"record":{"id":"2cfc99a483b4a1b2","repo":"MyCATApache/Mycat-Server","slug":"sub-table-not-exists-for-on-2cfc99","errorCode":null,"errorMessage":" sub table not exists for  on ","messagePattern":" sub table not exists for  on ","errorType":"exception","errorClass":"SQLSyntaxErrorException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/route/parser/druid/impl/DruidInsertParser.java","lineNumber":291,"sourceCode":"\t\t\t\t\tnodeValuesMap.get(nodeIndex).add(valueClause);\n\t\t\t\t}\n\n\n\t\t\t\tRouteResultsetNode[] nodes = new RouteResultsetNode[nodeValuesMap.size()];\n\t\t\t\tint count = 0;\n\t\t\t\tfor(Map.Entry<Integer,List<ValuesClause>> node : nodeValuesMap.entrySet()) {\n\t\t\t\t\tInteger nodeIndex = node.getKey();\n\t\t\t\t\tList<ValuesClause> valuesList = node.getValue();\n\t\t\t\t\tinsertStmt.getValuesList().clear();\n\t\t\t\t\tinsertStmt.getValuesList().addAll(valuesList);\n\t\t\t\t\t// insertStmt.setValuesList(valuesList);\n\t\t\t\t\tif(tableConfig.isDistTable()) {\n\t\t\t\t\t\tnodes[count] = new RouteResultsetNode(tableConfig.getDataNodes().get(0),\n\t\t\t\t\t\t\t\trrs.getSqlType(),insertStmt.toString());\n\t\t\t\t\t\tif(tableConfig.getDistTables()==null){\n\t\t\t\t\t\t\tString msg = \" sub table not exists for \" + nodes[count].getName() + \" on \" + tableName;\n\t\t\t\t\t\t\tLOGGER.error(\"DruidMycatRouteStrategyError \" + msg);\n\t\t\t\t\t\t\tthrow new SQLSyntaxErrorException(msg);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tString subTableName = tableConfig.getDistTables().get(nodeIndex);\n\t\t\t\t\t\t\n\t\t\t\t\t\tnodes[count].setSubTableName(subTableName);\n\t\t\t\t\t\tSQLInsertStatement insertStatement = (SQLInsertStatement) insertStmt;\n\t\t\t\t\t\tSQLExprTableSource tableSource = insertStatement.getTableSource();\n\t\t\t\t\t\t//getDisTable 修改表名称\n\t\t\t\t\t\tSQLIdentifierExpr sqlIdentifierExpr = new SQLIdentifierExpr();\n\t\t\t\t\t\tsqlIdentifierExpr.setParent(tableSource.getParent());\n\t\t\t\t\t\tsqlIdentifierExpr.setName(subTableName);\n\t\t\t\t\t\tSQLExprTableSource from2 = new SQLExprTableSource(sqlIdentifierExpr);\n\t\t\t\t\t\tinsertStatement.setTableSource(from2);\n\t\t\t\t\t\tnodes[count].setStatement(insertStatement.toString());\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnodes[count] = new RouteResultsetNode(tableConfig.getDataNodes().get(nodeIndex),\n\t\t\t\t\t\t\t\trrs.getSqlType(),insertStmt.toString());\n\t\t\t\t\t}\n\t\t\t\t\t","sourceCodeStart":273,"sourceCodeEnd":309,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/route/parser/druid/impl/DruidInsertParser.java#L273-L309","documentation":"For a distributed (dist) table, parserBatchInsert routes to the first datanode and then looks up the physical sub-table name via tableConfig.getDistTables().get(nodeIndex). If getDistTables() is null — the dist table mapping is not configured — it throws SQLSyntaxErrorException stating the sub table doesn't exist for the datanode on the logical table.","triggerScenarios":"statementParse -> parserBatchInsert on an INSERT into a tableConfig.isDistTable()==true table where schema.xml defines the table as distTable but the distTables sub-table list is missing/null.","commonSituations":"Incomplete schema.xml: table marked with distTable attribute but sub-table mappings not generated/declared; typo in the table name so config loaded partially; copying a dist-table config to a cluster where sub-tables were never created.","solutions":["Add the distTables configuration (sub-table name list) for the table in schema.xml and reload MyCat","Verify the table definition actually is a dist table; if not, remove the isDistTable/distTable flag","Confirm the target datanode's physical schema contains the expected sub-table","Re-run the dist table setup/migration script that registers sub-tables"],"exampleFix":"// before (schema.xml)\n<table name=\"order\" distTable=\"true\" dataNode=\"dn1\"/>\n// after\n<table name=\"order\" distTable=\"true\" dataNode=\"dn1\">\n  <childTable name=\"order_0\"/><childTable name=\"order_1\"/>\n</table>","handlingStrategy":"validation","validationCode":"TableConfig tc = schema.getTables().get(table.toUpperCase()); if (tc != null && tc.isDistTable() && tc.getDistTables() == null) throw new IllegalStateException(\"distTables not configured\");","typeGuard":null,"tryCatchPattern":"try { route(sql); } catch (SQLSyntaxErrorException e) { if (e.getMessage().contains(\"sub table not exists\")) { reloadSchemaConfig(); } else throw e; }","preventionTips":["Validate schema.xml at startup: every distTable must have distTables mappings","Keep a smoke-test INSERT per logical table in CI","Version-control schema.xml and review dist-table changes","Reload MyCat config after edits before running writes"],"tags":["sql","sharding","configuration","dist-table"],"backgroundTag":"missing-required-config-field","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"}