Professional Documents
Culture Documents
ADMT Experiments: Tushar Hirapure 18IT1036 B/B2
ADMT Experiments: Tushar Hirapure 18IT1036 B/B2
Tushar Hirapure
18IT1036
B/B2
Experiment No -1
Theory -
How the Query Optimizer Works
At the core of the SQL Server Database Engine are two major components: the
Storage Engine and the Query Processor, also called the Relational Engine. The
Storage Engine is responsible for reading data between the disk and memory in
a manner that optimizes concurrency while maintaining data integrity. The
Query Processor, as the name suggests, accepts all queries submitted to SQL
Server, devises a plan for their optimal execution, and then executes the plan
and delivers the required results.
Queries are submitted to SQL Server using the SQL language (or T-SQL, the
Microsoft SQL Server extension to SQL). Since SQL is a high-level declarative
language, it only defines what data to get from the database, not the steps
required to retrieve that data or any of the algorithms for processing the
request. Thus, for each query it receives, the first job of the query processor is
to devise a plan, as quickly as possible, which describes the best possible way
to execute the said query (or, at the very least, an efficient way). Its second
job is to execute the query according to that plan.
Implementation:-
Conclusion and Discussion:
Thus we have learned to write SQL equivalent Relational
Algebra Expressions and Query Tree.
Experiment No. : 3
Requirments: java/python.
Theory:
What is Concurrency Control? Concurrency control is a database
management systems (DBMS) concept that is used to address conflicts
with the simultaneous accessing or altering of data that can occur with
a multiuser system. Concurrency control, when applied to a DBMS, is
meant to coordinate simultaneous transactions while preserving data
integrity. The Concurrency is about to control the multi-user access of
database. When more than one transactions are running
simultaneously there are chances of a conflict to occur which can leave
database to an inconsistent state. To handle these conflicts we need
concurrency control in DBMS, which allows transactions to run
simultaneously but handles them in such a way so that the integrity of
data remains intact. C. What is Two-Phase Locking (2PL)?
• Two-Phase Locking (2PL) is a concurrency control method which
divides the execution phase of a transaction.
• It ensures conflict serializable schedules.
• If read and write operations introduce the first unlock operation in
the transaction, then it is said to be Two-Phase Locking Protocol. This
protocol can be divided into two phases, 1. In Growing Phase, a
transaction obtains locks, but may not release any lock. 2. In Shrinking
Phase, a transaction may release locks, but may not obtain any lock.
• Two-Phase Locking does not ensure freedom from deadlocks.
Varients of 2- Phase Locking Protocol 1. Strict Two-Phase Locking
Protocol
• Strict Two-Phase Locking Protocol avoids cascaded rollbacks.
• This protocol not only requires two-phase locking but also all
exclusive-locks should be held until the transaction commits or aborts.
• It is not deadlock free.
• It ensures that if data is being modified by one transaction, then other
transaction cannot read it until first transaction commits.
• Most of the database systems implement rigorous two – phase
locking protocol. 2. Rigorous Two-Phase Locking
• Rigorous Two – Phase Locking Protocol avoids cascading rollbacks. •
This protocol requires that all the share and exclusive locks to be held
until the transaction commits. 3. Conservative Two-Phase Locking
Protocol
• Conservative Two – Phase Locking Protocol is also called as Static Two
– Phase Locking Protocol.
• This protocol is almost free from deadlocks as all required items are
listed in advanced.
• It requires locking of all data items to access before the transaction
starts.
Implementation:
Conclusion: Thus, we have learnt the 2- Phase locking in concurrency
control and its implementation.
Experiment No. : 4
Requirments: java/python.
Implementation:
Conclusion: Thus, we have learnt the timestamp based protocol.
Experiment No. : 5
Implementation:
Conclusion: Thus, we have learnt different kinds of failures and the log
based recovery mechanism.
Experiment No. : 6
Conclusion: The DDB database real life scenarios is studied and its
requirements are documented. The simulation tool is used to
demonstrate the recovery mechanism in distributed environment.
Experiment No. : 7
Conclusion: Thus the case study for spatial and temporal data has been
performed.
Experiment No. : 8
Construction of Star Schema and Snowflake Schema for
company database
Implementation:
Experiment No. : 9 OLAP
Exercise a) Construction of cubes b) OLAP operations,
OLAP queries
Implementation:
ADMT Assignment 1
Tushar Hirapure
18IT1036
B/B2
Q1 (a) - Given the following SQL query:
SELECT S.name
FROM Student S, Book B, Checkout C
WHERE S.sid = C.sid
AND B.bid = C.bid
AND B.author = ’Olden Fames’
AND S.age > 12
AND S.age < 20 ;
And assuming:
• There are 10, 000 Student records stored on 1, 000 pages.
• There are 50, 000 Book records stored on 5, 000 pages.
• There are 300, 000 Checkout records stored on 15, 000 pages.
• There are 500 different authors.
• Student ages range from 7 to 24
Draw a query tree for the above mentioned query.
Answer -
Q1 (b) - Consider the schema R(a,b), S(b,c), T(b,d), U(b,e).
For the following SQL query, write two equivalent logical plans in relational algebra such
that one is likely to be more efficient than the other. Indicate which one is likely
more efficient. Reason.
SELECT R.a
FROM R, S
WHERE R.b = S.b
AND S.c = 3
Answer -
1. π(σ (R ⋈ (S)))
a c=3 b=b
2. π(R ⋈ σ (S)))
a b=b c=3
The second plan is more likely to be more efficient because, with the select
operator applied first, fewer tuples need to be joined.
Q2 (a) - Describe ACID properties of Transaction.
A=1000 A=950
+B=2000 B=2050
3000 3000
Before
After
EXAMPLE -
1st transaction :50$ to transfer from account A to account B
2nd transaction: 100$ to transfer from account B to account C\
In the following transactions, A has no role in the 2nd transaction ; whereas the data
item from B is shared.
4) Durability:- The changes applied to the transaction must persist in the database.
These changes must not be lost because of any failure. Once the transaction is
completed successfully, its impact will be forever over the database.
Q2 (b) - Determine whether the following schedule is serializable or
not? Justify.
T1 T2
read(A) -
write(A) -
- read(A)
- write(A)
read(B) -
write(B) -
- read(B)
- write(B)
Answer -
Step 1:-write(A) read(A) instruction causes conflict hence no swapping takes place.
Hence transaction will be as it is
Step 2:-write(A) read(B) will not cause conflict. Read(B) instruction is swapped up
and write(A) swapped down.
T1 T2
read(A) -
write(A) -
- read(A)
read(B) -
- write(A)
write(B) -
- read(B)
- write(B)
Step 3 - read(B) read(A) won't cause any conflict hence read(B) will be swapped up
and read(A) will be swapped down.
T1 T2
read(A) -
write(A) -
read(B) -
- read(A)
- write(A)
write(B) -
- read(B)
- write(B)
Step 4 - write(B) write(A) won't cause any conflict and hence their positions will be
swapped.
T1 T2
read(A) -
write(A) -
read(B) -
- read(A)
write(B) -
- write(A)
- read(B)
- write(B)
Step 5 - write(B) and read(A) won't cause any conflict and hence their positions are
swapped.
T1 T2
read(A) -
write(A) -
read(B) -
write(B) -
- read(A)
- write(A)
- read(B)
- write(B)
● Wait die : If TS(Ti) < TS(Tj) then (Ti older than Tj) is allowed to wait ; otherwise (Ti
younger than Tj) abort Ti(Ti dies) and restart it later with the same timestamp.
● Wound wait : If TS(Ti)<TS(Tj) then (Ti older than Tj) abort Tj(Ti wounds Tj) and
restart it later with the same timestamp; otherwise (Ti younger than Tj) Ti is
allowed to wait.
Example -
T1 T2
read(Q) -
write(Q) -
- read(Q)
- write(Q)
The information needed for ARIES to accomplish its recovery procedure includes, hte
log, the transaction table and the dirty page table
1 0 T1 update C ----
2 0 T2 update B ----
6 0 T3 update A ----
7 2 T2 update C ----
T1 3 Commit C 1
T2 2 In Progress B 2
T2 8 commit B 2
T3 6 In progress A 6
ADMT Assignment - 2
Tushar Hirapure
18IT1036
B/B2