On Sat, Jan 29, 2011 at 01:06:07PM -0800, Marian Cascaval wrote: > On Sat, January 29, 2011, Nicolas Williams wrote: > > If there's enough indices to satisfy all the ORDER BY expressions then > > how could a "last()" function do any better? For that matter, if there > > aren't enough indices to satisfy all the ORDER BY expressions then how > > could a "last()" function do any better? What optimization could such a > > function implement that the query optimizer couldn't? Syntactically > > speaking, there's no additional information in "last()" -- it's just > > syntactic sugar. > > As I see it,from the point of view of just retrieving the last row from a > table, > no ORDER BY is necessary thus saving processor time.
You seem to think that SQLite3 has to get all the rows and sort them, then pick the last. But remember, if there's enough indices then it's not picking the last, but the first row, and there's no sorting to do. Seriously, have SQLite3 explain the query plan to you and you'll see. If there's no suitable indices, then SQLite3 will have to do a full table scan, select specific rows, then sort them to pick the one you want -- a "last()" function wouldn't change that. If there is a suitable index then SQLite3 will not do any scanning, nor sorting, because of that LIMIT 1. Nico -- _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users