On Sat, Feb 8, 2014 at 11:51 AM, Simon Slavin <slav...@bigfraud.org> wrote:
> > While a database is in use it might use perhaps 100 pages for a particular > table. Almost every one of those pages will have a little space free: > anything from 1 byte to most of the page, depending on how much space each > row takes up. When writing a new row to a table, SQLite intelligently > figures out which existing page it can write the row to (or does it ? > someone who has read the source code can tell me I'm wrong and if it > searches for the 'best' page). > No. SQLite (as most other database engines) use B-Trees. Every row has a "key" (which is often, but not always, the ROWID in SQLite.) Rows need to be stored in key-order. Otherwise, you would not be able to find a row given its key, except by doing a slow and wasteful scan of the entire table. If four or five rows have adjacent keys, those rows can be placed arbitrarily on one page. There is a small index at the beginning of each page that tells where to find each row on that page. But you cannot spread those keys out arbitrarily on different pages. If they are adjacent, then they need to be logically adjacent in the file. -- D. Richard Hipp d...@sqlite.org _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users