Ecto.Query.with_cte/3 and keyword syntax

So I’m dealing with some massive keyword-based ecto queries that I need to optimize with a CTE. I’ve already measured a substantial improvement in using them.

The problem is, these are such huge queries that it’s not practical for me to convert them to function syntax if I don’t have to.

So it seems I can’t use this with keyword syntax: unsupported :with_cte in keyword query expression. That’s not necessarily a problem because I can do something like the following:

query = with_cte(Model, "stuff", as: ^stuff)
from(m in query, ... etc to massive kw-based query)

But the problem with this seems to be that whenever I reference the CTE in a join with keyword syntax, it tries to treat it as an actual table.

join: s in "stuff" # it thinks this is a table, not my CTE

This doesn’t happen when using the function syntax for join. Am I stuck converting this HUGE keyword-based query to the function syntax just so I can use with_cte?

Would using subquery work for your case? If you are using CTE to factor out and give a name to a gigantic part of a query this might do the trick.