Indexes Flashcards

(30 cards)

1
Q

What is the purpose of an index?

A

To help the database find data faster by using shortcuts.

Indexes improve query performance by reducing the amount of data the database needs to scan.

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

What happens without an index?

A

The database must read every row (full table scan).

This can significantly slow down query performance, especially with large datasets.

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

Analogy for no index?

A

Searching for one paper in a messy shoebox.

This illustrates the inefficiency of searching through unorganized data.

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

What happens with an index?

A

The database jumps straight to the correct spot.

This allows for quicker data retrieval compared to scanning the entire table.

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

Analogy for having an index?

A

Using a tab in a cookbook.

This shows how an index helps locate information quickly.

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

What is a clustered index?

A

The table is physically sorted in that order.

This means that the data rows are stored in the same order as the index.

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

How many clustered indexes can a table have?

A

Only one.

This is because the data can only be sorted in one way.

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

What is a clustered index usually built on?

A

The primary key.

This ensures that the most unique identifier is used for sorting.

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

What is a clustered index good for?

A

Searching ranges (e.g., ID 1000–2000, last week’s orders).

This allows efficient retrieval of a range of records.

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

Baby version of clustered index?

A

The table itself is sorted.

This simplifies the concept for easier understanding.

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

What is a non-clustered index?

A

A separate list that points to the actual data.

This allows for multiple indexes on different columns.

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

Analogy for a non-clustered index?

A

A library card catalogue.

This illustrates how a non-clustered index directs you to the location of data.

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

How many non-clustered indexes can a table have?

A

Many.

This flexibility allows optimization for various queries.

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

What are non-clustered indexes good for?

A

Searching columns like Email, LastName, ProductCategory.

This enhances performance for queries involving these columns.

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

Baby version of non-clustered index?

A

A cheat sheet that points to the data.

This analogy helps simplify the concept.

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

Why does a table scan happen?

A

Because no index exists on the searched column.

This leads to slower query performance.

17
Q

How do indexes improve speed?

A

They allow the database to jump directly to the needed rows.

This significantly reduces the time taken to retrieve data.

18
Q

How much faster can indexes be?

A

Up to 100x faster.

This highlights the efficiency gained through indexing.

19
Q

Example: finding CustomerID = 96 without an index?

A

Must check rows 1 → 96 one by one.

This illustrates the inefficiency of a full table scan.

20
Q

Example: finding CustomerID = 96 with an index?

A

Goes straight to “96” in the sorted list.

This demonstrates the efficiency of using an index.

21
Q

Baby version of why indexes are fast?

A

Skip the line and go straight to your name.

This analogy makes the concept relatable.

22
Q

Why do INSERTs slow down with indexes?

A

The index must be updated too.

This adds overhead to write operations.

23
Q

Why do UPDATEs slow down with indexes?

A

The database must keep the index in order.

This requires additional processing time.

24
Q

Analogy for index maintenance?

A

Adding a new recipe to an alphabetised cookbook.

This illustrates the effort needed to maintain order.

25
Baby version of **write slowdown**?
Reads are faster, but adding new stuff takes extra work. ## Footnote This simplifies the concept for easier understanding.
26
When should you **index a column**?
When it’s used in WHERE, ORDER BY, or JOIN, or searched often. ## Footnote This ensures optimal performance for frequently accessed data.
27
What happens if you **index everything**?
System becomes slower (too much index maintenance). ## Footnote This highlights the importance of selective indexing.
28
Baby version of **when to index**?
Index important things, not everything. ## Footnote This emphasizes the need for strategic indexing.
29
What is a **full table scan**?
Database checks every row to find a result. ## Footnote This is the least efficient way to retrieve data.
30
Baby version of **full table scan**?
Without indexes, the database is blind. ## Footnote This analogy illustrates the lack of direction in data retrieval.