Can anyone direct me to an easy to understand explanation (that doesn't require me to read a 300-page tome) about how to index things and how to identify what to index, what it means to normalize things, etc? Or provide very simple examples?
2 Answers
This is strictly for SQL Server
for every "serious" data table, there must be a well-chosen clustering index. A good clustering index is narrow, unique, static (never changes) and ideally ever-increasing - an
INT IDENTITY
is as close to perfect as it can beFor any column that is a foreign key, create a nonclustered index. This helps JOINs and other operations and is a generally accepted best practice
Don't OVER-INDEX! - too many indices can be worse than none!
Let your system run for a while, observe how it performs, identify potential performance bottlenecks
if you have identified some performance issues, generate a representative workload (not just a single query; by using server-side tracing) and try to optimize that by using e.g. the Data Tuning Advisor (but don't blindly adopt everything the DTA says!)
Implement one index at a time - observe your system again - did the performance (real or perceived) improve? If so: leave the index - if not: remove it again
Which indexes exactly to use - that's a bit of a black art based on a lot of know-how, experimentation, experience - you really can't give clear, black-or-white kind of ideas here. Try something - observe its benefit (or negative impact) - learn from it. Repeat until your retirement :-)
There's really no 10-page checklist and once you know that, you're done. Either you learn these things yourself, over the years - or you hire someone who has that expertise - your choice. There's no "easy way" to mastering everything about indexing in 5 easy lessons.....
-
The problem I have is that I have no idea how to even begin learning any of this. I am not sure what kind of data I should "experiment" with, what to practice with, etc. Mar 5, 2014 at 18:20
-
@user3219632: well - do you currently have a system with performance issues? It's always best to learn on a real, practical example. Otherwise: read, read, read! Lots of good blogs out there - or if you can, attend a course on SQL performance tuning techniques to learn the basics– marc_sMar 5, 2014 at 19:17
Paul Litwin's Fundamentals of Relational Database Design is worth a read if you're starting from scratch. (22 page tome...) http://sbuweb.tcu.edu/bjones/20263/Access/AC101_FundamentalsDB_Design.pdf
And as he says, database design is more art than science, so examples will only get you so far with improving your own system(s).