NIMCET, GATE, CUET & CBSE test series are live — start practicing free
syllabuzAI

File Organization and Indexing in DBMS | GATE CSE

Chapter overview of file organization and indexing for GATE CSE DBMS: blocking factor, I/O cost, dense, sparse, primary, clustering and secondary indexes, and B+ trees.

6 min read

AS

Aman Singh

Updated 26 November 2026

On this page

Quick answer: A database file is a set of blocks (pages) that hold records. Data moves between disk and memory one block at a time, so query cost is counted in block accesses (I/O cost). For an unspanned file the blocking factor is ⌊(block size − header) / record size⌋. Without an index, finding a record costs up to n block accesses on an unordered field and ⌈log₂ n⌉ on the ordering field. Indexes cut this cost: they can be dense or sparse; primary, clustering or secondary; single-level or multilevel. Multilevel indexes are usually built as B-trees or B+ trees, which pack many keys into each node so the tree stays shallow.

Many of GATE's numerical DBMS questions come from this chapter: blocking factor, number of index blocks, access cost, and the order of B and B+ tree nodes. This chapter page connects the three detailed notes.

Chapter overview

TopicKey ideasDetailed notes
File organizationFiles, blocks, records, spanned vs unspanned, blocking factor, access cost without an indexFile organization and blocking factor
IndexingDense vs sparse; primary, clustering and secondary indexes; index blocking factor; multilevel I/O costIndexing in DBMS
B and B+ treesNode structure, order calculation, minimum and maximum keys, height, B vs B+ treeB tree and B+ tree

Storage hierarchy

  • A database is a collection of files (tables).
  • A file is a collection of blocks (pages).
  • A block is a collection of records, possibly with a header.

Key formulas

B is the block size, H the header, R the record size, K the key size and P the pointer size.

QuantityFormula
Blocking factor (unspanned)⌊(B − H) / R⌋
Blocking factor (spanned, average)(B − H) / R
Blocks in file⌈records / BF⌉
Index blocking factor⌊(B − H) / (K + P)⌋
Search on an unordered field, no indexUp to n blocks
Search on the ordering field, no index⌈log₂ n⌉
Single-level index search⌈log₂(index blocks)⌉ + 1
Multilevel index with k levelsk + 1

Types of index at a glance

IndexSearch keyDense or sparseNumber per file
PrimaryOrdering field that is a keyUsually sparseAt most one
ClusteringOrdering field that is not a keySparse (one entry per distinct value)At most one
Secondary (key)Non-ordering key fieldDenseMany
Secondary (non-key)Non-ordering non-key fieldDense, or with an extra level of indirectionMany

A file can have a primary index or a clustering index, not both, because it can be physically sorted on only one field.

B and B+ trees in brief

FeatureB-treeB+ tree
Record pointersIn every nodeOnly in leaves
Internal nodesKeys, record pointers and child pointersKeys and child pointers only (higher order)
Leaves linkedNoYes
Range queriesSlowFast
Best-case searchCan stop at the root (2 block accesses including the data block)Always goes to a leaf

Worked example

Question: A file has 10,000 records of 100 bytes in 4096-byte blocks (unspanned, no header). How many blocks does it use, and what does it cost to find a record by its ordering key without an index?

Step 1: BF = ⌊4096 / 100⌋ = 40.

Step 2: Blocks = 10,000 / 40 = 250.

Step 3: Binary search costs ⌈log₂ 250⌉ = 8 block accesses, compared with up to 250 on an unordered field.

Summary table: what to compute first

Question typeStart withThen
File sizeData blocking factor⌈records / BF⌉
Index sizeIndex blocking factorEntries (records or blocks) ÷ index BF
Index access costNumber of index blocks⌈log₂(blocks)⌉ + 1, or k + 1 for multilevel
Tree orderNode-size inequalityLargest integer that fits

Exam tips

  • Every question in this chapter starts from two numbers: the data blocking factor and the index blocking factor. Get those right first.
  • Write down whether the index is dense (count records) or sparse (count data blocks) before dividing.
  • For B and B+ tree order, use the formula for the exact node type asked: B-tree node, B+ internal node or B+ leaf.

Common mistakes

  • Not taking the floor for the unspanned blocking factor, or the ceiling for the number of blocks.
  • Leaving out the data block access. Index access cost is index levels + 1.
  • Building a sparse index on an unordered field. Sparse indexes need a sorted file.
  • Using the B-tree order formula for B+ tree internal nodes.

Practice questions

Q1. Block size 1024 bytes, record size 100 bytes, unspanned. What is the blocking factor?

Answer: ⌊1024 / 100⌋ = 10.

Q2. Index entries are 16 bytes (9-byte key + 7-byte pointer) in 1024-byte blocks. What is the index blocking factor?

Answer: ⌊1024 / 16⌋ = 64.

Q3. Why are B+ trees preferred over AVL trees for database indexes?

Answer: Each B+ tree node fills a disk block with many keys, so the tree is shallow and needs far fewer block accesses. An AVL node holds one key, so the tree is much taller.

FAQs

What is the blocking factor in DBMS?

It is the number of records that fit in one block. For unspanned organization it is ⌊(block size − header) / record size⌋.

What is the difference between a dense and a sparse index?

A dense index has an entry for every record or search-key value. A sparse index has entries for only some records, usually one per block.

Why is a B+ tree better than a B-tree for databases?

B+ trees keep record pointers only in leaves, so internal nodes hold more keys and the tree is shallower. The linked leaves also make range queries fast.

How many primary indexes can a table have?

At most one, because a file can be physically sorted on only one field.

Why is query cost measured in block accesses?

Disks transfer whole blocks, and each disk access is much slower than processing in memory, so the number of blocks read decides the cost.

Conclusion

Compute the data and index blocking factors carefully, then apply the access-cost formulas or the tree-order inequality. Read file organization, indexing and B tree and B+ tree next. For the next DBMS chapter, see Transactions and Concurrency Control.

Concept Check

MEDIUM

Which one of the following statements is FALSE?

Suggested for you