Indexing Flashcards

1
Q

How to score an index?

A

Three star method

★ Puts relevant rows next to each other: “This minimizes the thickness of the index slice that must be scanned.”

★ Index is sorted in the order the query is looking for.

★ Index contains all columns needed by the query (covering).

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

Downsides to indexing

A

○ indexes take up extra space

○ Indexes speed up SELECT but slow down INSERT, UPDATE, and DELETE, since changes to a table will require that all indexes covering affected data will also be modified.

○ To earn the third star for an index we need to include every column used in the SELECT. This may create a very large index.

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

Approach to selecting an index?

A

Find Cardinality
Find Selectivity
Score index

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

How do you find index cardinality?

A

The cardinality of an index is the number of unique values that it actually contains.

This can be used to work out how effective an index might be for a query

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

Describe index selectivity

A

Index selectivity is the ratio of the number of distinct indexed values (the cardinality) to the total number of rows in the table (#T), and ranges from 1/#T to 1.

A highly selective index is goodbecause it lets MySQL filter out more rows when it looks for matches. A unique index has a selectivity of 1, which is as good as it gets.

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

What is a primary index?

A

A primary index is an index on a set of fields that includes the unique primary key for the field and is guaranteed not to contain duplicates. Also Called a Clustered index. eg. Employee ID can be Example of it.

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

What is a secondary index?

A

A Secondary index is an index that is not a primary index and may have duplicates. eg. Employee name can be example of it. Because Employee name can have similar values.

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

What is a multi-column index?

A

An index that combines multiple column index values into one column.

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

What is a prefix index?

A

Combines index columns with a prefix of long string indexes e.g. 12blac is a prefix index of product id and item name.

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