Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 775792E0293 for ; Thu, 13 Mar 2008 09:52:53 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 27903-01-9 for ; Thu, 13 Mar 2008 09:52:40 -0300 (ADT) X-Greylist: delayed 00:11:06.620103 by SQLgrey-1.7.5 Received: from mxout.ulb.ac.be (mxout.ulb.ac.be [164.15.128.111]) by postgresql.org (Postfix) with ESMTP id C05992E2D53 for ; Thu, 13 Mar 2008 09:52:24 -0300 (ADT) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqABAH692EekD30E/2dsb2JhbAAIqBg Received: from bebif01.ulb.ac.be (HELO [10.0.0.194]) ([164.15.125.4]) by mxout.ulb.ac.be with ESMTP; 13 Mar 2008 13:41:09 +0100 Subject: in() VS exists() From: Julien To: pgsql-sql Content-Type: text/plain; charset=UTF-8 Date: Thu, 13 Mar 2008 15:47:24 +0100 Message-Id: <1205419644.3240.19.camel@frodon.be-bif.ulb.ac.be> Mime-Version: 1.0 X-Mailer: Evolution 2.12.3 Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=AWL=0.001 X-Spam-Level: X-Archive-Number: 200803/66 X-Sequence-Number: 30394 Hello, Does anyone has an idea why sometimes: - select ... where ... in (select ...) is faster than : - select ... where ... exists(select ...) and sometimes it's the opposite ? I had such a situation, I've pasted the queries on: http://rafb.net/p/KXNZ6892.html and http://rafb.net/p/jvo5DO38.html It's running PostgreSQL 8.1 with an effective_cache_size of 30000. specimens.id is the primary key and there are indexes on sequences(specimen_id) and specimen_measurements(specimen_id) Is there a general "rule" to know when to use the in() version and when to use the exists() version ? Is it true to say that the exists() version is more scalable (with many rows) than the in() version (from the little tests I made it seems the case) ? Thanks, Julien -- Julien Cigar Belgian Biodiversity Platform http://www.biodiversity.be Université Libre de Bruxelles (ULB) Campus de la Plaine CP 257 Bâtiment NO, Bureau 4 N4 115C (Niveau 4) Boulevard du Triomphe, entrée ULB 2 B-1050 Bruxelles Mail: jcigar@ulb.ac.be @biobel: http://biobel.biodiversity.be/person/show/471 Tel : 02 650 57 52