-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Support simplify not for physical expr #18970
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| panic!("Expected binary OR expression result"); | ||
| } | ||
|
|
||
| Ok(()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a test for NOT(NOT(a) AND NOT(b)).
It should be simplified to a OR b but let's confirm.
| //! This module provides optimizations for NOT expressions such as: | ||
| //! - Double negation elimination: NOT(NOT(expr)) -> expr | ||
| //! - NOT with binary comparisons: NOT(a = b) -> a != b | ||
| //! - NOT with IN expressions: NOT(a IN (list)) -> a NOT IN (list) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really supported ?
I don't see neither implementation nor tests for IN
|
|
||
| fn f_up(&mut self, node: Self::Node) -> Result<Transformed<Self::Node>> { | ||
| // Apply NOT expression simplification first | ||
| let not_simplified = simplify_not_expr_recursive(&node, self.schema)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name of the variable is a bit confusing - not_simplified. It sounds like it is not simplified.
Maybe rename it to not_expr_simplified ?!
| return Ok(Transformed::yes(lit(ScalarValue::Boolean(Some(!val))))); | ||
| } | ||
| if let ScalarValue::Boolean(None) = literal.value() { | ||
| return Ok(Transformed::yes(lit(ScalarValue::Boolean(None)))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this return Transformed::yes ?
It returns the same value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually this is NOT(NULL) -> NULL. All is good!
| if not_simplified.transformed { | ||
| // Recursively simplify the result | ||
| let further_simplified = | ||
| simplify_not_expr_recursive(¬_simplified.data, schema)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder whether this could be a vector of an attack.
Someone may craft a query with many not(not(not(not(...)))) to cause a stack overflow due to the usage of recursion here.
Part of the #18868