Skip to content

Interpolating a query containing a where subquery into a join crashes the planner #4763

Description

@lukaszsamson

Elixir version

any

Database and Version

any

Ecto Versions

3.14

Database Adapter and Versions (postgrex, myxql, etc)

any

Current behavior

Repro:

import Ecto.Query

sq =
  from s in "subposts",
    select: s.id

join_query =
  from p in "posts",
    where: p.id in subquery(sq)

query =
  from p in "parent_posts",
    join: p2 in ^join_query,
    on: true

Ecto.Query.Planner.plan(query, :all, Ecto.TestAdapter)

Result:

** (KeyError) key :subqueries not found in:

%Ecto.Query.QueryExpr{
  expr: {:in, ..., [{:subquery, 0}]},
  params: [subquery: 0],
  ...
}

Expected behavior

where expression should be folded into the join’s on expression and planned normally

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions