{"record":{"id":"cc3416c528187975","repo":"MyCATApache/Mycat-Server","slug":"can-t-find-table-define-in-schema-tablename-cc3416","errorCode":null,"errorMessage":"can't find table define in schema  + tableName +  schema: + schema.getName()","messagePattern":"can't find table define in schema  \\+ tableName \\+  schema: \\+ schema\\.getName\\(\\)","errorType":"exception","errorClass":"SQLNonTransientException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/route/util/RouterUtil.java","lineNumber":1611,"sourceCode":"\t\treturn nodes;\r\n\t}\r\n\r\n\t/**\r\n\t * 处理分库表路由\r\n\t */\r\n\tpublic static void findRouteWithcConditionsForTables(SchemaConfig schema, RouteResultset rrs,\r\n\t\t\tMap<String, Map<String, Set<ColumnRoutePair>>> tablesAndConditions,\r\n\t\t\tMap<String, Set<String>> tablesRouteMap, String sql, LayerCachePool cachePool, boolean isSelect)\r\n\t\t\tthrows SQLNonTransientException {\r\n\r\n\t\t//为分库表找路由\r\n\t\tfor(Map.Entry<String, Map<String, Set<ColumnRoutePair>>> entry : tablesAndConditions.entrySet()) {\r\n\t\t\tString tableName = entry.getKey().toUpperCase();\r\n\t\t\tTableConfig tableConfig = schema.getTables().get(tableName);\r\n\t\t\tif(tableConfig == null) {\r\n\t\t\t\tString msg = \"can't find table define in schema \"\r\n\t\t\t\t\t\t+ tableName + \" schema:\" + schema.getName();\r\n\t\t\t\tLOGGER.warn(msg);\r\n\t\t\t\tthrow new SQLNonTransientException(msg);\r\n\t\t\t}\r\n\t\t\tif(tableConfig.getDistTables()!=null && tableConfig.getDistTables().size()>0){\r\n\t\t\t    routeToDistTableNode(schema,rrs,sql, tablesAndConditions, cachePool,isSelect, entry);\r\n\t\t\t}\r\n\t\t\t//全局表或者不分库的表略过（全局表后面再计算）\r\n\t\t\tif(tableConfig.isGlobalTable() || schema.getTables().get(tableName).getDataNodes().size() == 1) {\r\n\t\t\t\tcontinue;\r\n\t\t\t} else {//非全局表：分库表、childTable、其他\r\n\t\t\t\tMap<String, Set<ColumnRoutePair>> columnsMap = entry.getValue();\r\n\t\t\t\tString joinKey = tableConfig.getJoinKey();\r\n\t\t\t\tString partionCol = tableConfig.getPartitionColumn();\r\n\t\t\t\tString primaryKey = tableConfig.getPrimaryKey();\r\n\t\t\t\tboolean isFoundPartitionValue = partionCol != null && entry.getValue().get(partionCol) != null;\r\n\t\t\t\tboolean isLoadData=false;\r\n\t\t\t\tif (LOGGER.isDebugEnabled()\r\n\t\t\t\t\t\t&& sql.startsWith(LoadData.loadDataHint)||rrs.isLoadData()) {\r\n\t\t\t\t\t//由于load data一次会计算很多路由数据，如果输出此日志会极大降低load data的性能\r","sourceCodeStart":1593,"sourceCodeEnd":1629,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/route/util/RouterUtil.java#L1593-L1629","documentation":"RouterUtil iterates over tablesAndConditions (table -> column conditions) during multi-table route calculation and looks up each table's TableConfig in the schema. Any table not declared in schema.xml (lookup is done on the uppercased name) causes a SQLNonTransientException, since MyCat cannot route tables it has no definition for.","triggerScenarios":"Executing a JOIN/multi-table query where at least one referenced table has no <table> entry in the current MyCat schema; lookup key is the uppercased table name from the parsed SQL.","commonSituations":"Joining against a table present only in backend MySQL; case mismatch between SQL table name and schema.xml declaration; wrong schema selected; table added to DB but config never reloaded.","solutions":["Declare every table referenced in the query in schema.xml and reload MyCat","Match table-name case with the schema.xml declaration (MyCat uppercases for lookup)","Add a schema-level default dataNode as fallback for undeclared tables","Verify the connection's logical schema contains all tables your SQL references"],"exampleFix":"// before\nSELECT * FROM orders o JOIN items i ON ...; // 'items' undeclared\n// after (schema.xml)\n<table name=\"items\" dataNode=\"dn1\"/>","handlingStrategy":"validation","validationCode":"// verify all tables referenced by a join are declared in MyCat\nfor (String t : List.of(\"ORDERS\",\"ITEMS\")) {\n    ResultSet rs = stmt.executeQuery(\"SHOW TABLES LIKE '\" + t + \"'\");\n    if (!rs.next()) throw new IllegalStateException(\"Table not in MyCat schema: \" + t);\n}","typeGuard":null,"tryCatchPattern":"try {\n    execute(joinSql);\n} catch (SQLNonTransientException e) {\n    if (e.getMessage().startsWith(\"can't find table define in schema\"))\n        throw new IllegalStateException(\"Declare all joined tables in schema.xml\", e);\n    throw e;\n}","preventionTips":["Keep every join participant declared in schema.xml","Normalize table-name case in SQL generation (uppercase) to match MyCat lookups","Run a config-completeness test comparing schema.xml tables against DB tables in CI"],"tags":["sql","routing","join","schema-config"],"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-23T08:17:48.524Z"}