You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: column pruning failure when applying associative law rules (#23206)
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:
1. The JOIN structure was changed, but OnList conditions remained in their original positions
2. During column remapping phase, references to columns from moved tables could not be found in the expected context
3. This resulted in errors like "Column remapping failed: cannot find column reference"
### Solution
The fix adds proper OnList condition migration logic in all three associative law rules:
1. **Added `migrateOnListConditions` function**: Moves conditions involving specified table tags from source node to destination node
2. **Added `checkExprInvolvesTags` function**: Checks if an expression references any of the specified table tags
3. **Updated Rule 1, Rule 2, Rule 3**: Each rule now properly migrates OnList conditions when transforming JOIN structures:
- **Rule 1**: Migrates conditions involving table C to the outer join
- **Rule 2**: Migrates conditions involving table A to the outer join
- **Rule 3**: Migrates conditions involving B and C to their correct positions
### Testing
Added a comprehensive test case `TestAssociativeLawRemapping` that:
- Creates a scenario where associative law Rule 1 would be triggered
- Verifies that the query executes successfully without remapping errors
- Tests the exact scenario from the issue report
Approved by: @aunjgr, @XuPeng-SH
0 commit comments