Indexing in Database

0.0(0)
studied byStudied by 0 people
GameKnowt Play
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/49

flashcard set

Earn XP

Description and Tags

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

50 Terms

1
New cards

What is an index in a database?

A data structure that improves the speed of data retrieval operations on a table.

2
New cards

Why are indexes used?

To speed up SELECT queries and WHERE clause filtering.

3
New cards

What is the trade-off of using indexes?

They improve read performance but slow down INSERT, UPDATE, and DELETE operations.

4
New cards

What is a primary index?

An index created on the primary key of a table, automatically enforced by the database.

5
New cards

What is a secondary index?

An index created on a column that is not the primary key.

6
New cards

What is a unique index?

An index that ensures all values in the indexed column are unique.

7
New cards

Can a table have multiple indexes?

Yes, a table can have multiple indexes on different columns.

8
New cards

What is a composite index?

An index created on two or more columns of a table.

9
New cards

When should you use a composite index?

When queries frequently filter or sort by multiple columns together.

10
New cards

What is a clustered index?

An index where the table’s rows are stored in the order of the index itself.

11
New cards

How many clustered indexes can a table have?

Only one, because the data rows can be sorted in only one order.

12
New cards

What is a non-clustered index?

An index that maintains a separate structure from the actual table data and points to the data rows.

13
New cards

How many non-clustered indexes can a table have?

Many, depending on the database system.

14
New cards

What is a covering index?

An index that contains all the columns needed by a query, avoiding access to the table data.

15
New cards

What is a B-tree index?

A balanced tree structure commonly used to maintain sorted data and support range queries.

16
New cards

What is a hash index?

An index based on hash tables that is optimized for equality comparisons, not range queries.

17
New cards

What is a full-text index?

An index designed for efficient text searching within string columns.

18
New cards

What is a bitmap index?

An index that uses bitmaps and is suitable for columns with low cardinality.

19
New cards

What is cardinality in indexing?

The uniqueness of data in a column; high cardinality means many unique values.

20
New cards

When should you avoid indexing a column?

When the column has low selectivity or frequent updates.

21
New cards

What is index selectivity?

The ratio of unique indexed values to the total number of rows.

22
New cards

What is an index scan?

When the database reads the entire index to find matching rows.

23
New cards

What is an index seek?

When the database navigates directly to the relevant part of the index for efficient access.

24
New cards

What is an index-only scan?

A query that can be satisfied using just the index without accessing the table.

25
New cards

What does EXPLAIN or EXPLAIN PLAN do?

It shows how the database query planner intends to execute a query, including index usage.

26
New cards

What is index fragmentation?

The scattering of index pages across storage, which can slow down performance.

27
New cards

How do you reduce index fragmentation?

By rebuilding or reorganizing the index.

28
New cards

What is a partial index?

An index that only includes rows matching a certain condition.

29
New cards

What is a functional index?

An index on the result of a function or expression applied to a column.

30
New cards

What is a descending index?

An index that sorts values in descending order for performance optimization in queries with DESC.

31
New cards

Do indexes consume disk space?

Yes, indexes use additional storage to maintain the index data structures.

32
New cards

Can indexes be created on views?

Yes, through indexed (materialized) views in some databases.

33
New cards

Can NULL values be indexed?

Yes, but behavior may vary depending on the database engine and index type.

34
New cards

What is the difference between dense and sparse indexes?

Dense indexes have entries for every record; sparse indexes only for some records.

35
New cards

What is an index hint?

A directive given in a SQL query to force the use or avoidance of a specific index.

36
New cards

How does indexing affect JOIN operations?

Proper indexes on join columns can greatly improve join performance.

37
New cards

How are indexes created in SQL?

Using CREATE INDEX index_name ON table_name(column_name);

38
New cards

How do you drop an index in SQL?

Using DROP INDEX index_name;

39
New cards

Can indexes be automatically created?

Yes, primary keys and unique constraints automatically create indexes.

40
New cards

What is a virtual index?

A theoretical index created to test query performance without physically building the index (available in Oracle).

41
New cards

What is multi-column index ordering important for?

It affects which combinations of columns are optimized by the index.

42
New cards

What is a spatial index?

An index designed to efficiently query spatial data (e.g., geometries, locations).

43
New cards

What is an inverted index?

An index that maps content to its location, commonly used in full-text search engines.

44
New cards

Which operations are negatively affected by too many indexes?

INSERT, UPDATE, DELETE because indexes must be updated.

45
New cards

Should every column be indexed?

No, only columns frequently used in search, join, or sort operations should be indexed.

46
New cards

Can you rename an index?

Yes, in some databases using ALTER INDEX or equivalent syntax.

47
New cards

How does indexing support sorting?

Indexes maintain ordered data which can eliminate the need for extra sorting.

48
New cards

What is an expression index?

An index on the result of a computation, like LOWER(name) or YEAR(date).

49
New cards

Are indexes shared across tables?

No, indexes are specific to a single table.

50
New cards

What is the benefit of indexing foreign keys?

Improves JOIN and DELETE performance and maintains referential integrity efficiently.