IAE Academy

The whole Database Management and Warehousing formula sheet, to print

75 formulas in 7 topics, each with when to use it. Each is explained in the topic notes.

The entity-relationship (ER) model

Read the notes

UPPER BOUND ON A RELATIONSHIP SET

For an n-ary relationship set over entity sets . It holds because no two instances relate the same combination of entities. The bound is reached only when every combination is related.

BOUND FROM AN AT-MOST-ONE SIDE

In a binary 1:N relationship from A to B (each B related to at most one A), the count is at most . With total participation of B it equals . In a 1:1 relationship both sides are at-most-one, so .

LOWER BOUND FROM TOTAL PARTICIPATION

Every entity of appears in at least one instance, and each instance contains exactly one entity of .

BINARY M:N WITH TOTAL PARTICIPATION ON BOTH SIDES

Both bounds can be reached: the lower one by covering every entity with as few pairs as possible, the upper one by relating every pair.

KEY OF A WEAK ENTITY'S RELATION

The owner's key is copied in as a foreign key, normally declared ON DELETE CASCADE so that deleting an owner removes its weak entities. No separate relation is made for the identifying relationship.

KEY OF AN M:N RELATIONSHIP RELATION

Applies to a binary many-to-many relationship. Each key column is also a foreign key.

MINIMUM NUMBER OF TABLES (DEFAULT COUNT)

Counts recursive M:N relationship sets too. This is the count after merging every 1:1 and 1:N relationship (identifying relationships included) into an entity's relation. Each 1:1 relationship with total participation on both sides reduces the count by one more. Assumes no specialisation or aggregation.

The relational model: relational algebra and tuple calculus

Read the notes

SUPERKEY CONDITION

Every superset of a superkey (within the attributes of ) is a superkey, so under set semantics the set of all attributes is always a superkey. Candidate keys are the minimal superkeys.

COUNTING SUPERKEYS

is the number of attributes of . A superkey is any attribute set that contains at least one candidate key. With two keys, inclusion-exclusion subtracts the sets counted twice: those containing .

SELECTION

Keeps whole tuples satisfying the condition; schema unchanged; .

PROJECTION

Keeps the listed columns and removes duplicate rows (set semantics). For non-empty , , with whenever the list contains a superkey.

CARTESIAN PRODUCT

Pairs every tuple of with every tuple of . Clashing attribute names are qualified (, ) or renamed with .

UNION AND SET DIFFERENCE

Defined only for union-compatible relations: the same degree, with the -th attributes of both having the same domain. By convention the result takes its attribute names from the first operand. Union is commutative and associative; difference is neither.

CARDINALITY BOUNDS FOR SET OPERATIONS

Set semantics, and union-compatible. Also and . The upper bounds of and are reached when ; their lower bounds when the smaller relation is contained in the larger.

THETA JOIN

. An equi-join is a theta join whose condition is only equalities; it keeps both copies of the compared attributes.

NATURAL JOIN

are the attributes with the same name in both relations, and the result has degree . With no common attribute it equals ; when the two schemas are identical it equals . A NULL never matches, not even another NULL. Natural join is commutative and associative (up to column order).

INTERSECTION

Union-compatible relations; .

DIVISION

and , where the attributes of are a proper subset of those of and is the rest. The result has schema (degree ): the -values that appear in paired with every tuple of . If is empty, the formula gives .

DIVISION SIZE BOUNDS

Each -value in the result needs its own tuples in , one for each tuple of , and these tuples are different for different -values.

OUTER JOIN COUNTS

is the inner (natural) join; and are the numbers of tuples of and of that match no tuple of the other relation. Left outer adds only , right outer only .

NATURAL JOIN SIZE BOUNDS

If the common attributes form a key of , each tuple of matches at most one tuple of , so . If they are also a foreign key of referencing with no NULL in it, the size is exactly .

LARGEST VALUE WITHOUT AGGREGATION

is a renamed copy of . The subtracted part is every -value that some other value of exceeds, so what remains is the maximum value of . Use in place of for the minimum. This assumes contains no NULL.

TRC EXPRESSION

The result is the set of all tuples for which formula is true. is the only free variable of ; every other tuple variable must be bound by a quantifier.

LOGICAL EVALUATION ORDER OF A QUERY BLOCK

Rows are filtered by WHERE before grouping; groups are filtered by HAVING after aggregation; ORDER BY runs last and does not change which rows are returned.

BAG COUNTS FOR SET OPERATIONS

Here m and n are the number of copies of one particular tuple in the first and second operand. Without ALL, each of these results has at most one copy of every tuple.

AGGREGATES AND NULL

Both SUM and COUNT here skip NULLs, so AVG divides by the number of non-NULL values, not by the number of rows; when c has NULLs, AVG(c) differs from SUM(c)/COUNT(). If every value of c is NULL (or there are no rows), SUM, AVG, MIN and MAX return NULL and COUNT(c) returns 0, while COUNT() returns the number of rows (0 only when there are no rows).

ROW COUNT OF AN EQUI-JOIN ON ONE COLUMN

Here c_R(v) and c_S(v) are the numbers of rows of R and S with key value v. Sum over non-NULL values v only: a NULL key never satisfies equality, so it matches nothing.

ROW COUNTS OF OUTER JOINS

A row is unmatched if no row of the other table satisfies the ON condition; rows with a NULL join key are always unmatched. Every row of R appears at least once in R LEFT JOIN S, so the left join has at least |R| rows.

IN, ANY AND ALL

x op ANY S is TRUE if the comparison is TRUE for at least one value in S; x op ALL S is TRUE if it is TRUE for every value in S. On an empty S, ANY is FALSE and ALL is TRUE.

NEGATION IN THREE-VALUED LOGIC

Because NOT UNKNOWN is still UNKNOWN, a row failing both p and NOT p can exist: WHERE p OR NOT p does not return every row when p can be UNKNOWN.

Integrity constraints, functional dependencies and normal forms

Read the notes

ARMSTRONG'S AXIOMS (SOUND AND COMPLETE)

Sound: they derive only FDs implied by F. Complete: they derive every FD in the closure F^+.

DERIVED RULES

All follow from the three axioms. Decomposition applies to the right side only; does not give .

ATTRIBUTE CLOSURE

Algorithm: start with result = X; repeatedly, for any FD in F with result, add ; stop when nothing is added.

MEMBERSHIP TEST AND SUPERKEY TEST

Use the closure algorithm for both. A candidate key is a minimal superkey: removing any attribute breaks .

COUNTING SUPERKEYS

A superkey is any set containing at least one candidate key. For more keys, extend by inclusion and exclusion over unions of keys. Example: keys AB, BC, BD in R(A,B,C,D) give .

MAXIMUM NUMBER OF CANDIDATE KEYS

No candidate key contains another, and this bound is reached (for example, when every set of attributes is a key).

3NF AND BCNF CONDITIONS

For the relation R on which F is given, it is enough to test the FDs of F after splitting right sides into single attributes. For a part of a decomposition, test the FDs of that lie inside (the projection), not just those of F.

LOSSLESS-JOIN TEST FOR A BINARY DECOMPOSITION

Conditions: and F is the only set of constraints. The common attributes must be a superkey of at least one of the two parts. For more than two parts, use the tableau (chase) test.

DEPENDENCY PRESERVATION

Practical test for each in F: set , and repeat for every , with closures computed using F, until Z stops growing. The FD is preserved if .

File organisation and indexing

Read the notes

BLOCKING FACTOR (UNSPANNED)

Records per block. The floor is essential: with unspanned records the leftover bytes in each block are unused.

NUMBER OF DATA BLOCKS

Blocks needed for records; round up because a partly filled last block still occupies a block.

BINARY SEARCH ON A SORTED FILE

Applies only to the field the file is sorted on, and counts block accesses, not record comparisons. This is the usual convention in problems; the strict worst case of binary search is , which is one more only when is a power of 2. Follow the convention the question states.

INDEX BLOCKING FACTOR (FAN-OUT)

Entries per index block, where an entry is a key plus a block pointer (replace by if the entries hold record pointers).

SINGLE-LEVEL INDEX SIZE

Dense: one entry per record. Sparse primary index: one entry per data block. A clustering index on a field with distinct values needs blocks.

SEARCH WITH A SINGLE-LEVEL INDEX

Binary search over the index blocks (same convention as for a sorted file), plus one access to fetch the data block. A non-key secondary index with a level of indirection adds one more access for the block of record pointers.

MULTILEVEL INDEX LEVELS AND COST

is the fan-out, the number of first-level entries and the number of first-level blocks. The first form is valid for (for , ); the second for .

B+ TREE INTERNAL NODE ORDER

Largest satisfying this; internal nodes hold block pointers and keys.

B+ TREE LEAF CAPACITY

Largest number of keys in a leaf, where the extra is the next-leaf pointer.

B-TREE NODE ORDER

Each key in a B-tree node carries a record pointer, so one node type serves internal nodes and leaves.

KEYS STORED IN A B+ TREE OF HEIGHT H

Max: every node full, so leaves of keys. Min: the root has 2 children and every other internal node , giving leaves, each with keys.

KEYS STORED IN A B-TREE OF HEIGHT H

Max: all nodes full with keys each. Min: the root has 1 key (2 children) and every other node keys.

BLOCK ACCESSES FOR AN EQUALITY SEARCH

One block per level down to the leaf, plus one to read the data record. Leaves holding the record itself need only .

EXTENDIBLE HASHING DIRECTORY

is the global depth and a bucket's local depth.

Data types and data transformation: normalisation, discretisation, sampling and compression

Read the notes

MIN-MAX NORMALISATION TO [NEW_MIN, NEW_MAX]

Linear map of the observed range onto the target range; for [0,1] it reduces to (v - min)/(max - min). Preserves the shape of the distribution and the order of values. Undefined when max = min (all values equal).

Z-SCORE NORMALISATION

Result has mean 0 and standard deviation 1 (under the same convention for sigma). Convention: use the population standard deviation (divide by n) unless the question says sample (divide by n - 1). Not bounded to a fixed range; undefined when sigma = 0. A variant divides by the mean absolute deviation s = (1/n) times the sum of |v - mean| instead of sigma; it is less affected by outliers because deviations are not squared.

DECIMAL SCALING

Moves the decimal point; j is fixed by the value of largest absolute magnitude. Result lies strictly inside (-1, 1). Examples: max|v| = 986 gives j = 3; max|v| = 1000 gives j = 4.

EQUAL-WIDTH BINNING

Bins have the same width and usually unequal counts. Convention here: left-closed, right-open, with the last bin closed so the maximum belongs to it.

EQUAL-FREQUENCY (EQUAL-DEPTH) BINNING

Sort the data and put n/k consecutive values in each bin; widths differ. If k does not divide n, bin sizes are floor(n/k) or ceil(n/k) and the question must say which bins take the extra values. Tied values may need to share a bin.

ENTROPY-BASED (SUPERVISED) SPLIT

D_1 and D_2 are the tuples with attribute value at most, and above, the candidate split point T; p_i is the fraction of a set in class i. Choose the T that minimises Info_T(D), which is the same as maximising the information gain Entropy(D) - Info_T(D). Apply recursively to each part until a stopping rule is met.

INCLUSION PROBABILITY, SRSWOR

Sample of n distinct tuples from N, all subsets equally likely.

INCLUSION PROBABILITY, SRSWR

n independent draws, each tuple chosen with probability 1/N per draw; N^n ordered outcomes.

EXPECTED NUMBER OF DISTINCT TUPLES, SRSWR

By linearity of expectation over the N tuples. The limit is the bootstrap fact: a with-replacement sample of size N contains about 63.2% of the distinct tuples, and about 36.8% never appear.

PROPORTIONAL ALLOCATION IN STRATIFIED SAMPLING

Stratum h of size N_h receives a share of the total sample n in proportion to its size; round so that the n_h sum to n.

SYSTEMATIC SAMPLING

When N = nk exactly, every tuple has inclusion probability 1/k = n/N, but only k distinct samples are possible.

COMPRESSION RATIO

A ratio above 1 means the data shrank. Space saving = 1 - compressed/original.

FIXED-LENGTH CODE SIZE

For an alphabet of m >= 2 distinct symbols. A Huffman code never needs more bits per symbol on average than this, and needs fewer for some unequal frequency distributions (not all: probabilities 0.3, 0.3, 0.2, 0.2 give Huffman lengths 2, 2, 2, 2).

AVERAGE CODE LENGTH AND THE ENTROPY BOUND

p_i is the probability (relative frequency) of symbol i and l_i its code length in bits. No lossless symbol-by-symbol prefix code averages below H; Huffman's code is optimal among them and reaches H exactly when every p_i is a power of 1/2.

Data warehouse modelling: multidimensional schemas, concept hierarchies and measures

Read the notes

CUBOIDS WITH NO HIERARCHIES

n dimensions, each with a single level (apart from 'all'). Each dimension is either present or rolled up to all.

CUBOIDS WITH EXACTLY K DIMENSIONS (NO HIERARCHIES)

Choose which k of the n dimensions stay; summing over k = 0 to n gives 2^n.

CUBOIDS WITH CONCEPT HIERARCHIES

L_i is the number of distinct levels of dimension i, excluding the virtual top level 'all'; the +1 accounts for 'all'. A cuboid picks one level (or 'all') per dimension, so this holds for a total order and for a lattice; in a lattice count every level once (day, week, month gives L = 3).

GROUPINGS COMPUTED BY CUBE AND ROLLUP

Both counts include the grand total ().

MAXIMUM CELLS IN THE BASE CUBOID

c_i is the number of distinct values of dimension i at its lowest level; this is an upper bound that is reached only if every combination occurs.

CELLS IN THE WHOLE CUBE (NO HIERARCHIES)

Each dimension contributes its c_i values or the single value 'all' (written *). Counts every cell of every cuboid, assuming all combinations are non-empty. With hierarchies, replace c_i + 1 by 1 plus the total number of distinct values over all levels of dimension i.

AVERAGE FROM DISTRIBUTIVE PARTS

s_j and n_j are the sum and count of partition j. The average of the partition averages differs from this in general; it is guaranteed to equal it only when all n_j are equal.

VARIANCE FROM SUMS (POPULATION)

Needs only count N, sum and sum of squares, each distributive, so variance is algebraic with M = 3. Population variance (divide by N).