Skip to content

Conversation

alamb
Copy link

@alamb alamb commented Sep 5, 2025

adriangb and others added 10 commits August 27, 2025 14:16
This commit adds a new optional field `preferred_ordering` to the `TableScan` logical plan node to support sort pushdown optimizations. Changes include: - Add `preferred_ordering: Option<Vec<SortExpr>>` field to `TableScan` struct - Add `try_new_with_preferred_ordering` constructor method - Update all `TableScan` constructors throughout the codebase to include the new field - Update `Debug`, `PartialEq`, `Hash`, and `PartialOrd` implementations - Update pattern matching in optimizer and other modules The preferred_ordering field is currently not used by any optimization rules but provides the foundation for future sort pushdown implementations. This is part 2 of 2 PRs split from apache#17273 as requested in apache#17273 (comment) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit adds a new optimizer rule that pushes sort expressions down into TableScan nodes as preferred_ordering, enabling table providers to potentially optimize scans based on sort requirements. Features: - PushDownSort optimizer rule that detects Sort -> TableScan patterns - Pushes down simple column-based sort expressions only - Sets TableScan.preferred_ordering field for table provider optimization - Completely eliminates Sort node when all expressions can be pushed down - Comprehensive test coverage The rule is positioned strategically in the optimizer pipeline after limit pushdown but before filter pushdown to maximize optimization opportunities. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
}

// Create new TableScan with preferred ordering
let new_table_scan = TableScan {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the idea is we can avoid this clone in many cases by using the input directly

let LogicalPlan::TableScan(table_scan) = sort.input.as_ref() else {
return Ok(Transformed::no(plan));
};
let Sort { expr, input, fetch } = sort;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the key idea is to use the objects directly rather than references to them

@adriangb adriangb force-pushed the add-preferred-ordering-to-table-scan branch from c84cf55 to 39664ae Compare September 7, 2025 16:02
@adriangb adriangb force-pushed the add-preferred-ordering-to-table-scan branch 3 times, most recently from 0eba2fa to 9eff254 Compare October 15, 2025 04:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

2 participants