Re: IN vs EXISTS equivalence - Mailing list pgsql-hackers

From Kevin Grittner
Subject Re: IN vs EXISTS equivalence
Date
Msg-id 489C817C.EE98.0025.0@wicourts.gov
Whole thread Raw
In response to Re: IN vs EXISTS equivalence  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: IN vs EXISTS equivalence  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
>>> Tom Lane <tgl@sss.pgh.pa.us> wrote:

> I believe that the optimizable cases for EXISTS are those where the
> EXISTS() is either at the top level of WHERE, or just underneath a
NOT,

The rest of the plan makes sense to me, but this part seems narrow.
There's probably a good reason for that which is beyond my depth, but
attached is a view that is used for calculating statistics for a
database which is primarily used for "case management" purposes.  If
EXISTS could also be optimized in the contexts used there, it would be
great.

For context, this view references three other non-trivial views
(MatterHistSearch, MatterHistStage, & MatterHistStatus), and does
perform acceptably, so it's not a matter of complaining if it can't
work here, just providing a real-world example of other useful
contexts for EXISTS which might be worth covering if possible.

This view is used in a large number of queries, mostly either
selecting a single date with other selection criteria or counting rows
which match a set of matterNo values selected on complex criteria.

By the way, this view was totally unusable under 8.2.  Showing how it
worked under 8.3 was all it took to get them to expedite the upgrade.
These views, possible because of improvements in 8.3, saved "countless
programmer days" (to quote one of the programmers).

-Kevin

Attachment

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Replay attack of query cancel
Next
From: Alvaro Herrera
Date:
Subject: Re: autovacuum and TOAST tables