Skip to content

Commit

Permalink
chore: add extra bracket for and and or to make explain clear (#1โ€ฆ
Browse files Browse the repository at this point in the history
โ€ฆ6494)

* fix: add extra bracket for and or

* add task test
  • Loading branch information
xudong963 authored Sep 24, 2024
1 parent d44b675 commit 7cd13ba
Show file tree
Hide file tree
Showing 22 changed files with 97 additions and 98 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/query/expression/src/utils/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ impl<Index: ColumnIndex> Expr<Index> {
precedence: usize,
min_precedence: usize,
) -> String {
if precedence < min_precedence {
if precedence < min_precedence || matches!(op, "AND" | "OR") {
format!(
"({} {op} {})",
write_expr(lhs, precedence),
Expand Down
2 changes: 1 addition & 1 deletion src/query/functions/tests/it/scalars/testdata/boolean.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ error:
--> SQL:1:1
|
1 | 'a' and 1
| ^^^ cannot parse to type `BOOLEAN` while evaluating function `to_boolean('a')` in expr `to_boolean('a')`, during run expr: `to_boolean('a') AND to_boolean(1)`
| ^^^ cannot parse to type `BOOLEAN` while evaluating function `to_boolean('a')` in expr `to_boolean('a')`, during run expr: `(to_boolean('a') AND to_boolean(1))`



Expand Down
10 changes: 5 additions & 5 deletions tests/sqllogictests/suites/mode/cluster/explain_v2.test
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Exchange
โ”œโ”€โ”€ exchange type: Merge
โ””โ”€โ”€ Filter
โ”œโ”€โ”€ output columns: [t1.a (#0), t1.b (#1), t2.b (#3), t2.a (#2)]
โ”œโ”€โ”€ filters: [t1.a (#0) > 3 OR t2.a (#2) > 5 AND t1.a (#0) > 1]
โ”œโ”€โ”€ filters: [(t1.a (#0) > 3 OR (t2.a (#2) > 5 AND t1.a (#0) > 1))]
โ”œโ”€โ”€ estimated rows: 99.60
โ””โ”€โ”€ HashJoin
โ”œโ”€โ”€ output columns: [t1.a (#0), t1.b (#1), t2.b (#3), t2.a (#2)]
Expand All @@ -56,7 +56,7 @@ Exchange
โ”‚ โ”œโ”€โ”€ exchange type: Broadcast
โ”‚ โ””โ”€โ”€ Filter
โ”‚ โ”œโ”€โ”€ output columns: [t2.a (#2), t2.b (#3)]
โ”‚ โ”œโ”€โ”€ filters: [t2.a (#2) > 3 OR t2.a (#2) > 1]
โ”‚ โ”œโ”€โ”€ filters: [(t2.a (#2) > 3 OR t2.a (#2) > 1)]
โ”‚ โ”œโ”€โ”€ estimated rows: 99.92
โ”‚ โ””โ”€โ”€ TableScan
โ”‚ โ”œโ”€โ”€ table: default.default.t2
Expand All @@ -66,11 +66,11 @@ Exchange
โ”‚ โ”œโ”€โ”€ partitions total: 3
โ”‚ โ”œโ”€โ”€ partitions scanned: 3
โ”‚ โ”œโ”€โ”€ pruning stats: [segments: <range pruning: 1 to 1>, blocks: <range pruning: 3 to 3>]
โ”‚ โ”œโ”€โ”€ push downs: [filters: [t2.a (#2) > 3 OR t2.a (#2) > 1], limit: NONE]
โ”‚ โ”œโ”€โ”€ push downs: [filters: [(t2.a (#2) > 3 OR t2.a (#2) > 1)], limit: NONE]
โ”‚ โ””โ”€โ”€ estimated rows: 100.00
โ””โ”€โ”€ Filter(Probe)
โ”œโ”€โ”€ output columns: [t1.a (#0), t1.b (#1)]
โ”œโ”€โ”€ filters: [t1.a (#0) > 3 OR t1.a (#0) > 1]
โ”œโ”€โ”€ filters: [(t1.a (#0) > 3 OR t1.a (#0) > 1)]
โ”œโ”€โ”€ estimated rows: 99.92
โ””โ”€โ”€ TableScan
โ”œโ”€โ”€ table: default.default.t1
Expand All @@ -80,7 +80,7 @@ Exchange
โ”œโ”€โ”€ partitions total: 3
โ”œโ”€โ”€ partitions scanned: 3
โ”œโ”€โ”€ pruning stats: [segments: <range pruning: 1 to 1>, blocks: <range pruning: 3 to 3>]
โ”œโ”€โ”€ push downs: [filters: [t1.a (#0) > 3 OR t1.a (#0) > 1], limit: NONE]
โ”œโ”€โ”€ push downs: [filters: [(t1.a (#0) > 3 OR t1.a (#0) > 1)], limit: NONE]
โ””โ”€โ”€ estimated rows: 100.00

query T
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ Sort
โ”œโ”€โ”€ estimated rows: 0.00
โ””โ”€โ”€ Filter
โ”œโ”€โ”€ output columns: [onebrc.station_name (#0), onebrc.measurement (#1)]
โ”œโ”€โ”€ filters: [is_true(onebrc.measurement (#1) > 0), is_true(onebrc.station_name (#0) = 'Beijing'), is_true(onebrc.measurement (#1) = 1 OR onebrc.measurement (#1) = 2)]
โ”œโ”€โ”€ filters: [is_true(onebrc.measurement (#1) > 0), is_true(onebrc.station_name (#0) = 'Beijing'), is_true((onebrc.measurement (#1) = 1 OR onebrc.measurement (#1) = 2))]
โ”œโ”€โ”€ estimated rows: 0.00
โ””โ”€โ”€ TableScan
โ”œโ”€โ”€ table: default.test_index_db.onebrc
Expand All @@ -500,9 +500,9 @@ Sort
โ”œโ”€โ”€ read size: 0
โ”œโ”€โ”€ partitions total: 0
โ”œโ”€โ”€ partitions scanned: 0
โ”œโ”€โ”€ push downs: [filters: [and_filters(and_filters(onebrc.measurement (#1) > 0, onebrc.station_name (#0) = 'Beijing'), onebrc.measurement (#1) = 1 OR onebrc.measurement (#1) = 2)], limit: NONE]
โ”œโ”€โ”€ push downs: [filters: [and_filters(and_filters(onebrc.measurement (#1) > 0, onebrc.station_name (#0) = 'Beijing'), (onebrc.measurement (#1) = 1 OR onebrc.measurement (#1) = 2))], limit: NONE]
โ”œโ”€โ”€ aggregating index: [SELECT station_name, measurement, COUNT(), COUNT(measurement), MAX(measurement), MIN(measurement), SUM(measurement) FROM test_index_db.onebrc GROUP BY station_name, measurement]
โ”œโ”€โ”€ rewritten query: [selection: [index_col_0 (#0), index_col_1 (#1), index_col_5 (#5), index_col_6 (#6), index_col_3 (#3), index_col_4 (#4)], filter: is_true(index_col_1 (#1) > CAST(0 AS Float64 NULL) AND index_col_0 (#0) = CAST('Beijing' AS String NULL) AND (index_col_1 (#1) = CAST(1 AS Float64 NULL) OR index_col_1 (#1) = CAST(2 AS Float64 NULL)))]
โ”œโ”€โ”€ rewritten query: [selection: [index_col_0 (#0), index_col_1 (#1), index_col_5 (#5), index_col_6 (#6), index_col_3 (#3), index_col_4 (#4)], filter: is_true(((index_col_1 (#1) > CAST(0 AS Float64 NULL) AND index_col_0 (#0) = CAST('Beijing' AS String NULL)) AND (index_col_1 (#1) = CAST(1 AS Float64 NULL) OR index_col_1 (#1) = CAST(2 AS Float64 NULL))))]
โ””โ”€โ”€ estimated rows: 0.00

statement ok
Expand Down Expand Up @@ -620,7 +620,7 @@ Sort
โ”œโ”€โ”€ estimated rows: 0.00
โ””โ”€โ”€ Filter
โ”œโ”€โ”€ output columns: [onebrc.station_name (#0), onebrc.measurement (#1)]
โ”œโ”€โ”€ filters: [is_true(onebrc.station_name (#0) = 'Paris' OR onebrc.station_name (#0) = 'Beijing')]
โ”œโ”€โ”€ filters: [is_true((onebrc.station_name (#0) = 'Paris' OR onebrc.station_name (#0) = 'Beijing'))]
โ”œโ”€โ”€ estimated rows: 0.00
โ””โ”€โ”€ TableScan
โ”œโ”€โ”€ table: default.test_index_db.onebrc
Expand All @@ -629,7 +629,7 @@ Sort
โ”œโ”€โ”€ read size: 0
โ”œโ”€โ”€ partitions total: 0
โ”œโ”€โ”€ partitions scanned: 0
โ”œโ”€โ”€ push downs: [filters: [is_true(onebrc.station_name (#0) = 'Paris' OR onebrc.station_name (#0) = 'Beijing')], limit: NONE]
โ”œโ”€โ”€ push downs: [filters: [is_true((onebrc.station_name (#0) = 'Paris' OR onebrc.station_name (#0) = 'Beijing'))], limit: NONE]
โ”œโ”€โ”€ aggregating index: [SELECT station_name, COUNT(), COUNT(measurement), MAX(measurement), MIN(measurement), SUM(measurement) FROM test_index_db.onebrc WHERE station_name IN('Paris', 'Beijing') GROUP BY station_name]
โ”œโ”€โ”€ rewritten query: [selection: [index_col_0 (#0), index_col_4 (#4), index_col_5 (#5), index_col_2 (#2), index_col_3 (#3)]]
โ””โ”€โ”€ estimated rows: 0.00
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ explain select * from t left join t t1 on t.a = t1.a where t1.a <= 1 or t.a < 1
----
Filter
โ”œโ”€โ”€ output columns: [t.a (#0), t1.a (#1)]
โ”œโ”€โ”€ filters: [is_true(t1.a (#1) <= 1 OR t.a (#0) < 1)]
โ”œโ”€โ”€ filters: [is_true((t1.a (#1) <= 1 OR t.a (#0) < 1))]
โ”œโ”€โ”€ estimated rows: 1.90
โ””โ”€โ”€ HashJoin
โ”œโ”€โ”€ output columns: [t.a (#0), t1.a (#1)]
Expand Down Expand Up @@ -573,7 +573,7 @@ explain select * from t left join t t1 on t.a = t1.a where t1.a <= 1 or (t.a > 1
----
Filter
โ”œโ”€โ”€ output columns: [t.a (#0), t1.a (#1)]
โ”œโ”€โ”€ filters: [is_true(t1.a (#1) <= 1 OR t.a (#0) > 1 AND t1.a (#1) > 1)]
โ”œโ”€โ”€ filters: [is_true((t1.a (#1) <= 1 OR (t.a (#0) > 1 AND t1.a (#1) > 1)))]
โ”œโ”€โ”€ estimated rows: 6.13
โ””โ”€โ”€ HashJoin
โ”œโ”€โ”€ output columns: [t.a (#0), t1.a (#1)]
Expand All @@ -584,7 +584,7 @@ Filter
โ”œโ”€โ”€ estimated rows: 7.47
โ”œโ”€โ”€ Filter(Build)
โ”‚ โ”œโ”€โ”€ output columns: [t1.a (#1)]
โ”‚ โ”œโ”€โ”€ filters: [is_true(t1.a (#1) <= 1 OR t1.a (#1) > 1)]
โ”‚ โ”œโ”€โ”€ filters: [is_true((t1.a (#1) <= 1 OR t1.a (#1) > 1))]
โ”‚ โ”œโ”€โ”€ estimated rows: 8.20
โ”‚ โ””โ”€โ”€ TableScan
โ”‚ โ”œโ”€โ”€ table: default.eliminate_outer_join.t
Expand All @@ -594,11 +594,11 @@ Filter
โ”‚ โ”œโ”€โ”€ partitions total: 1
โ”‚ โ”œโ”€โ”€ partitions scanned: 1
โ”‚ โ”œโ”€โ”€ pruning stats: [segments: <range pruning: 1 to 1>, blocks: <range pruning: 1 to 1>]
โ”‚ โ”œโ”€โ”€ push downs: [filters: [is_true(t.a (#1) <= 1 OR t.a (#1) > 1)], limit: NONE]
โ”‚ โ”œโ”€โ”€ push downs: [filters: [is_true((t.a (#1) <= 1 OR t.a (#1) > 1))], limit: NONE]
โ”‚ โ””โ”€โ”€ estimated rows: 10.00
โ””โ”€โ”€ Filter(Probe)
โ”œโ”€โ”€ output columns: [t.a (#0)]
โ”œโ”€โ”€ filters: [is_true(t.a (#0) <= 1 OR t.a (#0) > 1)]
โ”œโ”€โ”€ filters: [is_true((t.a (#0) <= 1 OR t.a (#0) > 1))]
โ”œโ”€โ”€ estimated rows: 8.20
โ””โ”€โ”€ TableScan
โ”œโ”€โ”€ table: default.eliminate_outer_join.t
Expand All @@ -608,15 +608,15 @@ Filter
โ”œโ”€โ”€ partitions total: 1
โ”œโ”€โ”€ partitions scanned: 1
โ”œโ”€โ”€ pruning stats: [segments: <range pruning: 1 to 1>, blocks: <range pruning: 1 to 1>]
โ”œโ”€โ”€ push downs: [filters: [is_true(t.a (#0) <= 1 OR t.a (#0) > 1)], limit: NONE]
โ”œโ”€โ”€ push downs: [filters: [is_true((t.a (#0) <= 1 OR t.a (#0) > 1))], limit: NONE]
โ””โ”€โ”€ estimated rows: 10.00

query T
explain select * from t left join t t1 on t.a = t1.a where t1.a <= 1 or (t.a > 1 and t.a < 2)
----
Filter
โ”œโ”€โ”€ output columns: [t.a (#0), t1.a (#1)]
โ”œโ”€โ”€ filters: [is_true(t1.a (#1) <= 1 OR t.a (#0) > 1 AND t.a (#0) < 2)]
โ”œโ”€โ”€ filters: [is_true((t1.a (#1) <= 1 OR (t.a (#0) > 1 AND t.a (#0) < 2)))]
โ”œโ”€โ”€ estimated rows: 2.80
โ””โ”€โ”€ HashJoin
โ”œโ”€โ”€ output columns: [t.a (#0), t1.a (#1)]
Expand Down
Loading

0 comments on commit 7cd13ba

Please sign in to comment.