Yes! "set join_collapse_limit = 9" was enough to fix the plan, thanks Laurenz. I will set both to 11. -------- Original Message -------- From: Laurenz Albe [mailto:laurenz.albe@xxxxxxxxxxx] Sent: Thursday, April 11, 2024 at 14:21 UTC To: ilya Basin; pgsql-general@xxxxxxxxxxxxxxxxxxxx Subject: subquery plan rows = 1, but it's merge joined instead of index lookup On Thu, 2024-04-11 at 15:57 +0300, ilya Basin wrote: Is there some complexity limit after which the planner starts acting dumb? Yes, "join_collapse_limit" and "from_collapse_limit". You can try increasing them. Yours, Laurenz Albe