From: Tom Lane <tgl@sss.pgh.pa.us>
To: Alex@Icepick.com
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] How to get last 10 rows in a table on a large database?
Date: Sat, 06 Nov 1999 13:12:27 -0500
Message-ID: <2514.941911947@sss.pgh.pa.us> (raw)
In-Reply-To: <38270488.5980775@smtp.telekabel.nl>
Alex@Icepick.com (Alex) writes:
> Does anyone have a good idea to get the last 10 rows from a table? I
> tried
> SELECT * FROM table ORDER BY datetime DESC LIMIT 10
> But my table has over 1 million rows, so this takes forever.. anyone
> has a better idea on how to do this?
FWIW, that query should work the way you want in 7.0 (assuming you have
an index on datetime). 6.5.* isn't bright enough to use an index for
ORDER BY DESC, though. I think Stoyan's suggestion of declaring a
cursor is probably the best workaround for now --- or you could consult
the patches list archives for the patch that will make 6.5 use an index.
regards, tom lane
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, Alex@Icepick.com
Subject: Re: [SQL] How to get last 10 rows in a table on a large database?
In-Reply-To: <2514.941911947@sss.pgh.pa.us>
References: <38270488.5980775@smtp.telekabel.nl> <2514.941911947@sss.pgh.pa.us>
* 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