Skip to content

Commit

Permalink
fix(query): fix lazy columns missed in constant table scan (#17258)
Browse files Browse the repository at this point in the history
* fix(query): fix lazy columns missed in constant table scan

Signed-off-by: damon <[email protected]>

* clear lazy columns when rewriting false filter to be empty scan

Signed-off-by: damon <[email protected]>

---------

Signed-off-by: damon <[email protected]>
  • Loading branch information
Damon07 authored Jan 14, 2025
1 parent 009a5eb commit 51d8c54
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/query/sql/src/planner/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ impl Metadata {
self.lazy_columns.extend(indices);
}

pub fn clear_lazy_columns(&mut self) {
self.lazy_columns.clear();
}

pub fn add_non_lazy_columns(&mut self, indices: HashSet<usize>) {
debug_assert!(indices.iter().all(|i| *i < self.columns.len()));
self.non_lazy_columns.extend(indices);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ impl Rule for RuleEliminateFilter {
.derive_relational_prop(&RelExpr::with_s_expr(s_expr))?
.output_columns
.clone();

{
let mut metadata = self.metadata.write();
metadata.clear_lazy_columns();
}

let metadata = self.metadata.read();
let mut fields = Vec::with_capacity(output_columns.len());

Expand Down
8 changes: 8 additions & 0 deletions tests/sqllogictests/suites/query/issues/issue_17158.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
statement ok
create table tt2 (c0 bool, c1 int);

statement ok
insert into tt2 values(true, 1),(false, 2),(true, 3);

statement ok
select null, c0, 30, c1 from tt2 where false order by c0 LIMIT 3 OFFSET 0;

0 comments on commit 51d8c54

Please sign in to comment.