Skip to content

SetExpr: apply recursive-protection to Display - #2623

Merged
LucaCappelletti94 merged 2 commits into
apache:mainfrom
fengyue-xve:fix/setexpr-display-recursion
Oct 16, 2026
Merged

LucaCappelletti94 merged 2 commits into
apache:mainfrom
fengyue-xve:fix/setexpr-display-recursion

Conversation

@fengyue-xve

Copy link
Copy Markdown
Contributor

Printing a set-operation chain recurses once per branch through SetExpr's Display (left.fmt(f)), so a long chain overflows the stack: a 25,000-branch UNION ALL chain on a 2 MB release stack, as reported in the review on #2621. Expr's Display already carries #[cfg_attr(feature = "recursive-protection", recursive::recursive)]; SetExpr's did not. This adds the same attribute.

Follow-up to the review on #2621 (#2621 (review)):

A PR adding recursive::recursive to SetExpr's Display, as Expr already has, would be welcome.

Tests: long_set_operation_chain_display_does_not_stack_overflow parses a 25,000-branch UNION ALL chain and prints it on a thread with a 256 KiB stack, so the check does not depend on the platform's default test-thread stack. With the attribute removed, the test binary aborts with a stack overflow (STATUS_STACK_OVERFLOW on Windows); with it, the test passes. The parsed chain is torn down iteratively, because its recursive drop glue would overflow that small stack too — drop is the separate, pre-existing concern noted in the review.

Dialects: none

Printing a long left-deep chain of set operations recurses once per
branch through SetExpr's Display and overflows the stack, e.g. a
25,000-branch UNION ALL chain on a 2 MB stack. Expr's Display already
carries the recursive-protection attribute; SetExpr's did not.

@LucaCappelletti94 LucaCappelletti94 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the small nit of the comments verbosity, it looks good.

Comment thread tests/sqlparser_common.rs Outdated

#[test]
fn long_set_operation_chain_display_does_not_stack_overflow() {
// `SetExpr`'s `Display` recurses once per branch of a set-operation chain.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reduce a bit the comments verbosity please

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 874616e — trimmed the comments down to the small-stack rationale and the iterative-teardown note. Thanks!

@codecov-commenter

codecov-commenter commented Oct 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.21%. Comparing base (dacdbc9) to head (874616e).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2623      +/-   ##
==========================================
+ Coverage   81.16%   81.21%   +0.05%     
==========================================
  Files          42       42              
  Lines       33769    33866      +97     
  Branches    33769    33866      +97     
==========================================
+ Hits        27408    27505      +97     
+ Misses       2797     2796       -1     
- Partials     3564     3565       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@LucaCappelletti94 LucaCappelletti94 added bug Something isn't working waiting on contributor The review needs further refinements by its author labels Oct 15, 2026
Reduce the comment verbosity: keep only the small-stack rationale and the
iterative-teardown note.

@LucaCappelletti94 LucaCappelletti94 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

cc @alamb @iffyio

@LucaCappelletti94
LucaCappelletti94 added this pull request to the merge queue Oct 16, 2026
Merged via the queue into apache:main with commit 66d90fa Oct 16, 2026
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working waiting on contributor The review needs further refinements by its author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants