From: Peter Eisentraut <peter_e@gmx.net>
To: david_shadovitz@xontech.com
To: pgsql-sql@postgresql.org
Subject: Re: Fetch a single record
Date: Tue, 9 Dec 2003 21:21:37 +0100
Message-ID: <200312092121.37830.peter_e@gmx.net> (raw)
In-Reply-To: <8b37e2e5.0312051351.4045b4e@posting.google.com>
References: <8b37e2e5.0312051351.4045b4e@posting.google.com>
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.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: peter_e@gmx.net, david_shadovitz@xontech.com
Subject: Re: Fetch a single record
In-Reply-To: <200312092121.37830.peter_e@gmx.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox