{"record":{"id":"f27cd20554aec280","repo":"MyCATApache/Mycat-Server","slug":"sub-table-not-exists-for-on","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/impl/DruidMycatRouteStrategy.java","lineNumber":522,"sourceCode":"\t\t}\n\t\trrs.setNodes(nodes);\n\n\t\t//分表\n\t\t/**\n\t\t *  subTables=\"t_order$1-2,t_order3\"\n\t\t *目前分表 1.6 开始支持 幵丏 dataNode 在分表条件下只能配置一个，分表条件下不支持join。\n\t\t */\n\t\tif(rrs.isDistTable()){\n\t\t\treturn this.routeDisTable(statement,rrs);\n\t\t}\n\t\treturn rrs;\n\t}\n\n\tprivate SQLExprTableSource getDisTable(SQLTableSource tableSource,RouteResultsetNode node) throws SQLSyntaxErrorException{\n\t\tif(node.getSubTableName()==null){\n\t\t\tString msg = \" sub table not exists for \" + node.getName() + \" on \" + tableSource;\n\t\t\tLOGGER.error(\"DruidMycatRouteStrategyError \" + msg);\n\t\t\tthrow new SQLSyntaxErrorException(msg);\n\t\t}\n\n\t\tSQLIdentifierExpr sqlIdentifierExpr = new SQLIdentifierExpr();\n\t\tsqlIdentifierExpr.setParent(tableSource.getParent());\n\t\tsqlIdentifierExpr.setName(node.getSubTableName());\n\t\tSQLExprTableSource from2 = new SQLExprTableSource(sqlIdentifierExpr);\n\t\treturn from2;\n\t}\n\n\tprivate RouteResultset routeDisTable(SQLStatement statement, RouteResultset rrs) throws SQLSyntaxErrorException{\n\t\tSQLTableSource tableSource = null;\n\t\tif(statement instanceof SQLInsertStatement) {\n\t\t\tSQLInsertStatement insertStatement = (SQLInsertStatement) statement;\n\t\t\ttableSource = insertStatement.getTableSource();\n\t\t\tfor (RouteResultsetNode node : rrs.getNodes()) {\n\t\t\t\tSQLExprTableSource from2 = getDisTable(tableSource, node);\n\t\t\t\tinsertStatement.setTableSource(from2);\n\t\t\t\tnode.setStatement(insertStatement.toString());","sourceCodeStart":504,"sourceCodeEnd":540,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/route/impl/DruidMycatRouteStrategy.java#L504-L540","documentation":"When expanding an ER-distributed (child/sharded) table in a FROM clause, Mycat rewrites the table source into concrete sub-table names taken from each route node's subTableName. If a route node lacks a sub-table name (e.g. the parent/child relation was not resolved during routing), getDisTable throws indicating the sub table does not exist for that node.","triggerScenarios":"Executing SQL against a child table in an ER relation where a RouteResultsetNode's getSubTableName() is null during the from-clause rewrite (getDisTable, called from from2).","commonSituations":"Broken ER (foreign-key) configuration in schema.xml; queries joining child tables without the parent relation key; data nodes where the child sub-table was never created by the ER distribution.","solutions":["Verify childTable/parent (joinKey/parentKey) ER configuration in schema.xml is complete and correct.","Ensure the query includes the join key so the router can resolve which sub-table each node maps to.","Create the missing sub-tables on the relevant datanodes (check backend MySQL for missing child tables).","Enable Mycat's auto ER table creation or run the schema init scripts for the ER relation."],"exampleFix":"// before (schema.xml)\n<table name=\"order_item\" dataNode=\"dn1\" />\n// after (ER child table properly configured)\n<table name=\"order_item\" dataNode=\"dn1,dn2\" joinKey=\"order_id\" parentKey=\"id\" />","handlingStrategy":"validation","validationCode":"// verify ER child tables exist on all datanodes before querying\nfor (String dn : childTable.getChildNodes()) {\n    if (!backendTableExists(dn, childTable.getSubTableName(parentNode))) {\n        throw new IllegalStateException(\"Missing sub-table on datanode \" + dn);\n    }\n}","typeGuard":null,"tryCatchPattern":"try { rrs = route(sql); } catch (SQLSyntaxErrorException e) {\n    if (e.getMessage().contains(\"sub table not exists for\")) {\n        log.error(\"ER sub-table missing; check schema.xml joinKey/parentKey and backend DDL\", e);\n        throw e;\n    } else throw e;\n}","preventionTips":["Verify childTable/joinKey/parentKey ER settings in schema.xml.","Create all ER sub-tables on every mapped datanode (use Mycat's ER init scripts).","Always include the ER join key in queries against child tables.","Run automated checks that backend sub-tables exist after schema changes."],"tags":["sql","er-table","configuration"],"backgroundTag":"resource-not-found","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"}