From: Torsten Förtsch <torsten.foertsch@gmx.net>
To: Jean-Max Reymond <jmreymond@free.fr>
To: pgsql-performance@postgresql.org
Subject: Re: Performance of UNION vs IN
Date: Thu, 20 Mar 2014 18:13:58 +0100
Message-ID: <532B21D6.2030309@gmx.net> (raw)
In-Reply-To: <532B1E05.70409@free.fr>
References: <532B1E05.70409@free.fr>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-performance>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: torsten.foertsch@gmx.net, jmreymond@free.fr
Subject: Re: Performance of UNION vs IN
In-Reply-To: <532B21D6.2030309@gmx.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox