On 10/29/15, Jason H <jhihn at gmx.com> wrote: > > This seems to be at odds with my understanding of "2.1 Record Format" of the > document. Given that it reads the row varint, which contains the length of > itself and the serial types of the columns, in order, it should be > completely able to skip the reading of unneeded columns. If I have 39,39,39 > as my header (excepting the length of header) I know I am dealing with 3 > text columns of 13 bytes each. If I want only the last column, I can then > seek(78), read(26). At no time did I need to read the prior two columns. >
I think you are confusing "reading" with "decoding". SQLite always reads content from disk in page-size chunks. Each page is typically 1024 or 4096 bytes, but can be any power of two between 512 and 64K. Most of the time, a complete row is contained on a single page. And that whole page is read off of disk and into memory all in one go. If the row has 12 columns and you only ask for the 5th one, then only the 5th column is decoded. And only the first 5 "serial type" integers are decoded. But since all 12 columns are on the same page, they all get read into memory. If a single row overflows unto multiple pages, the overflow pages are only read if needed. -- D. Richard Hipp drh at sqlite.org