Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WQgXh-00011x-Fx for pgsql-performance@arkaria.postgresql.org; Thu, 20 Mar 2014 17:14:09 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WQgXh-0008BK-0U for pgsql-performance@arkaria.postgresql.org; Thu, 20 Mar 2014 17:14:09 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WQgXg-0008BE-8Q for pgsql-performance@postgresql.org; Thu, 20 Mar 2014 17:14:08 +0000 Received: from mout.gmx.net ([212.227.17.20]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WQgXd-0008B1-LY for pgsql-performance@postgresql.org; Thu, 20 Mar 2014 17:14:07 +0000 Received: from calvados.home ([134.3.109.51]) by mail.gmx.com (mrgmx102) with ESMTPSA (Nemesis) id 0LejNC-1Wty5K15iA-00qPrH; Thu, 20 Mar 2014 18:14:04 +0100 Message-ID: <532B21D6.2030309@gmx.net> Date: Thu, 20 Mar 2014 18:13:58 +0100 From: =?ISO-8859-15?Q?Torsten_F=F6rtsch?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 MIME-Version: 1.0 To: Jean-Max Reymond , pgsql-performance@postgresql.org Subject: Re: Performance of UNION vs IN References: <532B1E05.70409@free.fr> In-Reply-To: <532B1E05.70409@free.fr> X-Enigmail-Version: 1.6 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:6TEkVmzSUveMOc3SWxRYy9reqcoNoECpm2xQSc8EGAlamUqhxjx HP6/fgNCI4XSPPiSieOZHNJYpCAI/m69BESFTAM/HJlm1e3ONcU1vzvBiwW+Ng9uuYhKGTq D9JKtr6rFzw85Xc1YLdyebdWTBiJiD4lym2S45dcQI1dZy1lBLIiUlep0KuHOW4qCJpSCCI ZIFIBEUxKp42I7p2NtRJw== X-Pg-Spam-Score: -1.9 (-) 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 On 20/03/14 17:57, Jean-Max Reymond wrote: > I have a very complex view zinfoexp and running the view as: > SELECT * FROM zinfoexp WHERE idmembre in (1,84) > take 2700 ms > > So, I try another syntax: > SELECT * FROM zinfoexp WHERE idmembre = 1 > union > SELECT * FROM zinfoexp WHERE idmembre = 84 > > and for me, two calls to my view takes a lot of time (may be x2) and it > takes 134 ms ! try SELECT * FROM zinfoexp WHERE idmembre=1 OR idmembre=84 This will probably be even faster. Also, the 2 statements of your's are not semantically equal. UNION implies DISTINCT, see: select * from (values (1), (1), (2)) t(i) UNION select 19; i ---- 19 1 2 (3 rows) What you want is UNION ALL: select * from (values (1), (1), (2)) t(i) UNION ALL select 19; i ---- 1 1 2 19 (4 rows) Torsten -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance