-
Notifications
You must be signed in to change notification settings - Fork 595
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
feat(frontend): output explain result as graphviz dot format #19446
Conversation
b2da183
to
7d27c38
Compare
src/sqlparser/src/ast/mod.rs
Outdated
@@ -1161,6 +1161,8 @@ pub struct ExplainOptions { | |||
pub verbose: bool, | |||
// Trace plan transformation of the optimizer step by step | |||
pub trace: bool, | |||
// Output the plan information as graphviz format. | |||
pub graphviz: bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not add graphviz as an option, it should be an ExplainFormat
.
Further the format is DOT
, graphviz
is not a format.
So it should be explain (logical, format dot)
.
Thanks for your work in this PR. The output spawns new graph nodes for properties of plan nodes. I think it can be improved, these properties should be a part of their plan nodes' graph node. Perhaps it's hard to implement with the petgraph::Graph interface. You may do some further investigation to see if |
7d27c38
to
f27c73d
Compare
Thank you I have updated the pr. I had this approach to serialize every graph node as label, very simple but very inefficient. let me know if you found better options. |
Typically, our plan-nodes are structured with
That's just a
Next, if we look at the risingwave/src/frontend/src/optimizer/plan_node/mod.rs Lines 660 to 666 in 5b9cf24
We can see that we construct a Pretty::Record for this node.
So we can just assign graph nodes to Next, an
We can append the |
Feel free to let me know if you encounter any difficulties. |
f27c73d
to
481212f
Compare
Thank you for the pointers I learned a lot, the code is actually simpler and the results are much nicer as well. |
let mut label = String::new(); | ||
label.push_str(&r.name); | ||
if !r.fields.is_empty() { | ||
label.push_str(" fields: "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The alternative is to add each field to a new line, this is much closer to the desired pictures provided
for (k, v) in r.fields.iter() {
label.push_str("\n");
label.push_str(&k);
label.push_str(": ");
label.push_str(&serde_json::to_string(&PrettySerde(v.clone())).expect("failed to serialize plan to dot"));
}
However, the visualized output does not look great in terms of alignment, not sure if this is an dot output to png issue, or a rust string fmt issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/frontend/planner_test/tests/testdata/output/explain_dot_format.yaml
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add more test cases? Like in #19430.
Some further improvement would be to test large labels (stream_key has 200 columns for instance), and improve its DOT
output, for instance doing truncation.
This can be tracked and worked on in a separate issue and PR. We have a good starting point from this PR.
Rest LGTM. Thanks for your efforts!
481212f
to
09a7dca
Compare
Yep added the very long test case but i realize the output is not readable after convert it into graph because the serialization of the (nested) children nodes. |
09a7dca
to
12adb47
Compare
0357b12
to
b8ac5d5
Compare
In the large testcase that was just added, here's the original risingwave/src/frontend/planner_test/tests/testdata/output/subquery_expr_correlated.yaml Line 1308 in ad1d929
In our You can |
Great catch, thanks for the commit. |
6891a9f
to
de158f4
Compare
LGTM, thanks! |
a771dab
If you're interested there's a further extension of this task: #19542. We wish to use it in our kernel dashboard, to visualize distributed stream job fragments. |
I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.
What's changed and what's your intention?
add graphviz support for explain
Please do not leave this empty!
Add dot format output for explain, the output could be visualized as
Please explain IN DETAIL what the changes are in this PR and why they are needed:
close feat: explain a query and output a Graphviz representation of the query plan #18803
Checklist
./risedev check
(or alias,./risedev c
)Documentation
Release note
If this PR includes changes that directly affect users or other significant modifications relevant to the community, kindly draft a release note to provide a concise summary of these changes. Please prioritize highlighting the impact these changes will have on users.
Release note
Public Preview: Do note that the structure and format of EXPLAIN FORMAT=DOT is considered unstable, and may change overtime.
After this PR, one new explain option is supported
FORMAT DOT
. it will output dot format for logical and physical plans.examples:
result