Re: optimizing a join against a windowed function

2024-08-30 Thread Torsten Förtsch
Try perhaps something along these lines: ``` SELECT t.id, i.insight_id FROM taxpayers AS t JOIN LATERAL ( SELECT x.id AS insight_id FROM insights AS x WHERE x.taxpayer_id = t.id AND x.year IS NOT NULL ORDER BY year DESC

Re: optimizing a join against a windowed function

2024-08-30 Thread David Rowley
On Fri, 30 Aug 2024 at 23:36, James Brown wrote: > I have two tables: one named taxpayers which has a goodish number of columns > an an integer PK id, and one named insights, which has a taxpayer_id foreign > key to taxpayers, a year, and (again) a lot of other columns. There's an > index on in

optimizing a join against a windowed function

2024-08-30 Thread James Brown
Hello: I'm attempting to figure out whether an optimizer behavior I'm seeing is a PostgreSQL bug or expected behavior. The scenario: I have two tables: one named taxpayers which has a goodish number of columns an an integer PK id, and one named insights, which has a taxpayer_id foreign key to tax