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

Proposal: add support for EXPLAIN statement #3313

Closed
wants to merge 1 commit into from

Conversation

leandrocp
Copy link
Contributor

@leandrocp leandrocp commented May 24, 2020

During development a very common process is to optimize complex queries by using the EXPLAIN sql statement, which as for now requires to play with to_sql, copy & paste, manually building the query and calling it on a SQL client. This PR proposes to add Repo.explain/2 function to ease this process and improve the developer experience.

Of course It's just a WIP to gather feedback of the core team, as it's missing:

  • Maybe improve the function return? current output is just a string like "Seq Scan on barebones b0 (cost=0.00..30.40 rows=2040 width=4)"
  • Call EXPLAIN inside a transaction to avoid side effects
  • Support other statements besides SELECT
  • Pass options to the EXPLAIN statement
  • Implement callback for all adapters
  • Improve tests

ecto-sql implementation: elixir-ecto/ecto_sql#231

Please note I'm not an expert in Ecto internals so it may not be the best possible implementation.

It's still a WIP to gater feedbacks
@josevalim
Copy link
Member

Hi @leandrocp! Thanks so much for the PR. I think however we can implement this directly in Ecto.SQL. We probably don't need to change the planner and instead we can prepare it using :all and then append the EXPLAIN instructions. WDYT?

@leandrocp
Copy link
Contributor Author

The only reason I changed the planner was because I wasn't sure the best way to implement this and it looked right :)
So I'm fine with implementing this on ecto_sql side, maybe similar to to_sql?

@josevalim
Copy link
Member

So I'm fine with implementing this on ecto_sql side, maybe similar to to_sql?

Yes, exactly!

@josevalim
Copy link
Member

I will go ahead and close this but ping me if you feel like this is necessary. :)

@josevalim josevalim closed this May 25, 2020
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.

2 participants