Database Management and Warehousing
2. Relational algebra, tuple calculus and SQL
Relational algebra is procedural: a query is an explicit sequence of operators — σ (select rows by a condition), π (project columns), ⋈ (join two relations on a condition), ∪/∩/− (set union, intersection, difference), and ρ (rename) — applied in a stated order. Tuple relational calculus is declarative: a query states what the answer must satisfy ('the set of tuples t such that...') without saying how to compute it. SQL is the language actually used, and it is declarative in the same sense as tuple calculus — a SELECT statement describes the desired result, and the database engine decides how to execute it, typically by compiling the query down into something equivalent to a relational-algebra expression.
- Every tuple-calculus expression has an equivalent relational-algebra expression and vice versa — the two are formally equivalent in expressive power, which is exactly why a declarative SQL query can always be compiled down to a procedural algebra plan.
- A join (⋈) is not a primitive operator in the strictest sense — it can always be written as a selection over a Cartesian product, but it is given its own symbol because that combination is by far the most common query shape.
3. Normal forms
A relation in First Normal Form (1NF) has only atomic (indivisible) attribute values — no repeating groups or lists inside a single cell. Second Normal Form (2NF) additionally removes partial dependency: every non-key attribute must depend on the whole of a composite primary key, not just part of it. Third Normal Form (3NF) additionally removes transitive dependency: a non-key attribute may not depend on another non-key attribute. Boyce-Codd Normal Form (BCNF) is stricter still — every determinant (the left side of a functional dependency) must be a candidate key, with no exceptions carved out for the case 3NF still allows.
4. File organization, indexing and data types
A heap (pile) file simply appends new records with no order at all, so insertion is cheap but finding a record by key means scanning the whole file, O(n). A sorted sequential file supports binary search on the key, O(log n), but insertion means shifting records to keep the order, which is expensive. A hashed file maps a key directly to a storage location via a hash function, giving near-O(1) lookup by that key at the cost of losing any usable order for range queries.
An index is a separate, auxiliary structure that speeds up lookup on a column without reorganising the data file itself. A primary index is built on the field the file is physically sorted by (at most one per file); a secondary index can be built on any other field, and typically needs one entry per record rather than one per block. A B+ tree index — the standard choice in practice — keeps all actual data pointers at the leaf level with internal nodes holding only routing keys, so a lookup, an ordered range scan and an insertion are all O(log n) even as the tree grows.
5. Data transformation: normalization, discretization, sampling, compression
Discretization replaces a continuous attribute's values with a small number of labelled ranges or bins (e.g. age becomes 'young', 'middle-aged', 'senior'), useful for algorithms that expect categorical input or for making a pattern easier to read. Sampling selects a representative subset of the data to work with when the full dataset is too large to process directly — the accuracy of any conclusion then depends on how representative the sample actually is. Compression re-encodes data into a smaller representation, either losslessly (the original can be exactly reconstructed) or lossily (some detail is discarded permanently in exchange for a smaller size).
6. Data warehouse modelling
A data warehouse is modelled for analytical queries across many dimensions rather than for the transactional inserts and updates a normalized operational database is built for. A star schema puts numeric measures (e.g. quantity sold, revenue) in a single central fact table, surrounded by denormalized dimension tables (product, store, time, customer) that each describe one axis along which the measure can be sliced; a snowflake schema further normalizes those dimension tables into sub-tables, trading some query simplicity for reduced redundancy.
A concept hierarchy orders a dimension's values from finer to coarser granularity — day → month → quarter → year for time, or city → state → country for geography — and it is exactly what lets an OLAP query roll up (aggregate to a coarser level) or drill down (break out to a finer one) along that dimension. Measures themselves are categorised by how they behave under aggregation: additive measures (like sales revenue) can be summed across every dimension; semi-additive measures (like an account balance) can be summed across some dimensions but not time, since a month's balance is not the sum of its daily balances; and non-additive measures (like a ratio, e.g. a profit margin) cannot be meaningfully summed across any dimension at all and must be recomputed from summed components instead.
Key takeaways
- A many-to-many relationship needs its own table carrying a foreign key to each participating entity; folding it into either entity's table loses information the moment one side participates more than once.
- Relational algebra (procedural), tuple calculus (declarative) and SQL (declarative, compiled to an algebra plan) are formally equivalent notations for the same query language.
- Higher normal forms remove more redundancy; BCNF is stricter than 3NF, and decomposing all the way to BCNF can fail to preserve every original functional dependency, which 3NF is deliberately designed to always preserve.
- A B+ tree index turns a linear file scan into an O(log n) lookup, ordered range scan and insertion all at once, which is why it is the standard indexing structure in practice.
- Data-preprocessing 'normalization' (min-max/z-score scaling of numeric values) and schema 'normalization' (removing redundancy via normal forms) are unrelated operations that this section's own syllabus line happens to share one word for.
- A warehouse's star schema keeps measures in a central, deliberately denormalized fact table surrounded by dimension tables, and a concept hierarchy on a dimension is what lets an OLAP query roll up or drill down along it.
Practice questions (14)
Attempt each one before opening the answer. Every explanation names the tempting wrong option as well as the right one, because that is where marks are lost.
A many-to-many relationship set between two entity sets maps, in the relational model, to a table that carries
Show answer
Answer: C — foreign keys to both participating entities, plus any attributes of the relationship itself
A single foreign key on either entity's own table could only ever record one partner at a time, so the many-to-many relationship needs its own table referencing both sides.Which pair correctly matches a relational-algebra operator to what it does?
Show answer
Answer: A — σ selects rows satisfying a condition
σ (select) filters rows by a condition; π projects columns; ⋈ joins; ρ renames — the other three options each name the wrong operator for the job described.Which of the following are true of relational algebra, tuple calculus and SQL?
Show answer
Answer: A — Tuple relational calculus is declarative — it states what to retrieve, not how to compute it; B — Relational algebra is procedural — an ordered sequence of operators applied step by step; D — Every relational-algebra expression has an equivalent tuple-calculus expression
SQL's SELECT statements describe the desired result rather than the steps to compute it, which makes SQL declarative like tuple calculus, not procedural — the third option is the false one here.A relation that is in Second Normal Form (2NF) but not Third Normal Form (3NF) contains
Show answer
Answer: B — a transitive dependency of one non-key attribute on another non-key attribute
2NF already rules out partial dependency (option 1) and 1NF already rules out repeating groups (option 3); what 3NF additionally removes over 2NF is exactly transitive dependency.Decomposing a relation all the way to Boyce-Codd Normal Form (BCNF) can fail to preserve
Show answer
Answer: C — every original functional dependency
BCNF decomposition is always achievable losslessly, but it is not guaranteed to be dependency-preserving; a dependency can end up spanning two tables after the split, which is exactly the trade-off 3NF is designed to avoid.In a B+ tree index of order (maximum fan-out) 4, what is the maximum number of child pointers an internal node can have?
Numerical answer — type the value.
Show answer
Answer: 4
The order of a B+ tree is defined as the maximum number of children an internal node may have, so order 4 means at most 4 child pointers per internal node.Assuming a good hash function and a low collision rate, which file organization gives the fastest access to a record given its key?
Show answer
Answer: C — Hashed file
A hashed file maps the key directly to a storage location, giving near-O(1) access; the other three organizations need either a full scan or a logarithmic search at best.Min-max scaling and z-score standardization are both examples of, in the data-transformation sense this section uses,
Show answer
Answer: B — data normalization, rescaling values onto a common range or distribution
Both rescale a numeric attribute's values (onto [0,1], or to zero mean and unit variance) rather than restructuring a schema — this is data normalization in the preprocessing sense, distinct from schema normalization via normal forms.Replacing a continuous attribute's values with a small number of labelled ranges, such as 'low', 'medium' and 'high', is called
Show answer
Answer: A — discretization
Discretization is exactly the operation of binning a continuous attribute's range into a small number of labelled categories.In a star schema for a retail sales data warehouse, numeric measures such as quantity sold and revenue are stored in the
Show answer
Answer: B — fact table
The fact table is the central table holding the numeric measures, surrounded by dimension tables that describe the axes (time, product, store) along which those measures can be sliced.A concept hierarchy such as day → month → quarter → year primarily lets an OLAP query
Show answer
Answer: B — roll up or drill down between finer and coarser granularity along that dimension
A concept hierarchy orders a dimension's values from fine to coarse, and it is exactly that ordering an OLAP query walks up (roll up) or down (drill down) to aggregate or break out data.Which normal form requires every determinant (the left side of a functional dependency) to be a candidate key, with no exception carved out?
Show answer
Answer: D — Boyce-Codd Normal Form (BCNF)
BCNF is stricter than 3NF precisely because it drops the exception 3NF allows (a determinant that is part of some candidate key but not one itself), requiring every determinant to be a candidate key outright.Which of the following are goals a good decomposition of a relation is expected to preserve?
Show answer
Answer: A — The lossless-join property; B — Every original functional dependency; D — Atomicity of every attribute value
Decomposition aims to reduce redundancy, not maximise it — the third option describes the opposite of what normalization is for, while the other three are genuine goals a good decomposition preserves.When an insertion causes a B+ tree node to overflow beyond its capacity, the standard response is to
Show answer
Answer: B — split the node in two and push (or copy) a separating key up into the parent
An overflowing B+ tree node splits into two nodes, with a key pushed up to the parent to route between them — repeated up the tree if the parent itself then overflows, which is what keeps the tree balanced and lookups at O(log n).