michallepicki
How can I insert_all with a query in a way that a prepared statement will be used?
Hi!
When debugging slow Ecto queries (I’m using postgres), because Ecto uses named prepared statements which may use a different generic query plan than when running an individual query, I don’t use Ecto’s Repo.explain. 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(...).
Usually I see similar execution time as when the query is ran from Elixir. But this time the query in Elixir was running for 9s, and the psql query finished in .5s. I spent some time debugging Ecto code, and I think named prepared statements are never used with insert_all, even when a query is passed? So in this particular case, the generic plan would be much better.
So, my question is: is there a way to run a insert_all query with Ecto, where a named prepared statement will be used?
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









