











Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A portion of lecture notes from a database systems course, eecs 647, taught by luke huan at the university of kansas in spring 2009. The notes cover topics such as query optimization, cost estimation, and transaction management. The importance of query optimization in database systems and the process of selecting the best physical plan for a given logical plan. It also delves into cost estimation, focusing on the size of intermediate results and the need for accurate estimation. The document then discusses transactions, their abstract view in a dbms, and the acid properties, including atomicity, consistency, isolation, and durability.
Typology: Study notes
1 / 19
This page cannot be seen from the preview
Don't miss anything!












Instructor: Luke Huan
Spring 2009
4/15/
Luke Huan Univ. of Kansas
z^
One logical plan
“best” physical plan
z^
Questions z^
How to enumerate possible plans z^
How to estimate costs z^
How to pick the “best” one
z^
Often the goal is not getting the optimum plan, butinstead avoiding the horrible ones1 second
1 hour
1 minute
Any of these will do
4/15/
Luke Huan Univ. of Kansas
Query ExecutorBuffer ManagerStorage Manager
Storage
Transaction Manager
Logging &Recovery
Lock Manager Buffers
Lock TablesMain Memory
User/Web Forms/Applications/DBA
query
transaction
Query ParserQuery RewriterQuery Optimizer Files & Access Methods
4/15/
Luke Huan Univ. of Kansas
Query Compiler
query
Execution Engine
Logging/Recovery
LOCK TABLE Concurrency Control
Storage Manager
BUFFER POOL
BUFFERS
Buffer Manager
Schema Manager
Data Definition
DBMS: a set of cooperating software modules
Transaction Manager
transaction
Correctness criteria: The
properties
z^ z
tomicity: All actions in the Xact happen, or none happen. z^ z
onsistency: If each Xact is consistent, and the DB starts consistent, it ends up consistent. z^ z
z^ z
urability: If a Xact commits, its effects persist.
4/15/
Luke Huan Univ. of Kansas
z^
Consider two transactions (
Xacts
T1:
BEGIN
A=A+100,
B=B-
END
T2:
BEGIN
A=1.06*A,
B=1.06*B
END
-^
1st xact transfers $100 from B’s account to A’s
-^
2nd credits both accounts with 6% interest.
-^
Assume at first A and B each have $1000. What are thelegal outcomes of running T1 and T2???•^
-^
There is no guarantee that T1 will execute before T2 orvice-versa, if both are submitted together. But, the neteffect
must
be equivalent to these two transactions
running serially in some order.
4/15/
Luke Huan Univ. of Kansas
z^
Syntax in pgSQL: BEGIN^
A transaction is automatically started when a user executes anSQL statement (begin is optional) z^
Subsequent statements in the same session are executed as part ofthis transaction z^
Statements see changes made by earlier ones in the same transaction z^
Statements in other concurrently running transactions do not seethese changes
z^
COMMIT
command commits the transaction (flushing the update
to disk) z^
ROLLBACK
command aborts the transaction (all effects are
undone)
4/15/
Luke Huan Univ. of Kansas
z^
Partial effects of a transaction must be undone when z^
User explicitly aborts the transaction using
ROLLBACK
z^
E.g., application asks for user confirmation in the last stepand issues
COMMIT
or
ROLLBACK
depending on the
response z^
The DBMS crashes before a transaction commits
z^
Partial effects of a modification statement must beundone when any constraint is violated z^
However, only this statement is rolled back; thetransaction continues
z^
How is atomicity achieved? z^
Logging (to support undo)
4/15/
Luke Huan Univ. of Kansas
z^
Goal: ensure the “I” (isolation) in ACID
T^1
: read(
A ); write(
A );
read(
B ); write(
B );
commit;
T^2
: read(
A ); write(
A );
read(
C ); write(
C );
commit;
4/15/
Luke Huan Univ. of Kansas
r(
w(
r(
w(
r(
w(
r(
w(
r(
w(
r(
w(
r(
r(
w(
w(
r(
r(
w(
w(
r(
r(
w(
w(
Good!
Good! (But why?)
Bad!
Read 400
Read 400
Write400 – 100
Write 400 – 50
4/15/
Luke Huan Univ. of Kansas
z^
Two operations on the same data item conflict if at leastone of the operations is a write z^
r( X
) and w(
X ) conflict
z^
w(
X ) and r(
X ) conflict
z^
w(
X ) and w(
X ) conflict
z^
r( X
) and r(
X ) do not
z^
r/w(
X ) and r/w(
Y ) do not
z^
Order of conflicting operations matters z^
E.g., if
T
.r( 1
A ) precedes
T
.w( 2
A ), then conceptually,
T
1
should precede
T
2
4/15/
Luke Huan Univ. of Kansas
z^
A node for each transaction z^
A directed edge from
to i^
if an operation of j^
i
precedes and conflicts with an operation of
in the j^
schedule
T^1
T^2
r( A
) w(
A )
r( A
) w(
A )
r( B
)
r( C
)
w(
B )
w(
C )
T^1
T^2
r( A
)
r( A
)
w(
A )
w(
A )
r( B
)
r( C
)
w(
B )
w(
C )
T^1 T^2 Good:no cycle
T^1 T^2 Bad: cycle
4/15/
Luke Huan Univ. of Kansas
z^
Transaction view of DBMS z^
Read(x) z^
Write(x)
z^
ACID z^
Atomicity: TX’s are either completely done or not done at all z^
Consistency: TX’s should leave the database in a consistent state z^
Isolation: TX’s must behave as if they are executed in isolation z^
Durability: Effects of committed TX’s are resilient against failures
z^
SQL transactions --
Begins
implicitly
SELECT
…;
UPDATE
…;
ROLLBACK
|
COMMIT;