Skip to content

Commit

Permalink
remove replace outbound cond
Browse files Browse the repository at this point in the history
  • Loading branch information
ZENOTME committed Nov 28, 2023
1 parent 6fe26b4 commit ac68ca4
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 21 deletions.
37 changes: 37 additions & 0 deletions e2e_test/batch/basic/null_range_scan.slt.part
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,43 @@ query II rowsort
SELECT * FROM t0 WHERE (c1 > 1);
----


query II rowsort
SELECT * FROM t0 WHERE (c1 > 9223372036854775808) IS NULL;
----
1 NULL

query II rowsort
SELECT * FROM t0 WHERE (c1 < 9223372036854775808) IS NULL;
----
1 NULL

query II rowsort
SELECT * FROM t0 WHERE (c1 >= -9223372036854775808) IS NULL;
----
1 NULL

query II rowsort
SELECT * FROM t0 WHERE (c1 <= -9223372036854775808) IS NULL;
----
1 NULL

query II rowsort
SELECT * FROM t0 WHERE c1 > 9223372036854775808;
----

query II rowsort
SELECT * FROM t0 WHERE c1 < 9223372036854775808;
----

query II rowsort
SELECT * FROM t0 WHERE c1 >= -9223372036854775808;
----

query II rowsort
SELECT * FROM t0 WHERE c1 <= -9223372036854775808;
----

statement ok
create materialized view mv as select * from t0 order by c1 desc nulls last;

Expand Down
16 changes: 12 additions & 4 deletions src/frontend/planner_test/tests/testdata/output/range_scan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -339,27 +339,35 @@
SELECT * FROM mv WHERE x < 60000;
batch_plan: |-
BatchExchange { order: [], dist: Single }
└─BatchScan { table: mv, columns: [mv.x], distribution: UpstreamHashShard(mv.x) }
└─BatchFilter { predicate: (mv.x < 60000:Int32) }
└─BatchScan { table: mv, columns: [mv.x], distribution: UpstreamHashShard(mv.x) }
- name: When the constant with larger type is out of the upper bound of the column's type, we can convert > as false condition.
before:
- create_small
sql: |
SELECT * FROM mv WHERE x > 60000;
batch_plan: 'BatchValues { rows: [] }'
batch_plan: |-
BatchExchange { order: [], dist: Single }
└─BatchFilter { predicate: (mv.x > 60000:Int32) }
└─BatchScan { table: mv, columns: [mv.x], distribution: UpstreamHashShard(mv.x) }
- name: When the constant with larger type is out of the lower bound of the column's type, we can convert < as false condition.
before:
- create_small
sql: |
SELECT * FROM mv WHERE x < -60000;
batch_plan: 'BatchValues { rows: [] }'
batch_plan: |-
BatchExchange { order: [], dist: Single }
└─BatchFilter { predicate: (mv.x < -60000:Int32) }
└─BatchScan { table: mv, columns: [mv.x], distribution: UpstreamHashShard(mv.x) }
- name: When the constant with larger type is out of the lower bound of the column's type, we can convert > as true condition.
before:
- create_small
sql: |
SELECT * FROM mv WHERE x > -60000;
batch_plan: |-
BatchExchange { order: [], dist: Single }
└─BatchScan { table: mv, columns: [mv.x], distribution: UpstreamHashShard(mv.x) }
└─BatchFilter { predicate: (mv.x > -60000:Int32) }
└─BatchScan { table: mv, columns: [mv.x], distribution: UpstreamHashShard(mv.x) }
- name: When the constant with larger type is in range of the column's type, we can convert it.
before:
- create_small
Expand Down
18 changes: 1 addition & 17 deletions src/frontend/src/utils/condition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,23 +622,7 @@ impl Condition {
op,
) {
Ok(ResultForCmp::Success(expr)) => expr,
Ok(ResultForCmp::OutUpperBound) => {
if op == ExprType::GreaterThan || op == ExprType::GreaterThanOrEqual {
return Ok(None);
}
// op == < and <= means result is always true, don't need any extra
// work.
continue;
}
Ok(ResultForCmp::OutLowerBound) => {
if op == ExprType::LessThan || op == ExprType::LessThanOrEqual {
return Ok(None);
}
// op == > and >= means result is always true, don't need any extra
// work.
continue;
}
Err(_) => {
_ => {
other_conds.push(expr);
continue;
}
Expand Down

0 comments on commit ac68ca4

Please sign in to comment.