-
Notifications
You must be signed in to change notification settings - Fork 312
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
Add support for EXPLAIN statement #231
Conversation
It's still a WIP to gather feedback
Looks great! I have also dropped a comment on the Ecto issue, as I think this could be totally implemented on EctoSQL and not touch Ecto. Also, will we simply make sure the explain results are printable so people do @fxn I believe you implemented this for ActiveRecord, right? Do you have any words of wisdom to share? :) |
I'll update the PR for your review. 👍
Postgres and Mysql support the following formats, respectively:
I don't think a "special data structure" (a specific Struct for example) is needed but it could be |
Oh, good to know. Let's start with TEXT and we will see how to support multiple formats later. :) |
Hey!!! Sure! Let me share some things I recall from those days:
There goes some feedback. Cool that Ecto is getting this too! |
Thank you @fxn! This is very helpful! Some notes based on your comments:
|
Hey @fxn thanks for the feedback! Guys here's a new commit to check if I'm going into the right direction: https://github.com/elixir-ecto/ecto_sql/pull/231/commits/f28c8423e7752623658fff5f8abefa7d99aae2b9 - the idea is pretty simple, each adapter needs to implement its own |
@josevalim |
and addressed review comments. TODO: implement EXPLAIN for tds and myxql
Each adapter should be responsible for how to format the output of the EXPLAIN statement
Co-authored-by: José Valim <jose.valim@gmail.com>
Co-authored-by: José Valim <jose.valim@gmail.com>
Co-authored-by: José Valim <jose.valim@gmail.com>
Co-authored-by: José Valim <jose.valim@gmail.com>
lib/ecto/adapters/sql.ex
Outdated
Built-in adapters support passing `opts` to the EXPLAIN statement according to the following: | ||
|
||
Adapter | Supported opts | Notes | ||
---------------- | -------------- | ----- |
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.
Please see if this fixes the docs:
---------------- | -------------- | ----- | |
:--------------- | :------------- | :---- |
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.
Given this markdown:
Adapter | Supported opts | Notes
:--------------- | :------------- | :----
MyXQL | None | `EXTENDED` and `PARTITIONS`
It generates the correct HTML:
<table><thead><tr><th style="text-align: left;">Adapter</th><th style="text-align: left;">Supported opts</th><th style="text-align: left;">Notes</th></tr></thead><tbody><tr><td style="text-align: left;">MyXQL</td><td style="text-align: left;">None</td><td style="text-align: left;"><code class="inline">PARTITIONS</code> and <code class="inline">EXTENDED</code></td></tr></tbody></table>
But given this:
Adapter | Supported opts | Notes
:--------------- | :------------- | :----
MyXQL | None | `EXTENDED` and `PARTITIONS` opts
Generates:
<table><thead><tr><th style="text-align: left;">Adapter</th><th style="text-align: left;">Supported opts</th><th style="text-align: left;">Notes</th></tr></thead><tbody><tr><td style="text-align: left;">MyXQL</td><td style="text-align: left;">None</td><td style="text-align: left;"> opts<code class="inline">PARTITIONS</code> and <code class="inline">EXTENDED</code></td></tr></tbody></table>
For some reason the "opts" word in rendered before the inlined codes:
Using latest ex_doc, running mix compile && ex_doc "ecto_sql", "1", _build/dev/lib/ecto_sql/ebin
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.
Looks like a bug? I can open an issue or take a look on this.
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.
Sounds like a Earmark bug. Note you can generate the docs like this: MIX_ENV=docs mix docs
. Then I would try updating the Earmark version and see if it fixes it!
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.
Same result using latest versions:
cat mix.lock | grep earmark
"earmark": {:hex, :earmark, "1.4.5", "62ffd3bd7722fb7a7b1ecd2419ea0b458c356e7168c1f5d65caf09b4fbdd13c8", [:mix], [], "hexpm", "b7d0e6263d83dc27141a523467799a685965bf8b13b6743413f19a7079843f4f"},
"ex_doc": {:hex, :ex_doc, "0.22.1", "9bb6d51508778193a4ea90fa16eac47f8b67934f33f8271d5e1edec2dc0eee4c", [:mix], [{:earmark, "~> 1.4.0", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "d957de1b75cb9f78d3ee17820733dc4460114d8b1e11f7ee4fd6546e69b1db60"},
I found a related open issue pragdave/earmark#335, so I'll just comment there.
Co-authored-by: José Valim <jose.valim@gmail.com>
Co-authored-by: José Valim <jose.valim@gmail.com>
💚 💙 💜 💛 ❤️ |
Thank you, amazing work! |
@josevalim I'm gonna work on the TDS support and also to integrate EXPLAIN on LiveDashboard, following your idea: "Maybe this is something we can integrate with the Phoenix Live Dashboard? You can enable auto-explain with the RequestLogger or similar. So it is on demand and you can easily simulate production workloads" Sounds good? |
@leandrocp sounds great! Although I would have to think about how we would implement this without affecting performance. Today each repository emits a different telemetry event, so there is no easy way to "listen" to all of them. Perhaps the best option for now is to open up an issue in the LiveDashboard repo so we can discuss possible approaches. |
Sure, that's something I have been thinking about and will require a discussion before a draft. |
TDS support incoming.
Please see elixir-ecto/ecto#3313
Considering it's just a draft and the implementation isn't complete, the CI is gonna fail but it was tested against Postgres 12: