From: | Shane Wright <me(at)shanewright(dot)co(dot)uk> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: quickest query to check a table for existance of a value in a field |
Date: | 2002-03-26 23:55:50 |
Message-ID: | 200203262355.g2QNtpH17023@fullerruss.dsvr.co.uk |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Hi
Thanks, just tried this on my dev box (650,000 rows, ~50,000 per ID), the
original way (COUNT()) takes ~1/2 second (guestimating), while your way is as
instant as I can tel..
Beauty :)
--
Shane
On Monday 25 Mar 2002 9:41 pm, chester c young wrote:
> > I want a quick way to find out if there are any rows matching a
> > specified value for this indexed field. I dont care how many there
> > are or what their properties are, just if there are any or not.
> >
> > SELECT COUNT(c2) AS num FROM mytable WHERE c2=1234;
> >
> > Thanks
> > Shane
>
> Try: select 1 as yes from mytable where c2=1234 limit 1;
> or: select 1 as yes where exists( select 1 from mytable where c2=1234
> );
>
> would be interesting to see differences in performance on your data
>
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Movies - coverage of the 74th Academy Awards®
> http://movies.yahoo.com/
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org
From | Date | Subject | |
---|---|---|---|
Next Message | Ian Barwick | 2002-03-27 02:10:50 | Re: Possible to do this in one query? |
Previous Message | PG Explorer | 2002-03-26 20:32:23 | Re: Changeing Sequence |