Re: [GENERAL] Joining on a view containing a UNION ALL produces a suboptimal plan on 9.3.4

2014-07-10 Thread Chris Hanks
That did the trick! Thanks, Tom! On Thu, Jul 10, 2014 at 8:47 AM, Tom Lane wrote: > Chris Hanks writes: >> CREATE VIEW tables AS >> SELECT a.*, b.col AS other_col >> FROM a >> LEFT JOIN b ON a.id = b.id >> UNION ALL >> SELECT c.*, d.col AS other_col >> FROM c >> LEFT JOIN d ON c.id

Re: [GENERAL] Joining on a view containing a UNION ALL produces a suboptimal plan on 9.3.4

2014-07-10 Thread Tom Lane
Chris Hanks writes: > CREATE VIEW tables AS > SELECT a.*, b.col AS other_col > FROM a > LEFT JOIN b ON a.id = b.id > UNION ALL > SELECT c.*, d.col AS other_col > FROM c > LEFT JOIN d ON c.id = d.id; > EXPLAIN ANALYZE > SELECT * > FROM tables > WHERE id = 89; -- Index scans, as expec

Re: [GENERAL] Joining on a view containing a UNION ALL produces a suboptimal plan on 9.3.4

2014-07-10 Thread Chris Hanks
>> Sent: Thursday, July 10, 2014 5:02 AM >> To: PostgreSQL General >> Subject: [GENERAL] Joining on a view containing a UNION ALL produces a >> suboptimal plan on 9.3.4 >> >> Hi everyone - >> >> I have a slow query issue in an app I'm working on

Re: [GENERAL] Joining on a view containing a UNION ALL produces a suboptimal plan on 9.3.4

2014-07-10 Thread Igor Neyman
> -Original Message- > From: pgsql-general-ow...@postgresql.org [mailto:pgsql-general- > ow...@postgresql.org] On Behalf Of Chris Hanks > Sent: Thursday, July 10, 2014 5:02 AM > To: PostgreSQL General > Subject: [GENERAL] Joining on a view containing a UNION ALL produ

[GENERAL] Joining on a view containing a UNION ALL produces a suboptimal plan on 9.3.4

2014-07-10 Thread Chris Hanks
Hi everyone - I have a slow query issue in an app I'm working on. I'm unfortunately not at liberty to share the query/schema details, but I've put together a very similar reproduction of the issue: - CREATE TABLE a (id integer primary key, col integer); CREATE TABLE b (id integer primary key