Skip to content

Commit d6353b8

Browse files
committed
Set explain options to true
1 parent 50b3e3a commit d6353b8

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

lib/ecto/adapters/sql.ex

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,8 @@ defmodule Ecto.Adapters.SQL do
432432
end
433433

434434
def explain(%{repo: repo} = adapter_meta, operation, queryable, opts) do
435+
opts = conform_explain_opts(adapter_meta.adapter, opts)
436+
435437
Ecto.Multi.new()
436438
|> Ecto.Multi.run(:explain, fn _, _ ->
437439
{prepared, prepared_params} = to_sql(operation, repo, queryable)
@@ -448,6 +450,17 @@ defmodule Ecto.Adapters.SQL do
448450
end
449451
end
450452

453+
@auto_true ~w[analyze verbose costs settings buffers timing summary plan]a
454+
defp conform_explain_opts(Ecto.Adapters.Postgres, opts) do
455+
Keyword.new(opts, fn
456+
explain_opt when explain_opt in @auto_true ->
457+
{explain_opt, true}
458+
{opt, val} ->
459+
{opt, val}
460+
end)
461+
end
462+
defp conform_explain_opts(_, opts), do: opts
463+
451464
@doc """
452465
Forces all connections in the repo pool to disconnect within the given interval.
453466
@@ -952,8 +965,6 @@ defmodule Ecto.Adapters.SQL do
952965
953966
* `:format`
954967
955-
All options except `format` are boolean valued and default to `false`.
956-
957968
The allowed `format` values are `:map`, `:yaml`, and `:text`:
958969
* `:map` is the deserialized JSON encoding.
959970
* `:yaml` and `:text` return the result as a string.
@@ -970,9 +981,9 @@ defmodule Ecto.Adapters.SQL do
970981
971982
"""
972983

973-
_ -> :ok
984+
_ ->
985+
:ok
974986
end
975-
976987
@spec explain(:all | :update_all | :delete_all, Ecto.Queryable.t(), opts :: Keyword.t()) ::
977988
String.t() | Exception.t() | list(map)
978989
def explain(operation, queryable, opts \\ []) do

0 commit comments

Comments
 (0)