Hi,

A common query pattern I need to run is to get the first n items in
the database sorted by some column. E.g.

select foo from my table
where user_id=?
order by date_created
limit 50;

How can I make this query efficient? I have tried using indexes, and
explain shows that there are indeed being used, but despite that the
execution time of the query grows linearly with the number of rows in
the table.

The documentation contains this cryptic line:

Indexes are not used to order result sets: The results are sorted in
memory if required.

(Cryptic because I do not understand: is that a statement about the
database as a whole, or just a statement about the nature of the tests
run while profiling the database.

Anyway, I would think that there would be a way to run the query such
that the execution time remains roughly constant as the table gets
larger. (that is once, it gets larger than the number of rows
specified in the limit clause of the query)

What am I missing?

If you need more details on the nature of the test I am running, I can
give more concrete SQL, but based on that line in the documentation,
I'm half expecting to be told that "h2 doesn't do that".

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/h2-database?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to