zy-kkk opened a new pull request, #39064: URL: https://github.com/apache/doris/pull/39064
# Problem Description When handling complex SQL expressions, the `toSqlImpl` and `conjunctExprToString` methods lacked proper handling of parentheses, which could lead to incorrect operator precedence in the generated SQL expressions. This could result in incorrect logical operation order during query execution, thereby returning incorrect query results. # Solution We have modified the `toSqlImpl` and `conjunctExprToString` methods to ensure that necessary parentheses are added based on operator precedence when generating SQL expressions: 1. **toSqlImpl Method** - Add parentheses based on operator precedence. - For the `OR` operator, add parentheses around child expressions that are `AND` compound predicates. - For the `AND` operator, add parentheses around child expressions that are `OR` compound predicates. 2. **conjunctExprToString Method** - Iterate over the children of the compound predicate and add parentheses based on operator precedence. - Add parentheses to child expressions when necessary, avoiding redundant parentheses. - Remove the code that handled the removal of trailing operators, as it is no longer needed. # Detailed Changes - Updated the `toSqlImpl` method to ensure that generated SQL expressions have correct parentheses to reflect operator precedence. - Modified the `conjunctExprToString` method to add parentheses logic to ensure correct operator precedence and removed the logic for handling trailing operators that are no longer necessary. -- 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: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org