{"record":{"id":"5829eed1cbb5730e","repo":"MyCATApache/Mycat-Server","slug":"can-t-find-root-parent-sharding-node-for-sql","errorCode":null,"errorMessage":"can't find (root) parent sharding node for sql:","messagePattern":"can't find \\(root\\) parent sharding node for sql:","errorType":"exception","errorClass":"SQLNonTransientException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/route/parser/druid/impl/DruidInsertParser.java","lineNumber":164,"sourceCode":"\t\t}\n\n\t\t// route by sql query root parent's datanode\n\t\tString findRootTBSql = tc.getLocateRTableKeySql().toLowerCase() + joinKeyVal;\n\t\tif (LOGGER.isDebugEnabled()) {\n\t\t\tLOGGER.debug(\"find root parent's node sql \"+ findRootTBSql);\n\t\t}\n\n\t\tString dn = null;\n\t\tif (tc.getRootParent().getFetchStoreNodeByJdbc()) {\n\t\t\tJDBCFetchStoreNodeOfChildTableHandler jdbcFetchHandler = new JDBCFetchStoreNodeOfChildTableHandler();\n\t\t\tdn = jdbcFetchHandler.execute(schema.getName(),findRootTBSql, tc.getRootParent().getDataNodes());\n\t\t} else {\n\t\t\tFetchStoreNodeOfChildTableHandler FetchHandler = new FetchStoreNodeOfChildTableHandler();\n\t\t\tFetchHandler.execute(schema.getName(),findRootTBSql, tc.getRootParent().getDataNodes());\n\t\t}\n\n\t\tif (dn == null) {\n\t\t\tthrow new SQLNonTransientException(\"can't find (root) parent sharding node for sql:\"+ sql);\n\t\t}\n\t\tif (LOGGER.isDebugEnabled()) {\n\t\t\tLOGGER.debug(\"found partion node for child table to insert \"+ dn + \" sql :\" + sql);\n\t\t}\n\t\treturn RouterUtil.routeToSingleNode(rrs, dn, sql);\n\t}\n\t\n\t/**\n\t * 单条insert（非批量）\n\t * @param schema\n\t * @param rrs\n\t * @param partitionColumn\n\t * @param tableName\n\t * @param insertStmt\n\t * @throws SQLNonTransientException\n\t */\n\tprivate void parserSingleInsert(SchemaConfig schema, RouteResultset rrs, String partitionColumn,\n\t\t\tString tableName, MySqlInsertStatement insertStmt) throws SQLNonTransientException {","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/route/parser/druid/impl/DruidInsertParser.java#L146-L182","documentation":"To route a child-table insert, Mycat runs findRootTBSql (a SELECT on the root parent table using the join value) via FetchStoreNodeOfChildTableHandler against the root parent's dataNodes to learn which node holds the parent row. If that lookup returns null (parent row not found or not yet visible), the insert cannot be placed and this SQLNonTransientException is thrown.","triggerScenarios":"INSERT into a childTable whose joinKey value references a parent row that does not exist, was just inserted in the same uncommitted transaction, or is not visible on the root parent's dataNodes when the lookup executes.","commonSituations":"Referential mistakes: inserting child rows before/without the parent row; parent and child inserts in the same transaction where the lookup cannot see the uncommitted parent; rootParent dataNodes misconfigured in schema.xml so the lookup queries the wrong nodes.","solutions":["Insert the parent row (and commit it) before inserting child rows referencing it.","Verify the childTable's rootParent/dataNodes configuration in schema.xml points at the nodes actually holding the parent table.","Confirm the joinKey value in the child insert matches an existing parent primary/join key value."],"exampleFix":"// before — parent missing\nINSERT INTO order_items (item_id, order_id, qty) VALUES (9, 99999, 2);\n// after — insert parent first, then child\nINSERT INTO orders (id, customer_id) VALUES (99999, 7);\nINSERT INTO order_items (item_id, order_id, qty) VALUES (9, 99999, 2);","handlingStrategy":"validation","validationCode":"// Verify the parent row exists (and is committed) before child insert\n// SELECT node FROM root_parent WHERE join_value = ?  -- via Mycat\nconst exists = await query(\"SELECT 1 FROM orders WHERE id = ?\", [joinValue]);\nif (exists.length === 0) {\n  throw new Error(\"Parent row missing; child insert would fail lookup\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  execute(childInsert);\n} catch (SQLNonTransientException e) {\n  if (e.getMessage().startsWith(\"can't find (root) parent sharding node\")) {\n    // insert parent first, commit, then retry child insert\n  } else { throw e; }\n}","preventionTips":["Always insert and commit parent rows before child rows in ER relationships.","Avoid parent+child inserts in the same uncommitted transaction through Mycat.","Confirm rootParent/dataNodes in schema.xml cover all nodes holding the root parent table."],"tags":["insert","child-table","parent-lookup"],"backgroundTag":"record-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"}