From 292f9fcc60a9a267791884629616aeb37594fd45 Mon Sep 17 00:00:00 2001 From: joshua-spacetime Date: Mon, 16 Dec 2024 11:49:55 -0800 Subject: [PATCH] fix: filter pushdown over table scan --- crates/physical-plan/src/plan.rs | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/crates/physical-plan/src/plan.rs b/crates/physical-plan/src/plan.rs index 62bafdab21..99e10b1e91 100644 --- a/crates/physical-plan/src/plan.rs +++ b/crates/physical-plan/src/plan.rs @@ -753,12 +753,15 @@ impl RewriteRule for PushEqFilter { fn matches(plan: &PhysicalPlan) -> Option { if let PhysicalPlan::Filter(input, PhysicalExpr::BinOp(BinOp::Eq, expr, value)) = plan { if let (PhysicalExpr::Field(ProjectField { var, .. }), PhysicalExpr::Value(_)) = (&**expr, &**value) { - return input - .any(&|plan| match plan { - PhysicalPlan::TableScan(_, label) => label == var, - _ => false, - }) - .then_some(*var); + return match &**input { + PhysicalPlan::TableScan(..) => None, + input => input + .any(&|plan| match plan { + PhysicalPlan::TableScan(_, label) => label == var, + _ => false, + }) + .then_some(*var), + }; } } None @@ -825,12 +828,15 @@ impl RewriteRule for PushConjunction { if let PhysicalExpr::BinOp(BinOp::Eq, expr, value) = expr { if let (PhysicalExpr::Field(ProjectField { var, .. }), PhysicalExpr::Value(_)) = (&**expr, &**value) { - return input - .any(&|plan| match plan { - PhysicalPlan::TableScan(_, label) => label == var, - _ => false, - }) - .then_some(*var); + return match &**input { + PhysicalPlan::TableScan(..) => None, + input => input + .any(&|plan| match plan { + PhysicalPlan::TableScan(_, label) => label == var, + _ => false, + }) + .then_some(*var), + }; } } None