INTRODUCTION TO RELATIONAL DATABASE SYSTEMS
DATENBANKSYSTEME 1 (INF 3131)
Torsten Grust Universität Tübingen Winter 2015/16
1
INTRODUCTION TO RELATIONAL DATABASE SYSTEMS DATENBANKSYSTEME 1 (INF - - PowerPoint PPT Presentation
INTRODUCTION TO RELATIONAL DATABASE SYSTEMS DATENBANKSYSTEME 1 (INF 3131) Torsten Grust Universitt Tbingen Winter 2015/16 1 DATABASE DESIGN Given a particular mini-world, almost always there will be plenty of options on how to
1
2
3
shapes id id shape shape turtle turtle 1 square ‘d,0,10; d,10,0; d,0,–10; d,–10,0’ 2 triangle ‘d,5,10; d,5,–10; d,–10,0’ 3 cross ‘d,0,10; u,–5,–5; d,10,0’
4
5
ARRAY[v₁ :: ⟨t⟩, v₂ :: ⟨t⟩, …] -- array of ⟨t⟩ elements, printed as {v₁,v₂,...} ARRAY[] :: ⟨t⟩[] -- empty array of ⟨t⟩ elements, printed as {}
xs[⟨i⟩] -- indexed access, i ≥ 1 (NULL if outside bounds) xs[⟨i⟩:⟨j⟩] -- array slice
=, <>, <, > -- array to array comparison ⟨expression⟩ {=|<|>|…} {ANY|ALL}(xs) -- element to array comparison @>, <@, && -- contains, is contained by, overlaps || -- concatenation
6
shapes id id shape shape turtle turtle 1 square {(t,0,10), (t,10,0), (t,0,–10), (t,–10,0)} 2 triangle {(t,5,10), (t,5,–10), (t,–10,0)} 3 cross {(t,0,10), (f,–5,–5), (t,10,0)}
v₁ v₂ v₃
7
shapes id id shape shape turtle turtle 1 square
pos pos command command 1 (t,0,10) 2 (t,10,0) 3 (t,0,–10) 4 (t,–10,0)
2 triangle
pos pos command command 1 (t,5,10) 2 (t,5,–10) 3 (t,–10,0)
3 cross
pos pos command command 1 (t,0,10) 2 (f,–5,–5) 3 (t,10,0)
8
SELECT s.id, s.shape FROM shapes s WHERE EXISTS (SELECT 1 FROM s.turtle c -- s.turtle has type table() WHERE NOT (c.command).down);
9
(input: table , output: a table bundle of size ): For each do If then Create a new table For each row do Create a new value of type If table is not empty then For each row in do Insert row into Set to [if is empty, will not have a match in ] Set to nf2to1nf(R) R ⩾ 1
‐
a ∈ sch(R)
‐
type(a) = table( , … , ) , … , b1 t1 bk tk − − − − − − − − − − − bm tm 1. ( , … , ) Ra a surrogate, , … , b1 t1 bk tk − − − − − − − − − − − − − − − − − − − − − − bm tm 2. r ∈ inst(R) 1. τ surrogate 2.
‐
( , … , ) v1 vm
‐
(τ, , … , ) v1 vm Ra 3.
τ
τ Ra 3. type(a) surrogate
) Ra 10
shapes ( ) id id shape shape turtle turtle 1 square 2 triangle 3 cross turtles ( ) turtle turtle pos pos command command 1 (t,0,10) 2 (t,10,0) 3 (t,0,–10) 4 (t,–10,0) 1 (t,5,10) 2 (t,5,–10) 3 (t,–10,0) 1 (t,0,10) 2 (f,–5,–5) 3 (t,10,0)
R τ1 τ2 τ3 Rturtle τ1 τ1 τ1 τ1 τ2 τ2 τ2 τ3 τ3 τ3
11
id id shape shape turtle turtle
pos pos command command
5 rect
pos pos command command 1 (t,0,10) 2 (t,10,0) 3 (t,0,–10) 4 (t,–10,0)
12
SELECT s.id, s.shape FROM shapes s WHERE EXISTS (SELECT 1 FROM s.turtle c -- s.turtle has type table() WHERE NOT (c.command).down);
SELECT s.id, s.shape FROM shapes s WHERE EXISTS (SELECT 1 FROM (SELECT t.* ⎫ translation of FROM turtles t ⎬ expression WHERE t.turtle = s.turtle) c ⎭ s.turtle WHERE NOT (c.command).down);
13
14
SELECT s.id, s.shape FROM shapes s WHERE ⚑EMPTY(s.turtle);
SELECT s.id, s.shape FROM shapes s WHERE ⚑FORALL c IN s.turtle: (c.command).down
SELECT s.id, s.shape FROM shapes s WHERE ⚑EXISTS c IN s.turtle: sqrt((c.command).x² + (c.command).y²) > 10
15
SELECT s.id, s.shape, ⚑s.turtle[1].command AS head FROM shapes s;
SELECT s.id, s.shape, ⚑LENGTH(s.turtle) FROM shapes s;
16
17