by smyatkin_maxim · 9y ago · 0 comments
- On the 2nd year of education I knew that "index is something in database, which helps to locate data faster. Like an index at the end of a book, it helps to find the right page w/o whole scan of a book".
- Later, probably at 4th or 5th year I got the idea how these are implemented using B+-trees.
- And even later have seen some alternative implementations.
But anyways, IMO even for a senior web developer it's enough to know that index is SOME fast data structure on disc, which trades duplication and (usually) slower writes for faster lookup. And optimizer sometimes will chose index scan, sometimes won't. And to know some basic optimization techniques (like throwing ORDER BY away when data is already sorted by index).
On the other hand, if the first column isn't unique, such as employee's city or state, then the DB can use the next column as a "skip" index. So an index on "state, name" will still usually improve the query time of queries against "name" (but not as much improvement as if you had a separate index beginning with "name").
You don't need to know O notation or know what kind of trees they are (much less how they're implemented) to understand that. But if you only think of a database as an Excel table and not as trees sitting on top, you'll tend to make inefficient design decisions. And at the rate that data structures are moving into the frontend, arguably everyone in the stack should know how to think in this way.
More details on covering indexes here: https://www.simple-talk.com/sql/learn-sql-server/using-cover...