Log in

View Full Version : paths to enlightenment



traq
06-19-2011, 03:58 AM
How does a relational database implement SELECT author FROM books? In a relational database, every row in a table (e.g. the books table) is exactly the same length in bytes, and every fields is always at a fixed offset from the beginning of the row. So, for example, if each record in the books table is 100 bytes long, and the author field is at offset 23, then there are authors stored at byte 23, 123, 223, 323, etc. What is the code to move to the next record in the result of this query? Basically, it's this:

pointer += 100;

One CPU instruction. Faaaaaaaaaast.

This is from Joel on Software (http://www.joelonsoftware.com/articles/fog0000000319.html). I was just cruisin around, clicking on links, and I found his site and started reading. Some really enlightening stuff on a wide variety of programming topics, and he's not a bad writer, either. This particular excerpt demonstrates why relational databases (like mysql) are so far superior to flat files (e.g., xml) for data search and storage - a question that pops up here on DD fairly often.

Anyway, I thought I'd share it. If anyone else has resources that have really helped them in their development as a programmer, please share it!