Re: UNION causes horrible plan on JOIN

From: Craig James <cjames(at)emolecules(dot)com>
To: Justin Pryzby <pryzby(at)telsasoft(dot)com>, pgsql-performance(at)lists(dot)postgresql(dot)org
Subject: Re: UNION causes horrible plan on JOIN
Date: 2019-10-28 23:37:23
Message-ID: CAFwQ8reerNujJvUbiL7bZOf1aQHrdvXuBUjiB3dr-QjM97Ck8A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Mon, Oct 28, 2019 at 4:31 PM Justin Pryzby <pryzby(at)telsasoft(dot)com> wrote:

> On Mon, Oct 28, 2019 at 04:30:24PM -0700, Craig James wrote:
> > On Mon, Oct 28, 2019 at 3:45 PM Justin Pryzby <pryzby(at)telsasoft(dot)com>
> wrote:
> >
> > > On Mon, Oct 28, 2019 at 03:40:58PM -0700, Craig James wrote:
> > > > On Postgres 9.6 (config below), I have a case I don't understand:
> three
> > > > tables that can be separately queried in milliseconds, but when put
> > > > together into one view using UNION, take 150 seconds to query.
> Here's the
> > > > rough idea (actual details below):
> > >
> > > Do you want UNION ALL ?
> > >
> > > UNION without ALL distintifies the output.
> > > https://www.postgresql.org/docs/current/sql-select.html#SQL-UNION
> >
> >
> > Interesting idea, thanks. But it makes no difference. Tried it and got
> the
> > same bad performance.
>
> Could you mail the list the plan with union ALL ?
>

Here it is. It is indeed different, but takes 104 seconds instead of 140
seconds.
https://explain.depesz.com/s/zW6I

--
---------------------------------
Craig A. James
Chief Technology Officer
eMolecules, Inc.
3430 Carmel Mountain Road, Suite 250
San Diego, CA 92121
---------------------------------

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Kyotaro Horiguchi 2019-10-29 03:24:53 Re: UNION causes horrible plan on JOIN
Previous Message Craig James 2019-10-28 23:30:24 Re: UNION causes horrible plan on JOIN