feat: Add rewrite for IN special form#15663
feat: Add rewrite for IN special form#15663pramodsatya wants to merge 3 commits intofacebookincubator:mainfrom
Conversation
✅ Deploy Preview for meta-velox canceled.
|
|
@pramodsatya : Thanks for the code. Code looks good. Please rebase to fix the build issues. @mbasmanova : PTAL. |
There was a problem hiding this comment.
Pull request overview
This PR adds an optimization for the IN special form by introducing a rewrite rule that simplifies IN expressions when the search value is a constant. The rewrite returns true when the value is found in the IN-list, deduplicates NULL values, and removes non-matching constant values from the IN-list.
Key changes:
- Implements compile-time optimization for IN expressions with constant search values
- Reduces runtime overhead by pre-filtering IN-lists during expression compilation
- Maintains correctness by preserving NULL semantics in SQL IN predicates
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| velox/functions/prestosql/InRewrite.h | Header file defining the InRewrite class with static rewrite and registration methods |
| velox/functions/prestosql/InRewrite.cpp | Core implementation of IN expression optimization logic |
| velox/functions/prestosql/tests/InRewriteTest.cpp | Test cases covering basic rewrite scenarios including NULL handling and constant elimination |
| velox/functions/prestosql/tests/CMakeLists.txt | Adds InRewriteTest.cpp to the test build configuration |
| velox/functions/prestosql/CMakeLists.txt | Adds InRewrite.cpp to the library build configuration |
| velox/functions/prestosql/registration/GeneralFunctionsRegistration.cpp | Registers the IN rewrite rule during function initialization |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
| /// a non-NULL constant and the IN-list is not constant. Returns `true` if | ||
| /// `value` is in the IN-list. Removes constant expressions from IN-list that |
There was a problem hiding this comment.
The documentation states "the IN-list is not constant" but this constraint is not actually verified in the implementation. The rewrite will work correctly even when all elements in the IN-list are constants. Consider either removing this phrase from the documentation or clarifying what it means (e.g., "when not all elements of the IN-list are constants" or "when the entire IN expression cannot be fully evaluated to a constant").
| /// a non-NULL constant and the IN-list is not constant. Returns `true` if | |
| /// `value` is in the IN-list. Removes constant expressions from IN-list that | |
| /// a non-NULL constant. Returns `true` if `value` is in the IN-list, regardless | |
| /// of whether the IN-list is constant or not. Removes constant expressions from IN-list that |
Would you expand this to explain what wasn't working before and how it is fixed now? Please, clarify which tests were added to verify the fix. |
80534fc to
b640dbb
Compare
|
Thanks @mbasmanova, @aditi-pandit. I made changes to the IN rewrite to ensure constant expression comparison follows the same null handling mode, null-as-indeterminate, as the function implementation. This should effectively resolve #15648. I have verified the fix with reproducer attached in the issue, extended it into a test, and updated the PR description accordingly. The rewrite now relies on |
b640dbb to
4eaee48
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 25 out of 25 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
4eaee48 to
2b22eeb
Compare
Rewrites IN special form when the
valuebeing searched for is constant.trueifvalueis in theIN-list.IN-listthat do not match withvalue.Constant expression comparison for these 2 rules uses null-as-indeterminate null comparison mode in order to maintain consistency with the function implementation of IN predicate.
Tests are added to ensure the correctness issue from #15648 is resolved.
Examples:
Cherry-picked from #15488.
Depends on #15705, #15708.