-
Notifications
You must be signed in to change notification settings - Fork 327
Add support for EXPLAIN statement #231
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
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
3b5145d
Add support for EXPLAIN statement
f28c842
Implement explain_query callback
6c0e844
Add all explain options for Postgres from v9 to v12
d46c264
Add support for all Postgres versions
941d2cb
Leverage Ecto.Multi to guarantee a rollback after EXPLAIN statement
d25ba1c
Leverage iodata on explain query and add explain output callback
15cd28f
Update lib/ecto/adapters/sql.ex
e62542d
Update lib/ecto/adapters/sql.ex
6d08ba7
Update lib/ecto/adapters/postgres/connection.ex
7451fd9
Update lib/ecto/adapters/sql.ex
d34b522
Address review comments:
03002f2
Format mysql explain output as a table
8fcf356
Raise for Tds because currently it lacks support for multiple sets
24fe371
Fix explain query for postgres > v9.0
0a22eac
Update lib/ecto/adapters/tds/connection.ex
a9ad09a
Improve docs and fix TDS raise message
a95bb00
Refactor so the adapter runs the query and format output
cee7a28
Revert to explain raising on invalid queries
9367b63
Add missing shared opts
4f360f5
Unify explain_opts and shared_opts
44f8b39
Split keywords to avoid passing unecessary opts downstream
507f782
typo
e881efa
Update lib/ecto/adapters/sql.ex
a0dc8e9
Update lib/ecto/adapters/sql.ex
9f958ea
Update lib/ecto/adapters/sql.ex
1efd817
improve docs
9943af6
typo
72f89d9
Update lib/ecto/adapters/sql.ex
d6d4c0a
Update lib/ecto/adapters/sql.ex
9d5ba8d
improve docs
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
defmodule Ecto.Integration.ExplainTest do | ||
use Ecto.Integration.Case, async: true | ||
|
||
alias Ecto.Integration.TestRepo | ||
alias Ecto.Integration.Post | ||
import Ecto.Query, only: [from: 2] | ||
|
||
test "explain" do | ||
explain = TestRepo.explain(:all, from(p in Post, where: p.title == "title"), timeout: 20000) | ||
|
||
assert explain =~ | ||
"| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |" | ||
|
||
assert explain =~ "p0" | ||
assert explain =~ "SIMPLE" | ||
assert explain =~ "Using where" | ||
|
||
explain = TestRepo.explain(:delete_all, Post) | ||
assert explain =~ "DELETE" | ||
assert explain =~ "p0" | ||
|
||
explain = TestRepo.explain(:update_all, from(p in Post, update: [set: [title: "new title"]])) | ||
assert explain =~ "UPDATE" | ||
assert explain =~ "p0" | ||
|
||
assert_raise(MyXQL.Error, fn -> | ||
TestRepo.explain(:all, from(p in "posts", select: p.invalid, where: p.invalid == "title")) | ||
end) | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
defmodule Ecto.Integration.ExplainTest do | ||
use Ecto.Integration.Case, async: true | ||
|
||
alias Ecto.Integration.TestRepo | ||
alias Ecto.Integration.Post | ||
import Ecto.Query, only: [from: 2] | ||
|
||
test "explain" do | ||
explain = TestRepo.explain(:all, Post, analyze: true, verbose: true, timeout: 20000) | ||
assert explain =~ "cost=" | ||
assert explain =~ "actual time=" | ||
assert explain =~ "loops=" | ||
assert explain =~ "Output:" | ||
assert explain =~ ~r/Planning [T|t]ime:/ | ||
assert explain =~ ~r/Execution [T|t]ime:/ | ||
|
||
explain = TestRepo.explain(:delete_all, Post) | ||
assert explain =~ "Delete on posts p0" | ||
assert explain =~ "cost=" | ||
|
||
explain = TestRepo.explain(:update_all, from(p in Post, update: [set: [title: "new title"]])) | ||
assert explain =~ "Update on posts p0" | ||
assert explain =~ "cost=" | ||
|
||
assert_raise(ArgumentError, "bad boolean value 1", fn -> | ||
TestRepo.explain(:all, Post, analyze: "1") | ||
end) | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
defmodule Ecto.Integration.ExplainTest do | ||
use Ecto.Integration.Case, async: true | ||
|
||
alias Ecto.Integration.TestRepo | ||
alias Ecto.Integration.Post | ||
|
||
test "explain options" do | ||
assert_raise(Tds.Error, "EXPLAIN is not supported by Ecto.Adapters.TDS at the moment", fn -> | ||
TestRepo.explain(:all, Post) | ||
end) | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.