LIMIT and UNION ALL

From: Dave Johansen <davejohansen(at)gmail(dot)com>
To: pgsql-performance <pgsql-performance(at)postgresql(dot)org>
Subject: LIMIT and UNION ALL
Date: 2011-05-18 15:26:02
Message-ID: BANLkTikw+DqY+8S+5icmzfbnAE9-13pZGQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

I am using Postgres 8.3.3 and I have a VIEW which is a UNION ALL of two
tables but when I do a select on the view using a LIMIT, it scans the entire
tables and takes significantly longer than writing out the query with the
LIMITs in the sub-queries themselves. Is there a solution to get the view to
perform like the query with the LIMIT explicitly placed in the sub-queries?

I noticed a similar question in this post
http://archives.postgresql.org/pgsql-general/2005-06/msg00488.php but I
wasn't able to find an answer.

Thanks,
Dave

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Robert Klemme 2011-05-18 15:54:47 Re: LIMIT and UNION ALL
Previous Message Dave Johansen 2011-05-18 14:00:50 Re: hash semi join caused by "IN (select ...)"