Skip to content

fix(sqlengine): balance deep OR expression trees - #694

Open
Cuiyus wants to merge 2 commits into
alibaba:mainfrom
Cuiyus:fix/balance-deep-or-tree
Open

fix(sqlengine): balance deep OR expression trees#694
Cuiyus wants to merge 2 commits into
alibaba:mainfrom
Cuiyus:fix/balance-deep-or-tree

Conversation

@Cuiyus

@Cuiyus Cuiyus commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • consume deeply nested ANTLR OR parse trees iteratively
  • rebuild large OR runs as balanced binary trees while preserving operand order, AND boundaries, and the historical shape of small expressions
  • add a regression test for 4,096 non-foldable OR predicates and assert logarithmic tree depth

Motivation

ANTLR represents a flat OR chain as a left-deep binary tree. The parser and downstream query-analysis paths recursively traverse that shape, so sufficiently large filters can overflow the worker stack. Balancing the OR tree reduces the logic depth from O(N) to O(log N).

Validation

  • CMake configuration completed successfully
  • modified parser and regression-test translation units pass clang++ -fsyntax-only
  • repository commit/push hooks passed clang-format, Ruff, gitleaks, conventional-commit, and branch-name checks

The full query_info_test binary was not built locally because this was a cold worktree build; CI is expected to run the complete target.

@Cuiyus
Cuiyus marked this pull request as ready for review August 21, 2026 09:35
@Cuiyus
Cuiyus requested a review from zhourrr as a code owner August 21, 2026 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant