The Joy of Indexing
kylebanker.com
kylebanker.com
Not really, as the example only allows a search on ingredient, since it explicitly says the name is not known at all, and hence could never be used for search.
Now let's say we know two things about the unknown recipe: it contains chicken and it's from the Italian kitchen.
Given these two indexes:
Chicken
1, 15, 582, 1032
Italian
3, 15, 16, 82, 1032, 6821
I could definitely use both to speed up my search by looking only at pages that occur in both indexes (in this case, 15 and 1032). This can be done in O(# of indexes * index length) time if both indexes are in sorted order.Incidentally you can make indexes on Ingredient->Page/Cuisine->Page rather than maintaining Page indexes for specific ingredients/cuisines. So with just two indexes you can filter out any Cuisine/Ingredient combo (You can even do multiple ingredients! As it's an intersection though, multiple cuisines wouldn't be useful as few dishes are likely to fall under multiple cuisines, you could still do it though.)
Did they ever write the promised second part where they wanted to present B-trees in a similar form? I think I understand B-trees, but it wouldn't be the first time I realise I didn't really understand something after all...
it isn't an intuition. It is knowledge about access paths your system uses in query plans and how to manage them. "Intuition" and "use [always] indexes" - these 2 perpetrated legends is what frequently the root cause of the pitiful performance of reasonably large DB systems (ie. ones that many times larger than the RAM of the DB [cluster]). People get charmed by the "magic" of B-tree and miss the iron-platter reality of random vs stream IO. You see a DBA or DB developer expressing unconditional disgust pointing toward the red line of "Full-Table Scan" in query plan he managed to display in the GUI tool and you immediately understand what the situation at this client site is :)
Again, don't get me wrong, i'n not saying that indexes shouldn't be used - that would be the same mistake as to say they should always be used. What i'm saying is that you need to know (not intuit) when and how and why to use or not to use specific access paths.
I think this article is about learning about both the art and the science of database design.
http://download.oracle.com/docs/cd/B14117_01/server.101/b107...
It's the best resource that I've seen with respect to databases and indexing.