Dennis Cote wrote:
Igor Tandetnik wrote:

From: "Dennis Cote"

I don't know of a way to do what you want with a user defined
function, but your example can be solved quite simply using SQL. The
following query will return a table with the required results.

select * from test order by col desc limit 3;

If you have an index on col then it will also be very fast
regardless of the size of the table, *** if not  it will do a single
table scan to find the three maximum values. ***

(emphasis mine).

Are you sure it will do a single scan, rather than sorting into a
temporary table and picking three topmost records?

If you have an index on col then SQLite will use that index.

That's obvious. What about the case when there is no index on col? You specifically claimed SQLite can manage in "a single table scan" even in this case. I find it rather difficult to believe - assuming that by a "single table scan" you mean some O(N) operation. Maybe I misunderstand your use of this term.

Igor Tandetnik

Reply via email to