Implement and Maintain Indexes Flashcards
What is a table called when it doesn’t have an index attached?
Heap
What are the two fixes for Index Fragmentation?
Reorganize
Rebuild
What does Reorganize do for an index?
It restructures the ROOT level node. It takes less resources. It also compacts the pages together.
What does Rebuild do for an index?
It completely rebuilds the index. Much more system intensive solution.
What is the t-sql syntax to REORGANIZE (Or Rebuild)?
ALTER INDEX [INDEXNAME] ON [TABLENAME] REORGANIZE/REBUILD
When you use REBUILD, make sure to add WITH (ONLINE=ON)
What is the system table that has Index statistics?
SYS.DM_DB_INDEX_PHYSICAL_STATS
PARAMETERS: database_id (OR NULL) , object_id (OR NULL) , index_id (OR NULL) , partition_number (OR NULL) , mode (OR NULL)
When should you rebuild or reorganize an index?
If the fragmentation is over 30% - Rebuild
If the fragmentation is between 5 - 30% - Reorganize
What is an index Fill Factor?
It is the ability to leave some space at the end of a page instead of trying to fill it up. Makes it so
How do you set the FILL FACTOR when creating (or rebuilding) and index?
In the WITH statement:
ALTER INDEX [INDEXNAME] ON [TABLENAME] WITH (FILLFACTOR = 80)
What does the fill factor number mean?
It is the Percentage of the page that will be filled up (80% full, 20% will be left empty)
What is the system table that you can use to see how much an index is being used?
SYS.DM_DB_INDEX_USAGE_STATS
What do you look for in SYS.DM_DB_INDEX_USAGE_STATS?
High number of SEEKS, Low number of SCANS and LOOKUPS and a low number of USER_UPDATES compared to SEEKS (That means that the index is having to be maintained while giving no benefit)
What are Index STATISTICS? How are they created?
It is basically a hint that the database uses to have an idea of what data exists in an index.
Created with the same syntax as an index, but use STATISTICS instead of INDEX
How can you update statics?
- Execute STATS_DATE function with the object_id of the table and the stats_id of the statistic.
- execute the sp_autostats stored procedure with the table name