2 ms·
Awesome guide! If you want to see a very minimal walkthrough of actually implementing this in code, the third post of my "write a SQL database in Go" series doe
by eatonphil 5y ago
Awesome guide! If you want to see a very minimal walkthrough of actually implementing this in code, the third post of my "write a SQL database in Go" series does just this [0].
Once you have the index set up and are able to use it the next challenging part is pattern matching (plus algebraic rewrites) to figure out if the index is actually applicable.
For example, in my linked blog post, an index is only used if the WHERE expression has only AND-ed operations and one of those expressions is a filter using <, >, =, <> (and a few other operators) and one of the columns is indexed. This is simpler than what a real database might attempt.
Another interesting part of seeing it in code (and messing with the code) is observing cases like where even though you're using an index it doesn't speed anything up if you filter still matches every item in the index.
Also if you just want to learn more about indexes as a user, I highly recommend the site "Use the index, Luke" that has many useful guides/explanations.
[0] https://notes.eatonphil.com/database-basics-indexes.html https://notes.eatonphil.com/database-basics-indexes.html
[1] https://use-the-index-luke.com/ https://use-the-index-luke.com/