Skip to content

fix: linearized operands in physical binaryexpr protobuf to avoid recursion limit#21031

Open
haohuaijin wants to merge 2 commits intoapache:mainfrom
haohuaijin:fix-recursion-limit
Open

fix: linearized operands in physical binaryexpr protobuf to avoid recursion limit#21031
haohuaijin wants to merge 2 commits intoapache:mainfrom
haohuaijin:fix-recursion-limit

Conversation

@haohuaijin
Copy link
Contributor

Which issue does this PR close?

Rationale for this change

When a SQL query contains many filter conditions (e.g., 40+ AND/OR clauses in a WHERE), serializing the physical plan to protobuf and deserializing it fails with DecodeError: recursion limit reached. This is because prost has a default recursion limit of 100, and each BinaryExpr nesting consumes ~2 levels of protobuf recursion depth, so a chain of ~50 AND conditions exceeds the limit.

What changes are included in this PR?

Applied the same linearization approach that logical expressions already use. Instead of encoding a chain of same-operator binary expressions as a deeply nested tree, we flatten it into a flat operands list:

Before (nested, O(n) recursion depth):

BinaryExpr(AND) { l: BinaryExpr(AND) { l: BinaryExpr(AND) { l: a, r: b }, r: c }, r: d }

After (flat, O(1) recursion depth for the chain):

BinaryExpr(AND) { operands: [a, b, c, d] }

Are these changes tested?

yes, add some test case

Are there any user-facing changes?

@github-actions github-actions bot added the proto Related to proto crate label Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

proto Related to proto crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant