Pushing LIMIT into sub-queries of a UNION ALL

From: Dave Johansen <davejohansen(at)gmail(dot)com>
To: pgsql-performance(at)postgresql(dot)org
Subject: Pushing LIMIT into sub-queries of a UNION ALL
Date: 2011-05-16 19:38:12
Message-ID: BANLkTinpyHPbf_e3js7PhKtM6AbaX7+c4A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

I am using Postgres 8.3 and I have an issue very closely related to the one
described here:
http://archives.postgresql.org/pgsql-general/2005-06/msg00488.php

Basically, 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 sub-query version?

Thanks,
Dave

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Tom Lane 2011-05-16 19:41:00 Re: reducing random_page_cost from 4 to 2 to force index scan
Previous Message Nathan Boley 2011-05-16 19:10:37 Re: reducing random_page_cost from 4 to 2 to force index scan