{"record":{"id":"9900f97c6e629a72","repo":"MyCATApache/Mycat-Server","slug":"can-t-find-table-define-in-schema-tablename-alia","errorCode":null,"errorMessage":"can't find table define in schema {tableName} alias：{alias}, schema:{schemaName}","messagePattern":"can't find table define in schema (.+?) alias：(.+?), schema:(.+?)","errorType":"exception","errorClass":"SQLNonTransientException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/route/util/RouterUtil.java","lineNumber":1264,"sourceCode":"\t\tfor(String tableName : tables) {\r\n\r\n\t\t\tTableConfig tableConfig = schema.getTables().get(tableName.toUpperCase());\r\n\r\n\t\t\tif(tableConfig == null) {\r\n\t\t\t\t//add 如果表读取不到则先将表名从别名中读取转化后再读取\r\n\t\t\t\tString alias = ctx.getTableAliasMap().get(tableName);\r\n\t\t\t\tif(!StringUtil.isEmpty(alias)){\r\n\t\t\t\t\ttableConfig = schema.getTables().get(alias.toUpperCase());\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif(tableConfig == null){\r\n\t\t\t\t\tif (StringUtils.isNotEmpty(schema.getDataNode())) {\r\n\t\t\t\t\t\treturn routeToSingleNode(rrs, schema.getDataNode(), ctx.getSql());\r\n\t\t\t\t\t} else {\r\n\t\t\t\t\t\tString msg = \"can't find table define in schema \" + tableName + \" alias：\" + alias + \", schema:\"\r\n\t\t\t\t\t\t\t\t+ schema.getName();\r\n\t\t\t\t\t\tLOGGER.warn(msg);\r\n\t\t\t\t\t\tthrow new SQLNonTransientException(msg);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t}\r\n\t\t\tif(tableConfig.isGlobalTable()) {//全局表\r\n\t\t\t\tif(tablesRouteMap.get(tableName) == null) {\r\n\t\t\t\t\ttablesRouteMap.put(tableName, new HashSet<String>());\r\n\t\t\t\t}\r\n\t\t\t\ttablesRouteMap.get(tableName).addAll(tableConfig.getDataNodes());\r\n\t\t\t} else if(tablesRouteMap.get(tableName) == null) { //余下的表都是单库表\r\n\t\t\t\ttablesRouteMap.put(tableName, new HashSet<String>());\r\n\t\t\t\ttablesRouteMap.get(tableName).addAll(tableConfig.getDataNodes());\r\n\t\t\t}\r\n\r\n\t\t\tif(tableConfig.getDistTables().size() > 0) {\r\n\t\t\t\tMap<String, List<String>> subTablesmap = rrs.getSubTableMaps();\r\n\t\t\t\tif (subTablesmap == null) {\r\n\t\t\t\t\tsubTablesmap = Maps.newHashMap();\r","sourceCodeStart":1246,"sourceCodeEnd":1282,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/route/util/RouterUtil.java#L1246-L1282","documentation":"During SELECT routing, the table (or its alias) could not be matched to a tableConfig, and when the schema has no default dataNode there is nowhere to send the query, so SQLNonTransientException('can't find table define in schema ...') is thrown. It reports the table name, alias, and schema to help locate the config gap.","triggerScenarios":"SELECT statements referencing a table or alias that is not defined in the schema's tables map, where the <schema> element has no dataNode attribute; frequently hit for aliased or non-qualified names the router cannot resolve.","commonSituations":"Querying tables not declared in schema.xml; using aliases/subqueries that confuse table-name resolution; information_schema or system tables not configured; connecting to a schema whose tables are all sharded but the SQL references an undeclared helper table.","solutions":["Declare the missing table in schema.xml (<table name=\"...\" .../>) and reload config","Add dataNode=\"...\" to the <schema> element as a default node for undeclared tables","Qualify the table with the correct schema name or fix aliases so the router can match tableConfig"],"exampleFix":"// before (schema.xml)\n<schema name=\"db\" sqlMaxLimit=\"100\"/>\n// after\n<schema name=\"db\" sqlMaxLimit=\"100\" dataNode=\"dn1\"/>\n  <table name=\"t_config\" dataNode=\"dn1\" type=\"global\"/>","handlingStrategy":"validation","validationCode":"// before querying\nTableConfig tc = schema.getTables().get(tableName);\nif (tc == null && (schema.getDataNode() == null || schema.getDataNode().isEmpty())) {\n  throw new IllegalStateException(\"table \" + tableName + \" not defined in schema \" + schema.getName());\n}","typeGuard":null,"tryCatchPattern":"try { routeSelect(sql); } catch (SQLNonTransientException e) { if (e.getMessage().startsWith(\"can't find table define in schema\")) { /* declare table or set default dataNode */ } throw e; }","preventionTips":["Declare every queryable table in schema.xml","Set a schema-level default dataNode as safety net","Standardize table/alias naming to ease router matching"],"tags":["sql","routing","config"],"backgroundTag":"entity-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"}