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

chore: add extra bracket for and and or to make explain clear #16494

Merged
merged 3 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading