Skip to content

Commit 7fb2efc

Browse files
committed
perf(file): prepare static pruning proofs for multi-file scans
Prepare file-statistics proofs once for DuckDB V2 scans and evaluate supported comparisons directly from footer scalars. Preserve three-valued logic, a general-expression fallback, root dtype validation, and rejection of dynamic predicates. Missing statistics remain unknown; each file supplies its own statistics. Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
1 parent 2bc5703 commit 7fb2efc

5 files changed

Lines changed: 503 additions & 9 deletions

File tree

‎vortex-duckdb/src/file_reader.rs‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use vortex::error::VortexExpect;
2020
use vortex::error::VortexResult;
2121
use vortex::error::vortex_err;
2222
use vortex::error::vortex_panic;
23+
use vortex::file::FilePruningPredicate;
2324
use vortex::file::Footer;
2425
use vortex::file::VortexFile;
2526
use vortex::file::multi::MultiFileSession;
@@ -167,12 +168,20 @@ impl OpenFileReader {
167168
&self.scan_state().reader
168169
}
169170

170-
fn can_skip(&self, filter: &Filter, layout_pruning: bool) -> VortexResult<bool> {
171+
fn can_skip(
172+
&self,
173+
filter: &Filter,
174+
prepared: Option<&FilePruningPredicate>,
175+
layout_pruning: bool,
176+
) -> VortexResult<bool> {
171177
let Some(filter) = &filter.filter else {
172178
return Ok(false);
173179
};
174180
if !layout_pruning {
175-
return self.scan_state().file.can_prune_bound(filter);
181+
return match prepared {
182+
Some(prepared) => prepared.can_prune(&self.scan_state().file),
183+
None => self.scan_state().file.can_prune_bound(filter),
184+
};
176185
}
177186
let row_count = self.reader().row_count();
178187
let row_range = 0..row_count;
@@ -218,7 +227,11 @@ pub fn reader_bind(file: &OpenFileReader, result: &mut BindResultRef) -> VortexR
218227
/// whether the opened file should be skipped. If this function returns false,
219228
/// duckdb closes the file and doesn't call reader_try_initialize_scan on it.
220229
pub fn reader_initialize(file: &mut OpenFileReader, global: &GlobalState) -> VortexResult<bool> {
221-
if file.can_skip(&global.filter, global.layout_pruning)? {
230+
if file.can_skip(
231+
&global.filter,
232+
global.file_pruning_predicate.as_ref(),
233+
global.layout_pruning,
234+
)? {
222235
// DuckDB releases a skipped file under the global lock. Here only the
223236
// file-local lock is held, so drop the scan state now.
224237
file.scan_state = None;

‎vortex-duckdb/src/table_function.rs‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ use vortex::expr::Expression;
3939
use vortex::expr::analysis::referenced_field_paths;
4040
use vortex::expr::col;
4141
use vortex::expr::proto::ExprSerializeProtoExt;
42+
use vortex::file::FilePruningPredicate;
4243
#[cfg(unix)]
4344
use vortex::metrics::tracing::get_global_labels;
4445
use vortex::proto::expr as expr_pb;
@@ -185,6 +186,7 @@ impl<'a> TableInitInput<'a> {
185186
pub struct GlobalState {
186187
pub projection: BoundExpression,
187188
pub filter: Filter,
189+
pub file_pruning_predicate: Option<FilePruningPredicate>,
188190
pub file_row_number_column_pos: Option<usize>,
189191
/// Whether the scan runs on the planner-driven V2 executor.
190192
pub scan_v2: bool,
@@ -360,9 +362,20 @@ pub fn init_global(init_input: &TableInitInput) -> VortexResult<GlobalState> {
360362
// For projections without input fields, the layout probe starts zone reads before V2
361363
// planning. Keep that overlap for count-only and constant-projection scans.
362364
let layout_pruning = !scan_v2 || referenced_field_paths(&projection)?.iter().next().is_none();
365+
let file_pruning_predicate = if !layout_pruning {
366+
filter
367+
.filter
368+
.as_ref()
369+
.map(|filter| FilePruningPredicate::try_new(filter.clone(), &SESSION))
370+
.transpose()?
371+
.flatten()
372+
} else {
373+
None
374+
};
363375
Ok(GlobalState {
364376
projection,
365377
filter,
378+
file_pruning_predicate,
366379
aggregates: bind_data.aggregates.clone(),
367380
has_count_star,
368381
aggregate_state: Mutex::new(AggregateState::default()),

‎vortex-file/src/lib.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ pub use file::*;
126126
pub use footer::*;
127127
pub use forever_constant::*;
128128
pub use open::*;
129+
pub use pruning::FilePruningPredicate;
129130
pub use strategy::*;
130131
use vortex_array::arrays::Patched;
131132
use vortex_array::arrays::patched::use_experimental_patches;

0 commit comments

Comments
 (0)