diff --git a/src/frontend/planner_test/tests/testdata/order_by.yaml b/src/frontend/planner_test/tests/testdata/order_by.yaml index 2ada1226dce34..ea1f2df3b8faa 100644 --- a/src/frontend/planner_test/tests/testdata/order_by.yaml +++ b/src/frontend/planner_test/tests/testdata/order_by.yaml @@ -214,3 +214,24 @@ └─BatchSort { order: [$expr1 ASC] } └─BatchProject { exprs: [(test.b % 2:Int32) as $expr1, test.a] } └─BatchScan { table: test, columns: [test.a, test.b], distribution: SomeShard } +- name: Orderby with always-false predicate + sql: | + create table t1 (v1 int); + select + 1 as col_0 + from + t1 as t_0 + where + false + group by + t_0.v1 + order by + t_0.v1 asc; + batch_plan: | + BatchProject { exprs: [1:Int32] } + └─BatchExchange { order: [t1.v1 ASC], dist: Single } + └─BatchProject { exprs: [1:Int32, t1.v1] } + └─BatchSortAgg { group_key: [t1.v1], aggs: [] } + └─BatchExchange { order: [t1.v1 ASC], dist: HashShard(t1.v1) } + └─BatchSort { order: [t1.v1 ASC] } + └─BatchValues { rows: [] } diff --git a/src/frontend/src/optimizer/plan_node/logical_scan.rs b/src/frontend/src/optimizer/plan_node/logical_scan.rs index bfe1b19303407..0989528a6ad4e 100644 --- a/src/frontend/src/optimizer/plan_node/logical_scan.rs +++ b/src/frontend/src/optimizer/plan_node/logical_scan.rs @@ -544,8 +544,12 @@ impl LogicalScan { let (scan, predicate, project_expr) = scan.predicate_pull_up(); if predicate.always_false() { - return LogicalValues::create(vec![], scan.schema().clone(), scan.ctx()).to_batch(); + let plan = + LogicalValues::create(vec![], scan.schema().clone(), scan.ctx()).to_batch()?; + assert_eq!(plan.schema(), self.schema()); + return required_order.enforce_if_not_satisfies(plan); } + let mut plan: PlanRef = BatchSeqScan::new(scan, scan_ranges).into(); if !predicate.always_true() { plan = BatchFilter::new(LogicalFilter::new(plan, predicate)).into();