Possible bug in Ecto Query Planner?

Hi,

I have a query that is named, and includes a number of subqueries in a select_merge that returns a count. These subqueries utilize the parent_as method referencing the named query. A simplified example of the query:

foo = from(n in FileSystem.Schema.FSNode,
                 where: n.collection_id == parent_as(:directories).collection_id and
                        n.internal_id == 9, select: count())

from(n in FileSystem.Schema.FSNode,
     as: :directories,
     where: n.collection_id == "d0810555-0113-464b-fd5a-9e9e726b35c3" and
            not is_nil(n.node_id) and n.fs_type in [:link, :directory] and
            not n.is_deleted and n.is_latest)
|> select_merge([n], %{fs_type: n.fs_type})
|> select_merge([n], %{count_foo: subquery(foo)})

The query can be called multiple times, where the only difference is the subqueries may change (different subqueries or different combination of subqueries).

Here is where I run into a problem. It looks like Ecto.Query.Planner saves in an ets cache the query when it executed the first time. When it is called again with different subqueries in the select it looks like it retrieves the original query and fails to recognize that it is actually a different query. So it throws an exception like:

Postgrex expected a binary, got ~N[2024-07-11 00:00:00.000000]. Please make sure the value you are passing matches the definition in your table or in your query or convert the value accordingly.

I can workaround the problem by changing the name of the parent query for each combination of subqueries in the select, but that seems a rather awkward workaround.

Thanks