Re: Pet-peevishness (When does a check constraint execute?)

From: Alban Hertroys <alban(at)magproductions(dot)nl>
To: "Jim C(dot) Nasby" <jnasby(at)pervasive(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Pet-peevishness (When does a check constraint execute?)
Date: 2006-03-27 13:46:17
Message-ID: 4427ECA9.8040701@magproductions.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Jim C. Nasby wrote:
> On Fri, Mar 24, 2006 at 11:25:35AM -0700, Edmund(dot)Bacon(at)elb_lx(dot)onesystem(dot)ca wrote:
> <pet-peeve>
> If you only want to know if something exists, do NOT use count!
>
>
>>test$# (select * from test_dates t1
>>test$# where EXISTS ( select * from test_dates t2
>>test$# where (t1.from_date, t1.to_date) overlaps
>>test$# (t2.from_date, t2.to_date)) )$$;
>
>
> On a small dataset you may not notice much difference, but you'll
> certainly see it on a large dataset.
> </pet-peeve>

Certainly true, I keep telling people here at work. But I was kind of
wondering why you'd "select * from" inside "exists", if you're not going
to use those values.

I tend to write "where exists (select 1 from", but now I'm curious
whether the planner handles this for you or if there's actually a
difference in meaning?

I assume it's always better to not let the planner decide these kind of
things. Try to write what you really want, instead of waving hands in
the general direction and make the planner decide what you mean ;)

Well, this is getting awfully pet-peevish, of course...

--
Alban Hertroys
alban(at)magproductions(dot)nl

magproductions b.v.

T: ++31(0)534346874
F: ++31(0)534346876
M:
I: www.magproductions.nl
A: Postbus 416
7500 AK Enschede

// Integrate Your World //

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jim C. Nasby 2006-03-27 14:08:42 Re: Pet-peevishness (When does a check constraint execute?)
Previous Message Jim C. Nasby 2006-03-27 13:31:36 Re: PostgreSQL's XML support comparison against other RDBMSes