Logical and Physical Data Independence
Data independence is the ability to change a schema at one level without changing the level above. Physical independence is easy to achieve; logical independence is harder, and knowing why is the exam answer.
-
DBMS Fundamentals
- Data, Information and Databases
- What a DBMS Is and Why It Exists
- File System versus DBMS
- Advantages and Limitations of a DBMS
- Database Users and the Role of the DBA
- Three Level Architecture and Data Abstraction
- Logical and Physical Data Independence
- Schema, Instance and Metadata
- Database Applications and the Database System Environment
- Database Architecture
- Data Models
-
ER Model
- Entities, Entity Sets and Entity Types
- Types of Attributes in the ER Model
- Keys in the ER Model
- Relationships, Relationship Sets and Degree
- Cardinality and Participation Constraints
- Strong and Weak Entities
- Drawing and Reading ER Diagrams
- Extended ER: Generalisation, Specialisation and Aggregation
- Converting an ER Diagram into Relational Tables
- ER Design Projects
- Relational Model
- Relational Algebra
- Functional Dependencies
-
Normalisation
- Why Normalisation Exists: Anomalies and Redundancy
- First Normal Form
- Second Normal Form and Partial Dependency
- Third Normal Form and Transitive Dependency
- BCNF and BCNF Decomposition
- 4NF, 5NF, Multivalued and Join Dependencies
- Lossless Decomposition and Dependency Preservation
- Complete Worked Normalisation: Unnormalised to BCNF
- Denormalisation and When to Use It
Concept
Data independence is the capacity to change the schema at one level of the three level architecture without being forced to change the schema at the level above it.
It comes in two kinds, named after the level being changed.
| Physical data independence | Logical data independence | |
|---|---|---|
| Change is made to | The internal (physical) schema | The conceptual (logical) schema |
| Level protected | The conceptual schema | The external schemas and applications |
| Mapping that absorbs it | Conceptual / internal | External / conceptual |
| Examples of the change | Add an index, change file organisation, move to a faster disk, compress, repartition | Add a column, split a table, rename a column, add a new entity |
| How hard to achieve | Easier | Harder |
Why logical independence is harder
This is the question that separates a memorised answer from an understood one.
Applications are written against the logical structure. They name tables and columns. So a logical change has a real chance of touching something an application actually mentions. A physical change touches nothing an application ever names — no program says use the B+ tree or read block 4,096.
PHYSICAL CHANGE LOGICAL CHANGE
add an index on dept_code split employees into
employees + salaries
application code: application code:
unchanged SELECT salary FROM employees
now refers to a column
queries: that has moved
unchanged, just faster
a view named employees can
nothing above the internal restore the old shape, and
level mentions an index, THAT is how logical
so nothing above it breaks independence is achievedHow each is achieved in practice
- Physical independence comes almost free from the architecture. The DBMS chooses access paths at query time, so changing them changes only performance.
- Logical independence has to be worked for. The usual technique is to let applications read views rather than base tables. When a table is split or renamed, the view is rewritten to present the old shape, and the applications never notice.
Example
-- Illustration only.
-- Original conceptual schema
employees ( emp_id, name, dept_code, salary )
-- Logical change: salary moves to its own table
employees ( emp_id, name, dept_code )
salaries ( emp_id, amount, effective_from )
-- Logical independence restored with a view, so every
-- application that referred to employees.salary keeps working
CREATE VIEW employees_full AS
SELECT e.emp_id, e.name, e.dept_code, s.amount AS salary
FROM employees e
JOIN salaries s ON s.emp_id = e.emp_id;Important terminology
| Term | Meaning |
|---|---|
| Data independence | Immunity of an upper level to changes at a lower level. |
| Mapping | The definition that translates between two levels; where the change is absorbed. |
| View | A named query presenting data in a chosen shape. The main tool for logical independence. |
| Schema evolution | Changing a schema after the database is in use. |
Common mistakes
- Swapping the two definitions. Remember it by the level being changed, not the level being protected. Physical independence means the physical level changed.
- Claiming logical independence is easier. It is harder, and saying so with the reason earns the mark.
- Thinking adding an index is a logical change. It is purely physical.
- Believing independence is absolute. Dropping a column an application selects will break it. Independence reduces coupling; it does not abolish it.
Exam and interview questions
- Define physical and logical data independence with two examples each.
- Which is harder to achieve, and why?
- Which mapping absorbs each kind of change?
- How do views help achieve logical data independence?
- Give one change that no amount of data independence can hide from an application.
Practice
- Classify each as physical or logical: adding an index, adding a column, changing the page size, renaming a table, moving a file to another disk, merging two tables.
- A table is split in two. Write the view that preserves the original shape for existing applications.
- Explain in three sentences why a DBMS can change its access path without telling anyone.
Conclusion
Physical data independence protects the conceptual schema from storage changes and is close to free. Logical data independence protects applications from schema changes, is harder, and is usually bought with views.