Repository navigation
fix: preserve analyzer rewrites and simplify session instrumentation - #67
Merged
Merged
Conversation
geoffreyclaude
force-pushed
the
fix/instrument-session-builder
branch
from
September 20, 2026 02:50
90bbd98 to
1841562
Compare
geoffreyclaude
force-pushed
the
fix/instrument-session-builder
branch
from
September 20, 2026 15:29
1841562 to
fbd4b51
Compare
geoffreyclaude
force-pushed
the
fix/instrument-session-builder
branch
from
October 8, 2026 13:47
fbd4b51 to
f8ec319
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Applying rule instrumentation to a
SessionStatecurrently drops registered analyzer function rewrites. When physical optimizer phase tracing is enabled, it also rebuilds the session twice to install tracing.This PR preserves the analyzer's rewrites and installs rule and planner tracing during one rebuild. The two commits can be reviewed independently.
Preserve analyzer function rewrites
An analyzer contains both analyzer rules and function rewrites. The rewrites transform expressions before the analyzer rules run.
The current instrumentation code calls
with_analyzer_rulesto install tracing wrappers around the rules:Although the builder initially carries the existing analyzer,
with_analyzer_rulesreplaces it with a new analyzer whose function rewrite list is empty. This can change query results or cause queries to fail after instrumentation is applied.For a simple example, suppose an application registers a rewrite that changes the literal
1to2.SELECT 1 AS valueshould return2both before and after instrumentation. Previously, instrumentation removed the rewrite, so the query returned1instead.The fix keeps the existing analyzer and replaces only its rules:
This preserves the registered rewrite instances and their order. The regression test registers a rewrite, applies instrumentation, and checks that the rewrite is retained.
Install rule and planner instrumentation in one rebuild
When physical optimizer phase tracing is enabled, instrumentation currently rebuilds the state once to install the rule wrappers, then rebuilds it again to install the tracing query planner:
Each rebuild reconstructs the function registries and registers the functions again. The fix wraps the state's existing query planner on the same builder used to install the rule wrappers, then builds once. This avoids one round of registry reconstruction and function registration.
Custom query planners continue to be wrapped, and planner tracing remains conditional on physical optimizer phase tracing being enabled.
Function alias precedence during DataFusion's registry reconstruction remains a separate issue: this change still performs one reconstruction.