Nazarbayev University
SEDS CS, GrM
DS 507, Fall 2025
Instructor: Yesdaulet Izenov
Lecture 1b: Database Systems
Where do Database Systems and SQL fit in?
Where do Database Systems and SQL fit in?
Database System Architecture Overview
Database System Architecture Overview
Arithmetic Algebra Mixed Operation
EXAMPLE:
527 * 14 + 3 / ((4 + 2) – 4) - 3 + 2
Input = Table(s) and Output = Table
Arithmetic Algebra:
527 * 14 + 3 / ((4 + 2) – 4) - 3 + 2
Performance Metrics
Users/Clients want accurate and fast results!
Companies want to provide the results accurately, fast, and with minimum computer
resource consumption!
Why some queries run fast than others?
For the same question/task, one can write two different SQL but semantically identical.
However, why two SQLs can have different speed/runtime?
Query Performance
Total:
16736.860 ms or 16.74 sec
SQL → RA, etc.: 0.534 ms
0.179 ms
16736.147 ms (or 16.74 sec)
Structured Query Language (aka. SQL)
Declarative language (abstraction)
No Direct Access to Database Storage
Only via SQL language to interact with (R)DBMS to consequently access databases
Relational Data Model Operations
Sublanguages:
Data Definition Language (DDL) – CREATE, DROP, ALTER
Data Manipulation Language (DML) – INSERT, UPDATE, DELETE
Data Query Language (DQL) – SELECT
SQL Query Skeleton
SELECT result_table_schema
← (output = table)
FROM input_tables
[ WHERE selection_predicates AND join_predicates ]
[ GROUP BY grouping_attributes ]
[ HAVING group_selection_predicates ]
[ ORDER BY sorting_attributes ]
[ LIMIT number ]
Relational Algebra Operators and Expressions
Scan: R, S (table names)
Projection: π (pi)
Example SQL:
Alias: ρ (rho)
SELECT R.a, S.b, T.c
Selection: σ (sigma)
FROM R, S, T
Distinct: δ (delta)
WHERE R.a > 1 AND S.b = “Student”
Sort: τ (tau)
COUNT, MAX, MIN, AVG, SUM (aggregations)
AND R.d = S.d AND S.e = T.e;
---------------------------------------------
Group By: γ (gamma)
ΠR.a, S.b, T.c = R’
← operator 1
Set operations: U, ∩, -
σR.a > 1 AND S.b=”Student”
← operator 2
R ⋈R.d=S.d S
← operator 3
S ⋈S.e=T.e T
← operator 4
Outer Join: ⋈Fθ ⋈Lθ ⋈Rθ
scan (R)
← operator 5
Self Join: ⋈Sθ
scan (S)
← operator 6
scan (T)
← operator 7
Cross Join: x
Natural Join: ⋈
Theta Join: ⋈θ
Relational Algebra Trees
example SQL:
SELECT R.a, S.b, T.c
FROM R, S, T
WHERE R.a > 1 AND S.b = “Student”
AND R.d = S.d AND S.e = T.e;
---------------------------------------------
ΠR.a, S.b, T.c = R’ (operator 1)
σR.a > 1, S.b=”Student” (operator 2)
R ⋈d=d S (operator 3)
T ⋈e=e S (operator 4)
Decisions on Join Operator Algorithms
Algorithms:
Nested-loop
Merge-join
Hash-join
Probing Table
10 GB data
Building Table
2GB data
Which table is good to keep in the RAM?
Which join operator to choose?
Combinations of Joining Relations and Operators
N! (factorial) number of combination! (loose upper bound)
Query Execution Time >>> Optimization Time
5! = 120
10! ≈ 3.6M
Cardinality and Selectivity Estimation
How do we choose an optimal query plan ??
Research with over 50 years history!!
Reading materials, Q&A
Book chapters:
Chapter 2 (2.2, 2.3, 2.4.1-2.4.3)