cs186 mt2 cheatsheat

2
Relational Algebra No duplicate tuples in relation Cross-product – takes all rows from A and combines with B Join – takes two talbes and puts them together based on 1 column Diff – takes rows in A that aren’t in B Tips: If using AND for certain thing, multiple projections; ER Primary key always underlined FD XY is X determines Y If XA YA, cannot infer XY. Attribute closer: given just X, what can we determine Algorithm: initialize X+ with X; if UV is in F s.t. U is in X+, add V to X+; repeat until no change If X+ has all elements of R, then X is key of R If XA violates BCNf, decompose R into R-A and XA; repeat Minimal Cover Query Optimization System R Optimizer 1. Plan space; 2. Cost estimation; 3. Search Algorithm Search algorithm: first find best 1 table access method; then using 1-table method, find the second; then third; then continue no more ACID Atomicity – either none or all executed; Consistency – database remains in consistent state afterwards; Isolation –

Upload: ryan-ma

Post on 14-Apr-2016

198 views

Category:

Documents


16 download

DESCRIPTION

Cheatsheet

TRANSCRIPT

Page 1: cs186 mt2 cheatsheat

Relational AlgebraNo duplicate tuples in relation

Cross-product – takes all rows from A and combines with B Join – takes two talbes and puts them together based on 1 columnDiff – takes rows in A that aren’t in B Tips: If using AND for certain thing, multiple

projections; ER Primary key always underlined

FDXY is X determines Y

If XA YA, cannot infer XY. Attribute closer: given just X, what can we determineAlgorithm: initialize X+ with X; if UV is in F s.t. U is in X+, add V to X+; repeat until no changeIf X+ has all elements of R, then X is key of R

If XA violates BCNf, decompose R into R-A and XA; repeat

Minimal Cover

Query Optimization

System R Optimizer1. Plan space; 2. Cost estimation; 3. Search Algorithm

Search algorithm: first find best 1 table access method; then using 1-table method, find the second; then third; then continue no moreACID – Atomicity – either none or all executed; Consistency – database remains in consistent state afterwards; Isolation – runs as if it is only transaction; Durability – commited changes never lost

Page 2: cs186 mt2 cheatsheat

Serial – run 1 transaction at a time; Equivalent – schedules with same transactions, same final state; Serializable – schedule equivalent to serial Conflict

Locks Shared – multiple transactions can have shared lock on same item (reading) Exclusive – only one lock on itme (writing) 2PL – Once you release lock, you may never require new lock; ensure conflict serializability; earliest release = after last lock Strict 2PL – all locks held by transaction only released at end of transaction; watch out for cascading aborts Deadlock – cycle of Xacts waiting for locks to be releasedPrevent by prevention (stop from occurring)

Detection (stop while occurring) – create wait-for graphs; if cycle, then abort

ER diagrams used to model logical schema. Entity set can be associated with relationship set more than once If using B+ trees, can use index nested loop joinEX. Human may own at most one kitty and one puppy(but may have one of each). All kitties and puppies are owned by exactly on human. Kitties and puppies may enter into pact. A kitty or puppy may participate in multiple pacts, but each pact involves eactly one kitty and one puppy. A pact may eternally hate any # humans (or none). Single human can only be hated by up to one pact. Human have nicknames assigned by pact.

Candidate key if attribute closures include all attributes and no subset of them is a superkey by itself. Not BCNF if left hand side is not super key