Distributed Database

A distributed database is a collection of logically related data spread over several sites connected by a network, with each site able to run local transactions and take part in global ones. A distributed DBMS (DDBMS) manages it and makes the distribution invisible to users (distribution transparency).

  • Homogeneous DDBMS: every site runs the same DBMS software; heterogeneous: different systems and models, linked by a multidatabase layer.
  • Advantages: local control and fast local access, availability and reliability, easier growth. Disadvantages: complex design, costly communication, harder concurrency control and recovery.

Architectures

Common architectures are client/server (a few servers hold data), peer-to-peer (every site is equal, with a global conceptual schema, local conceptual schemas and local internal schemas), and multidatabase systems with a federated schema over autonomous databases.

Data Fragmentation

A relation is divided into fragments:

  • Horizontal: a subset of the rows chosen by a predicate (employees of Delhi). Recombined by union.
  • Vertical: a subset of the columns that includes the key. Recombined by a join on the key.
  • Mixed (hybrid): a combination of both.

Correctness rules: completeness (every item is in some fragment), reconstruction (the relation can be rebuilt) and disjointness (horizontal fragments do not overlap).

Replication

Replication keeps copies of a fragment at several sites. It raises availability and read speed, but updates must reach every copy (cost and consistency). It may be full, partial or none.

Allocation

Allocation decides which site stores each fragment (or copy) so as to minimise communication cost, using how often each site accesses it, the volume of data and the cost of storage.

Definition: Fragmentation. The division of a relation into smaller parts, by rows (horizontal), by columns (vertical) or both, so that the parts can be stored at different sites.

Table 3.3: Fragmentation types

Type Division Rebuilt by
Horizontal Rows by predicate Union
Vertical Columns plus key Join on key
Mixed Rows and columns Union and join

Example 3.3: Choosing a site for a fragment

Problem: A fragment is read from site A 50 times a day, from site B 30 times and from site C 20 times. Each remote access costs 2 units and local access costs nothing. Where should the fragment be stored, and what is the daily cost?

Solution:

  1. Stored at A: remote accesses = 30 + 20 = 50, cost = 100 units.
  2. Stored at B: remote accesses = 50 + 20 = 70, cost = 140 units.
  3. Stored at C: remote accesses = 50 + 30 = 80, cost = 160 units.

Result: Store the fragment at site A, the daily cost being 100 units.

import sqlite3
access = {"A": 50, "B": 30, "C": 20}
total = sum(access.values())
for site, n in access.items():
    print("Store at", site, "-> remote accesses", total - n,
          "cost", (total - n) * 2)
db = sqlite3.connect(":memory:")
db.executescript("""
CREATE TABLE emp(id, name, city, salary);
INSERT INTO emp VALUES (1,'Asha','Delhi',50),(2,'Bimal','Pune',60),
  (3,'Chitra','Delhi',55),(4,'Dev','Pune',45);
CREATE TABLE emp_delhi AS SELECT * FROM emp WHERE city = 'Delhi';
CREATE TABLE emp_pune AS SELECT * FROM emp WHERE city = 'Pune';
""")
n = db.execute("""SELECT COUNT(*) FROM (SELECT * FROM emp_delhi
                  UNION SELECT * FROM emp_pune)""").fetchone()[0]
print("Rebuilt rows:", n, "of 4")

Output

Store at A -> remote accesses 50 cost 100
Store at B -> remote accesses 70 cost 140
Store at C -> remote accesses 80 cost 160
Rebuilt rows: 4 of 4

Common mistakes

  • Making a vertical fragment without the primary key, so it cannot be rebuilt.
  • Overlapping horizontal fragments, which breaks disjointness.
  • Replicating heavily updated data everywhere.
  • Allocating fragments without looking at where they are used.

Key takeaways

  • Horizontal fragments are rebuilt by union; vertical fragments by join.
  • Correct fragmentation is complete, reconstructible and disjoint.
  • Replication improves availability but makes updates costly.
  • Allocation places fragments close to where they are used.

Practice questions

  1. What is distribution transparency?
  2. Why must a vertical fragment contain the key?
  3. What is the cost of replication?

Answers to the practice questions

  1. Hiding from users that the data is spread over several sites.
  2. So that the fragments can be joined to rebuild the relation.
  3. Every update must be applied to all the copies.

Sources

  • Official BCA syllabus Advanced Database Systems, course code 25BCA406DS04, Unit III