Closed KiKoS0 closed 11 months ago
In Postgres, thanks to array support, all x in ^param
compiles to the same query, which allows us to reuse it as prepared statements. Such optimization is not possible in MySQL, so every time you call it with a different amount of parameter, it is a different query, which we cannot cache. That's the reason why they are different.
If you care about this, you could check param == []
yourself, but the PG behaviour is consistent within itself. :)
Elixir version
Elixir 1.15.4 (compiled with Erlang/OTP 24)
Database and Version
PostgreSQL 14.6
Ecto Versions
ecto_sql 3.10.2
Database Adapter and Versions (postgrex, myxql, etc)
postgrex 0.17.4
Current behavior
👋
It's not technically a bug but in PostgreSQL, pinning an empty array in a
where in
clause yields different SQL from directly passing an empty array.https://github.com/elixir-ecto/ecto_sql/blob/da2b3b5f42186d70395464f19fabf50e7d9aa1b5/lib/ecto/adapters/myxql/connection.ex#L661-L663
It's handled correctly in MySQL though so can I add the clause in the Postgrex adapter as well? Since PostgreSQL query optimizer doesn't noop with
ANY('{}')
:Expected behavior
Generate the same SQL for the two expressions: