| From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
|---|---|
| To: | Ryszard Kurek <rychu(at)sky(dot)pl> |
| Cc: | pgsql-interfaces(at)postgreSQL(dot)org |
| Subject: | Re: [INTERFACES] Table viewer for big sorted tables |
| Date: | 1999-10-16 20:20:30 |
| Message-ID: | 9459.940105230@sss.pgh.pa.us |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-interfaces |
Ryszard Kurek <rychu(at)sky(dot)pl> writes:
> The slow version is:
> SELECT min(product_symbol) FROM products WHERE product_name > 'current_product';
Try
SELECT ... FROM products WHERE product_name > 'current_product' ORDER BY product_name LIMIT 1;
You will need to have an index on product_name to make this fast ---
without the index there will be a sort step.
The ideal solution to your problem is probably
SELECT ... FROM products ORDER BY product_name LIMIT 1 OFFSET n;
which avoids issues like what happens when there is more than one row
with the same product_name. However, 6.5.* is not bright enough to
use an index for this kind of query (it only considers an index if
there is a matching WHERE clause). 7.0 will be smarter.
regards, tom lane
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Ryszard Kurek | 1999-10-16 21:02:50 | Re: [INTERFACES] Table viewer for big sorted tables |
| Previous Message | Ryszard Kurek | 1999-10-16 19:02:15 | Table viewer for big sorted tables |