In general, how do you index something in database queries? How do you know what to index? [closed]

StackOverflow https://stackoverflow.com/questions/22201043

  •  08-06-2023
  •  | 
  •  

문제

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?

올바른 솔루션이 없습니다

다른 팁

This is strictly for SQL Server

  1. 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 be

  2. For any column that is a foreign key, create a nonclustered index. This helps JOINs and other operations and is a generally accepted best practice

  3. Don't OVER-INDEX! - too many indices can be worse than none!

  4. Let your system run for a while, observe how it performs, identify potential performance bottlenecks

  5. 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!)

  6. 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.....

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).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top