File and Index Structures

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/75

encourage image

There's no tags or description

Looks like no tags are added yet.

76 Terms

1
New cards

Physical database design

The phase where the logical data model is translated into an actual physical structure for a specific DBMS; focuses on HOW data is stored, accessed, and optimized for performance.

2
New cards

Three main phases of database design

1) Conceptual design, 2) Logical design, 3) Physical design.

3
New cards

Conceptual/logical design vs. physical design

Conceptual and logical design focus on WHAT data is stored and how it is logically organized; physical design focuses on HOW it is stored, accessed, and optimized.

4
New cards

SQL query evaluation

The process by which a DBMS interprets a SQL query, determines the most efficient execution plan (optimization), and carries it out (execution).

5
New cards

Relational operators

Basic operations used to process queries: selection, projection, join, union, and intersection. The DBMS combines them to execute complex SQL queries.

6
New cards

Access methods

Techniques for efficiently retrieving data from storage. Examples: sequential scan, index scan, hash lookup, B+ tree traversal.

7
New cards

Buffer management

Manages in-memory storage of disk pages during query execution; reduces disk I/O by keeping frequently accessed data in RAM.

8
New cards

Disk/file management

Organizes how data is stored on physical media; includes file structures, page allocation, and strategies to minimize seek time and maximize throughput.

9
New cards

Storage device hierarchy (fastest to slowest)

Cache memory, main memory, flash memory, magnetic disk, optical drives, magnetic tapes. Arranged by speed, cost, and capacity.

10
New cards

Why not store everything in main memory?

Cost (RAM is expensive compared to disk) and volatility (data in RAM is lost when power is off).

11
New cards

Typical storage hierarchy in a DBMS

Main memory (RAM) = data currently in use; Disk (secondary storage) = persistent main database; Tape (tertiary storage) = archive of older or less frequently accessed data.

12
New cards

Disks vs. tapes

Disks allow random access at a fixed cost per page (consecutive pages are much cheaper than random ones). Tapes are sequential-only, cheaper, and mainly used for archival storage.

13
New cards

Why is disk access the primary bottleneck in a DBMS?

Disk access is thousands of times slower than memory access.

14
New cards

Disk block (page)

The unit in which data is stored on and transferred between disk and main memory.

15
New cards

Disk organization

The disk surface is divided into tracks, which are subdivided into sectors; each track is divided into equal-sized disk blocks (pages).

16
New cards

Three components of disk block access time

1) Seek time (move head to the correct track), 2) Rotational delay (wait for block to rotate under head), 3) Transfer time (move data to/from disk surface).

17
New cards

Which access-time components dominate?

Seek time and rotational delay.

18
New cards

Best practice to reduce disk I/O cost

Store the blocks of a file sequentially on disk to minimize seek and rotational delays.

19
New cards

Record ID (rid)

Identifies a record's physical location on external storage.

20
New cards

Index

A data structure that allows efficient retrieval of record IDs based on a search key.

21
New cards

Buffer manager

Loads pages from physical storage into main memory (the buffer cache/pool) as needed. File and index layers go through it to access data.

22
New cards

Buffer pool bookkeeping

A table of pairs tracks which pages are in memory; each frame also has a pin count and a dirty bit.

23
New cards

Steps when a requested page is not in the buffer pool

1) Choose a frame for replacement, 2) If the frame is dirty, write it back to disk, 3) Read the requested page into that frame, 4) Pin the page and return its memory address.

24
New cards

Pin count

The number of active requestors using a page. If it is zero, the page is a candidate for replacement.

25
New cards

Dirty bit

Indicates whether a page has been modified in memory (so it must be written back to disk before its frame is replaced).

26
New cards

Prefetching

Reading multiple pages at once when page requests are predictable (e.g., during sequential scans) to improve performance.

27
New cards

Write-Ahead Log (WAL)

Concurrency control and recovery mechanisms may require extra I/O, such as writing to a WAL, when a frame is selected for replacement.

28
New cards

Buffer replacement policies

Least-Recently-Used (LRU), Clock, and Most-Recently-Used (MRU). The best choice depends on the access pattern.

29
New cards

Sequential flooding

A problem with LRU during repeated sequential scans: if buffer frames < pages in the file, every page request causes an I/O. MRU performs much better here (workload-dependent).

30
New cards

Why a DBMS doesn't just rely on the OS for buffer/disk management

OS-based management has limited support for database-specific features and potential portability problems. A DBMS needs to pin pages, force pages to disk, customize replacement policy, and prefetch based on access patterns.

31
New cards

Blocking factor (bfr) formula

bfr = floor(B / R), where B = block size and R = record size.

32
New cards

Unused space per block formula

B - (bfr x R)

33
New cards

System catalogs

Store metadata about the database schema (relations, attributes and types, indexes, integrity constraints, views, statistics, authorization info, buffer pool size, etc.). Catalogs are themselves stored as relations.

34
New cards

What the catalog stores for each index

Its structure (e.g., B+ tree) and its search key fields (columns).

35
New cards

What the catalog stores for each relation

Relation name, file name and file structure (e.g., heap file), attribute names and types, names of associated indexes, and integrity constraints.

36
New cards

What the catalog stores for each view

The view name and definition.

37
New cards

Basic fixed-format record layout

Fields stored consecutively in a fixed order. Simple, but reaching the i'th field may require scanning preceding fields, and NULLs waste space because every field has reserved storage.

38
New cards

Directory-based record layout

A small directory at the start of the record stores offsets to each field. Gives direct access to the i'th field, handles NULLs efficiently by skipping unused fields, with minimal overhead.

39
New cards

Variable-length record: basic layout

Field count at the start, with fields delimited by special symbols (e.g., $).

40
New cards

Variable-length record: directory-based layout

An array of field offsets at the start of the record pointing to each field.

41
New cards

File (in DBMS terms)

A collection of pages (blocks), where each page contains a collection of records.

42
New cards

Operations a file must support

Insert, delete, or modify a record; read a specific record by rid; scan all records (optionally with conditions to retrieve a subset).

43
New cards

Heap (unordered) file

Simplest file structure; records are stored in no particular order. Best when most operations scan the entire file. Pages are allocated and de-allocated dynamically.

44
New cards

What a heap file must track

The pages belonging to the file, free space on each page, and the records stored within each page.

45
New cards

Heap file implemented as a list

A header page points to two linked lists of data pages: full pages and pages with free space. Each page has two pointers (previous and next) in addition to record data.

46
New cards

Heap file using a page directory

A header page leads to a directory (a collection of pages, e.g., a linked list) whose entries point to data pages; an entry can include the number of free bytes on that page.

47
New cards

Sorted file

Records are kept in order on a search key. Ideal when records must be retrieved in a specific order or when only a range is needed.

48
New cards

File organizations: heap vs. sorted vs. index

Heap: scan all records. Sorted: ordered or range retrieval. Index: tree or hash structure on search key fields; speeds up searches for subsets like a sorted file, but updates are generally much faster than in sorted files.

49
New cards

Primary index

An index on a set of fields that includes the primary key, so it has no duplicate search key values.

50
New cards

Secondary index

Any index that is not a primary index; may contain duplicate search key values.

51
New cards

Unique index

An index whose search key corresponds to a candidate key, so each search key value is unique.

52
New cards

Clustered index

An index where the physical order of data records on disk is the same as (or closely follows) the order of the index's search key values.

53
New cards

Unclustered index

An index where data records are stored in an order independent of the index's search key order.

54
New cards

Clustering constraint

A data file can be clustered on at most one search key, so at most one clustered index can exist per data file (multiple unclustered indexes are allowed).

55
New cards

Why clustered indexes matter for performance

They generally give significantly lower I/O cost for range queries than unclustered indexes.

56
New cards

Building a clustered index

First sort the heap file on the search key, typically leaving some free space on each page for future insertions.

57
New cards

Hash-based index

Organized as a collection of buckets; well suited for equality selections (not range queries).

58
New cards

Bucket (in hashing)

A primary page plus zero or more overflow pages.

59
New cards

Hash function h(r)

Maps a record r to its bucket by applying h to r's search key fields. Example: h(x) = x mod 4.

60
New cards

Modulo operation

Returns the remainder of a division; used here to define hash functions.

61
New cards

Two hashing techniques covered

Extendible hashing and linear hashing (both are dynamic).

62
New cards

Extendible hashing

A dynamic hashing technique that uses a directory of bucket pointers plus buckets. Characterized by a global depth and a local depth per bucket.

63
New cards

Global depth (d) in extendible hashing

Determines how directory entries map to buckets. The directory has 2^d entries, each storing a bucket address.

64
New cards

Local depth (d') in extendible hashing

The number of hash bits used to identify records in a bucket. Always d' <= d.

65
New cards

When is local depth equal to global depth for every bucket?

When each directory entry points to a distinct bucket.

66
New cards

Extendible hashing: bucket overflows and d' < d

Allocate a new bucket (split) and update the directory entries; the directory does not need to double.

67
New cards

Extendible hashing: bucket overflows and d' = d

The directory must be doubled and the global depth increased by one; the bucket is split and its local depth increases by one.

68
New cards

Extendible hashing example: insert 20 into d=2 (mod 4) with bucket 0 full (4, 12, 16, 32)

Local depth = global depth, so the directory doubles to d=3 (mod 8). Bucket 0 splits into 16, 32 (000) and 4, 12, 20 (100); both get local depth 3.

69
New cards

Extendible hashing example: insert 9 into d=3 where bucket 001 is full (1, 5, 21, 13, local depth 2)

Local depth < global depth, so just split without doubling: 1, 9 go to bucket 001 and 5, 13, 21 go to bucket 101; both get local depth 3.

70
New cards

Linear hashing

A dynamically updatable, disk-based hash index that grows or shrinks one bucket at a time. Mainly supports exact-match queries. Uses overflow pages.

71
New cards

Linear hashing: which bucket is split?

Buckets are split in round-robin order (bucket 0, then 1, 2, …), NOT necessarily the one that overflowed. A split is triggered whenever any bucket overflows.

72
New cards

Linear hashing: Next pointer

Marks the next bucket to split. Buckets 0 to Next-1 have already been split in the current round.

73
New cards

Linear hashing: family of hash functions

h0 = x mod 2^2, h1 = x mod 2^3, h2 = x mod 2^4, … (h_level, h_level+1, …). Used to determine the bucket for a key.

74
New cards

Linear hashing example: insert 43 (43 mod 4 = 3) when bucket 11 is full

Create an overflow page for bucket 11 and place 43 there; then split the bucket at Next (bucket 00) using h1 (mod 8), moving 36 and 44 to new bucket 100 and leaving 32.

75
New cards

Linear hashing weakness

Skewed data distributions can create long overflow chains, hurting performance.

76
New cards

Extendible vs. linear hashing (key difference)

Extendible uses a directory and doubles it when needed, with no overflow chains in the basic scheme. Linear uses no directory, splits buckets round-robin, and relies on overflow pages.