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

fix(batch): enforce order for LogicalValues created by empty LogicalScan #8079

Merged
merged 5 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
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