0% found this document useful (0 votes)
10 views9 pages

Answer 1

The document discusses key concepts in database management, including serializability, recoverability, and locking mechanisms to ensure data consistency during transactions. It explains various types of databases, recovery techniques, and physical query plan operators for efficient data retrieval. Additionally, it covers aggregate functions in SQL for performing calculations on data sets.

Uploaded by

Anik Dutta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views9 pages

Answer 1

The document discusses key concepts in database management, including serializability, recoverability, and locking mechanisms to ensure data consistency during transactions. It explains various types of databases, recovery techniques, and physical query plan operators for efficient data retrieval. Additionally, it covers aggregate functions in SQL for performing calculations on data sets.

Uploaded by

Anik Dutta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Serializability is a key concept in database that checks the correctness of the repeated transactions.

It can also be defined as the ability to execute many transactions in such a way that their combined
effect is same as they were executed in a sequentially manner. This practice ensures the data
consistency if there’s multiple transactions is running parallelly.

There are two types of serializability:

a. Conflict Serializability: This means if we can rearrange the execution order then we can say
it’s conflict serializability.
b. View Serializability: If the outcome of their execution is same following serial schedule then
it is consider as view serializability.

Recoverability means restoring the data if anything happens that can lead to data loss then it
ensures to restore the data. If a transaction commits only after all the transaction whose changes it
has read then it is called recoverable. This helps in preventing the rollbacks In difficult situations,
where failure of one transaction can lead to failure of others also.

Now, Managing the Rollbacks with the Locks

Locking by it’s term is a mechanism that manages the access to database resources and helps in
maintaining the consistency during the rollbacks. Whenver locks present it prevents from conflicting
transaction to access same data again and again and makes the chance of error to less.

Some types of locks are:

a. Shared Lock : Allows multiple transactions to read data resource but prevents writing.
b. Exclusive Locks: It allows single transaction to read or write a data resource.

Lock in nature helps in rollbacks by ensuring that no changes were done in resources and will not
cause any harm to transaction. Refer to the below steps to understand the locking mechanism:

a. Avoiding Cascading Rollback: This means when one transaction relies on another’s
uncommitted data then locking prevents from taking access to other’s uncommitted data
until the transaction have lock.
 If the rollback happens the databases remain same or unaffected.

b. Preventing Dirty Reads: When a transaction acquires a shared or exclusive lock then it
ensures that no other transaction can read the uncommitted data resource.

-> If the rollback happens no transaction will participate thus preventing errors.
c. Two-phase Locking: It has two phases
-> Growing Phase: When a transaction aquires all the necessary locks.
-> Shrinking Phase: When a transaction releases the lock after transaction completed.

Example: If T1 writes to X, and T2 reads X, using exclusive locks:


1. T1 acquires the exclusive lock on X.

2. T2 will wait until T1 commits or do a rollback.

3. If the T1 rollbacks then changes to X are rejected and T2 will read the data.

2.

A. What is a network database model?

This means a model that presents the data in a graphical structure. In this model the data can be
presented as a records and the relationship among the records can be presented as pointers.

A schema is used to define the relation between the data and relationships. The records at a same
time can have multiple parents and child records. The conference on Data Systems language is a real
life example of the database security.

It is useful as it is supporting multiple parent and the child records, secondly as it uses pointers so
traversing is easy. It can also handles the complex queries.

B. D/b Hierarchical and Network Database.

1. Data is totally organized using graphs. 1. Data is organized using the trees like structure.

2. It uses pointers to locate between 2. It uses predefined way from the root to leaves.
Multiple records.

3. If want to modify the relation then 3. Modifying a heirachy can be difficult.


it is easy as of its simple structure.

4. Queries is complex as it supports the 4. Queries here is simple but limited to the
many to many relation. Predefined structure of hierarchy.

5. Supports many to many type of 5. Supports one to many type of relationship.


relationship.

6. Examples can be banking systems 6. Example : file systems.


3.

The database management system involves the query to breakdown a high-level to low-level query
operation. This approach helps in manipulating and retrieval of data efficiently. It include selection,
projection, aggregation and set operation.

Some algorithms used in this are:

(A) Selection Operation: It retrieves the tuples that helps in satisfying specific conditions
example where clause.

a. Binary Search: This is applies when the data is sorted on the attribute called selection
attribute. It is efficient range queries and for equality. Cost is O(log n).

b. Index-based Search: It uses the indexes to pull out the tuples quickly. Cost associated is
O(log n) for B+ tree and O(1) for hash indexes.

c. Linear Search : It scans all the tuples sequentially and select only those which negotiate with
the condition. It is also used where no index exists. The cost is (O)n where n is number of the
tuples.

(B) Projection Operation: It helps in retrieving the specific columns from the relation.

Algorithm used in this is :

* Naïve Method: It only scans the required columns and remove the duplicacy.

* Sort Based Projection: It sorts the tuples on the projected columns and identifies
duplicated and if there’s a duplicate present then it removes it.

* Hash Based Projection: It uses the hash based table to identify and remove duplicacy.

(C) Join Operation: It combines tuples from two relations by comparing the common attribute.
This is the most expensive solution in queries execution.

Algorithms used is:

a. Nested loop join: In this the each tuple in outer relation, it basically scans the entire inner
relation to check and find the match. Cost is O(n*m).
b. Block Nested Loop Join: This processes only the blocks of the data thus preventing I/O. Cost in
this depends on the size of the blocks and the relations.
c. Sort Merge join: In this both the relations are sorted on the join attribute and then the merge
operation is performed. The cost is O(n log n +m log m ) for sorting.
d. Hash joins: In this one relation is distributed into buckets using the hash function mechanism
and other relation uses these buckets for matches. The cost is O(n+m).
(D) Sorting Operation: This is required for an operations that is order by and group by and joins.

Algorithms:
a. External merge sort: This is used for the data sets that is exceeding the memory or not fiiting
inside the memory. Cost is O(n log n).

b. In-Memory Sort: This is reverse of above algorithm, used for short datasets like Heapsort.
Cost is O(n log n).

4.

A) Database recovery means recovering the database to the existing or to back to normal state. This
is the technique to reconfigure or revive the database with the help of backups. The primary urge is
to maintain the intergrity and availability by undoing transaction.

Key components:

a. Loggings: This means taking logs of changes and any modification. This can also be explained
as a record keeping of any data modification and changes.
b. Snapshots: This means taking the pointer backup at a given point of time or taking backups.
c. Version Rollbacks: Helps in reverting the changes or in reverting the failed state.

Types of recovery technique:

a. Fast updates: This updates are applied so that it can be rollbacked easily.
b. Shadow paging: This is useful for recovery of the database to make sure the recovery
process without the logs.

B) Levels of Backup :

a. Full Backup: It is the backup of whole database that includes the metadata, logs and the data

Advantage:

 it is easy to recover whole data at once.


 It is best suited for the situation where whole database got corrupted.

b. Incremental backups: it takes the recent changes in the memory blocks and captures that
information only.
Advantage:

 Faster and the storage required by this is very less.


 It is good for the frequent backup like situations.

c. Differential Backups: It takes only the changes that is made since the last full or incremental
backups.

Advantage:

 It is way faster then full backups.


 It is less complex in nature in compare to the incremental backups.

d. Mirror Backups: This means creating the exact same copy of the data in somewhere else.

Advantage:

 It is easy to recover whole thing in this backup.


 Data is available at a time. Very fast recovery.

5.

A) Physical query plan operators are used to do basic operations that is selection, projections,
joins and aggregation. The operators helps in retrieving the data efficiently from the ongoing
database.

Important Key physical query plan operators:

a. Selection Operators: This is used to filter the rows on given condition. For example WHERE

Example: Table Scan, Index Scan, Index Seek.

b. Projection Operators: This is used to retrieve specific columns from the table.

Example: Naïve Projection, Distinct Projection.


c. Join operators: It basically combines the two tables on a column. Inner join

Example: Nested loop Join, Hash Join, Sort-Merge Join

d. Set Operators: It is used in operations like union, intersection and difference on tuples.

Example: Union All, Intersection, difference

e. Aggregation Operators: It compute the functions like sum, avg, min, max.

Example:
 Sort Based Aggregation: It makes job easier by sorting the tuples group attribute
before the aggregation process.
 Hash based aggregation: Groups tuples using a hash based table.

B) One-Pass Algorithm for Database.

This means the ample amount of data that is fitting our memory and making it efficient for
that memory size. It also helps in processing data in single pass.

Key Features: It is easy to operate on datasets that is small in size.


* it requires no additional I/O beyond reading and writing the data.

Applications:

1. Selection: It reads each tuple and applies the selection predicate and write based on the
qualified tuple as the outputs.
Example: SELECT * FROM Students WHERE age > 16

2. Projection: It helps in extracting the data attributes while the scanning of dataset and
removal of the duplicates if required.
Example: SELECT DISTINCT department FROM Employees.

3. Aggregation: It reads the tuples and computes the aggregate functions then helps in storing
the result in the memory.
Example: SELECT AVG(salary) FROM Employee

Limitation: It is not suitable for the datasets that is large in size and another limitation is it requires
multipass algorithm for large scale operations.
6.

Aggregate functions are helpful for doing the calculation inside the SQL on set of defined values
and then returns the single value. Please find the list below:

a. COUNT(): counts the number of rows


b. SUM(): calculates the sum
c. AVG(): calculates the average of two numbers.
d. MAX(): find the max value in defined set.
e. MIN(): find the min value in defined set.
f. GROUPING(): it helps in identifying whether a column is group by result is aggregated.

Creating the student Table

CREATE TABLE student (

ID INT PRIMARY KEY,

Name VARCHAR (50),

Marks INT

);

INSERT INTO student (ID, Name, Marks) VALUES

(1, Ram, 85),

(2, 'Das', 90),

(3, 'Charan', 78),

(4, 'David', 92),

(5, 'Elena', 88);

1. COUNT(): Now we are Counting the Number of Students

SELECT COUNT(*) AS Total_Students FROM student;

Result:

Total_Students ar

2. SUM(): Calculating the Total Marks

SELECT SUM(Marks) AS Total_Marks FROM student;

Result:
Total_Marks

433

7. AVG(): Calculate the Average Marks

SELECT AVG(Marks) AS Average_Marks FROM student;

Result:

Average_Marks

86.6

8. MAX(): Find the Highest Marks

SELECT MAX(Marks) AS Highest_Marks FROM student;

Result:

Highest_Marks

92

9. MIN(): Find the Lowest Marks

SELECT MIN(Marks) AS Lowest_Marks FROM student;

Result:

Lowest_Marks

78

10. COUNT() with Condition: Count Students Scoring Above 85

SELECT COUNT(*) AS Students_Above_85 FROM student WHERE Marks > 85;

Result:

Students_Above_85

 Using GROUP BY with Aggregate Functions


 If we add another column, Grade, we can group students by their grades and apply
aggregate functions.

Adding the Grade Column

ALTER TABLE student ADD Grade CHAR(1);

UPDATE student

SET Grade = CASE

WHEN Marks >= 90 THEN 'A‘


’ WHEN Marks >= 80 THEN 'B‘

’ ELSE 'C‘

’ND;

Example: Group Students by Grade and Find Average Marks

SELECT Grade, COUNT (*) AS Students, AVG(Marks) AS Average_Marks

FROM student

GROUP BY Grade;

Result:

Grade Students Average_Marks

A 2 91

B 3 83.67

You might also like