Re: IN vs EXIIST

From: "Jan Weerts" <j(dot)weerts(at)i-views(dot)de>
To: "'pgsql-general'" <pgsql-general(at)postgresql(dot)org>
Cc: "'Jean-Christian Imbeault'" <jc(at)mega-bucks(dot)co(dot)jp>
Subject: Re: IN vs EXIIST
Date: 2002-09-19 11:09:26
Message-ID: B349BABAF9A92F4D9FBFCADF8D5FEDD5081090@ivsrv03.i-views.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

>Strangely enough doing an EXPLAIN on the two queries shows that using
>EXISTS would be faster than IN ... even though it isn't ..

A sad sidenote: I am stuck here with a similar IN/EXIST problem. One
of our expensive queries contains NOT IN and IN as subqueries. As I
was advised on this list, I tried to replace IN with EXISTS. When
doing so for part of the query (omitting one of the IN subqueries) the
IN and EXIST versions are both about the same speed in execution
(about 30sec).

EXPLAIN tells me, that the EXIST version should be 15 times faster,
which it is not. Caching is also not an issue here.

EXPLAIN also shows, that both queries want to perform a sequential
scan on the outermost query part, instead of an index scan (where
clause on the primary key). If I replace the innermost query by the
results it gives (splitting the request in two requests), than the
planner uses the index scan and is in fact much faster!

My next plan is to switch from 7.1.3 to 7.2, but that requires some
planning, as the database is permamently used.

Regards
Jan

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ciprian Popovici 2002-09-19 11:14:52 some optimization?
Previous Message Jean-Christian Imbeault 2002-09-19 11:04:53 Re: IN vs EXIIST