Re: union all taking years - PG 9.6

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Patrick B <patrickbakerbr(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: union all taking years - PG 9.6
Date: 2017-05-15 23:36:18
Message-ID: CAKFQuwaEsjjk3tPnSvnsejSr1AYQvfxyHOUaBxvCk8zXvwFpBw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, May 15, 2017 at 4:21 PM, Patrick B <patrickbakerbr(at)gmail(dot)com> wrote:

> Hi guys.
>
> I have two tables, where 'tableA' is the old and 'tableC' is the new one.
> I say "new/old" because we are migrating the data from tableA to tableC
> soon.
>
> I created a view selecting from both tables, with a UNION ALL between
> them. When selecting from that view, it's really slow. I can't even run
> explain analyze (it's been 1h and query did not finished yet).
>
>
​Try just comparing the explain plans.

However, when running both selects with explain analyze, query is fast.
>
>
​Do those selects contain where clauses?​

> What should I do in this case? Why is that taking so long? I assume it's
> because the UNION will look for duplicates?
>
>
​It won't because you specified "ALL"​

I'll presume there is a where clause involved because concatenating two
queries via UNION ALL without either having WHERE clause should be pretty
much interchangeable. Its unclear to me where things stand regarding
pushing down WHERE clauses through the UNION ALL which if it cannot for
some reason would result in what you are observing.

PostgreSQL version would help too.

David J.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2017-05-15 23:37:23 Re: Add NAMEDATALEN to PG_CONFIG?
Previous Message Adrian Klaver 2017-05-15 23:34:35 Re: Add NAMEDATALEN to PG_CONFIG?