Re: [INTERFACES] Table viewer for big sorted tables
| От | Tom Lane |
|---|---|
| Тема | Re: [INTERFACES] Table viewer for big sorted tables |
| Дата | |
| Msg-id | 9459.940105230@sss.pgh.pa.us обсуждение исходный текст |
| Ответ на | Table viewer for big sorted tables (Ryszard Kurek <rychu@sky.pl>) |
| Ответы |
Re: [INTERFACES] Table viewer for big sorted tables
|
| Список | pgsql-interfaces |
Ryszard Kurek <rychu@sky.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
В списке pgsql-interfaces по дате отправления: