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

Enhance explain #146

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft

Enhance explain #146

wants to merge 1 commit into from

Conversation

kysshsy
Copy link
Contributor

@kysshsy kysshsy commented Oct 7, 2024

Ticket(s) Closed

What

Why

How

Support the ANALYZE option: add a timer to record the actual execution time.
Support the STYLE option: Provide the query plan and execution time in DuckDB style.

Tests

@kysshsy
Copy link
Contributor Author

kysshsy commented Oct 7, 2024

It depends on sqlparser apache/datafusion-sqlparser-rs#1426. Awaiting the next release of the library.

src/hooks/query.rs Outdated Show resolved Hide resolved
@philippemnoel
Copy link
Collaborator

Should this be based off of #140?

@kysshsy
Copy link
Contributor Author

kysshsy commented Oct 9, 2024

Should this be based off of #140?

:) It actually doesn’t depend on #140; it’s just that part of them are the same. (split the explain in a single file.)

@philippemnoel
Copy link
Collaborator

Should this be based off of #140?

:) It actually doesn’t depend on #140; it’s just that part of them are the same. (split the explain in a single file.)

Got it. Let's still get the PREPARE PR in first though, since this one is blocked. Thank YOU for doing this, your PRs are always so clean!

Ok(r)
})?;

Ok(rows.join(""))
Copy link
Collaborator

Choose a reason for hiding this comment

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

This just adds a new row right?

Comment on lines +57 to +71
Style::Postgres => {
let mut output = format!("DuckDB Scan: {}\n", query);
if state.analyze {
let start_time = Instant::now();
set_search_path_by_pg()?;
connection::execute(&query, [])?;
let duration = start_time.elapsed();
output += &format!(
"Execution Time: {:.3} ms\n",
duration.as_micros() as f64 / 1_000.0
);
}
output
}
Style::Duckdb => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is cool. What do you see as the use case for supporting both styles? Is there anything the DuckDB style offers that can't be in a single style?

I don't want to increase cognitive load on the user. Ideally, they wouldn't need to pass any setting to EXPLAIN if they can avoid it. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image image

Copy link
Collaborator

Choose a reason for hiding this comment

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

That looks super clean, I really like that. Great work, wow! We should document this in the docs/ in paradedb/paradedb.

Really nice stuff. I assume it works with (analyze) even without the ()? i.e. EXPLAIN ANALYZE?

Copy link
Collaborator

@philippemnoel philippemnoel left a comment

Choose a reason for hiding this comment

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

Could you please provide output examples for all the style/options you are adding here? I.e. what the query looks like, and what the output looks like? I'd like to build a better understanding of what this will look like before we merge anything.

Also some tests, but I understand this PR isn't ready for review yet.

@kysshsy
Copy link
Contributor Author

kysshsy commented Oct 13, 2024

image image

Now supports :

  1. analyze (add a execution time statistics)
  2. duckdb style
  3. duckdb style and analyze

We can consider whether we need to add this style option.
The output of the EXPLAIN command in DuckDB differs significantly from that of PostgreSQL. Therefore, I would like to introduce a style option that allows users to obtain more detailed information about the query plan and performance tuning.

@philippemnoel
Copy link
Collaborator

image image
Now supports :

  1. analyze (add a execution time statistics)
  2. duckdb style
  3. duckdb style and analyze

We can consider whether we need to add this style option. The output of the EXPLAIN command in DuckDB differs significantly from that of PostgreSQL. Therefore, I would like to introduce a style option that allows users to obtain more detailed information about the query plan and performance tuning.

That looks really great. I think we should totally add this STYLE option :). Great idea!

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.

Enhance EXPLAIN Statement: Add analyze option, Support style option
2 participants