Chapter 6

File organisation, indexes and access cost

Count bytes before nodes, and nodes before I/Os. Distinguish a record pointer from a child-block pointer. Search cost depends on clustering, buffer contents and whether the query needs the data row after locating an index entry.

6.1 Records, blocks and file layouts

Past papers · CS 2014–2026 (23 papers): 1 question, 1 mark

A heap file keeps no search-key order; insertion is simple and a full scan reads its data blocks. A sorted file supports ordered lookup and range scans but incurs insertion/deletion maintenance. A hashed file places records by a hash function; it favours equality search, not ordered ranges. A slotted page stores offsets to variable-length records so a record can move within the page while its slot stays stable.

With unrestricted spanning and no per-fragment overhead, a tightly packed file needs ⌈nrL/(B−H)⌉\lceil n_rL/(B-H)\rceil blocks. Do not use that expression for records required to fit entirely in a block. A heap scan costs brb_r reads; a successful search for a uniformly located unique row averages about half a file, while an unsuccessful search reads all blocks. For an ordered array of brb_r blocks, ordinary binary search uses at most ⌊log⁡2br⌋+1\lfloor\log_2 b_r\rfloor+1 block probes when br>0b_r>0. Some questions explicitly prescribe ⌈log⁡2br⌉\lceil\log_2 b_r\rceil instead; use that stated cost model. On a single-level ordered index of bib_i blocks, apply the given binary-search cost to bib_i, then add a data-block fetch only if retrieving the record is required.

6.2 Dense, sparse, clustered and secondary indexes

Past papers · CS 2014–2026 (23 papers): 4 questions, 6 marks

An index search key is an indexed attribute set; it need not be a candidate key. A dense index represents every search-key value, either with individual record entries or a value entry pointing to a list of matching records. A sparse index represents only selected values, typically the first key in each sorted data block. To find a missing exact entry in a sparse index, take the greatest indexed key not exceeding the target, then search the corresponding ordered region.

Index organisationData order and use
Primary, textbook terminologyData ordered on a unique key; often sparse, one anchor per block
Clustering, textbook terminologyData ordered on a non-key field; entries locate matching groups
SecondaryData not ordered on this search key; must represent every searchable value
Clustered, broader terminologyPhysical row order follows or nearly follows index order, whether or not key values are unique

A file has one physical ordering, but may have many secondary indexes. B+ trees can implement dense or sparse ordered indexes. A conventional hash index represents all searchable values: there is no “preceding key then sequential scan” shortcut for missing values. Sparse anchor indexing needs the underlying order; hashing does not provide it.

For a multilevel sparse index, make one upper-level entry per lower-level block and repeatedly apply the ceiling until one root block remains. If all ℓ\ell index levels are uncached, a point lookup uses ℓ\ell index reads and normally one data-block read. Merely identifying the candidate data block does not include that final read. A covering index can answer a query without a separate data fetch.

6.3 B trees and B+ trees

Past papers · CS 2014–2026 (23 papers): 3 questions, 3 marks

Both are balanced multiway search trees: all leaves are at the same depth. Keys within a node are sorted. In a B tree, data entries or record pointers can accompany keys in internal nodes and a successful search may finish there. In a B+ tree, internal keys guide navigation; data entries are in leaves, which are linked for ordered scanning. An internal separator may therefore also appear as a leaf key.

Node rule using maximum fan-out mmOrdinary B/B+ internal node
Maximum childrenmm
Maximum separator keysm−1m-1
Non-root minimum children⌈m/2⌉\lceil m/2\rceil
Non-root minimum separator keys⌈m/2⌉−1\lceil m/2\rceil-1
Internal root minimumTwo children and one separator

In a B tree, every non-root leaf also holds between ⌈m/2⌉−1\lceil m/2\rceil-1 and m−1m-1 data keys. The root can also be the only leaf; an empty tree is a special case. B+ leaf capacity LfL_f is determined separately from internal fan-out; with the usual occupancy rule, a non-root leaf has at least ⌈Lf/2⌉\lceil L_f/2\rceil entries. If a question explicitly defines a different minimum occupancy, use that definition.

An original B+ tree: separators direct the search, and linked leaves store all entries.An original B+ tree: separators direct the search, and linked leaves store all entries.

6.4 Node capacities from byte budgets

Past papers · CS 2014–2026 (23 papers): 2 questions, 4 marks · DA 2024–2026 (3 papers): 1 question, 1 mark

6.5 Height bounds and range I/O

Past papers · CS 2014–2026 (23 papers): 2 questions, 3 marks

For a clustered index, a long range often touches consecutive data blocks. An unclustered range may need a data-block read for each matching row in the worst case. A large range can therefore favour a full file scan over an index.

6.6 Insertions, splits, deletions and merges

Past papers · CS 2014–2026 (23 papers): 2 questions, 3 marks · DA 2024–2026 (3 papers): 1 question, 2 marks

Search the leaf, insert in sorted order, then repair any overflow upwards. In the separator convention used here, each internal key is the minimum key in its right child subtree; an equal key descends right. Follow the stated convention if a question uses a different one.

For a B+ leaf split, distribute data entries between two legal leaves and copy the right leaf's smallest key to the parent. The copied key remains in the leaf. For an internal split, promote the middle separator and remove it from the two resulting internal nodes. A root split creates a new root, increasing height by one. In a B tree, a promoted data key moves into the parent.

After deletion, first try borrowing from a sibling with spare occupancy, updating parent separators. Otherwise merge nodes and remove the obsolete parent separator/child pointer, possibly propagating underflow. A root with only one child is replaced by that child. A separator may need updating even if occupancy remains valid.

6.7 Hash and bitmap indexes

Past papers · CS 2014–2026 (23 papers): 1 question, 2 marks · DA 2024–2026 (3 papers): 1 question, 2 marks

Static hashing fixes the bucket array and uses overflow handling when a bucket fills. Extendible hashing uses selected hash bits to index a directory; directory entries can share buckets. A bucket's local depth is the number of distinguishing bits it uses; global depth is the number used by the directory.

Repeated collisions can require repeated splits. A directory doubling does not double the number of physical buckets. In a bit-trie variant, create just the branches needed to distinguish colliding keys; do not assume a complete tree. Hash indexes accelerate equality and equijoins; they do not place nearby numerical values together for range queries.

A bitmap index keeps a bit vector over rows for each indexed value. Bitwise AND, OR and NOT combine predicates, with a separate null policy. It is especially useful for analytical queries over low-cardinality columns.

6.8 Join algorithms and external sorting

Past papers · CS 2014–2026 (23 papers): 1 question, 2 marks

Let br,bsb_r,b_s be relation sizes in blocks, nrn_r the outer row count and M≥3M\ge3 the number of available buffer blocks. The costs below count reads and necessary intermediate writes, exclude writing the final result, and assume inputs are not already cached.

With three buffers, compare br+brbsb_r+b_rb_s and bs+bsbrb_s+b_sb_r: the smaller relation should be outer. With more buffers, compute both orientations because ceiling effects matter. If one input fits entirely in the usable buffers, read each input once and join in memory.

A merge join on already sorted inputs scans them in about br+bsb_r+b_s reads when duplicate-key groups fit the available buffers. Otherwise groups may need rescanning or temporary storage. Add sorting costs when inputs are unordered; avoid counting a pipelined final merge twice.

Last-minute recall

  • Floor records per block; ceil blocks needed.
  • A sparse index locates an ordered region, not every record separately.
  • B+ internal capacity excludes record pointers.
  • B+ leaves keep promoted separators; internal splits move a separator upward.
  • Height counts edges here; root-to-leaf reads count nodes.
  • Add a data-block read only when the requested result requires it.
  • Global hash depth counts directory bits; local depth counts bucket bits.
  • Query I/O costs depend on buffers, clustering and final-output conventions.

Revise offline: the whole Databases and Data Warehousing handbook as one PDF

58 pages · 2.7 MBFree to read online. Sign in to download the PDF.We save the handbook, version and request time in My downloads. Privacy policy

All chapters · Corrections