Re: [INTERFACES] Table viewer for big sorted tables - Mailing list pgsql-interfaces

From Tom Lane
Subject Re: [INTERFACES] Table viewer for big sorted tables
Date
Msg-id 9459.940105230@sss.pgh.pa.us
Whole thread Raw
In response to Table viewer for big sorted tables  (Ryszard Kurek <rychu@sky.pl>)
Responses Re: [INTERFACES] Table viewer for big sorted tables
List 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 by date:

Previous
From: Ryszard Kurek
Date:
Subject: Table viewer for big sorted tables
Next
From: Ryszard Kurek
Date:
Subject: Re: [INTERFACES] Table viewer for big sorted tables