Files
G4G0-1/Semester 2/Database Systems/Week 1/Week 1 Database Systems.md

37 lines
1.7 KiB
Markdown

### [Relational Algebra - Recap](obsidian://open?vault=Computer%20Science%20Year%201&file=Semester%201%2FDatabase%20Systems%2FWeek%2010%2FWeek%2010%20Database%20Systems)
- High level & procedural
- Defines how to build relations
- SELECT represented by pi ( projection )
- FROM represented by sigma ( selection )
- WHERE represented by x ( cartesian product )
#### Data Manipulation Language
- Provides set of operations
- Data retrieval - query language
- ex. SQL
#### Closure
- Operations work on one or more relations to define another relation without changing the original
- Both operands and results are relations, output from one operation can become the input for another operation.
- This allows nested expressions.
#### Theta Join
R theta(f) S defines a relation that contains tuples satisfying F from the Cartesian product of two relations R and S.
Takes the Cartesian product of two relations r and s than selects the rows which satisfy the condition F.
R theta(f) S is the same as sigma(f) (R x S ).
F may contain comparison operators to form a condition.
#### Query Processing
The activities involved in parsing, validating, optimising and executing a query.
Purpose is to transform a query written in a high level language into correct and efficient strategy in low level language. Also to execute strategy to retrieve data.
#### Common Optimisation Rules
- Begin with initial query tree for SQL
- Move SELECT operations down the tree
- Apply more restrictive SELECT operations first ( eg. equalities before range queries )
- Replace Cartesian products followed by selection with theta joins ( eg. *sigma(f) ( RxS )* -> *R theta(f) S* )
- Move PROJECT operations down the query tree ( add project operations as inputs to theta joins ).