Background pattern

Volume 3

Databases

Study Notes

Concept reference & formula sheet for this chapter

ER-model. Relational model:Relational algebra, Tuple calculus, SQL. Integrity constraints, Normal forms. File organization, Indexing (e.g., B and B+ trees). Transactions and concurrency control.

Mark Distribution in Previous GATE

Welcome to the Databases chapter of your GATE Computer Science preparation. This crucial subject forms the backbone of modern data management and is indispensable for any computer science professional. In GATE, Databases typically carries a significant weightage, ranging from 6 to 10 marks, often featuring a mix of conceptual questions, problem-solving scenarios, and direct application of formulas. You can expect questions on topics like relational algebra/calculus, SQL queries, functional dependencies, normal forms, B-trees, and concurrency control protocols. A strong grasp of these fundamentals is vital not just for the exam but also for practical applications in software development and data engineering.

Topic-wise Key Concepts

Armstrong Axioms

Armstrong Axioms are a set of inference rules used to derive all functional dependencies (FDs) implied by a given set of FDs. They are sound (do not generate incorrect FDs) and complete (can generate all correct FDs).

Formulas/Theorems:

    1. Reflexivity: If B⊆AB \subseteq A, then A→BA \rightarrow B. (Trivial FD)
    1. Augmentation: If A→BA \rightarrow B, then AC→BCAC \rightarrow BC (where CC is any set of attributes).
    1. Transitivity: If A→BA \rightarrow B and B→CB \rightarrow C, then A→CA \rightarrow C.

Derived Rules:

    1. Union: If A→BA \rightarrow B and A→CA \rightarrow C, then A→BCA \rightarrow BC.
    1. Decomposition: If A→BCA \rightarrow BC, then A→BA \rightarrow B and A→CA \rightarrow C.
    1. Pseudotransitivity: If A→BA \rightarrow B and BC→DBC \rightarrow D, then AC→DAC \rightarrow D.

Key Properties/Identities:

  • Used to find the closure of an attribute set X+X^+.

  • Fundamental for determining candidate keys and normal forms.

Common Pitfalls:

  • Confusing derived rules with basic axioms.

  • Incorrectly applying augmentation or transitivity.

Problem-Solving Techniques:

  • To find X+X^+: Start with XX. Repeatedly add attributes to X+X^+ if they are determined by any subset of X+X^+ using the given FDs.

  • To check if A→BA \rightarrow B is implied by a set of FDs FF: Check if B⊆A+B \subseteq A^+.

B Tree

A B-tree is a self-balancing tree data structure that maintains sorted data and allows searches, sequential access, insertions, and deletions in logarithmic time. It is optimized for systems that read and write large blocks of data, such as disk storage.

Formulas/Theorems:

  • Order mm: Each node (except root) has at least ⌈m/2⌉\lceil m/2 \rceil children and at most mm children.
  • Number of keys: A node with kk children has k−1k - 1 keys.
  • Minimum keys (non-root): ⌈m/2⌉−1\lceil m/2 \rceil - 1.
  • Maximum keys: m−1m - 1.
  • Maximum height hh: For NN keys and order mm, h≤log⁡⌈m/2⌉(N+12)h \leq \log_{\lceil m/2 \rceil} \left( \frac{N+1}{2} \right).
  • Minimum height hh: For NN keys and order mm, h≥log⁡m(N+1)h \geq \log_m(N + 1).

Key Properties/Identities:

  • All leaf nodes are at the same level.
  • Keys within a node are sorted.
  • Efficient for disk-based indexing due to high fan-out.

Common Pitfalls:

  • Miscalculating minimum/maximum number of keys or children per node.
  • Incorrectly performing split/merge operations during insertion/deletion.

Problem-Solving Techniques:

  • Trace insertion/deletion operations step-by-step, paying attention to splits (when a node overflows) and merges (when a node underflows).
  • Calculate disk I/Os by counting the number of nodes visited (including root and leaf) for search, insertion, or deletion.

Candidate Key

A Candidate Key is a minimal Super Key. It is a set of attributes that uniquely identifies each tuple in a relation, and no proper subset of these attributes can uniquely identify tuples.

Formulas/Theorems:

  • A set of attributes KK is a Candidate Key if:
    1. K→RK \rightarrow R (where RR is all attributes in the relation) - Uniqueness property.
    1. For no proper subset K′⊂KK' \subset K, K′→RK' \rightarrow R - Minimality property.

Key Properties/Identities:

  • Every relation must have at least one candidate key.
  • One candidate key is chosen as the Primary Key.

Common Pitfalls:

  • Confusing with Super Key (Super Key doesn't require minimality).
  • Forgetting to check the minimality condition.

Problem-Solving Techniques:

  • Find the closure of various attribute sets. A set KK is a super key if K+K^+ contains all attributes of the relation.
  • From the super keys, identify those that are minimal (i.e., no subset is also a super key) to find candidate keys.

Conflict Serializable

A schedule is Conflict Serializable if it is conflict equivalent to some serial schedule. Two operations conflict if they are on the same data item, belong to different transactions, and at least one of them is a write operation (W-W, W-R, R-W conflicts).

Formulas/Theorems:

  • Precedence Graph (Serialization Graph):
  • Nodes represent transactions.
  • An edge Ti→TjT_i \rightarrow T_j exists if TiT_i performs an operation that conflicts with an operation of TjT_j, and TiT_i's operation occurs before TjT_j's.
  • Theorem: A schedule is conflict serializable if and only if its precedence graph contains no cycles.

Key Properties/Identities:

  • Guarantees that the concurrent execution produces the same result as some sequential execution.
  • A weaker condition than view serializability but easier to test.

Common Pitfalls:

  • Incorrectly identifying conflicting operations (e.g., R-R operations do not conflict).
  • Missing cycles in the precedence graph, especially in complex schedules.

Problem-Solving Techniques:

  • Construct the precedence graph by identifying all conflicting pairs of operations and drawing edges accordingly.
  • Use a cycle detection algorithm (e.g., DFS) on the graph to check for serializability.

Database Design

Database design is the process of creating a detailed data model for a database. It involves translating conceptual requirements into a logical schema, and then into a physical schema, ensuring data integrity, efficiency, and scalability.

Formulas/Theorems:

  • No direct formulas, but relies on principles of normalization and ER-to-Relational mapping rules.

Key Properties/Identities:

  • Phases: Conceptual (ER Model), Logical (Relational Schema), Physical (Storage details).
  • Goals: Minimize redundancy, maximize integrity, optimize performance.

Common Pitfalls:

  • Poor choice of primary/foreign keys.
  • Not adequately normalizing the schema, leading to update anomalies.
  • Over-normalization, leading to complex queries and performance issues.

Problem-Solving Techniques:

  • Start with an ER diagram to capture requirements.
  • Apply ER-to-Relational mapping rules systematically.
  • Normalize relations to an appropriate normal form (e.g., BCNF or 3NF) using functional dependencies.

Database Normalization

Database Normalization is a systematic process of restructuring a relational database schema to minimize data redundancy and improve data integrity. It involves decomposing relations into smaller, well-structured relations based on functional dependencies.

Formulas/Theorems:

  • 1NF (First Normal Form): All attributes must be atomic (no multi-valued or composite attributes).

  • 2NF (Second Normal Form): In 1NF and no non-prime attribute is partially dependent on a candidate key.

  • 3NF (Third Normal Form): In 2NF and no non-prime attribute is transitively dependent on a candidate key.

  • BCNF (Boyce-Codd Normal Form): For every non-trivial functional dependency A→BA \rightarrow B, AA must be a super key.

  • 4NF (Fourth Normal Form): In BCNF and no non-trivial multi-valued dependencies exist.

  • 5NF (Fifth Normal Form): In 4NF and no non-trivial join dependencies exist.

Key Properties/Identities:

  • Hierarchy: 1NF⊂2NF⊂3NF⊂BCNF⊂4NF⊂5NF1NF \subset 2NF \subset 3NF \subset BCNF \subset 4NF \subset 5NF.

  • Desirable properties of decomposition: Lossless Join and Dependency Preservation. BCNF decomposition is always lossless but not always dependency preserving. 3NF decomposition is always lossless and dependency preserving.

Common Pitfalls:

  • Incorrectly identifying prime and non-prime attributes.

  • Mistaking partial dependency for transitive dependency.

  • Failing to check for both lossless join and dependency preservation after decomposition.

Problem-Solving Techniques:

  • Identify all candidate keys and functional dependencies.

  • Systematically check for violations of each normal form.

  • If a violation exists, decompose the relation into smaller relations.

Database Schema

A Database Schema is the logical structure or design of the entire database. It defines the tables, attributes, data types, relationships, and constraints that govern the data within the database. It is defined using Data Definition Language (DDL).

Formulas/Theorems:

  • No specific formulas, but it's the blueprint for the database.

Key Properties/Identities:

  • Internal Schema: Physical storage structure.

  • Conceptual Schema: Logical structure of the entire database.

  • External Schema (View): User-specific views of the database.

  • Schema defines the intension, while data (instance) defines the extension.

Common Pitfalls:

  • Confusing schema (structure) with database instance (actual data).

  • Overlooking important constraints during schema design.

Problem-Solving Techniques:

  • Understand the mapping from ER diagrams to relational schemas.

  • Be familiar with DDL commands like CREATE TABLE, ALTER TABLE, DROP TABLE.

Decomposition

Decomposition is the process of breaking down a relation (table) into two or more smaller relations. It is primarily used in normalization to eliminate redundancy and anomalies, ensuring that the resulting relations are in a higher normal form.

Formulas/Theorems:

  • Lossless Join Decomposition: A decomposition of RR into R1R_1 and R2R_2 is lossless if R=R1⋈R2R = R_1 \bowtie R_2.

  • Condition: (R1∩R2)→R1(R_1 \cap R_2) \rightarrow R_1 or (R1∩R2)→R2(R_1 \cap R_2) \rightarrow R_2 must hold based on the FDs of RR.

  • Dependency Preservation: A decomposition preserves dependencies if the union of FDs on the decomposed

relations is equivalent to the original set of FDs. Formally, if FF is the original set of FDs and FiF_i is the set of FDs on RiR_i, then (F1∪F2∪⋯∪Fk)+=F+(F_1 \cup F_2 \cup \cdots \cup F_k)^+ = F^+.

Key Properties/Identities:

  • Desirable properties for decomposition are lossless join and dependency preservation.
  • BCNF decomposition is always lossless but not always dependency preserving.
  • 3NF decomposition is always lossless and dependency preserving.

Common Pitfalls:

  • Incorrectly applying the lossless join test.
  • Failing to check for dependency preservation, especially for BCNF.

Problem-Solving Techniques:

  • For lossless join: Check if the common attributes form a super key for at least one of the decomposed relations.
  • For dependency preservation: For each original FD A→BA \rightarrow B, check if it can be derived from the FDs of the decomposed relations.

ER Diagram

An Entity-Relationship (ER) Diagram is a high-level conceptual data model that represents the entities, attributes, and relationships within a system. It is used during the conceptual design phase of database development.

Formulas/Theorems:

  • No direct formulas, but specific rules for mapping to relational schema.

Key Properties/Identities:

  • Entities: Represented by rectangles (e.g., Student, Course).
  • Attributes: Represented by ovals (e.g., Name, ID). Key attributes are underlined.
  • Relationships: Represented by diamonds (e.g., Enrolls, Teaches).
  • Cardinality: (1:1, 1:N, M:N) specifies the number of instances of one entity that can be associated with another.
  • Participation: (Total/Partial) specifies whether an entity instance must participate in a relationship.
  • Weak Entity: An entity that cannot be uniquely identified by its own attributes and depends on a strong (owner) entity. Represented by double rectangles.

Common Pitfalls:

  • Incorrectly identifying cardinalities or participation constraints.
  • Confusing strong and weak entities.
  • Errors in mapping complex ER constructs (e.g., ternary relationships, generalization) to relational schema.

Problem-Solving Techniques:

  • Carefully read the problem description to identify entities, attributes, and relationships.
  • Pay close attention to cardinality and participation rules.
  • Practice mapping ER diagrams to relational schemas using standard rules.

Functional Dependency

A Functional Dependency (FD) A→BA \rightarrow B means that the value of attribute set AA uniquely determines the value of attribute set BB. If two tuples have the same values for attributes in AA, they must also have the same values for attributes in BB.

Formulas/Theorems:

  • Closure of an attribute set X+X^+: The set of all attributes that are functionally determined by XX.

  • Algorithm: Start with X+=XX^+ = X. Repeatedly add attributes YY to X+X^+ if there is an FD W→YW \rightarrow Y such that W⊆X+W \subseteq X^+.

  • Minimal Cover (or Minimal Basis): A set of FDs FmF_m equivalent to FF such that:

    1. Every FD in FmF_m has a single attribute on the right-hand side.
    1. No FD in FmF_m can be removed without changing Fm+F_m^+.
    1. No attribute can be removed from the left-hand side of any FD in FmF_m without changing Fm+F_m^+.

Key Properties/Identities:

  • Fundamental for database normalization and identifying keys.

  • Armstrong's Axioms are used to infer FDs.

Common Pitfalls:

  • Incorrectly calculating attribute closure.

  • Errors in finding a minimal cover.

Problem-Solving Techniques:

  • Master the algorithm for finding X+X^+.

  • For minimal cover, systematically apply the three conditions: right-hand side single attribute, remove redundant FDs, remove redundant attributes from LHS.

Indexing

Indexing is a technique used to optimize the performance of database queries by allowing the database server to quickly locate and retrieve specific rows without scanning the entire table. It creates a data structure (like B-tree or hash table) that stores a small, ordered subset of the data.

Formulas/Theorems:

  • Disk I/O for B-tree index: For a search, typically height of tree+1\text{height of tree} + 1 (for data block) disk accesses.

  • Disk I/O for hash index: Typically 1-2 disk accesses for exact match, if no collision.

Key Properties/Identities:

  • Primary Index: Index on the primary key, usually clustered.

  • Secondary Index: Index on non-key attributes, usually unclustered.

  • Clustered Index: Data rows are stored physically in the order of the index key. Only one per table.

  • Unclustered Index: Index stores pointers to the data rows, which are not physically ordered by the index key.

Common Pitfalls:

  • Misunderstanding the difference between clustered and unclustered indexes.

  • Incorrectly calculating disk I/Os for different index types and query patterns.

Problem-Solving Techniques:

  • Analyze the query type (equality search, range search) and index type to determine disk I/O.

  • Remember that clustered indexes can retrieve multiple data records with fewer I/Os for range queries.

Joins

Joins combine rows from two or more tables based on a related column between them. They are fundamental operations in relational algebra and SQL for retrieving data from multiple relations.

Formulas/Theorems:

  • Cartesian Product (Cross Join): R×SR \times S. Combines every row of RR with every row of SS. If RR has nn tuples and SS

has mm tuples, R×SR \times S has n×mn \times m tuples.

  • Theta Join: R⋈θS=σθ(R×S)R \bowtie_{\theta} S = \sigma_{\theta}(R \times S). Combines tuples from RR and SS where the condition θ\theta is true.
  • Equijoin: A theta join where θ\theta is an equality condition (e.g., R.A=S.BR.A = S.B).
  • Natural Join: R⋈SR \bowtie S. An equijoin on all common attributes, with duplicate common columns removed from the result.
  • Outer Joins (Left, Right, Full): Preserve tuples that do not have a match in the other relation, filling unmatched attributes with NULLs.

Key Properties/Identities:

  • Result schema of a join is the union of attributes from participating relations (with common attributes appearing once in natural join).
  • Join operations are associative and commutative (for inner joins).

Common Pitfalls:

  • Confusing different types of joins, especially natural join vs. equijoin.
  • Misunderstanding how NULL values are handled in outer joins.
  • Incorrectly calculating the number of tuples in the result.

Problem-Solving Techniques:

  • For natural join, identify common attributes and their values.
  • For outer joins, remember to include unmatched tuples from the specified side(s).
  • Trace the operation step-by-step for small example relations.

Multivalued Dependency 4NF

A Multivalued Dependency (MVD) A↠BA \twoheadrightarrow B exists in a relation RR if, for a given value of AA, there is a set of values for BB, and this set is independent of the values of other attributes in RR. 4NF (Fourth Normal Form) requires that for every non-trivial MVD A↠BA \twoheadrightarrow B in a relation, AA must be a super key.

Formulas/Theorems:

  • Trivial MVD: A↠BA \twoheadrightarrow B is trivial if B⊆AB \subseteq A or A∪B=RA \cup B = R.
  • MVD Inference Rules (some are similar to FDs):
  • Reflexivity: If B⊆AB \subseteq A, then A↠BA \twoheadrightarrow B.
  • Augmentation: If A↠BA \twoheadrightarrow B, then AC↠BCAC \twoheadrightarrow BC.
  • Transitivity: If A↠BA \twoheadrightarrow B and B↠CB \twoheadrightarrow C, then A↠(C−B)A \twoheadrightarrow (C - B).
  • Complementation: If A↠BA \twoheadrightarrow B, then A↠(R−A−B)A \twoheadrightarrow (R - A - B).
  • Union: If A↠BA \twoheadrightarrow B and A↠CA \twoheadrightarrow C, then A↠BCA \twoheadrightarrow BC.
  • Decomposition: If A↠BA \twoheadrightarrow B and A↠CA \twoheadrightarrow C, then A↠(B∩C)A \twoheadrightarrow (B \cap C), A↠(B−C)A \twoheadrightarrow (B - C), and A↠(C−B)A \twoheadrightarrow (C - B).
  • Replication (FD to MVD): If A→BA \rightarrow B, then A↠BA \twoheadrightarrow B.

Key Properties/Identities:

  • MVDs address redundancy arising from multi-valued facts that are independent of each other.
  • 4NF eliminates these MVDs by decomposition.

Common Pitfalls:

  • Confusing MVDs with FDs. MVDs imply FDs, but not vice versa.
  • Incorrectly identifying trivial MVDs.

Problem-Solving Techniques:

  • Identify MVDs by looking for independent multi-valued facts.
  • Decompose relations based on non-trivial MVDs to achieve 4NF. For R(A,B,C)R(A, B, C) with A↠BA \twoheadrightarrow B, decompose into R1(A,B)R_1(A, B) and R2(A,C)R_2(A, C).

Natural Join

The Natural Join operation (⋈\bowtie) combines two relations based on equality of their common attributes. It implicitly creates an equijoin condition for all attributes that share the same name in both relations and projects out the duplicate common attributes.

Formulas/Theorems:

  • Given relations RR and SS, let C=attributes(R)∩attributes(S)C = \text{attributes}(R) \cap \text{attributes}(S) be the set of common attributes.

R⋈S=πattributes(R)∪attributes(S)(σR.c1=S.c1∧⋯∧R.ck=S.ck(R×S))R \bowtie S = \pi_{\text{attributes}(R) \cup \text{attributes}(S)} (\sigma_{R.c_1=S.c_1 \wedge \cdots \wedge R.c_k=S.c_k} (R \times S))

where ci∈Cc_i \in C.

Key Properties/Identities:

  • The resulting schema contains all attributes from both relations, with common attributes appearing only once.
  • It is a special case of equijoin followed by projection.

Common Pitfalls:

  • Misunderstanding the implicit join condition (all common attributes).
  • Incorrectly determining the schema or number of tuples in the result.

Problem-Solving Techniques:

  • Identify all common attributes between the two relations.
  • For each pair of tuples (one from each relation), check if their values for all common attributes are equal. If so, combine them into a single result tuple, keeping common attributes only once.

Normal Forms

Normal Forms (1NF, 2NF, 3NF, BCNF, 4NF, 5NF) are a series of guidelines for designing relational database schemas to reduce data redundancy and improve data integrity. Each normal form builds upon the previous one, imposing stricter rules.

Formulas/Theorems:

  • 1NF: All attributes are atomic.
  • 2NF: In 1NF and no non-prime attribute is partially dependent on any candidate key.
  • 3NF: In 2NF and no non-prime attribute is transitively dependent on any candidate key.
  • BCNF: For every non-trivial FD A→BA \rightarrow B, AA is a super key.
  • 4NF: In BCNF and no non-trivial MVDs exist.
  • 5NF: In 4NF and no non-trivial join dependencies exist.

Key Properties/Identities:

  • Higher normal forms generally reduce more redundancy but may require more joins for queries.
  • BCNF is generally preferred, but 3NF is often a practical compromise as it guarantees lossless join and dependency preservation.

Common Pitfalls:

  • Incorrectly identifying candidate keys, which is crucial for all normal forms.
  • Confusing partial, transitive, and multi-valued dependencies.

Problem-Solving Techniques:

  • First, find all candidate keys and the closure of all FDs.

  • Then, systematically check the conditions for 1NF, 2NF, 3NF, and BCNF in order.

  • If a relation is not in a desired normal form, decompose it into smaller relations that satisfy the conditions.

Query

A query is a request for data or information from a database. Queries are typically written using a query language like SQL, Relational Algebra, or Relational Calculus. They specify what data to retrieve, how to filter it, and how to present it.

Formulas/Theorems:

  • No specific formulas, but relies on the syntax and semantics of query languages.

Key Properties/Identities:

  • Selectivity: The fraction of tuples that satisfy a selection condition.
  • Projection: Selecting specific columns.
  • Join: Combining data from multiple tables.

Common Pitfalls:

  • Syntax errors in SQL.
  • Logical errors leading to incorrect results (e.g., wrong join conditions, incorrect aggregation).
  • Inefficient queries that perform poorly.

Problem-Solving Techniques:

  • Break down complex queries into smaller, manageable parts.
  • Understand the order of operations in SQL (FROM, WHERE, GROUP BY, HAVING, SELECT, ORDER BY).
  • Practice translating natural language requirements into formal query language expressions.

Referential Integrity

Referential Integrity is a database concept that ensures that relationships between tables remain consistent. It is enforced using foreign key constraints, which dictate that a foreign key in one table must either match a primary key in another table or be NULL.

Formulas/Theorems:

  • No specific formulas, but it's a constraint rule.

Key Properties/Identities:

  • Prevents "dangling references" where a foreign key refers to a non-existent primary key.
  • Actions on deletion/update of primary key: CASCADE, SET NULL, SET DEFAULT, RESTRICT (default).

Common Pitfalls:

  • Violating referential integrity constraints during data modification.
  • Misunderstanding the behavior of different ON DELETE/ON UPDATE actions.

Problem-Solving Techniques:

  • Identify primary and foreign keys correctly during schema design.
  • Choose appropriate ON DELETE/ON UPDATE actions based on business rules.
  • Trace data modification operations to check for constraint violations.

Relational Algebra

Relational Algebra is a procedural query language that takes relations as input and produces relations as output. It consists of a set of fundamental operations (selection, projection, union, set difference, Cartesian product, rename) and

derived operations (join, intersection, division).

Formulas/Theorems:

  • Select: σP(R)\sigma_P(R) (selects tuples satisfying predicate PP).
  • Project: πA(R)\pi_A(R) (selects attributes AA).
  • Union: R∪SR \cup S (combines tuples from RR and SS; relations must be union-compatible).
  • Set Difference: R∖SR \setminus S (tuples in RR but not in SS; union-compatible).
  • Cartesian Product: R×SR \times S (combines every tuple of RR with every tuple of SS).
  • Rename: ρS(A1,…,An)(R)\rho_{S(A_1, \dots, A_n)}(R) (renames relation RR to SS and its attributes).
  • Intersection: R∩S=R∖(R∖S)R \cap S = R \setminus (R \setminus S) (derived).
  • Join: R⋈PS=σP(R×S)R \bowtie_P S = \sigma_P(R \times S) (derived).

Key Properties/Identities:

  • Closure property: The result of any operation is also a relation.
  • Forms the theoretical basis for SQL.

Common Pitfalls:

  • Incorrectly applying operators, especially for complex queries.
  • Forgetting union compatibility requirements for set operations.
  • Operator precedence issues.

Problem-Solving Techniques:

  • Break down complex queries into a sequence of simpler relational algebra operations.
  • Practice converting SQL queries to relational algebra and vice versa.

Relational Calculus

Relational Calculus is a non-procedural (declarative) query language that describes what data to retrieve without specifying how to retrieve it. It comes in two forms: Tuple Relational Calculus (TRC) and Domain Relational Calculus (DRC).

Formulas/Theorems:

  • Tuple Relational Calculus (TRC): {t∣P(t)}\{t \mid P(t)\} where tt is a tuple variable and P(t)P(t) is a formula (predicate) involving tt.
  • Example: {t∣t∈Student∧t.Age>20}\{t \mid t \in \text{Student} \wedge t.\text{Age} > 20\}
  • Domain Relational Calculus (DRC): {⟨x1,x2,…,xn⟩∣P(x1,x2,…,xn)}\{\langle x_1, x_2, \dots, x_n \rangle \mid P(x_1, x_2, \dots, x_n)\} where xix_i are domain variables and PP is a formula.
  • Example: {⟨N,A⟩∣∃I(⟨I,N,A⟩∈Student∧A>20)}\{\langle N, A \rangle \mid \exists I(\langle I, N, A \rangle \in \text{Student} \wedge A > 20)\}

Key Properties/Identities:

  • Expressive power equivalent to Relational Algebra (Codd's Theorem).
  • Uses quantifiers (∃\exists - existential, ∀\forall - universal).

Common Pitfalls:

  • Incorrectly using quantifiers, especially universal quantification.
  • Formulating predicates that are not "safe" (may yield infinite results).

Problem-Solving Techniques:

  • Translate natural language queries into logical predicates using tuple or domain variables.
  • Pay close attention to the scope of quantifiers.
  • Ensure queries are safe by bounding all variables.

Relational Model

The Relational Model is a data model based on the concept of relations (tables). Data is organized into two-dimensional tables, where each table represents an entity or a relationship, and rows (tuples) represent records, while columns (attributes) represent fields.

Formulas/Theorems:

  • No specific formulas, but defines the structure.

Key Properties/Identities:

  • Relation (Table): A set of tuples.
  • Tuple (Row): A record in a relation.
  • Attribute (Column): A named property of a relation.
  • Domain: The set of permissible values for an attribute.
  • Schema: The logical design of the database.
  • Instance: The actual data stored in the database at a particular time.
  • Integrity Constraints: Entity Integrity (Primary Key not NULL), Referential Integrity (Foreign Key rules).

Common Pitfalls:

  • Confusing the formal definitions of relation, tuple, and attribute.
  • Not understanding the role of domains and integrity constraints.

Problem-Solving Techniques:

  • Understand the basic terminology and how data is represented.
  • Be able to identify components of a relational schema.

SQL

SQL (Structured Query Language) is the standard language for managing and manipulating relational databases. It is used for defining database schemas (DDL), querying data (DML), controlling access (DCL), and managing transactions (TCL).

Formulas/Theorems:

  • No specific formulas, but adheres to a strict syntax.

Key Properties/Identities:

  • DDL (Data Definition Language): CREATE, ALTER, DROP (for schema objects).
  • DML (Data Manipulation Language): SELECT, INSERT, UPDATE, DELETE (for data).
  • DCL (Data Control Language): GRANT, REVOKE (for permissions).
  • TCL (Transaction Control Language): COMMIT, ROLLBACK, SAVEPOINT.

Common Pitfalls:

  • Complex queries involving subqueries, aggregate functions, GROUP BY, and HAVING clauses.
  • Understanding the order of execution of SQL clauses.
  • Differences in SQL dialects (though GATE usually sticks to standard SQL).

Problem-Solving Techniques:

  • Practice writing queries for various scenarios, including joins, subqueries, and aggregation.
  • Understand the logical processing order of a SELECT statement: FROM -> WHERE -> GROUP BY -> HAVING -> SELECT -> ORDER BY.

Safe Query

A query in Relational Calculus is considered "safe" if it produces a finite number of tuples as its result for any valid database instance. Unsafe queries can potentially produce an infinite result set, which is undesirable in practice.

Formulas/Theorems:

  • No direct formulas, but a conceptual property.

Key Properties/Identities:

  • Every query expressible in Relational Algebra is safe.
  • Safety typically requires that all variables are "bounded" – their values must come from the active domain of the database (values currently present in the tables).

Common Pitfalls:

  • Queries with unbounded variables, especially those using universal quantifiers without proper restrictions.
  • Example of unsafe query: {t∣¬(t∈R)}\{t \mid \neg(t \in R)\} (all tuples not in R, potentially infinite).

Problem-Solving Techniques:

  • Ensure that all variables in a relational calculus query are restricted to range over finite sets (e.g., relations in the database or active domain).
  • For universal quantifiers, ensure they are used in a limited context (e.g., "for all X in Y...").

Super Key

A Super Key is any set of attributes in a relation that, taken together, uniquely identifies each tuple in that relation. It guarantees uniqueness but does not necessarily imply minimality.

Formulas/Theorems:

  • A set of attributes KK is a Super Key if K→RK \rightarrow R (where RR is all attributes in the relation).

Key Properties/Identities:

  • Every candidate key is a super key.
  • A super key can contain redundant attributes (i.e., attributes not necessary for uniqueness).

Common Pitfalls:

  • Confusing with Candidate Key (Candidate Key is a minimal super key).
  • Forgetting that adding more attributes to a super key still results in a super key.

Problem-Solving Techniques:

  • To find super keys, start with candidate keys and add any combination of remaining attributes.
  • Alternatively, find the closure of attribute sets. Any set XX for which X+X^+ contains all attributes of the relation is a super key.

Timestamp Ordering

Timestamp Ordering is a concurrency control protocol that ensures serializability by assigning a unique timestamp to each transaction. Transactions are executed in the order of their timestamps, and conflicts are resolved by rolling back transactions that violate this order.

Formulas/Theorems:

  • Each transaction TiT_i is assigned a unique timestamp TS(Ti)TS(T_i).
  • Each data item XX has a R_TS(X)R\_TS(X) (read timestamp) and a W_TS(X)W\_TS(X) (write timestamp).
  • Read Rule: If TS(Ti)<W_TS(X)TS(T_i) < W\_TS(X), TiT_i must abort and restart with a new timestamp. Otherwise, read XX and set

R_TS(X)=max⁡(R_TS(X),TS(Ti)).R\_TS(X) = \max(R\_TS(X), TS(T_i)).

  • Write Rule: If TS(Ti)<R_TS(X)TS(T_i) < R\_TS(X) or TS(Ti)<W_TS(X)TS(T_i) < W\_TS(X), TiT_i must abort and restart. Otherwise, write XX and set W_TS(X)=TS(Ti)W\_TS(X) = TS(T_i).

Key Properties/Identities:

  • Guarantees conflict serializability.
  • Can lead to cascading rollbacks and starvation.
  • Basic timestamp ordering is prone to aborts.

Common Pitfalls:

  • Incorrectly applying the read/write rules, especially the abort conditions.
  • Tracing complex schedules with multiple transactions.

Problem-Solving Techniques:

  • Assign timestamps to transactions.
  • Maintain R_TS(X)R\_TS(X) and W_TS(X)W\_TS(X) for each data item.
  • Step through the schedule, applying the read and write rules and determining if any transaction needs to abort.

Transaction and Concurrency

A Transaction is a logical unit of work that accesses and possibly modifies the contents of a database. Concurrency Control is the management of simultaneous operations on a database to ensure data consistency and integrity, especially when multiple transactions execute concurrently.

Formulas/Theorems:

  • No direct formulas, but concepts like serializability and isolation levels are key.

Key Properties/Identities:

  • ACID Properties of Transactions:
  • Atomicity: All or nothing.
  • Consistency: Transaction takes database from one consistent state to another.
  • Isolation: Concurrent transactions appear to execute serially.
  • Durability: Changes are permanent once committed.
  • Concurrency Anomalies: Dirty Read, Lost Update, Unrepeatable Read, Phantom Read.
  • Isolation Levels: Read Uncommitted, Read Committed, Repeatable Read, Serializable.

Common Pitfalls:

  • Identifying which anomaly occurs in a given schedule.
  • Understanding how different concurrency control mechanisms (locking, timestamping) prevent anomalies.

Problem-Solving Techniques:

  • Analyze schedules to identify potential anomalies.
  • Understand how each ACID property is maintained or violated.
  • Relate isolation levels to the anomalies they prevent.

Tuple Relational Calculus

Tuple Relational Calculus (TRC) is a non-procedural query language where variables range over tuples. It allows users to specify the properties of the tuples they want in the result without detailing the exact steps to retrieve them.

Formulas/Theorems:

  • General form: {t∣P(t)}\{t \mid P(t)\} where tt is a tuple variable and P(t)P(t) is a formula (predicate) that tt must satisfy.

Predicates can involve:

  • Membership: t∈Rt \in R

  • Attribute access: t.At.A

  • Comparison operators: =,≠,<,>,≤,≥=, \neq, <, >, \leq, \geq

  • Logical connectives: ∧,∨,¬\wedge, \vee, \neg

  • Quantifiers: ∃\exists (exists), ∀\forall (for all)

Key Properties/Identities:

  • Expressive power equivalent to Relational Algebra.

  • More declarative than Relational Algebra.

Common Pitfalls:

  • Incorrectly formulating complex predicates, especially with multiple tuple variables and quantifiers.

  • Ensuring the query is "safe" (produces a finite result).

Problem-Solving Techniques:

  • Break down the query into smaller logical conditions.

  • Use a separate tuple variable for each relation involved in the query.

  • Carefully use quantifiers, ensuring variables are appropriately bound.

Two Phase Locking Protocol

The Two-Phase Locking (2PL) protocol is a concurrency control mechanism that ensures serializability by requiring transactions to acquire all necessary locks before releasing any. It divides a transaction's execution into two phases: a growing phase and a shrinking phase.

Formulas/Theorems:

  • No direct formulas, but a protocol with rules for lock acquisition and release.

Key Properties/Identities:

  • Growing Phase: Transaction can acquire new locks but cannot release any.

  • Shrinking Phase: Transaction can release existing locks but cannot acquire new ones.

  • Guarantees conflict serializability.

  • Can lead to deadlocks.

  • Strict 2PL: All exclusive (write) locks are held until commit/rollback, preventing cascading rollbacks.

Common Pitfalls:

  • Incorrectly identifying the growing and shrinking phases.

  • Detecting deadlocks in schedules using 2PL (e.g., using a wait-for graph).

  • Understanding the difference between basic 2PL and strict 2PL.

Problem-Solving Techniques:

  • Trace transaction execution, noting when locks are acquired and released.

  • Construct a wait-for graph to detect deadlocks: an edge Ti→TjT_i \rightarrow T_j exists if TiT_i is waiting for a lock held by TjT_j. A cycle indicates a deadlock.

Quick Formula Reference

Armstrong Axioms:

  • Reflexivity: If B⊆AB \subseteq A, then A→BA \rightarrow B

  • Augmentation: If A→BA \rightarrow B, then AC→BCAC \rightarrow BC

  • Transitivity: If A→BA \rightarrow B and B→CB \rightarrow C, then A→CA \rightarrow C

  • B-Tree (Order mm):

  • Min keys (non-root): ⌈m/2⌉−1\lceil m/2 \rceil - 1

  • Max keys: m−1m - 1

  • Min children (non-root): ⌈m/2⌉\lceil m/2 \rceil

  • Max children: mm

  • Candidate Key: K→RK \rightarrow R and KK is minimal.

  • Conflict Serializable: Precedence graph has no cycles.

  • Functional Dependency Closure: X+X^+ (algorithm based on Armstrong's axioms).

  • Decomposition Lossless Join: For R1,R2R_1, R_2, (R1∩R2)→R1(R_1 \cap R_2) \rightarrow R_1 or (R1∩R2)→R2(R_1 \cap R_2) \rightarrow R_2.

Relational Algebra Operators:

  • Select: σP(R)\sigma_P(R)

  • Project: πA(R)\pi_A(R)

  • Union: R∪SR \cup S

  • Set Difference: R∖SR \setminus S

  • Cartesian Product: R×SR \times S

  • Natural Join: R⋈SR \bowtie S

  • Tuple Relational Calculus: {t∣P(t)}\{t \mid P(t)\}

  • Timestamp Ordering Rules (for transaction TiT_i on data item XX):

  • Read: If TS(Ti)<W_TS(X)TS(T_i) < W\_TS(X), abort TiT_i. Else, R_TS(X)=max⁡(R_TS(X),TS(Ti))R\_TS(X) = \max(R\_TS(X), TS(T_i)).

  • Write: If TS(Ti)<R_TS(X)TS(T_i) < R\_TS(X) or TS(Ti)<W_TS(X)TS(T_i) < W\_TS(X), abort TiT_i. Else, W_TS(X)=TS(Ti)W\_TS(X) = TS(T_i).

Important Tips for GATE

  • Master Functional Dependencies and Normal Forms: These are high-yield topics. Practice finding candidate keys, attribute closures, and checking normal forms (especially 3NF and BCNF). Understand the implications of lossless join and dependency preservation.

  • Hands-on with Relational Algebra/Calculus and SQL: Be proficient in writing queries in all three languages. Practice converting queries between them. Pay attention to operator precedence in RA and quantifier usage in RC.

  • B-Tree Operations and I/O Calculation: Understand the structure, insertion, deletion, and search operations. Crucially, be able to calculate the number of disk I/Os for various scenarios, as this is a common numerical question.

  • Concurrency Control Protocols: Understand the ACID properties, common anomalies (dirty read, lost update, etc.), and how 2PL and Timestamp Ordering prevent them. Practice drawing precedence graphs for conflict serializability and wait-for graphs for deadlock detection.

  • ER Diagram to Relational Schema Mapping: Know the standard rules for mapping entities, attributes (simple, composite, multi-valued), and relationships (1:1, 1:N, M:N, weak entities) to relational tables.

  • Read Questions Carefully: Database questions often have subtle details. For example, in normalization, the given FDs are critical. In concurrency, the exact sequence of operations matters.

  • Time Management: Some problems, like tracing B-tree operations or complex concurrency schedules, can be time-consuming. Practice efficiently solving these to save time during the exam.

  • Conceptual Clarity: While formulas are important, a deep conceptual understanding of why certain rules exist (e.g., why BCNF is stricter than 3NF, why 2PL guarantees serializability) will help you tackle tricky theoretical questions.