Ecto, through Postgrex and DB Connection, automatically uses prepared statements for all queries. To my knowledge the only way to disable prepared statements is to set
prepare: :unnamed in the repo’s global configuration.
This question is prompted by a lingering issue in Oban, wherein a particular query gets dramatically slower once the prepared version of the query is used:
- Have others ran into a similar problem?
- Does anybody know a way to disable prepared statements for a specific query?
- Did you work around the issue somehow?
My current thoughts for a workaround are to avoid using
Repo.one or Repo.all entirely and instead generate a query, convert that to sql, run
Repo.query directly, then convert the result using
Repo.load. It isn’t too much work, but it isn’t intuitive and wouldn’t scale for multiple queries.