Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,12 @@ impl RuleFactory {
RuleID::CommuteJoinBaseTable => Ok(Box::new(RuleCommuteJoinBaseTable::new())),
RuleID::LeftExchangeJoin => Ok(Box::new(RuleLeftExchangeJoin::new())),
RuleID::EagerAggregation => Ok(Box::new(RuleEagerAggregation::new(metadata))),
RuleID::PushDownPrewhere => Ok(Box::new(RulePushDownPrewhere::new(metadata))),
RuleID::PushDownPrewhere => Ok(Box::new(RulePushDownPrewhere::new(
metadata,
ctx.get_table_ctx()
.get_settings()
.get_enable_parquet_prewhere()?,
))),
RuleID::TryApplyAggIndex => Ok(Box::new(RuleTryApplyAggIndex::new(metadata))),
RuleID::EliminateSelfJoin => Ok(Box::new(RuleEliminateSelfJoin::new(ctx))),
RuleID::EliminateSort => Ok(Box::new(RuleEliminateSort::new())),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ pub struct RulePushDownPrewhere {
id: RuleID,
matchers: Vec<Matcher>,
metadata: MetadataRef,
enable_parquet_prewhere: bool,
}

impl RulePushDownPrewhere {
pub fn new(metadata: MetadataRef) -> Self {
pub fn new(metadata: MetadataRef, enable_parquet_prewhere: bool) -> Self {
Self {
id: RuleID::PushDownPrewhere,
matchers: vec![
Expand All @@ -82,6 +83,7 @@ impl RulePushDownPrewhere {
},
],
metadata,
enable_parquet_prewhere,
}
}

Expand Down Expand Up @@ -175,7 +177,11 @@ impl RulePushDownPrewhere {
let metadata = self.metadata.read().clone();

let table = metadata.table(scan.table_index).table();
if !table.support_prewhere() {
if !should_push_down_prewhere(
table.support_prewhere(),
table.storage_format_as_parquet(),
self.enable_parquet_prewhere,
) {
// cannot optimize
return Ok(s_expr.clone());
}
Expand Down Expand Up @@ -240,6 +246,14 @@ impl RulePushDownPrewhere {
}
}

fn should_push_down_prewhere(
support_prewhere: bool,
storage_format_as_parquet: bool,
enable_parquet_prewhere: bool,
) -> bool {
support_prewhere && (!storage_format_as_parquet || enable_parquet_prewhere)
}

impl Rule for RulePushDownPrewhere {
fn id(&self) -> RuleID {
self.id
Expand All @@ -260,3 +274,16 @@ impl Rule for RulePushDownPrewhere {
&self.matchers
}
}

#[cfg(test)]
mod tests {
use super::should_push_down_prewhere;

#[test]
fn test_should_push_down_prewhere_respects_parquet_setting() {
assert!(!should_push_down_prewhere(true, true, false));
assert!(should_push_down_prewhere(true, true, true));
assert!(should_push_down_prewhere(true, false, false));
assert!(!should_push_down_prewhere(false, false, true));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
statement ok
drop table if exists t_disable_parquet_prewhere

statement ok
create table t_disable_parquet_prewhere (
bucket_num int,
bucket_scores array(int)
) storage_format = 'parquet' row_per_block = 2

statement ok
insert into t_disable_parquet_prewhere values
(1, [10, 11, 12]),
(2, [20]),
(2, [21, 22]),
(3, [30, 31, 32, 33])

statement ok
set enable_parquet_prewhere = 1

statement error Parquet argument error
select count(*), sum(array_length(coalesce(bucket_scores, [])))
from t_disable_parquet_prewhere
where bucket_num = 2

statement ok
set enable_parquet_prewhere = 0

query II
select count(*), sum(array_length(coalesce(bucket_scores, [])))
from t_disable_parquet_prewhere
where bucket_num = 2
----
2 3

statement ok
drop table t_disable_parquet_prewhere
Loading