Re: Using left joins instead of inner joins as an optimization

2024-09-06 Thread Greg Sabino Mullane
On Fri, Sep 6, 2024 at 7:05 AM Xavier Solomon wrote: > > explain select b_id from b natural left join a; > results in a `Seq Scan on b`. Whereas the query > > explain select b_id from b natural join a; > results in a join with sequential scans on both a and b. > I think your example is a little

Re: Using left joins instead of inner joins as an optimization

2024-09-06 Thread David Rowley
On Fri, 6 Sept 2024 at 23:05, Xavier Solomon wrote: > > create table a(a_id int primary key generated always as identity, a_data > > text); > > create table b(b_id int primary key generated always as identity, a_id int > > not null references a(a_id), b_data text); > > Then the query > > explain

Using left joins instead of inner joins as an optimization

2024-09-06 Thread Xavier Solomon
Hi All! I'm currently writing a view that joins many tables and I was wondering how PostgreSQL optimizes projections on such a view. In particular I was wondering if it is a correct and valid optimization technique to use left joins when they are equivalent to an inner join. I have created a mini