Re: IN, EXISTS or ANY? - Mailing list pgsql-sql

From Tom Lane
Subject Re: IN, EXISTS or ANY?
Date
Msg-id 17935.1020056063@sss.pgh.pa.us
Whole thread Raw
In response to IN, EXISTS or ANY?  ("Josh Berkus" <josh@agliodbs.com>)
Responses Re: IN, EXISTS or ANY?  ("Josh Berkus" <josh@agliodbs.com>)
List pgsql-sql
"Josh Berkus" <josh@agliodbs.com> 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


pgsql-sql by date:

Previous
From: "Josh Berkus"
Date:
Subject: IN, EXISTS or ANY?
Next
From: "Josh Berkus"
Date:
Subject: Re: IN, EXISTS or ANY?