Re: LEFT JOINs not optimized away when not needed - Mailing list pgsql-bugs

From Moshe Jacobson
Subject Re: LEFT JOINs not optimized away when not needed
Date
Msg-id CAJ4CxL=vTAQ1dVYtAQoeS636qniO1mOy8E83Q4w7YzWuYyqtdg@mail.gmail.com
Whole thread Raw
In response to Re: LEFT JOINs not optimized away when not needed  (Robert Haas <robertmhaas@gmail.com>)
Responses Re: LEFT JOINs not optimized away when not needed
List pgsql-bugs
On Thu, Jul 10, 2014 at 11:06 AM, Robert Haas <robertmhaas@gmail.com> wrote=
:

> CREATE VIEW person_with_cars AS
> SELECT p.id, p.full_name, p.something_else, array_agg(c.plate_number)
> AS plate_numbers
> FROM person p LEFT JOIN cars c ON p.id =3D c.person_id
> GROUP BY p.id, p.full_name, p.something_else;
>
> It's reasonable to hope that if the aggregated column isn't selected,
> the join will get removed, but cars (person_id) is not unique.
>

Exactly. But the same should be true even if c.plate_number is not
aggregated in the view def.
As long as it's not selected, the output should list one row per person_id
and the cars table should be removed from the join.
What I've just described is our most common use case.

Moshe Jacobson
Manager of Systems Engineering, Nead Werx Inc. <http://www.neadwerx.com>
2323 Cumberland Parkway =C2=B7 Suite 201 =C2=B7 Atlanta, GA 30339

"Quality is not an act, it is a habit." -- Aristotle

pgsql-bugs by date:

Previous
From: emonrockz143@gmail.com
Date:
Subject: BUG #10917: How to connect pgadmin of another system.
Next
From: Francisco Olarte
Date:
Subject: Re: BUG #10917: How to connect pgadmin of another system.