Skip to content

Commit

Permalink
fix(batch): enforce order for LogicalValues created by empty `Logic…
Browse files Browse the repository at this point in the history
…alScan` (#8079)

- Fix #8067.

Approved-By: chenzl25
Approved-By: jon-chuang

Co-Authored-By: Noel Kwan <noelkwan1998@gmail.com>
Co-Authored-By: Noel Kwan <47273164+kwannoel@users.noreply.github.com>
  • Loading branch information
kwannoel and kwannoel authored Feb 22, 2023
1 parent 4b6e093 commit 8bc69d4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/frontend/planner_test/tests/testdata/order_by.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: [] }
6 changes: 5 additions & 1 deletion src/frontend/src/optimizer/plan_node/logical_scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 8bc69d4

Please sign in to comment.