Skip to content

Non-inner joins + single column filters don't work #606

@MBkkt

Description

@MBkkt

There 2 reasons:

  1. When we do distributeConjuncts we don't account that we can pushdown such filters through such joins
  2. Same when we actually enumerate plans in makeJoins
TEST_F(PlanTest, pushdownFilterThroughJoin) {
  testConnector_->addTable("t1", ROW({"id1", "data1"}, {BIGINT(), BIGINT()}));
  testConnector_->addTable("t2", ROW({"id2", "data2"}, {BIGINT(), BIGINT()}));

  auto makePlan = [&](lp::JoinType joinType) {
    lp::PlanBuilder::Context ctx{kTestConnectorId};
    return lp::PlanBuilder{ctx}
        .from({"t1"})
        .join(lp::PlanBuilder{ctx}.from({"t2"}), "id1 = id2", joinType)
        .filter("data1 IS NULL")
        .filter("data2 IS NULL")
        .build();
  };

  {
    SCOPED_TRACE("Inner Join");
    auto logicalPlan = makePlan(lp::JoinType::kInner);
    auto matcher = core::PlanMatcherBuilder{}
                       .tableScan("t1")
                       .filter("data1 IS NULL")
                       .hashJoin(
                           core::PlanMatcherBuilder{}
                               .tableScan("t2")
                               .filter("data2 IS NULL")
                               .build(),
                           core::JoinType::kInner)
                       .build();
    auto plan = toSingleNodePlan(logicalPlan);
    AXIOM_ASSERT_PLAN(plan, matcher);
  }
  {
    SCOPED_TRACE("Left Join");
    auto logicalPlan = makePlan(lp::JoinType::kLeft);
    auto matcher = core::PlanMatcherBuilder{}
                       .tableScan("t1")
                       .filter("data1 IS NULL")
                       .hashJoin(
                           core::PlanMatcherBuilder{}.tableScan("t2").build(),
                           core::JoinType::kLeft)
                       .filter("data2 IS NULL")
                       .build();
    auto plan = toSingleNodePlan(logicalPlan);
    AXIOM_ASSERT_PLAN(plan, matcher);
  }
  {
    SCOPED_TRACE("Right Join");
    auto logicalPlan = makePlan(lp::JoinType::kRight);
    auto matcher = core::PlanMatcherBuilder{}
                       .tableScan("t1")
                       .hashJoin(
                           core::PlanMatcherBuilder{}
                               .tableScan("t2")
                               .filter("data2 IS NULL")
                               .build(),
                           core::JoinType::kRight)
                       .filter("data1 IS NULL")
                       .build();
    auto plan = toSingleNodePlan(logicalPlan);
    AXIOM_ASSERT_PLAN(plan, matcher);
  }
  {
    SCOPED_TRACE("Full Join");
    auto logicalPlan = makePlan(lp::JoinType::kFull);
    auto matcher = core::PlanMatcherBuilder{}
                       .tableScan("t1")
                       .hashJoin(
                           core::PlanMatcherBuilder{}.tableScan("t2").build(),
                           core::JoinType::kFull)
                       .filter("data1 IS NULL AND data2 IS NULL")
                       .build();
    auto plan = toSingleNodePlan(logicalPlan);
    AXIOM_ASSERT_PLAN(plan, matcher);
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions