{"record":{"id":"5970ebfd98f44e9e","repo":"apache/shardingsphere","slug":"41","errorCode":"41","errorMessage":"Can not get route result, please check your sharding rule configuration.","messagePattern":"Can not get route result, please check your sharding rule configuration\\.","errorType":"exception","errorClass":"EmptyShardingRouteResultException","httpStatus":null,"severity":"error","filePath":"features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingPrepareRouteContextChecker.java","lineNumber":40,"sourceCode":"import org.apache.shardingsphere.infra.route.context.RouteContext;\nimport org.apache.shardingsphere.infra.route.context.RouteUnit;\nimport org.apache.shardingsphere.infra.session.query.QueryContext;\nimport org.apache.shardingsphere.sharding.exception.connection.EmptyShardingRouteResultException;\nimport org.apache.shardingsphere.sharding.exception.syntax.UnsupportedPrepareRouteToSameDataSourceException;\nimport org.apache.shardingsphere.sharding.route.engine.checker.ShardingRouteContextChecker;\nimport org.apache.shardingsphere.sharding.rule.ShardingRule;\n\nimport java.util.stream.Collectors;\n\n/**\n * Sharding prepare route context checker.\n */\npublic final class ShardingPrepareRouteContextChecker implements ShardingRouteContextChecker {\n    \n    @Override\n    public void check(final ShardingRule shardingRule, final QueryContext queryContext, final ShardingSphereDatabase database, final ConfigurationProperties props, final RouteContext routeContext) {\n        if (routeContext.getRouteUnits().isEmpty()) {\n            throw new EmptyShardingRouteResultException();\n        }\n        if (routeContext.getRouteUnits().stream().collect(Collectors.groupingBy(RouteUnit::getDataSourceMapper)).entrySet().stream().anyMatch(each -> each.getValue().size() > 1)) {\n            throw new UnsupportedPrepareRouteToSameDataSourceException();\n        }\n    }\n}\n","sourceCodeStart":22,"sourceCodeEnd":47,"githubUrl":"https://github.com/apache/shardingsphere/blob/e952770a215630a3659c75d64369168cd3e26b82/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingPrepareRouteContextChecker.java#L22-L47","documentation":"EmptyShardingRouteResultException is thrown by ShardingPrepareRouteContextChecker when a PREPARE/distributed-preparation statement finishes routing with zero route units. For prepared statements ShardingSphere requires at least one concrete route target; if the sharding conditions eliminate every data node (for example an always-false condition or a sharding key value that matches no actual node), the route result is empty and the statement is rejected with 'Can not get route result, please check your sharding rule configuration.'","triggerScenarios":"A PREPARE statement whose RouteContext has no RouteUnits after routing: sharding key predicate matches no configured actual data node, a contradictory WHERE on the sharding column, or a rule/algorithm configuration that yields no mappings for the given sharding values.","commonSituations":"Using server-side PREPARE (or drivers that use it) with a sharding value outside the algorithm's range (e.g. inline expression ds_${id % 4} with a non-numeric or out-of-range value), or after editing sharding rules so the statement's tables no longer route anywhere.","solutions":["Check the sharding rule for the prepared statement's tables: confirm the sharding column, algorithm, and actualDataNodes actually cover the bound parameter values.","Verify the PREPARE parameters: parameter markers must be bound before execution so sharding conditions can be derived; ensure you PREPARE with types/values the sharding algorithm supports.","Test the equivalent SELECT/DELETE with literal values — if it also returns no route, the rule (not PREPARE) is the problem.","If the table is not intended to be sharded, remove it from the sharding rule or use a default sharding strategy."],"exampleFix":"-- before: value outside inline algorithm range\nPREPARE p AS DELETE FROM t_order WHERE order_id = ?;\nSET @id = 99999;  -- id % 4 is fine, but e.g. non-numeric binding fails routing\n\n-- after: bind a value the sharding algorithm can evaluate\nPREPARE p AS DELETE FROM t_order WHERE order_id = ?;\nSET @id = 101;  -- order_id % 4 -> ds_1.t_order_1\nEXECUTE p USING @id;","handlingStrategy":"validation","validationCode":"// Before PREPARE, verify the sharding value maps to at least one actual data node\nObject shardingValue = params[0];\nCollection<DataNode> nodes = shardingRule.getShardingTable(\"t_order\")\n        .map(t -> t.getActualDataNodes()).orElse(Collections.emptyList());\nif (nodes.isEmpty()) { throw new IllegalStateException(\"No actual data nodes for t_order\"); }\n// additionally smoke-test the literal form:\n// SELECT 1 FROM t_order WHERE order_id = <literal> LIMIT 1","typeGuard":null,"tryCatchPattern":"try {\n    connection.prepareStatement(\"...\", RETURN_GENERATED_KEYS);\n} catch (final EmptyShardingRouteResultException ex) {\n    // log sharding key + params; surface 'check sharding rule configuration' to operator\n}","preventionTips":["Always bind parameters before executing PREPARE so sharding conditions are derivable.","Validate sharding-key values against the algorithm's domain (range, type) in application code.","Add integration tests for each PREPARE statement against the real rule set."],"tags":["sharding","prepare","routing","empty-result","configuration"],"backgroundTag":null,"analyzedSha":"e952770a215630a3659c75d64369168cd3e26b82","analyzedAt":"2026-08-14T13:54:53.392Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}