You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "somiljain2006 (via GitHub)" <gi...@apache.org> on 2026/03/20 06:14:16 UTC
[PR] Fix incorrect routing when irrelevant sharding conditions are present [shardingsphere]
somiljain2006 opened a new pull request, #38527:
URL: https://github.com/apache/shardingsphere/pull/38527
Fixes #38456
Changes proposed in this pull request:
- Fix incorrect routing behavior when irrelevant ShardingConditions are present in ShardingStandardRouteEngine.
- Filter sharding conditions to include only those relevant to the current logical table or its binding table group.
- Prevent unnecessary full routing (route explosion) caused by conditions belonging to unrelated tables
- Preserve original routing semantics by evaluating each relevant condition independently and merging results
- If no relevant conditions are found, routing falls back to full routing or hint-based routing as before.
- Add regression tests to verify:
1. Mixed relevant and irrelevant conditions do not trigger full routing.
2. Subquery scenarios do not cause route explosion.
3. Correct fallback when no relevant conditions exist.
---
Before committing this PR, I'm sure that I have checked the following options:
- [ ] My code follows the [code of conduct](https://shardingsphere.apache.org/community/en/involved/conduct/code/) of this project.
- [ ] I have self-reviewed the commit code.
- [ ] I have (or in the comment I request) added corresponding labels for the pull request.
- [ ] I have passed maven check locally: `./mvnw clean install -B -T1C -Dmaven.javadoc.skip -Dmaven.jacoco.skip -e`.
- [ ] I have made corresponding changes to the documentation.
- [ ] I have added corresponding unit tests for my changes.
- [ ] I have updated the Release Notes of the current development version. For more details, see [Update Release Note](https://shardingsphere.apache.org/community/en/involved/contribute/contributor/)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix incorrect routing when irrelevant sharding conditions are present [shardingsphere]
Posted by "somiljain2006 (via GitHub)" <gi...@apache.org>.
somiljain2006 commented on PR #38527:
URL: https://github.com/apache/shardingsphere/pull/38527#issuecomment-4106957686
@terrymanu All P1 issues have been addressed with additional regression and validation tests:
1. Full Pipeline Regression Validation
All new tests use ShardingRouteAssert.assertRoute(sql, params), which executes the complete routing pipeline.
Each test now asserts routeContext.getRouteUnits().size() == 1, ensuring the subquery routing no longer causes route explosion.
2. Issue Reproduction Test
Added assertRouteWithConditionsFromNonBindingSubqueryTable, which reproduces the reported issue scenario using a non-binding (broadcast) table in a subquery and verifies correct single-shard routing.
3. Binding Table Validation
Added assertBindingTableSubqueryDoesNotBreakRouting to confirm that binding-table conditions are still correctly treated as relevant by isConditionRelevantToTable().
4. Hint Precedence Validation
Added assertHintRoutingWithIrrelevantSubqueryConditions to verify that Hint-based routing remains unaffected by irrelevant SQL conditions.
5. Shared-Path / Complex Routing Coverage
Added assertComplexRouteWithIrrelevantSubquery to validate that the same filtering logic works correctly in JOIN scenarios and does not impact ShardingComplexRouteEngine.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix incorrect routing when irrelevant sharding conditions are present [shardingsphere]
Posted by "somiljain2006 (via GitHub)" <gi...@apache.org>.
somiljain2006 commented on PR #38527:
URL: https://github.com/apache/shardingsphere/pull/38527#issuecomment-4124979116
@terrymanu Thanks for the detailed review.
All P1 concerns have been addressed with an updated test suite that aligns with the reported #38456 scenario and exercises the full routing path:
1. Full-chain reproduction: Removed the previous t_category/MySQL-based cases. Added a PostgreSQL-based regression test (assertFullChainNonBindingSubqueryProducesSingleRoute) using two non-binding sharding tables (t_user and t_order_non_binding). This test goes through SQLParser -> SQLBindEngine -> WhereClauseShardingConditionEngine -> SQLRouteEngine and verifies that the final RouteContext contains exactly one route unit.
2. Shared-path coverage: Added assertComplexRouteWithIrrelevantSubquery to validate that the change in ShardingStandardRouteEngine does not impact ShardingComplexRouteEngine behavior when binding tables and non-binding subqueries coexist.
3. Hint precedence: Added assertHintRoutingWithIrrelevantSubqueryConditions to confirm that HintManager routing remains unaffected in the presence of irrelevant subquery-derived conditions.
4. Binding-table safety: Added assertBindingTableSubqueryDoesNotBreakRouting to ensure that valid binding-table conditions are still recognized and merged correctly.
Additionally, all newly added tests now use sharding tables that actually produce ShardingConditions, so the filtering branch introduced in ShardingStandardRouteEngine is exercised directly.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix incorrect routing when irrelevant sharding conditions are present [shardingsphere]
Posted by "somiljain2006 (via GitHub)" <gi...@apache.org>.
somiljain2006 commented on PR #38527:
URL: https://github.com/apache/shardingsphere/pull/38527#issuecomment-4096777259
@terrymanu Can you please review this pr?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix incorrect routing when irrelevant sharding conditions are present [shardingsphere]
Posted by "terrymanu (via GitHub)" <gi...@apache.org>.
terrymanu merged PR #38527:
URL: https://github.com/apache/shardingsphere/pull/38527
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org