Re: LATERAL subquery predicate pushdown: filter applied after JSON construction instead of inside join (PG 18) - Mailing list pgsql-performance

From Nyasha Chigwamba
Subject Re: LATERAL subquery predicate pushdown: filter applied after JSON construction instead of inside join (PG 18)
Date
Msg-id CH0PR10MB49081B6CC0088E6533A890CFB46BA@CH0PR10MB4908.namprd10.prod.outlook.com
Whole thread Raw
In response to Re: LATERAL subquery predicate pushdown: filter applied after JSON construction instead of inside join (PG 18)  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-performance
Hi Tom,

Thank you for this - much appreciated. Removing the ORDER BY LIMIT does change the query and after some further investigation, it looks like I also need to project the raw columns then apply the filters on the projected columns as a opposed to filtering on the constructed JSONB.

Regards,
Nyasha

From: Tom Lane <tgl@sss.pgh.pa.us>
Sent: February 11, 2026 12:37 PM
To: Nyasha Chigwamba <nyasha.chigwamba@voss-solutions.com>
Cc: pgsql-performance@lists.postgresql.org <pgsql-performance@lists.postgresql.org>
Subject: Re: LATERAL subquery predicate pushdown: filter applied after JSON construction instead of inside join (PG 18)
 
Nyasha Chigwamba <nyasha.chigwamba@voss-solutions.com> writes:
> Question: Can the planner push predicates on view columns into the underlying LATERAL subqueries?

It can, but it will not push them into a subquery with LIMIT,
because that would potentially change the subquery result.

I'd try to get rid of all those ORDER BY LIMIT bits in your
view definition.  That's generally considered an antipattern
in SQL.  It's definitely an optimization fence.

                        regards, tom lane
This communication is confidential and if not addressed to you and has been received in error, you must: (i) notify the sender immediately and delete the e-mail; and (ii) refrain from copying, printing, forwarding, publishing or disclosing the contents of the e-mail.

pgsql-performance by date:

Previous
From: Laurenz Albe
Date:
Subject: Re: unstable query plan on pg 16,17,18
Next
From: Lea Führer
Date:
Subject: MERGE INTO... WHEN NOT MATCHED BY SOURCE index usage