Re: Fetch a single record

From: Paul Thomas <paul(at)tmsl(dot)demon(dot)co(dot)uk>
To: David Shadovitz <david_shadovitz(at)xontech(dot)com>
Cc: "pgsql-sql (at) postgresql (dot) org" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Fetch a single record
Date: 2003-12-10 00:11:29
Message-ID: 20031210001129.A30762@bacon
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


On 05/12/2003 21:51 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.
> [snip]

Have you also tried
SELECT * from mytable limit 1

If you genuinely don't care what the record is (I assume you're justing
testing that table is not empty?) then this might be the way to go. My
rather limited knowledge of PG internals leads me to believe that this
will generally cause just one page being read from disk (I'm assuming the
99% case of no mega-sized text/bytea/whatever columns here). I'd be
interested to know just how far off the mark by understanding is...

--
Paul Thomas
+------------------------------+---------------------------------------------+
| Thomas Micro Systems Limited | Software Solutions for the Smaller
Business |
| Computer Consultants |
http://www.thomas-micro-systems-ltd.co.uk |
+------------------------------+---------------------------------------------+

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message greg 2003-12-10 00:45:40 Re: Fetch a single record
Previous Message Stephan Szabo 2003-12-09 21:51:19 Re: Values like ''