Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id 6CA02475872 for ; Mon, 29 Apr 2002 00:54:19 -0400 (EDT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.11.4/8.11.4) with ESMTP id g3T4sNF17938; Mon, 29 Apr 2002 00:54:23 -0400 (EDT) To: "Josh Berkus" Cc: pgsql-sql@postgresql.org Subject: Re: IN, EXISTS or ANY? In-reply-to: References: Comments: In-reply-to "Josh Berkus" message dated "Sun, 28 Apr 2002 21:44:55 -0700" Date: Mon, 29 Apr 2002 00:54:23 -0400 Message-ID: <17935.1020056063@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200204/349 X-Sequence-Number: 7613 "Josh Berkus" writes: > I was wondering if there is any difference in execution speed for the > following three statements: > WHERE case_id IN (SELECT case_id FROM case_clients > WHERE matter_no = '123.122342'); > or: > WHERE case_id = ANY (SELECT case_id FROM case_clients > WHERE matter_no = '123.122342'); > or > WHERE EXISTS ( SELECT case_id FROM case_clients > WHERE matter_no = '123.122342' > AND case_id = cases.case_id); IN is the same as = ANY (cf. row_expr production in src/backend/parser/gram.y for implementation, or SQL92 8.4 rule 4 for specification; there ain't *no* difference). But EXISTS is an entirely different animal which is often faster ... isn't that in the FAQ? regards, tom lane