Skip to content

Commit

Permalink
feat: output explain result as dot format
Browse files Browse the repository at this point in the history
  • Loading branch information
lyang24 committed Nov 21, 2024
1 parent 3fdd6a5 commit 12adb47
Show file tree
Hide file tree
Showing 10 changed files with 420 additions and 16 deletions.
19 changes: 19 additions & 0 deletions Cargo.lock

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
- name: test dot output format (logical)
sql: |
CREATE TABLE t (v1 int);
explain (logical, format dot) SELECT approx_percentile(0.5) WITHIN GROUP (order by v1) from t;
expected_outputs:
- explain_output
- name: test dot output format (batch)
sql: |
CREATE TABLE t (v1 int);
explain (physical, format dot) SELECT approx_percentile(0.5) WITHIN GROUP (order by v1) from t;
expected_outputs:
- explain_output
- name: test dot output format (stream)
sql: |
CREATE TABLE t (v1 int);
explain (physical, format dot) create materialized view m1 as SELECT approx_percentile(0.5) WITHIN GROUP (order by v1) from t;
expected_outputs:
- explain_output
- name: test long dot output format (stream)
sql: |
create table t1(a int, b int);
create table t2(c int primary key, d int);
explain (physical, format dot) create materialized view m1 as SELECT
COALESCE((SELECT b FROM t2 WHERE t1.a = t2.c), 0) col1,
COALESCE((SELECT b FROM t2 WHERE t1.a = t2.c), 0) col2,
COALESCE((SELECT b FROM t2 WHERE t1.a = t2.c), 0) col3,
COALESCE((SELECT b FROM t2 WHERE t1.a = t2.c), 0) col4,
COALESCE((SELECT b FROM t2 WHERE t1.a = t2.c), 0) col5,
COALESCE((SELECT b FROM t2 WHERE t1.a = t2.c), 0) col6,
COALESCE((SELECT b FROM t2 WHERE t1.a = t2.c), 0) col7,
COALESCE((SELECT b FROM t2 WHERE t1.a = t2.c), 0) col8,
COALESCE((SELECT b FROM t2 WHERE t1.a = t2.c), 0) col9,
COALESCE((SELECT b FROM t2 WHERE t1.a = t2.c), 0) col10,
COALESCE((SELECT b FROM t2 WHERE t1.a = t2.c), 0) col11,
COALESCE((SELECT b FROM t2 WHERE t1.a = t2.c), 0) col12,
COALESCE((SELECT b FROM t2 WHERE t1.a = t2.c), 0) col13,
COALESCE((SELECT b FROM t2 WHERE t1.a = t2.c), 0) col14,
COALESCE((SELECT b FROM t2 WHERE t1.a = t2.c), 0) col15,
COALESCE((SELECT b FROM t2 WHERE t1.a = t2.c), 0) col16,
COALESCE((SELECT b FROM t2 WHERE t1.a = t2.c), 0) col17,
COALESCE((SELECT b FROM t2 WHERE t1.a = t2.c), 0) col18
from t1;
expected_outputs:
- explain_output
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
# This file is automatically generated. See `src/frontend/planner_test/README.md` for more information.
- name: test dot output format (logical)
sql: |
CREATE TABLE t (v1 int);
explain (logical, format dot) SELECT approx_percentile(0.5) WITHIN GROUP (order by v1) from t;
explain_output: |
digraph {
0 [ label = "LogicalAgg\laggs: [\"approx_percentile($expr1)\"]\l" ]
1 [ label = "LogicalProject\lexprs: [\"t.v1::Float64 as $expr1\"]\l" ]
2 [ label = "LogicalScan\ltable: \"t\"\lcolumns: [\"v1\"]\l" ]
0 -> 1 [ ]
1 -> 2 [ ]
}
- name: test dot output format (batch)
sql: |
CREATE TABLE t (v1 int);
explain (physical, format dot) SELECT approx_percentile(0.5) WITHIN GROUP (order by v1) from t;
explain_output: |
digraph {
0 [ label = "BatchSimpleAgg\laggs: [\"approx_percentile($expr1)\"]\l" ]
1 [ label = "BatchExchange\lorder: []\ldist: \"Single\"\l" ]
2 [ label = "BatchProject\lexprs: [\"t.v1::Float64 as $expr1\"]\l" ]
3 [ label = "BatchScan\ltable: \"t\"\lcolumns: [\"v1\"]\l" ]
0 -> 1 [ ]
1 -> 2 [ ]
2 -> 3 [ ]
}
- name: test dot output format (stream)
sql: |
CREATE TABLE t (v1 int);
explain (physical, format dot) create materialized view m1 as SELECT approx_percentile(0.5) WITHIN GROUP (order by v1) from t;
explain_output: |
digraph {
0 [ label = "StreamMaterialize\lcolumns: [\"approx_percentile\"]\lstream_key: []\lpk_columns: []\lpk_conflict: \"NoCheck\"\l" ]
1 [ label = "StreamGlobalApproxPercentile\lquantile: \"0.5:Float64\"\lrelative_error: \"0.01:Float64\"\l" ]
2 [ label = "StreamExchange\ldist: \"Single\"\l" ]
3 [ label = "StreamLocalApproxPercentile\lpercentile_col: \"$expr1\"\lquantile: \"0.5:Float64\"\lrelative_error: \"0.01:Float64\"\l" ]
4 [ label = "StreamProject\lexprs: [\"t.v1::Float64 as $expr1\",\"t._row_id\"]\l" ]
5 [ label = "StreamTableScan\ltable: \"t\"\lcolumns: [\"v1\",\"_row_id\"]\l" ]
0 -> 1 [ ]
1 -> 2 [ ]
2 -> 3 [ ]
3 -> 4 [ ]
4 -> 5 [ ]
}
- name: test long dot output format (stream)
sql: |
create table t1(a int, b int);
create table t2(c int primary key, d int);
explain (physical, format dot) create materialized view m1 as SELECT
COALESCE((SELECT b FROM t2 WHERE t1.a = t2.c), 0) col1,
COALESCE((SELECT b FROM t2 WHERE t1.a = t2.c), 0) col2,
COALESCE((SELECT b FROM t2 WHERE t1.a = t2.c), 0) col3,
COALESCE((SELECT b FROM t2 WHERE t1.a = t2.c), 0) col4,
COALESCE((SELECT b FROM t2 WHERE t1.a = t2.c), 0) col5,
COALESCE((SELECT b FROM t2 WHERE t1.a = t2.c), 0) col6,
COALESCE((SELECT b FROM t2 WHERE t1.a = t2.c), 0) col7,
COALESCE((SELECT b FROM t2 WHERE t1.a = t2.c), 0) col8,
COALESCE((SELECT b FROM t2 WHERE t1.a = t2.c), 0) col9,
COALESCE((SELECT b FROM t2 WHERE t1.a = t2.c), 0) col10,
COALESCE((SELECT b FROM t2 WHERE t1.a = t2.c), 0) col11,
COALESCE((SELECT b FROM t2 WHERE t1.a = t2.c), 0) col12,
COALESCE((SELECT b FROM t2 WHERE t1.a = t2.c), 0) col13,
COALESCE((SELECT b FROM t2 WHERE t1.a = t2.c), 0) col14,
COALESCE((SELECT b FROM t2 WHERE t1.a = t2.c), 0) col15,
COALESCE((SELECT b FROM t2 WHERE t1.a = t2.c), 0) col16,
COALESCE((SELECT b FROM t2 WHERE t1.a = t2.c), 0) col17,
COALESCE((SELECT b FROM t2 WHERE t1.a = t2.c), 0) col18
from t1;
explain_output: |
digraph {
0 [ label = "StreamMaterialize\lcolumns: [\"col1\",\"col2\",\"col3\",\"col4\",\"col5\",\"col6\",\"col7\",\"col8\",\"col9\",\"col10\",\"col11\",\"col12\",\"col13\",\"col14\",\"col15\",\"col16\",\"col17\",\"col18\",\"t1._row_id(hidden)\",\"t1.b(hidden)\",\"t1.a(hidden)\",\"t1.b#1(hidden)\",\"t1.b#2(hidden)\",\"t1.b#3(hidden)\",\"t1.b#4(hidden)\",\"t1.b#5(hidden)\",\"t1.b#6(hidden)\",\"t1.b#7(hidden)\",\"t1.b#8(hidden)\",\"t1.b#9(hidden)\",\"t1.b#10(hidden)\",\"t1.b#11(hidden)\",\"t1.b#12(hidden)\",\"t1.b#13(hidden)\",\"t1.b#14(hidden)\",\"t1.b#15(hidden)\",\"t1.b#16(hidden)\",\"t1.b#17(hidden)\",\"t1.b#18(hidden)\"]\lstream_key: [\"t1._row_id\",\"t1.b\",\"t1.a\",\"t1.b#1\",\"t1.b#2\",\"t1.b#3\",\"t1.b#4\",\"t1.b#5\",\"t1.b#6\",\"t1.b#7\",\"t1.b#8\",\"t1.b#9\",\"t1.b#10\",\"t1.b#11\",\"t1.b#12\",\"t1.b#13\",\"t1.b#14\",\"t1.b#15\",\"t1.b#16\",\"t1.b#17\",\"t1.b#18\"]\lpk_columns: [\"t1._row_id\",\"t1.b\",\"t1.a\",\"t1.b#1\",\"t1.b#2\",\"t1.b#3\",\"t1.b#4\",\"t1.b#5\",\"t1.b#6\",\"t1.b#7\",\"t1.b#8\",\"t1.b#9\",\"t1.b#10\",\"t1.b#11\",\"t1.b#12\",\"t1.b#13\",\"t1.b#14\",\"t1.b#15\",\"t1.b#16\",\"t1.b#17\",\"t1.b#18\"]\lpk_conflict: \"NoCheck\"\l" ]
1 [ label = "StreamProject\lexprs: [\"Coalesce(t1.b, 0:Int32) as $expr1\",\"Coalesce(t1.b, 0:Int32) as $expr2\",\"Coalesce(t1.b, 0:Int32) as $expr3\",\"Coalesce(t1.b, 0:Int32) as $expr4\",\"Coalesce(t1.b, 0:Int32) as $expr5\",\"Coalesce(t1.b, 0:Int32) as $expr6\",\"Coalesce(t1.b, 0:Int32) as $expr7\",\"Coalesce(t1.b, 0:Int32) as $expr8\",\"Coalesce(t1.b, 0:Int32) as $expr9\",\"Coalesce(t1.b, 0:Int32) as $expr10\",\"Coalesce(t1.b, 0:Int32) as $expr11\",\"Coalesce(t1.b, 0:Int32) as $expr12\",\"Coalesce(t1.b, 0:Int32) as $expr13\",\"Coalesce(t1.b, 0:Int32) as $expr14\",\"Coalesce(t1.b, 0:Int32) as $expr15\",\"Coalesce(t1.b, 0:Int32) as $expr16\",\"Coalesce(t1.b, 0:Int32) as $expr17\",\"Coalesce(t1.b, 0:Int32) as $expr18\",\"t1._row_id\",\"t1.b\",\"t1.a\",\"t1.b\",\"t1.b\",\"t1.b\",\"t1.b\",\"t1.b\",\"t1.b\",\"t1.b\",\"t1.b\",\"t1.b\",\"t1.b\",\"t1.b\",\"t1.b\",\"t1.b\",\"t1.b\",\"t1.b\",\"t1.b\",\"t1.b\",\"t1.b\"]\l" ]
2 [ label = "StreamHashJoin\ltype: \"LeftOuter\"\lpredicate: \"t1.a IS NOT DISTINCT FROM t1.a AND t1.b IS NOT DISTINCT FROM t1.b\"\l" ]
3 [ label = "StreamExchange\ldist: \"HashShard(t1.a)\"\l" ]
4 [ label = "StreamTableScan\ltable: \"t1\"\lcolumns: [\"a\",\"b\",\"_row_id\"]\l" ]
5 [ label = "StreamProject\lexprs: [\"t1.a\",\"t1.b\",\"t1.b\"]\l" ]
6 [ label = "StreamHashJoin\ltype: \"Inner\"\lpredicate: \"t1.a = t2.c\"\l" ]
7 [ label = "StreamProject\lexprs: [\"t1.a\",\"t1.b\"]\l" ]
8 [ label = "StreamHashAgg\lgroup_key: [\"t1.a\",\"t1.b\"]\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]
3 -> 7 [ ]
7 -> 8 [ ]
8 -> 9 [ ]
9 -> 4 [ ]
6 -> 10 [ ]
10 -> 11 [ ]
2 -> 5 [ ]
5 -> 6 [ ]
6 -> 3 [ ]
3 -> 7 [ ]
7 -> 8 [ ]
8 -> 9 [ ]
9 -> 4 [ ]
6 -> 10 [ ]
10 -> 11 [ ]
2 -> 5 [ ]
5 -> 6 [ ]
6 -> 3 [ ]
3 -> 7 [ ]
7 -> 8 [ ]
8 -> 9 [ ]
9 -> 4 [ ]
6 -> 10 [ ]
10 -> 11 [ ]
}
1 change: 1 addition & 0 deletions src/frontend/src/handler/explain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ async fn do_handle_explain(
ExplainFormat::Json => blocks.push(plan.explain_to_json()),
ExplainFormat::Xml => blocks.push(plan.explain_to_xml()),
ExplainFormat::Yaml => blocks.push(plan.explain_to_yaml()),
ExplainFormat::Dot => blocks.push(plan.explain_to_dot()),
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/frontend/src/optimizer/logical_optimization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,9 @@ impl LogicalOptimizer {
ExplainFormat::Yaml => {
ctx.store_logical(plan.explain_to_yaml());
}
ExplainFormat::Dot => {
ctx.store_logical(plan.explain_to_dot());
}
}
}

Expand Down Expand Up @@ -819,6 +822,9 @@ impl LogicalOptimizer {
ExplainFormat::Yaml => {
ctx.store_logical(plan.explain_to_yaml());
}
ExplainFormat::Dot => {
ctx.store_logical(plan.explain_to_dot());
}
}
}

Expand Down
Loading

0 comments on commit 12adb47

Please sign in to comment.