-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 07/10/11 11:57, Simon Slavin wrote: > My problem really seems to be with the way SQLite implements LIMIT n. > If I understand previous posts on this list correctly, instead of > finding only the first n records, it does the entire search first, then > returns the first n of the results it found.
That is completely incorrect. Each time you call sqlite3_step it finds the next row that matches the query and no more. This is why SQLite uses that virtual machine (VDBE) stuff. It needs to execute some code to find a matching row, return it, and then allow another call to get the next row. This requires some way of encapsulating the processing state of a query so it can be resumed from where it was left off in order to get the next row. The one fly in the ointment is if the results are sorted. For example if there are 10,000 result rows then there is no way to return the first 100 without getting all result rows since doing a sort requires you have all the data first to sort. But as I mentioned you can add together the numbers from EXPLAIN QUERY PLAN which will at least give you an idea of probable order of magnitude of the results (eg if there are tens, thousands or millions). Roger -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iEYEARECAAYFAk6PbtIACgkQmOOfHg372QSczQCfdEFFqE798O53wHsdPLYOkkua 9rIAnj/4E2BZLqdD1W+X1k0WfIFxq+zL =NNCg -----END PGP SIGNATURE----- _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users