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
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
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