Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(planner): improve push down filter join #14872

Merged
merged 61 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
9cee5ca
feat: improve push down filter join
Dousir9 Mar 7, 2024
52b37be
Merge branch 'main' of github.com:datafuselabs/databend into refactor…
Dousir9 Mar 7, 2024
e49f510
fix: reverse operator when (constant, column_ref)
Dousir9 Mar 7, 2024
3155513
chore: add more test
Dousir9 Mar 7, 2024
7a995c7
chore: complete sqllogictest
Dousir9 Mar 7, 2024
569b803
fix: outer join push down
Dousir9 Mar 7, 2024
04f0946
chore: remove z3 and add new method
Dousir9 Mar 8, 2024
d677b87
chore: move
Dousir9 Mar 8, 2024
5329c9f
chore: refactor try push down filter join
Dousir9 Mar 8, 2024
ca60f7a
chore: update sqllogictest
Dousir9 Mar 8, 2024
d1fea55
chore: update sqllogictest
Dousir9 Mar 8, 2024
128bbe1
chore: update sqllogictest
Dousir9 Mar 8, 2024
f3af1e6
chore: fix push down single join
Dousir9 Mar 9, 2024
c75b259
chore: update subquery
Dousir9 Mar 11, 2024
89089e3
fix: after join reorder don not push down
Dousir9 Mar 11, 2024
2d06059
chore: update native
Dousir9 Mar 11, 2024
13ca91c
chore: improve can_filter_null
Dousir9 Mar 11, 2024
624b65c
chore: fix test
Dousir9 Mar 11, 2024
dc056f2
feat: improve infer and / or filter
Dousir9 Mar 11, 2024
53d720f
chore: update native sqllogictest
Dousir9 Mar 11, 2024
db77b4a
chore: update sqllogictest
Dousir9 Mar 11, 2024
b15e43c
Merge branch 'main' of github.com:datafuselabs/databend into refactor…
Dousir9 Mar 11, 2024
e332ff2
feat: add SingleToInnerOptimizer
Dousir9 Mar 12, 2024
b8e478a
chore: remove after_join_reorder
Dousir9 Mar 12, 2024
55c3857
chore: fix outer join to inner join
Dousir9 Mar 12, 2024
f625d97
test: update parquet explain sqllogictest
Dousir9 Mar 12, 2024
206e3ad
test: update native explain sqllogictest
Dousir9 Mar 12, 2024
03240f7
chore: make lint code
Dousir9 Mar 12, 2024
96300d6
chore: fix Cascades optimizer
Dousir9 Mar 13, 2024
53c0055
chore: add z3-prove
Dousir9 Mar 13, 2024
b2c74aa
chore: update sqllogictest
Dousir9 Mar 13, 2024
101a222
Merge branch 'main' of github.com:datafuselabs/databend into refactor…
Dousir9 Mar 13, 2024
68a08a7
chore: fix infer filter for outer join
Dousir9 Mar 13, 2024
04d256e
chore: update sqllogictest
Dousir9 Mar 13, 2024
6135e31
chore: update ee test
Dousir9 Mar 13, 2024
71c7af1
chore: fix tpcds test
Dousir9 Mar 14, 2024
a0cace9
chore: update sqllogictest
Dousir9 Mar 14, 2024
ba9b47b
chore: update ee test
Dousir9 Mar 14, 2024
10d47ac
chore: fix distributed query plan
Dousir9 Mar 14, 2024
4acd3ce
Merge branch 'main' of github.com:datafuselabs/databend into refactor…
Dousir9 Mar 14, 2024
e29cbbd
chore: update sqllogictet
Dousir9 Mar 14, 2024
826a87c
chore: update test comment
Dousir9 Mar 15, 2024
0912b8c
chore: add comments
Dousir9 Mar 15, 2024
8ce11a5
Merge branch 'main' of github.com:datafuselabs/databend into refactor…
Dousir9 Mar 15, 2024
06357f8
chore: make lint
Dousir9 Mar 15, 2024
34ff694
chore: update sqllogictest
Dousir9 Mar 15, 2024
a178ae1
chore: suuport more join type
Dousir9 Mar 15, 2024
c8c9535
chore: refine code
Dousir9 Mar 18, 2024
ba9548a
chore: add semi / anti test
Dousir9 Mar 18, 2024
83775a8
Merge branch 'main' of github.com:datafuselabs/databend into refactor…
Dousir9 Mar 18, 2024
c7f5114
chore: update sqllogictest
Dousir9 Mar 18, 2024
0ae07d4
chore: improve infer filter
Dousir9 Mar 24, 2024
9298350
chore: update sqllogictest
Dousir9 Mar 24, 2024
d93823a
Merge branch 'main' of github.com:datafuselabs/databend into refactor…
Dousir9 Mar 24, 2024
067f668
chore: add more comments and remove useless code
Dousir9 Mar 24, 2024
c9e3296
chore: make lint
Dousir9 Mar 24, 2024
d4f102c
test: update memo sqllogictest
Dousir9 Mar 24, 2024
9d7d420
Merge branch 'main' of github.com:datafuselabs/databend into refactor…
Dousir9 Mar 24, 2024
4b4c4d3
chore: update memo test
Dousir9 Mar 24, 2024
671e792
Merge branch 'main' of github.com:datafuselabs/databend into refactor…
Dousir9 Mar 26, 2024
a6a0733
chore: update ee test
Dousir9 Mar 26, 2024
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 @@ -36,7 +36,7 @@ pub struct HashJoinDesc {
pub(crate) build_keys: Vec<Expr>,
pub(crate) probe_keys: Vec<Expr>,
pub(crate) join_type: JoinType,
pub(crate) original_join_type: Option<JoinType>,
pub(crate) single_to_inner: Option<JoinType>,
/// when we have non-equal conditions for hash join,
/// for example `a = b and c = d and e > f`, we will use `and_filters`
/// to wrap `e > f` as a other_predicate to do next step's check.
Expand Down Expand Up @@ -88,7 +88,7 @@ impl HashJoinDesc {
from_correlated_subquery: join.from_correlated_subquery,
probe_keys_rt,
broadcast: join.broadcast,
original_join_type: join.original_join_type.clone(),
single_to_inner: join.single_to_inner.clone(),
enable_bloom_runtime_filter: join.enable_bloom_runtime_filter,
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ impl HashJoinBuildState {
pub(crate) fn add_build_block(&self, data_block: DataBlock) -> Result<()> {
let block_outer_scan_map = if self.hash_join_state.need_outer_scan()
|| matches!(
self.hash_join_state.hash_join_desc.original_join_type,
self.hash_join_state.hash_join_desc.single_to_inner,
Some(JoinType::RightSingle)
) {
vec![false; data_block.num_rows()]
Expand All @@ -266,7 +266,7 @@ impl HashJoinBuildState {
let build_state = unsafe { &mut *self.hash_join_state.build_state.get() };
if self.hash_join_state.need_outer_scan()
|| matches!(
self.hash_join_state.hash_join_desc.original_join_type,
self.hash_join_state.hash_join_desc.single_to_inner,
Some(JoinType::RightSingle)
)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl HashJoinProbeState {
.other_predicate
.is_none();
match self.hash_join_state.hash_join_desc.join_type {
JoinType::Inner => match self.hash_join_state.hash_join_desc.original_join_type {
JoinType::Inner => match self.hash_join_state.hash_join_desc.single_to_inner {
Some(JoinType::LeftSingle) => {
self.inner_join::<_, true, false>(input, keys, hash_table, probe_state)
}
Expand Down
2 changes: 1 addition & 1 deletion src/query/service/src/schedulers/fragments/fragmenter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ impl PhysicalPlanReplacer for Fragmenter {
probe_keys_rt: plan.probe_keys_rt.clone(),
enable_bloom_runtime_filter: plan.enable_bloom_runtime_filter,
broadcast: plan.broadcast,
original_join_type: plan.original_join_type.clone(),
single_to_inner: plan.single_to_inner.clone(),
}))
}

Expand Down
2 changes: 1 addition & 1 deletion src/query/sql/src/executor/physical_plan_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ pub trait PhysicalPlanReplacer {
probe_keys_rt: plan.probe_keys_rt.clone(),
enable_bloom_runtime_filter: plan.enable_bloom_runtime_filter,
broadcast: plan.broadcast,
original_join_type: plan.original_join_type.clone(),
single_to_inner: plan.single_to_inner.clone(),
}))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ pub struct HashJoin {
pub enable_bloom_runtime_filter: bool,
// Under cluster, mark if the join is broadcast join.
pub broadcast: bool,
// Original join type. Left/Right single join may be convert to inner join
// Record the original join type and do some special processing during runtime.
pub original_join_type: Option<JoinType>,
// When left/right single join converted to inner join, record the original join type
// and do some special processing during runtime.
pub single_to_inner: Option<JoinType>,
Dousir9 marked this conversation as resolved.
Show resolved Hide resolved
}

impl HashJoin {
Expand Down Expand Up @@ -510,7 +510,7 @@ impl PhysicalPlanBuilder {
need_hold_hash_table: join.need_hold_hash_table,
stat_info: Some(stat_info),
broadcast: is_broadcast,
original_join_type: join.original_join_type.clone(),
single_to_inner: join.single_to_inner.clone(),
enable_bloom_runtime_filter: adjust_bloom_runtime_filter(
self.ctx.clone(),
&self.metadata,
Expand Down
1 change: 1 addition & 0 deletions src/query/sql/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#![feature(try_blocks)]
#![feature(extend_one)]
#![feature(lazy_cell)]
#![feature(if_let_guard)]

pub mod evaluator;
pub mod executor;
Expand Down
2 changes: 1 addition & 1 deletion src/query/sql/src/planner/binder/join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ impl Binder {
from_correlated_subquery: false,
need_hold_hash_table: false,
is_lateral,
original_join_type: None,
single_to_inner: None,
};
Ok(SExpr::create_binary(
Arc::new(logical_join.into()),
Expand Down
4 changes: 0 additions & 4 deletions src/query/sql/src/planner/binder/scalar_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,6 @@ impl<'a> JoinPredicate<'a> {
left_prop: &RelationalProperty,
right_prop: &RelationalProperty,
) -> Self {
if contain_subquery(scalar) {
return Self::Other(scalar);
}

if scalar.used_columns().is_empty() {
return Self::ALL(scalar);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl ApplyRuleTask {
let group = optimizer.memo.group(self.target_group_index)?;
let m_expr = group.m_expr(self.m_expr_index)?;
let mut state = TransformResult::new();
let rule = RuleFactory::create_rule(self.rule_id, optimizer.metadata.clone(), false)?;
let rule = RuleFactory::create_rule(self.rule_id, optimizer.metadata.clone())?;
m_expr.apply_rule(&optimizer.memo, &rule, &mut state)?;
optimizer.insert_from_transform_state(self.target_group_index, state)?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl SubqueryRewriter {
from_correlated_subquery: true,
need_hold_hash_table: false,
is_lateral: false,
original_join_type: None,
single_to_inner: None,
};

// Rewrite plan to semi-join.
Expand Down Expand Up @@ -290,7 +290,7 @@ impl SubqueryRewriter {
from_correlated_subquery: true,
need_hold_hash_table: false,
is_lateral: false,
original_join_type: None,
single_to_inner: None,
};
let s_expr = SExpr::create_binary(
Arc::new(join_plan.into()),
Expand Down Expand Up @@ -339,7 +339,7 @@ impl SubqueryRewriter {
from_correlated_subquery: true,
need_hold_hash_table: false,
is_lateral: false,
original_join_type: None,
single_to_inner: None,
};
let s_expr = SExpr::create_binary(
Arc::new(join_plan.into()),
Expand Down Expand Up @@ -403,7 +403,7 @@ impl SubqueryRewriter {
from_correlated_subquery: true,
need_hold_hash_table: false,
is_lateral: false,
original_join_type: None,
single_to_inner: None,
}
.into();
Ok((
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl SubqueryRewriter {
from_correlated_subquery: false,
need_hold_hash_table: false,
is_lateral: false,
original_join_type: None,
single_to_inner: None,
}
.into();

Expand Down Expand Up @@ -469,7 +469,7 @@ impl SubqueryRewriter {
from_correlated_subquery: false,
need_hold_hash_table: false,
is_lateral: false,
original_join_type: None,
single_to_inner: None,
}
.into(),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ impl SubqueryRewriter {
from_correlated_subquery: false,
need_hold_hash_table: false,
is_lateral: false,
original_join_type: None,
single_to_inner: None,
}
.into();
Ok((
Expand Down Expand Up @@ -553,7 +553,7 @@ impl SubqueryRewriter {
from_correlated_subquery: false,
need_hold_hash_table: false,
is_lateral: false,
original_join_type: None,
single_to_inner: None,
}
.into();
let s_expr = SExpr::create_binary(
Expand Down Expand Up @@ -584,7 +584,7 @@ impl SubqueryRewriter {
from_correlated_subquery: false,
need_hold_hash_table: false,
is_lateral: false,
original_join_type: None,
single_to_inner: None,
}
.into();

Expand Down
Loading
Loading