You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "strongduanmu (via GitHub)" <gi...@apache.org> on 2026/10/22 11:42:32 UTC
[PR] Fix ORDER BY scope resolution and preserve statement metadata [shardingsphere]
strongduanmu opened a new pull request, #40342:
URL: https://github.com/apache/shardingsphere/pull/40342
Changes proposed in this pull request:
- Resolve `ORDER BY` columns from the current query's FROM scope before searching correlated outer scopes when the projection scope has no match, and restore the temporary scope after binding.
- Preserve SELECT INTO metadata when copying and binding statements, and move LOAD DATA metadata into the shared statement model while preserving the MySQL statement API.
- Add regression coverage for local and outer scope precedence, ambiguous columns, scope restoration, and SELECT statement metadata copying.
Validation: 59 focused binder and statement-model tests passed locally. Scoped Spotless and Checkstyle checks and the repository RAT check passed. Full CI is requested through this pull request's GitHub Actions checks.
AI assistance disclosure: Codex materially assisted with the SQL binder changes, shared SQL statement models, and corresponding regression tests in this pull request.
Please apply the appropriate SQL binder and SQL parser statement labels. No documentation changes are required.
---
Before submitting this PR, I confirm that:
- [x] My code follows the [code of conduct](https://shardingsphere.apache.org/community/en/involved/conduct/code/) of this project.
- [x] I have reviewed my changes.
- [ ] I have (or in comment I request) added corresponding labels for the pull request.
- [ ] I have passed the required local checks: `./mvnw clean install -B -T1C -Pcheck`.
- [x] I have updated the relevant documentation, if applicable.
- [x] I have added or updated unit tests for my changes, if applicable.
- [ ] I have updated the Release Notes of the current development version, if applicable. For more details, see [Update Release Note](https://shardingsphere.apache.org/community/en/involved/contribute/contributor/).
- [x] I have disclosed the tool and affected files or scope for any material AI assistance, as required by the [AI-assisted contribution policy].
[AI-assisted contribution policy]: https://github.com/apache/shardingsphere/blob/master/AI_POLICY.md
--
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] Enhance ORDER BY scope resolution and SQL statement metadata preservation [shardingsphere]
Posted by "FlyingZC (via GitHub)" <gi...@apache.org>.
FlyingZC merged PR #40342:
URL: https://github.com/apache/shardingsphere/pull/40342
--
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] Enhance ORDER BY scope resolution and SQL statement metadata preservation [shardingsphere]
Posted by "strongduanmu (via GitHub)" <gi...@apache.org>.
strongduanmu commented on PR #40342:
URL: https://github.com/apache/shardingsphere/pull/40342#issuecomment-6358545920
### Result
Review Result: Mergeable
The code correctness review passed for commit `a2496a0d4c802a02a14730dc8a15c7a58e6e9e75`, rebased onto upstream master `50cd58771c484f5f6b281a349aff9c3f7c27ffbb`. No blocking issues or recommended changes remain within the reviewed scope.
This records the completed Codex-assisted review and local verification. It is a code-scope assessment, not a maintainer approval or confirmation that all CI checks have passed.
### Behavior and Compatibility
- **ORDER BY resolution:** Projection matches retain precedence. When the projection scope has no matching column, the current query's FROM scope is searched before correlated outer scopes. Reviewed qualified owner lookup, local alias shadowing, ambiguous local columns, genuine outer references, and external table contexts. Non-ORDER BY resolution paths retain their existing behavior.
- **Temporary scope lifecycle:** ORDER BY binding installs the current FROM scope and restores the previous scope in a `finally` block, including failure paths. Nested subqueries create their own binder context, preventing the temporary scope from leaking into nested SELECT binding.
- **SELECT metadata:** The `intoVariables` flag survives both statement copying through `withSubqueryType` and SELECT binding. The rebase conflict was resolved by retaining upstream's inline builder and Optional FROM handling while preserving the flag. Existing callers retain the default `false` behavior.
- **LOAD DATA metadata:** The shared statement model retains the existing MySQL metadata and inherited accessor contracts. The MySQL statement remains final with its existing public constructor, and the binder copies the newly exposed statement and column-list index metadata. This does not introduce new SQL syntax support or activate another dialect.
- **Allocation and lookup changes:** Reverse outer-scope traversal preserves lookup order; variable-name matching remains case-insensitive and short-circuiting. Reusing immutable table-bound metadata does not introduce mutable aliasing. The qualified-function expression retains upstream's equivalent string construction.
- **Release Notes:** The current development version contains two enhancement entries describing ORDER BY scope resolution and statement metadata preservation, both linked to this PR.
### Local Verification
The following focused reactor test command completed with exit code `0` and `BUILD SUCCESS`:
```sh
./mvnw -B \
-pl parser/sql/statement/core,parser/sql/statement/dialect/mysql,infra/binder/core,infra/binder/dialect/mysql \
-am -DskipITs -Dspotless.skip=true -Dcheckstyle.skip=true \
-Dtest=ColumnSegmentBinderTest,OrderBySegmentBinderTest,SelectStatementBinderTest,SelectStatementTest,MySQLLoadDataStatementBinderTest \
-Dsurefire.failIfNoSpecifiedTests=false test
```
Actual executed tests: **64 passed, 0 failures, 0 errors**:
- `ColumnSegmentBinderTest`: 40
- `OrderBySegmentBinderTest`: 3
- `SelectStatementBinderTest`: 20
- `SelectStatementTest`: 1
The MySQL statement and binder modules compiled from current reactor sources. No dedicated `MySQLLoadDataStatementBinderTest` matched the requested filter; the test count above does not claim otherwise.
Spotless and Checkstyle completed with exit code `0` using exact file filters for all 12 Java files changed by the PR. All four owning modules reported zero Checkstyle violations:
- `infra/binder/core`: `ColumnSegmentBinder`, `OrderBySegmentBinder`, `SQLStatementBinderContext`, `SelectStatementBinder`, and the corresponding changed `ColumnSegmentBinderTest`, `OrderBySegmentBinderTest`, and `SelectStatementBinderTest` files.
- `infra/binder/dialect/mysql`: `MySQLLoadDataStatementBinder`.
- `parser/sql/statement/core`: `LoadDataStatement`, `SelectStatement`, and `SelectStatementTest`.
- `parser/sql/statement/dialect/mysql`: `MySQLLoadDataStatement`.
The repository license check also passed with exit code `0`:
```sh
./mvnw apache-rat:check -Pcheck -T1C
```
The only source edit after the functional test and RAT runs joined an expression onto one line without changing its tokens or license header; the final exact-file style checks passed afterward.
### Review Coverage
Two mutually blind independent assessments covered all 13 changed files, including `RELEASE-NOTES.md`, through root-cause and behavior analysis, affected contracts and consumers, tests and runtime behavior, and a final convergence pass. Their reports were substantively checked and reconciled; no unresolved differences or outcome-sensitive evidence gaps remain.
The comparison with the original PR commit `dcd60e594a85cc58f03733f8247f654bd4720351` confirmed that the synchronization preserved the proposed behavior while adapting to upstream's SELECT builder relocation and qualified-function expression changes. The additional task changes were the enhancement-focused commit/title and Release Note entries.
Direct static mocks in the ORDER BY tests were examined: those tests verify static interactions using handles that `AutoMockExtension` does not expose, and the mocks are closed through try-with-resources.
**Limits:** The full `./mvnw clean install -B -T1C -Pcheck` build was not run. GitHub Actions and CI status were outside this code correctness review.
--
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] Enhance ORDER BY scope resolution and SQL statement metadata preservation [shardingsphere]
Posted by "strongduanmu (via GitHub)" <gi...@apache.org>.
strongduanmu commented on PR #40342:
URL: https://github.com/apache/shardingsphere/pull/40342#issuecomment-6359387195
<img width="616" height="503" alt="image" src="https://github.com/user-attachments/assets/5f58f8e2-04af-4a1f-b049-6afc0812db41" />
--
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