unit-4-dbms
unit-4-dbms
1 Google Active
2 Amazon Active
3 Apple Inactiv
e
4 Alibaba Active
• SQL
– Query language used in most RDBMSs
• Query decomposed into query blocks
– Basic units that can be translated into the
algebraic operators
– Contains single SELECT-FROM-WHERE expression
• May contain GROUP BY and HAVING clauses
Translating SQL Queries (cont’d.)
• Example:
– Inner block
– Outer block
Translating SQL Queries (cont’d.)
• Example (cont’d.)
– Inner block translated into:
• Single-User System:
– At most one user at a time can use the system.
• Multiuser System:
– Many users can access the system concurrently.
• Concurrency
– Interleaved processing:
• Concurrent execution of processes is interleaved in a
single CPU
– Parallel processing:
• Processes are concurrently executed in multiple CPUs.
Introduction to Transaction Processing (2)
• A Transaction:
– Logical unit of database processing that includes one or more
access operations (read -retrieval, write - insert or update, delete).
• A transaction (set of operations) may be stand-alone specified
in a high level language like SQL submitted interactively, or
may be embedded within a program.
• After a transaction is committed, database reaches to a new
consistent state.
• It may be rolled back or undone.
• Transaction boundaries:
– Begin and End transaction.
• An application program may contain several transactions
separated by the Begin and End transaction boundaries.
Introduction to Transaction Processing (3)
ACID properties:
• Atomicity: A transaction is an atomic unit of processing; it is either
performed in its entirety or not performed at all.
• Consistency preservation: A correct execution of the transaction must
take the database from one consistent state to another.
• Isolation: A transaction should not make its updates visible to other
transactions until it is committed; this property, when enforced strictly,
solves the temporary update problem and makes cascading rollbacks of
transactions unnecessary (see Chapter 21).
• Durability or permanency: Once a transaction changes the database and
the changes are committed, these changes must never be lost because of
subsequent failure.
4 Characterizing Schedules based on
Recoverability (1)
• Transaction schedule or history:
– When transactions are executing concurrently in an interleaved
fashion, the order of execution of operations from the various
transactions forms what is known as a transaction schedule (or
history).
• A schedule (or history) S of n transactions T1, T2, …, Tn:
– It is an ordering of the operations of the transactions subject to the
constraint that, for each transaction Ti that participates in S, the
operations of T1 in S must appear in the same order in which they
occur in T1.
– Note, however, that operations from other transactions Tj can be
interleaved with the operations of Ti in S.
5 Characterizing Schedules based on
Serializability (1)
• Serial schedule:
– A schedule S is serial if, for every transaction T
participating in the schedule, all the operations of
T are executed consecutively in the schedule.(ie.
No interleaved schedule)
• Otherwise, the schedule is called nonserial schedule.
(ie. Schedule is interleaved)
• Serializable schedule:
– A schedule S is serializable if it is equivalent to
some serial schedule of the same n transactions.
Testing of Serializability
• There will be a directed graph(N,E) constructed with the
folloing serializability
• Create a node for each transaction
• Create a directed edge from Ti -> Tj, if Tj reads the value of an
item written by Ti
• Create a directed edge from Ti -> Tj,if Tj writes the value of an
item after Ti reads it.
• Create a directed edge from Ti -> Tj, if Tj writes a value of an
item after Ti wrote it
• Ti(write(x))->Tj(read(x))
• Ti(R/W(x)-> Tj(W(X))
Example of Serializability Testing
Another Example of Serializability Testing