Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 13837B5DBD2 for ; Mon, 16 May 2011 16:38:21 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 61183-09 for ; Mon, 16 May 2011 19:38:13 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-ww0-f50.google.com (mail-ww0-f50.google.com [74.125.82.50]) by mail.postgresql.org (Postfix) with ESMTP id 6BCE8B5DBBC for ; Mon, 16 May 2011 16:38:13 -0300 (ADT) Received: by wwc33 with SMTP id 33so5071329wwc.19 for ; Mon, 16 May 2011 12:38:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:date:message-id:subject:from:to :content-type; bh=MaOBSSF0JWrK5PJmZlF4gmaWZoOPgjPmSjK7uWNpTUA=; b=KH4sddsOa0gD51Jd0tnbhrEduIMHuxeh7ZBMOgY1pdgodJ68V9B1H5r24KvhDKAaU3 0EOw4CWezQaopqRAmg5Goa+gFR9t2rH0JtKfPgckx6uvjo5ihkVvXzs9r0bY1I3UoR0f remCXLcr45tk5xJ0yFLiikx+Ll13GFhgQgYVg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=iaYsLNHp3RiW3WaI5qr7xWf047/cGa6X7cypZbDBkRLa4cQU4POx9A6aaDfatujhOG pktWN2RVb6BZiOP9ScWTSmGFwT3MKJGiskU3pBCiMfLM8pDcrBz+oV8MlomZTxISNAqP RcXfgBRfaKySKCF/4PsU+RuEd+U9fQwas7J5o= MIME-Version: 1.0 Received: by 10.227.32.73 with SMTP id b9mr4553051wbd.86.1305574692367; Mon, 16 May 2011 12:38:12 -0700 (PDT) Received: by 10.227.129.81 with HTTP; Mon, 16 May 2011 12:38:12 -0700 (PDT) Date: Mon, 16 May 2011 12:38:12 -0700 Message-ID: Subject: Pushing LIMIT into sub-queries of a UNION ALL From: Dave Johansen To: pgsql-performance@postgresql.org Content-Type: multipart/alternative; boundary=002215b0399ac42df504a369cb20 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.887 tagged_above=-10 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RFC_ABUSE_POST=0.001, T_TO_NO_BRKTS_FREEMAIL=0.01 X-Spam-Level: X-Archive-Number: 201105/281 X-Sequence-Number: 43790 --002215b0399ac42df504a369cb20 Content-Type: text/plain; charset=ISO-8859-1 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 --002215b0399ac42df504a369cb20 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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 th= e sub-query version?

Thanks,
Dave

--002215b0399ac42df504a369cb20--