Indexes Flashcards

Learn Indexes

1
Q

What is a page?

A
  • Page has a size of 8k
  • 8 consecutive pages make one extent
  • Page can only belong to a single object. Table, index…etc.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is an extent?

A
  • An extent is made up of 8 pages
  • Uniform extent - All pages belong to single object
  • Mixed extent - Pages belong to multiple objects
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What happens when an object exceeds 8 pages?

A

SQL server allocates additional uniform extents for this object.

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

What is a heap?

A

A heap is just a bunch of pages and extents.

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

How does SQL server track where pages and extent belong?

A

Using a special page called Index Allocation Map to trace which page and extent belong to an object.

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

How many levels does a clustered index (TREE) has?

A
  • Root - contains pointers
  • Intermediate (when needed) - contains pointers
  • Leaf - contains data
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is internal fragmentation?

A
  • Clustered index only
  • Caused by page split and when pages are not filled.
  • Can be controlled by FILLFACTOR or PAD_INDEX
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is external fragmentation?

A

Clustered index only

When pages are physical out of order.

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

Non clustered index levels?

A

Similar to clustered index

  • Root and intermediate level are pointers
  • leaf level does not hold data instead it contains index keys and the RID (row identifier)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How is row identifier used?

A

It depends if the underlying table is a heap or a balanced tree.

  • Balance tree - RID is the clustered index. Points to a logical structure
  • Heap - RID has the dbs file ID, page ID, target row ID…etc. Points to a physical structure.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a filtered index?

A

Filter index is a nonclustered index optimized to cover queries that select from a well defined subset of data.

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

What is columnstore index?

A
  • When a query references a single column that is a part of the columnstore index, SQL server fetches only that column from disk. The rows are reconstructed.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the steps to create indexed view?

A
  • Verify that all the SET options are correct
  • Verify that the view is deterministic
  • create using WITH SCHEMABINDING
  • First index create on the view must be clustered index
  • If there is GROUP BY, don’t use HAVING. Use COUNT_BIG(*) instead.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Waht does SQL server use to aggregate data?

A
  • hash
  • Stream aggregate operator - faster but requries a sorted input
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Why use INCLUDE with CREATE INDEX?

A

Add nonkey column to the non clustered index so that the queries are covered.

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

What does DBCC SHOW_STATISTICS return?

A
  • STAT_HEADER
  • DENSITY VECTOR
  • HISTOGRAM