chore(query): Optimize Optimizer Performance by Reducing Redundant Computations #18979
+67
−41
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/
Summary
This PR introduces several performance optimizations to query optimizer, primarily by reducing redundant computations and simplifying call patterns.
OptimizerContext::is_optimizer_disabledfor Rule Skipping ChecksThe
is_optimizer_disabledfunction is frequently invoked during the optimization process, which would repeatedly callquery_settings.unchecked_apply_changes()and read theskip_listsetting, parse it by comma delimiters. Theskip_listis now parsed and converted into aHashSetduring the initialization ofOptimizerContext, eliminating redundant compute operations.optimize_expressionandapply_transform_rulesoptimize_expressionandapply_transform_rulescall each other repeatedly, this nested invocation pattern increased call stack depth and could complicate control flow. The control flow has been refactored to simplify the call stack.common_super_typeResults inresolve_arrayThe
resolve_arrayfunction frequently callscommon_super_typeto determine the common super type of array elements. Thecommon_super_typefunction can be computationally expensive, and its repeated invocation for the same type combinations led to performance bottlenecks. A caching mechanism (using aHashSet) has been introduced to avoid redundant and expensive common type compute.Tests
Type of change
This change is