| From: | Peter Eisentraut <peter_e(at)gmx(dot)net> |
|---|---|
| To: | david_shadovitz(at)xontech(dot)com (David Shadovitz), pgsql-sql(at)postgresql(dot)org |
| Subject: | Re: Fetch a single record |
| Date: | 2003-12-09 20:21:37 |
| Message-ID: | 200312092121.37830.peter_e@gmx.net |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
David Shadovitz wrote:
> I'm looking for the fastest way to fetch a single record from a
> table. I don't care what record it is.
>
> Here are two techniques I've explored:
>
> 1. Use LIMIT
> SELECT * FROM myTable LIMIT 1
>
> 2. Get a valid OID and then get the record.
> SELECT MIN(oid) AS anOID FROM myTable
> SELECT * FROM myTable WHERE oid = anOID
>
> The 1st technique is slow. (I think PostgreSQL fetches all records
> and then returns just one.) The 2nd is faster, but not fast enough.
This is hard to believe. The first technique should be the fasted, but
might suffer from a bad plan. Please make sure that you have run
ANALYZE, and then post EXPLAIN ANALYZE output.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | David B | 2003-12-09 21:35:24 | Faster performance when using where cust_id = '123' vs cust_id = 123. Does 7.4 fix this?? |
| Previous Message | Peter Eisentraut | 2003-12-09 19:49:25 | Re: Values like '' |