Skip to content

Conversation

abramk
Copy link
Contributor

@abramk abramk commented Sep 14, 2024

HTML and Graphviz were only supported for explain output, not explain analyze. This PR adds support for explain analyze as well. In addition, the total query elapsed time is written into the root (Query) node so that it is available in the rendered html or graphviz output.

@duckdb-draftbot duckdb-draftbot marked this pull request as draft September 16, 2024 02:03
@abramk abramk marked this pull request as ready for review September 16, 2024 02:04
@Mytherin Mytherin requested a review from Tishj September 16, 2024 08:10
@Tishj
Copy link
Contributor

Tishj commented Sep 16, 2024

While this technically works, it does result in a lot of code duplication and this code duplication has to be extended further for every format that gets added.
I ideally want to make it possible for formats to be added by extensions, but maybe that's too big of a step.

I agree that this issue with analyze has to be fixed first, but hopefully we can move this logic into the TreeRenderer class. So derived classes only have to implement what is specific to their respective format and not have to duplicate a lot of the existing code

return str.str();
}

void QueryProfiler::GraphvizToStream(std::ostream &ss) const {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above, can we avoid this duplication?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I also changed the call from connection.cpp to call into query_profiler::ToString(ProfilerPrintFormat)

@@ -247,6 +252,10 @@ string QueryProfiler::ToString(ExplainFormat explain_format) const {
return ToJSON();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we merge ToJSON, ToHTML and ToGraphViz, only the ExplainFormat has to be passed down I feel.
Ideally we make adjustments to QueryTreeToString to unify all these paths but that can be done at a later point

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ToJSON implementation in query_profiler.cpp is different from the JSONTreeRenderer and they produce different output. If client code is integrated with the current json output, this will be a breaking change to use the JSONTreeRendere here. Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the functionality into the ToString() method itself. Eventually, if we move the differences in json and querytree rendering to the tree_renderer derivatives, this this function should be able to handle it all.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ToJSON implementation in query_profiler.cpp is different from the JSONTreeRenderer and they produce different output. If client code is integrated with the current json output, this will be a breaking change to use the JSONTreeRendere here. Thoughts?

Yes, that's one of the reasons I haven't touched it yet and I don't have an immediate answer for you because I was not involved in creating the ToJSON logic query_profiler.cpp so I don't yet know what the implications behind changing that are

@duckdb-draftbot duckdb-draftbot marked this pull request as draft September 16, 2024 16:00
@abramk abramk marked this pull request as ready for review September 16, 2024 23:46
@duckdb-draftbot duckdb-draftbot marked this pull request as draft September 17, 2024 00:15
@abramk abramk marked this pull request as ready for review September 17, 2024 00:15
@abramk
Copy link
Contributor Author

abramk commented Sep 18, 2024

@Tishj ready for re-review.

@Mytherin Mytherin changed the base branch from main to feature September 19, 2024 06:50
@duckdb-draftbot duckdb-draftbot marked this pull request as draft September 21, 2024 12:58
@abramk abramk marked this pull request as ready for review September 21, 2024 12:58
HTML and Graphviz were only supported for explain output, not explain analyze.
This PR adds support for explain analyze as well. In addition, the total query
elapsed time is written into the root (Query) node so that it is available in
the rendered html or graphviz output.
@duckdb-draftbot duckdb-draftbot marked this pull request as draft September 23, 2024 20:54
@abramk abramk marked this pull request as ready for review September 23, 2024 20:54
@abramk
Copy link
Contributor Author

abramk commented Oct 2, 2024

@Mytherin or @Tishj are you able to review this?

Copy link
Contributor

@Tishj Tishj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I will eventually rework this probably if we ever care about making the explain format extendable.

For now not having it error and display a decent rendition of the analyze data is a welcome change 👍

@Mytherin Mytherin merged commit a6441ee into duckdb:feature Oct 7, 2024
40 checks passed
@Mytherin
Copy link
Collaborator

Mytherin commented Oct 7, 2024

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants