You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "thswlsqls (via GitHub)" <gi...@apache.org> on 2026/10/06 05:34:18 UTC

[PR] Fix recursive CTE binding when anchor query uses shorthand projection [shardingsphere]

thswlsqls opened a new pull request, #40073:
URL: https://github.com/apache/shardingsphere/pull/40073

   Fixes #35164.
   
   Changes proposed in this pull request:
     - When a recursive CTE has no column list, `CommonTableExpressionSegmentBinder#createRecursiveWithProjections` turned a shorthand anchor projection (`SELECT *`, `t.*`) into a single column named `*`, so the recursive member and the outer query failed with `Unknown column` for every CTE column.
     - The no-column-list path now builds the CTE columns with `SubqueryTableBindUtils.createSubqueryProjections`, the same call the column-list branch and the non-recursive path already use, which expands shorthand projections. The anchor query is still bound once.
     - Side effect: an aliased anchor column (`SELECT user_id AS id ...`) is now exposed to the recursive member as `id` rather than `user_id`, matching MySQL and PostgreSQL semantics.
     - Added `SelectStatementBinderTest#assertBindRecursiveCteWithShorthandAnchorProjection`; it fails with `ColumnNotFoundException` without the fix.
   
   AI assistance: Claude Code was used to draft the change and its unit test in `infra/binder/core` (`CommonTableExpressionSegmentBinder`, `SelectStatementBinderTest`) and the `RELEASE-NOTES.md` entry. I reviewed, verified, and take responsibility for every line submitted.
   
   ---
   
   Before committing this PR, I'm sure that I have checked the following options:
   - [x] My code follows the [code of conduct](https://shardingsphere.apache.org/community/en/involved/conduct/code/) of this project.
   - [x] I have self-reviewed the commit code.
   - [ ] I have (or in comment I request) added corresponding labels for the pull request. (I don't have permission to add labels.)
   - [ ] I have passed maven check locally : `./mvnw clean install -B -T1C -Dmaven.javadoc.skip -Dmaven.jacoco.skip -e`. (Not run for the whole repository; I ran `spotless:apply`, `checkstyle:check`, and `apache-rat:check` with `-Pcheck -pl infra/binder/core`, `./mvnw install -pl infra/binder/core -am -B -T1C -Dmaven.javadoc.skip -Dmaven.jacoco.skip -e`, and the `test/it/binder` IT suite, all passing. E2E tests were not run.)
   - [ ] I have made corresponding changes to the documentation. (No user-facing documentation is affected.)
   - [x] I have added corresponding unit tests for my changes.
   - [x] 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/)
   - [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] Fix recursive CTE binding when anchor query uses shorthand projection [shardingsphere]

Posted by "terrymanu (via GitHub)" <gi...@apache.org>.
terrymanu commented on PR #40073:
URL: https://github.com/apache/shardingsphere/pull/40073#issuecomment-6209289192

   ### Result
   
   Review Result: Mergeable
   
   No blocking issues were found at the current head. Both test coding-standard findings from the previous review are fixed. This conclusion covers code correctness only; CI was not reviewed.
   
   ### Evidence
   
   - Recursive CTE seed columns now use the existing `SubqueryTableBindUtils.createSubqueryProjections` utility, fixing the treatment of `*` and `t.*` as single columns while preserving explicit column-list mapping. [Production change](https://github.com/apache/shardingsphere/blob/164d0698501cd14362278f86f12ef2e015151e0d/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/dml/with/CommonTableExpressionSegmentBinder.java#L133-L138)
   - Aliased columns follow the existing CTE column-name inference contract. [MySQL 8.0 documentation](https://dev.mysql.com/doc/refman/8.0/en/with.html), [PostgreSQL 17 documentation](https://www.postgresql.org/docs/17/sql-select.html)
   - After compiling the exact-head snapshot, all 15 `SelectStatementBinderTest` tests passed, including the new regression case, with no failures, errors, or skipped tests.
   
   ### Coverage
   
   - Candidate: public PR #40073, with no local code delta.
   - Head: `164d0698501cd14362278f86f12ef2e015151e0d`.
   - Base / merge-base: `5756b72bfa9da47c24c4856915fd8159ce60a1be`. Both head and base were confirmed unchanged before completion.
   - All 3 files in GitHub’s authoritative changed-file list were reviewed:
     - `RELEASE-NOTES.md:52`
     - `infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/dml/with/CommonTableExpressionSegmentBinder.java:133`
     - `infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/engine/statement/dml/SelectStatementBinderTest.java:498`
   - Requirements basis: Issue #35164, existing Binder contracts, CODE_OF_CONDUCT, and applicable implementation and testing rules. This restores existing behavior without adding a project commitment.
   - Reviewed projection expansion, aliases, explicit column lists, recursive-member and outer-query binding, SEARCH/CYCLE, tests, and release notes. Completed root-cause, blast-radius, and test/runtime review passes, followed by a final convergence pass. No unresolved evidence gaps remain.
   - Local style verification command:
     `./mvnw -pl infra/binder/core -DspotlessFiles="$JAVA_REGEX" -Dcheckstyle.includes="$JAVA_INCLUDES" -Dcheckstyle.includeResources=false -Dcheckstyle.includeTestResources=false spotless:check checkstyle:check -Pcheck -T1C`
     The combined command exited with code `0`. The variables restrict selection to the two Java files above using canonical absolute-path regular expressions and source-root-relative paths, respectively. Spotless confirmed exactly 2 files selected and clean; Checkstyle XML confirmed coverage of the same 2 files with no error-level violations.
   - Both checks are Not Applicable to `RELEASE-NOTES.md`: the current configuration does not cover Markdown.


-- 
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 recursive CTE binding when anchor query uses shorthand projection [shardingsphere]

Posted by "thswlsqls (via GitHub)" <gi...@apache.org>.
thswlsqls commented on PR #40073:
URL: https://github.com/apache/shardingsphere/pull/40073#issuecomment-6116354765

   @terrymanu Thanks for the review. Both fixed: the test now passes `Collections.singleton(...)` to `WithSegment` directly, and the `bind(...)` call is on one line. Also rebased to clear the release-note conflict.
   


-- 
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 recursive CTE binding when anchor query uses shorthand projection [shardingsphere]

Posted by "terrymanu (via GitHub)" <gi...@apache.org>.
terrymanu merged PR #40073:
URL: https://github.com/apache/shardingsphere/pull/40073


-- 
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