Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

DBMS UNIT-3,4

What is transaction?
A transaction is any operation that is treated as a single unit of work,
which either completes fully or does not complete at all, and leaves
the storage system in a consistent state. The classic example of a
transaction is what occurs when you withdraw money from your bank
account. Either the money has left your bank account, or it has not —
there cannot be an in-between state.
Explain ACID properties for transaction?
ACID Properties

1) Atomicity - The term atomicity defines that the data remains


atomic. It means if any operation is performed on the data, either
completes fully or does not complete at all. It further means
that the operation should not break in between or execute
partially.

1
DBMS UNIT-3,4

2. Consistency: This means that integrity constraints must be


maintained so that the database is consistent before and after the
transaction. It refers to the correctness of a database.

3. Isolation - The term 'isolation' means separation. In DBMS, Isolation


is the property of a database where no data should affect the other one
and may occur concurrently. In short, the operation on one database
should begin when the operation on the first database gets complete. It
means if two operations are being performed on two different databases,
they may not affect the value of one another. This isolation prevents dirty
reads, non-repeatable reads, and phantom reads.

2
DBMS UNIT-3,4

Account A is making T1 and T2 transactions to account B and C, but both


are executing independently without affecting each other. It is known as
Isolation.

4. Durability: This property ensures that once the transaction has


completed execution, the updates and modifications to the database are
stored in and written to disk and they persist even if a system failure
occurs. These updates now become permanent and are stored in non-
volatile memory. The transaction’s changes are saved to the database
permanently, and even if the system crashes, the changes remain intact
and can be recovered.

Advantages of ACID Properties in DBMS:


1. Data Consistency: ACID properties ensure that the data remains
consistent and accurate after any transaction execution.
2. Data Integrity: ACID properties maintain the integrity of the data by
ensuring that any changes to the database are permanent and cannot
be lost.
3. Concurrency Control: ACID properties help to manage multiple
transactions occurring concurrently by preventing interference
between them.

3
DBMS UNIT-3,4

4. Recovery: ACID properties ensure that in case of any failure or crash,


the system can recover the data up to the point of failure or crash.

What is tree in DBMS?


• A tree refers to a hierarchical data structure known as a tree
structure that is used for organizing and representing data in a
specific way.
• In a tree structure, data is organized in a parent-child relationship,
where each node (except for the root node) has a single parent and
zero or more child nodes.
• The topmost node in the tree is called the "root" node. The root
node may have child nodes and so on.
• In addition to the root node and child nodes, each node in the tree
contains a key or multiple keys that help organize and sort the data.
These keys are used to navigate the tree and locate the desired data
efficiently.

B Tree
B Tree is a specialized m-way tree that can be widely used for disk access.
A B-Tree of order m can have at most m-1 keys and m children.
A B tree of order m contains all the properties of an M way tree which
are-
• Every node in a B-Tree contains at most m children.
• Every node in a B-Tree except the root node and the leaf node
contain at least m/2 children.
• The root nodes must have at least 2 nodes.
• All leaf nodes must be at the same level.
A B tree of order 4 is shown in the following image.

4
DBMS UNIT-3,4

Why do we need B trees in DBMS ?Explain briefly with example?


B-trees are essential in database management systems (DBMS) for
efficient data storage and retrieval because -
1. Balanced Tree Structure: B-trees are self-balancing tree structures.
They ensure that all leaf nodes are at the same depth, providing
efficient search operations. This balanced property allows for faster
search operations, as the number of comparisons required to find data
is minimized.
2. Disk-Based Storage Optimization: DBMS often deals with data
stored on disk, and B-trees are designed to optimize disk-based
storage. The nodes in a B-tree are large, allowing each disk block read
or written to hold multiple keys. This reduces the number of disk I/O
operations required to access or modify data, improving overall
performance.
3. Efficient Range Queries: B-trees support efficient range queries. As
the data is sorted within the tree, it is easy to find a range of values.
4. Indexing: B-trees are commonly used for indexing in DBMS. An index
provides a quick lookup mechanism for locating data based on a
specific column or set of columns. B-trees allow for fast searching and
retrieval of data based on indexed keys.

Operations
1. Searching- Searching in B Trees is similar to that in Binary search
tree. For example, if we search for an item 49 in the following B
Tree. The process will something like following:
• Compare item 49 with root node 78. since 49 < 78 hence, move to
its left sub-tree.
• Since, 40<49<56, traverse right sub-tree of 40.
• 49>45, move to right. Compare 49.
• match found, return.

5
DBMS UNIT-3,4

2. Inserting - Insertions are done at the leaf node level.


Example
Insert the node 8 into the B Tree of order 5 shown in the
following image.

8 will be inserted to the right of 5, therefore insert 8.

The node, now contain 5 keys which is greater than (5 -1 = 4 )


keys. Therefore, split the node from the median i.e. 8 and push it
up to its parent node shown as follows.

6
DBMS UNIT-3,4

Deletion
Deletion is also performed at the leaf nodes. The node which is to be
deleted can either be a leaf node or an internal node.
Example
Delete the node 53 from the B Tree of order 5 shown in the
following figure.

53 is present in the right child of element 49. Delete it.

Now, 57 is the only element which is left in the node, the


minimum number of elements that must be present in a B tree
of order 5, is 2. it is less than that, the elements in its left and
right sub-tree are also not sufficient therefore, merge it with the
left sibling and intervening element of parent i.e. 49.
The final B tree is shown as follows

7
DBMS UNIT-3,4

Difference between B+ Tree and B Tree


Parameters B+ Tree B Tree

In the B tree, all the In the B+ tree, keys are


keys and records are the indexes stored in the
1. Structure stored in both internal internal nodes and
as well as leaf nodes. records are stored in the
leaf nodes.

Leaf nodes form a


Leaf nodes do not form a
2. Leaf Nodes linked list for efficient
linked list.
range-based queries.

Higher order (more Lower order (fewer


3. Order
keys) keys)

In B tree, keys cannot In the B+ tree, there can


be repeatedly stored, be redundancy in the
4. Key
which means that there occurrence of the keys.
Duplication
is no duplication of keys
or records.

In B tree, searching is In B+ tree, searching is


not very efficient very efficient or quicker
5. Searching because the records are because all the records
either stored in leaf or are stored in the leaf
internal nodes. nodes.

Deletion of internal Deletion in B+ tree is


nodes is very slow and very fast because all the
a time-consuming records are stored in the
6. Deletion
process as we need to leaf nodes so we do not
consider the child of the have to consider the child
deleted key also. of the node.

8
DBMS UNIT-3,4

Parameters B+ Tree B Tree

In B tree, sequential In the B+ tree, all the


access is not possible. leaf nodes are connected
7. Sequential
to each other through a
Access
pointer, so sequential
access is possible.

8. Width n B tree has more height B+ tree has more width


Height as compared to width. as compared to height.

Database systems, file In-memory data


9. Applications systems, where range structures, databases,
queries are common general-purpose use

Requires less memory as


10. Memory Requires more memory
keys and values are
Usage for internal nodes
stored in the same node

B+ tree

9
DBMS UNIT-3,4

B Tree

Why do we need B+ trees in DBMS ?


B+ trees are used in database management systems (DBMS) for –
1. Efficient searching - In B+ tree, searching is very efficient or quicker
because all the records are stored in the leaf nodes.
2. Sorted data storage - B+ trees maintain the data in sorted order
based on the key values. This property enables efficient range queries
and range-based operations, such as finding all records within a certain
range of values.
3. Support for efficient insertions – Insertion in a B+ tree is highly
efficient because the new records are inserted directly into the leaf
nodes finding the appropriate position within the leaf node and
inserting the new key-value pair while maintaining the sorted property.
4. Support for efficient deletion - B+ trees provide efficient support
for inserting and deleting data. Deletion in B+ tree is very fast because
all the records are stored in the leaf nodes so we do not have to
consider the child of the node.

10

You might also like