Skip to content

Commit c93b6a7

Browse files
perf[duckdb]: dont push down pack & dedup filters for ddb (#5773)
Signed-off-by: Joe Isaacs <[email protected]>
1 parent be9c708 commit c93b6a7

File tree

2 files changed

+33
-33
lines changed

2 files changed

+33
-33
lines changed

vortex-array/src/arrays/dict/vtable/rules.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::arrays::DictArray;
1515
use crate::arrays::DictVTable;
1616
use crate::arrays::ScalarFnArray;
1717
use crate::builtins::ArrayBuiltins;
18+
use crate::expr::Pack;
1819
use crate::optimizer::ArrayOptimizer;
1920
use crate::optimizer::rules::ArrayParentReduceRule;
2021
use crate::optimizer::rules::ParentRuleSet;
@@ -44,6 +45,12 @@ impl ArrayParentReduceRule<DictVTable> for DictionaryScalarFnValuesPushDownRule
4445
// Check that the scalar function can actually be pushed down.
4546
let sig = parent.scalar_fn().signature();
4647

48+
// Don't push down pack expressions since we might want to unpack them in exporters
49+
// later.
50+
if parent.scalar_fn().is::<Pack>() {
51+
return Ok(None);
52+
}
53+
4754
// If the scalar function is fallible, we cannot push it down since it may fail over a
4855
// value that isn't referenced by any code.
4956
if !array.all_values_referenced && sig.is_fallible() {

vortex-duckdb/src/scan.rs

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,8 @@ use vortex::error::vortex_bail;
4040
use vortex::error::vortex_err;
4141
use vortex::expr::Expression;
4242
use vortex::expr::Pack;
43-
use vortex::expr::and;
4443
use vortex::expr::and_collect;
4544
use vortex::expr::col;
46-
use vortex::expr::lit;
4745
use vortex::expr::root;
4846
use vortex::expr::select;
4947
use vortex::file::OpenOptionsSessionExt;
@@ -53,6 +51,7 @@ use vortex::io::runtime::BlockingRuntime;
5351
use vortex::io::runtime::current::ThreadSafeIterator;
5452
use vortex::layout::layouts::USE_VORTEX_OPERATORS;
5553
use vortex::session::VortexSession;
54+
use vortex_utils::aliases::hash_set::HashSet;
5655

5756
use crate::RUNTIME;
5857
use crate::SESSION;
@@ -179,38 +178,32 @@ fn extract_table_filter_expr(
179178
init: &TableInitInput<VortexTableFunction>,
180179
column_ids: &[u64],
181180
) -> VortexResult<Option<Expression>> {
182-
let table_filter_expr = init
183-
.table_filter_set()
184-
.and_then(|filter| {
185-
filter
186-
.into_iter()
187-
.map(|(idx, ex)| {
188-
let idx_u: usize = idx.as_();
189-
let col_idx: usize = column_ids[idx_u].as_();
190-
let name = init
191-
.bind_data()
192-
.column_names
193-
.get(col_idx)
194-
.vortex_expect("exists");
195-
try_from_table_filter(
196-
&ex,
197-
&col(name.as_str()),
198-
init.bind_data().first_file.dtype(),
199-
)
200-
})
201-
.reduce(|l, r| l?.zip(r?).map(|(l, r)| Ok(and(l, r))).transpose())
202-
})
203-
.transpose()?
204-
.flatten();
205-
206-
let complex_filter_expr = and_collect(init.bind_data().filter_exprs.clone());
207-
let filter_expr = complex_filter_expr
208-
.into_iter()
209-
.chain(table_filter_expr)
210-
.reduce(and)
211-
.unwrap_or_else(|| lit(true));
181+
let mut table_filter_exprs: HashSet<Expression> = if let Some(filter) = init.table_filter_set()
182+
{
183+
filter
184+
.into_iter()
185+
.map(|(idx, ex)| {
186+
let idx_u: usize = idx.as_();
187+
let col_idx: usize = column_ids[idx_u].as_();
188+
let name = init
189+
.bind_data()
190+
.column_names
191+
.get(col_idx)
192+
.vortex_expect("exists");
193+
try_from_table_filter(
194+
&ex,
195+
&col(name.as_str()),
196+
init.bind_data().first_file.dtype(),
197+
)
198+
})
199+
.collect::<VortexResult<Option<HashSet<_>>>>()?
200+
.unwrap_or_else(HashSet::new)
201+
} else {
202+
HashSet::new()
203+
};
212204

213-
Ok(Some(filter_expr))
205+
table_filter_exprs.extend(init.bind_data().filter_exprs.clone());
206+
Ok(and_collect(table_filter_exprs.into_iter().collect_vec()))
214207
}
215208

216209
/// Helper function to open a Vortex file from either a local or S3 URL

0 commit comments

Comments
 (0)