From ac68ca4de3536b869a5d24f10386cff223d338df Mon Sep 17 00:00:00 2001 From: ZENOTME Date: Tue, 28 Nov 2023 08:51:57 +0800 Subject: [PATCH] remove replace outbound cond --- e2e_test/batch/basic/null_range_scan.slt.part | 37 +++++++++++++++++++ .../tests/testdata/output/range_scan.yaml | 16 ++++++-- src/frontend/src/utils/condition.rs | 18 +-------- 3 files changed, 50 insertions(+), 21 deletions(-) diff --git a/e2e_test/batch/basic/null_range_scan.slt.part b/e2e_test/batch/basic/null_range_scan.slt.part index 85c71f143c28d..761c63c1f1788 100644 --- a/e2e_test/batch/basic/null_range_scan.slt.part +++ b/e2e_test/batch/basic/null_range_scan.slt.part @@ -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; diff --git a/src/frontend/planner_test/tests/testdata/output/range_scan.yaml b/src/frontend/planner_test/tests/testdata/output/range_scan.yaml index fb66ddb3f399b..d892c2d2417b9 100644 --- a/src/frontend/planner_test/tests/testdata/output/range_scan.yaml +++ b/src/frontend/planner_test/tests/testdata/output/range_scan.yaml @@ -339,19 +339,26 @@ 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 @@ -359,7 +366,8 @@ 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 diff --git a/src/frontend/src/utils/condition.rs b/src/frontend/src/utils/condition.rs index d078e06bcea6c..105d45dbc5153 100644 --- a/src/frontend/src/utils/condition.rs +++ b/src/frontend/src/utils/condition.rs @@ -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; }