mzabaluev opened a new pull request, #27586: URL: https://github.com/apache/datafusion/pull/27586
## Which issue does this PR close? - Implements the suggestion in https://github.com/apache/datafusion/pull/26609#issuecomment-6978052156 ## Rationale for this change When `CASE WHEN` selects branches by a tight range of literals, using a direct table lookup may be faster than using a hash table. ## What changes are included in this PR? For `CASE` expressions whose `WHEN` literals are integers spanning a range of at most 1024 values, map each value to its `WHEN` index by indexing a table covering the range at the offset of the value from the lowest literal. Values outside the range are clamped to an entry holding the else index, so the lookup takes a constant time with no branches, regardless of the number of literals. Comparing with all the literals remains faster for up to 4 literals of 32 bits or narrower, or 2 of 64 bits, so these are still looked up linearly. Rename the `ToHashableKey` trait to `ToLookupKey`, as it now provides the operations on keys for all the kinds of lookup. ## What is the testing strategy for this PR? Added a `lookup_table_case_when_contiguous` benchmark case to the `case_when` benchmark to test the optimization. ## Are there any user-facing changes? No. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
