Implement and Maintain Indexes Flashcards

1
Q

What is a table called when it doesn’t have an index attached?

A

Heap

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the two fixes for Index Fragmentation?

A

Reorganize

Rebuild

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does Reorganize do for an index?

A

It restructures the ROOT level node. It takes less resources. It also compacts the pages together.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does Rebuild do for an index?

A

It completely rebuilds the index. Much more system intensive solution.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the t-sql syntax to REORGANIZE (Or Rebuild)?

A

ALTER INDEX [INDEXNAME] ON [TABLENAME] REORGANIZE/REBUILD

When you use REBUILD, make sure to add WITH (ONLINE=ON)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the system table that has Index statistics?

A

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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

When should you rebuild or reorganize an index?

A

If the fragmentation is over 30% - Rebuild

If the fragmentation is between 5 - 30% - Reorganize

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is an index Fill Factor?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you set the FILL FACTOR when creating (or rebuilding) and index?

A

In the WITH statement:

ALTER INDEX [INDEXNAME] ON [TABLENAME] WITH (FILLFACTOR = 80)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does the fill factor number mean?

A

It is the Percentage of the page that will be filled up (80% full, 20% will be left empty)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the system table that you can use to see how much an index is being used?

A

SYS.DM_DB_INDEX_USAGE_STATS

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What do you look for in SYS.DM_DB_INDEX_USAGE_STATS?

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are Index STATISTICS? How are they created?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How can you update statics?

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly