Hi!
When debugging slow Ecto queries (I’m using postgresql), I recently stopped using Ecto’s Repo.explain. Ecto uses
named prepared statements which may use a completely different generic query plan
than when running an individual query. A query executed individually in postgresql will be planned together with its specific parameter values in mind, so the plan that Repo.explain returns can sometimes be very different than the plan postgresql will use in practice when using Ecto. As a workaround, instead I copy the query’s SQL debug output, and from psql console I set plan_cache_mode='force_generic_plan', create a prepared statement annotating my argument types, and execute it with EXPLAIN (ANALYZE) EXECUTE mystatement(...).
Maybe to avoid potential differences between Repo.explain plan output, and the plan used in practice, Repo.explain could run the query through the same prepared statements mechanism as regular query execution, and then run EXPLAIN on that prepared statement execution?
Thanks,
- Michał