DBMS
DBMS Part-1
- DBMS Introduction
- DBMS Architecture
- Database Approach vs Traditional File System
- Advantages of DBMS
- Data Models in DBMS
- Schemas in DBMS
- Instances in DBMS
- Data Independence in DBMS
- Database Languages in DBMS
- Interfaces in DBMS
- Structure of DBMS
- Functions of DBA and Designer
- Entities and Attributes in DBMS
- ER Diagram in DBMS
- Generalization, Specialization and Aggregation in DBMS
- Converting ER Diagram to Tables in DBMS
- Difference between Object Oriented, Network and Relational Data Models
DBMS Part-2
- Relational Data Model in DBMS
- Keys in DBMS
- SQL Introduction
- DDL(Data Definition Language)
- DML(Data Manipulation Language)
- Integrity Constraints in DBMS
- Complex SQL Queries
- Joins in DBMS
- Indexing in DBMS
- Triggers in DBMS
- Assertions in DBMS
- Relational Algebra in DBMS
- Tuple Relational Calculus in DBMS
- Domain Relational Calculus in DBMS
DBMS Part-3
- Introduction to Normalization in DBMS
- Normal Forms in DBMS
- Functional Dependency in DBMS
- Decomposition in DBMS
- Dependency Preserving Decomposition in DBMS
- Lossless Join Decomposition in DBMS
- Problems with Null Values and Dangling Tuples
- Multivalued Dependency in DBMS
- Query Optimization in DBMS
- Algorithms for Select, Project and Join Operations in DBMS
- Query Optimization Methods in DBMS
DBMS Part-4
- Transactions in DBMS
- Serializability in DBMS
- Recoverability in DBMS
- Recovery Techniques in DBMS
- Log Based Recovery in DBMS
- Checkpoint in DBMS
- Deadlock in DBMS
- Concurrency Control in DBMS
- Lock Based Protocol in DBMS
- Timestamp Based Protocol in DBMS
- Validation Based Protocol in DBMS
- Multiple Granularity in DBMS
- Multi-Version Concurrency Control(MVCC) in DBMS
- Recovery with Concurrent Transactions in DBMS
DBMS Part-5
Query Optimization Methods in DBMS
Jab hum SQL query likhte hain, toh us query ko chalane ke alag-alag tareeke (plans) ho sakte hain. DBMS ka kaam hota hai ki sabse fast aur sasta tareeka choose kare — is process ko Query Optimization kehte hain.
Query ko optimize karne ke 2 main methods hote hain:
Heuristic-Based Optimization
Cost-Based Optimization
1. Heuristic-Based Optimization
Yeh kya hota hai?
“Heuristics” ka matlab hota hai rules ya shortcuts. Is method mein DBMS kuch fixed rules follow karta hai query ko optimize karne ke liye — bina actual cost calculate kiye.
Goal:
Intermediate results (beech ke data) ko kam karna aur query fast banana.
Common Heuristic Rules
Rule No. | Rule |
---|---|
1 | SELECT ko jitni jaldi ho sake apply karo |
2 | PROJECT (columns choose karna) bhi early apply karo |
3 | Multiple SELECTs ko combine karo |
4 | SELECT + JOIN ko combine karo |
5 | JOIN ko Cartesian Product se pehle karo |
Example Query
SELECT name
FROM Students, Departments
WHERE Students.dept_id = Departments.id AND Departments.name = 'CSE';
Relational Algebra:
π_name (σ_Students.dept_id = Departments.id AND Departments.name = 'CSE' (Students × Departments))
Heuristics Apply karte hain
Step by step SELECT ko upar le jaate hain:
π_name (Students ⨝_Students.dept_id = Departments.id (σ_Departments.name = 'CSE' (Departments)))
Pehle Departments me se sirf “CSE” wale select kiye, fir join kara — to size kam ho gaya.
Benefits:
Simple aur fast
Query size chhoti ho jaati hai
Bina statistics ke kaam chalta hai
Limitations:
Har baar best plan nahi milta
Cost (time, memory) ka estimate nahi karta
Query Tree Diagram (Heuristics se pehle aur baad me)
Pehle (without rules):
π_name
|
σ_condition
|
Students × Departments
Baad me (rules apply karke):
π_name
|
Students ⨝ Departments
|
σ_Departments.name = 'CSE'
2. Cost-Based Optimization
Yeh kya hota hai?
Is method me DBMS query ke multiple plans banata hai, aur har plan ka cost estimate karta hai (kitna data process hoga, kitni I/O lagegi, etc.). Fir jo sabse sasta (lowest cost) hota hai, usse choose karta hai.
Goal:
Jo plan sabse efficient aur fast ho, usko run karna.
Example
SELECT *
FROM Orders, Customers
WHERE Orders.customer_id = Customers.id AND Orders.amount > 100;
DBMS ke paas 2 options ho sakte hain:
Plan | Description | Estimated Cost |
---|---|---|
A | Pehle Orders pe filter, fir join | 500 |
B | Pehle join karo, fir filter lagao | 1000 |
Yahan DBMS Plan A choose karega — kyunki cost kam hai.
Kaunse Cheezein Cost Decide karti hain?
Table me kitni rows hain (cardinality)
Index hai ya nahi
Filter condition kitna narrow hai
Disk I/O lagega ya memory
Sorting lag rahi hai ya nahi
Query Plan Diagrams
Plan A (Best Plan):
Filter Orders.amount > 100
↓
Join with Customers
Plan B:
Orders ⨝ Customers
↓
Filter amount > 100
DBMS dono ka cost estimate karta hai, aur lowest cost wale plan ko choose karta hai.
Benefits:
Accurate aur fast result milta hai
Real data ke stats ka use karta hai
Jo plan best hoga, wahi chalega
Limitations:
Query optimization thoda slow ho sakta hai
Data statistics updated hone chahiye
System complex hota hai
Heuristic vs Cost-Based Optimization: Comparison
Feature | Heuristic-Based Optimization | Cost-Based Optimization |
---|---|---|
Kaise kaam karta hai | Rules ya shortcuts use karta hai | Real data ka cost estimate karta hai |
Speed | Fast (rules fix hain) | Thoda slow (many plan comparisons) |
Accuracy | Medium (kabhi best plan nahi milta) | High (most efficient plan milta hai) |
Statistics zaroori? | Nahi | Haan |
Complex Queries | Nahi handle karta | Achhi tarah handle karta hai |
Conclusion
Dono methods ka apna importance hai:
Heuristic-Based: Jab simple query ho aur jaldi result chahiye
Cost-Based: Jab query complex ho aur performance matter karta ho
Modern DBMS dono ka combination use karte hain:
Pehle heuristic rules apply karte hain (basic clean-up)
Fir cost-based analysis se best plan choose karte hain