Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UAhsu-0003Mp-PX for pgsql-performance@arkaria.postgresql.org; Wed, 27 Feb 2013 14:21:28 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UAhst-0000sT-TR for pgsql-performance@arkaria.postgresql.org; Wed, 27 Feb 2013 14:21:27 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UAhst-0000sO-2d for pgsql-performance@postgresql.org; Wed, 27 Feb 2013 14:21:27 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UAhsr-0004GY-Rx for pgsql-performance@postgresql.org; Wed, 27 Feb 2013 14:21:26 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id r1RELIMs017938; Wed, 27 Feb 2013 09:21:18 -0500 (EST) From: Tom Lane To: Dmitry Karasik cc: pgsql-performance@postgresql.org Subject: Re: seqscan on UNION'ed views In-reply-to: <20130227100352.GA46292@nataraj.karasik.eu.org> References: <20130227100352.GA46292@nataraj.karasik.eu.org> Comments: In-reply-to Dmitry Karasik message dated "Wed, 27 Feb 2013 11:03:52 +0100" Date: Wed, 27 Feb 2013 09:21:18 -0500 Message-ID: <17937.1361974878@sss.pgh.pa.us> X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org Dmitry Karasik writes: > I need to have a sort of a time machine, where select statements on tables > could be easily replaced to select statements on tables as they were some time in the past, > including all related table. To do so, I used views (see in the script) that UNION > both current and archive tables and filter them by a timestamp. If you use UNION ALL instead of UNION, you should get better results (as well as inherently cheaper queries, since no duplicate-elimination step will be needed). regards, tom lane -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance