-
Notifications
You must be signed in to change notification settings - Fork 285
fix: column pruning failure when applying associative law rules #23206
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
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
||||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||||||||||
User description
What type of PR is this?
Which issue(s) this PR fixes:
issue https://github.com/matrixorigin/MO-Cloud/issues/6708
What this PR does / why we need it:
This PR fixes a column pruning failure issue caused by applying associative law optimization rules. When the query optimizer applies associative law transformations to reorder JOIN operations, the OnList conditions were not properly migrated to match the new JOIN structure, leading to remapping errors during column reference resolution.
Problem
When applying associative law rules (Rule 1, Rule 2, Rule 3) to transform JOIN structures like
A*(B*C)to(A*B)*C, the OnList conditions that reference columns from moved tables were not migrated to the correct JOIN nodes. This caused column remapping failures because:Solution
The fix adds proper OnList condition migration logic in all three associative law rules:
migrateOnListConditionsfunction: Moves conditions involving specified table tags from source node to destination nodecheckExprInvolvesTagsfunction: Checks if an expression references any of the specified table tagsTesting
Added a comprehensive test case
TestAssociativeLawRemappingthat:PR Type
Bug fix
Description
Fix column pruning failure when applying associative law JOIN reordering rules
Add OnList condition migration logic to properly handle JOIN transformations
Implement helper functions to detect and migrate conditions involving specific table tags
Add optimization history tracking for debugging remap errors
Include comprehensive test case for associative law remapping scenarios
Diagram Walkthrough
File Walkthrough
associative_law.go
Implement OnList condition migration for associative law rulespkg/sql/plan/associative_law.go
checkExprInvolvesTags()function to detect if expressionsreference specific table tags
migrateOnListConditions()function to move JOIN conditions betweennodes based on table involvement
getTableNameOrLabel()andformatStatsInfo()fordebugging
transforming JOIN structures
names and stats
types.go
Add optimization history tracking fieldpkg/sql/plan/types.go
optimizationHistoryfield toQueryBuilderstruct to trackoptimization steps
transformations
query_builder.go
Include optimization history in remap error messagespkg/sql/plan/query_builder.go
optimizationHistoryslice inNewQueryBuilder()buildRemapErrorMessage()to include optimization history inerror messages
join_order.go
Add join order optimization history loggingpkg/sql/plan/join_order.go
determineJoinOrder()functionpushdown.go
Add filter pushdown optimization history loggingpkg/sql/plan/pushdown.go
pushdownFilters()functionUNION, TABLE_SCAN)
sql_executor_context.go
Add test stats cache support for testingpkg/sql/compile/sql_executor_context.go
logutilpackageStats()method using context valueavailable
sql_executor.go
Support injecting stats cache from contextpkg/sql/compile/sql_executor.go
getCompileContext()to check for test stats cache in contextassociative_law_remap_test.go
Add comprehensive associative law remapping testpkg/vm/engine/test/associative_law_remap_test.go
TestAssociativeLawRemapping()forassociative law transformations
with primary key constraints
1 transformation
remapping errors