• Keine Ergebnisse gefunden

Functional Programming for Databases Stefan Stanczyk 1

N/A
N/A
Protected

Academic year: 2022

Aktie "Functional Programming for Databases Stefan Stanczyk 1"

Copied!
13
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

FP for DB Introduction 1 June 2009

Functional Programming for Databases

Stefan Stanczyk

stef@brookes.ac.uk

OBJECTIVES

Presentation of the functional programming paradigm,

its attributes and structures to achieve deeper insight

into the database architecture and thus better design

(2)

FP for DB Introduction 3 June 2009

REQUIRED KNOWLEDGE

• Familiarity with database concepts and reasonable programming skills

• Certain mathematical ability (logic, discrete mathematics) beneficial

• No prior knowledge of functional programming or its theoretical basis

CONTENT

• Database foundations - concepts, structures, operations, behaviour.

• Data models for databases.

• Model of computation based on λ− calculus.

• Imperative versus declarative programming. Functional programming paradigm.

• Programming elements and components in a strongly typed FP language:

functions, primitive and defined types, overloading, guards, currying, recursion, list comprehension pattern matching, lambda expressions, higher order functions, type classes, algebraic types, infinite lists, sets, relations.

• Data structures and abstract data types.

• Examples of classical algorithms expressed in a functional style.

• Examples of common database processes coded in Haskell.

• Functional database programming systems.

(3)

FP for DB Introduction 5 June 2009

REFERENCES

S Thompson, Haskell - The Craft of Functional Programming, 2nd ed., Addison-Wesley, 1999

www.cs.ukc.ac.uk/people/staff/sjt/craft2e & www.haskell.org

F Rabhi, G Lapalme, Algorithms: a Functional Programming Approach, 2nd ed., Addison-Wesley, 1999

J R Abrial, Data Semantics, Proceedings of IFIP Working Conference on DB Management, North Holland, 1974

D Shipman, The Functional Data Model and the Data Language DAPLEX, ACM TODS, Vol.6, No 1, March 1981, pp. 140-173

S Stanczyk, et al, Theory & Practice of Relational Databases, Taylor & Francis, 2001

database recap

(4)

FP for DB Introduction 7 June 2009

data design separated from process design

database philosophy

the effect of process structure omitted for data design

relationships between data and processes are of the first-order type thus the final technical’ design is achieved by superposition

CONCEPTUAL MODEL VIEW A

VIEW B

VIEW C

INTERNAL MODEL

D B M

S

mapping between

CONCEPTUAL and INTERNAL models mapping between CONCEPTUAL and EXTERNAL models

database architecture

(5)

FP for DB Introduction 9 June 2009

• Minimised data redundancy

• Data shared amongst applications

• Data maintained centrally

• Common processes between applications

• Application software transparent benefits

relational model

STRUCTURE BEHAVIOUR

OPERATIONS

(6)

FP for DB Introduction 11 June 2009

R = (r 1 , r 2 , …r i-1 , r i , r i+1 , …r n )

• none of r i is a structure itself 1NF

structure

a relation - a constrained subset of a product of simple domains

r

n

…..

r

4

r

3

r

2

r

1

• ∃ k = (r i , r j , …): [ΠR(k)] ≡ [R] superkey → identifier (PK) r

n

…..

r

4

r

3

r

2

r

1

behaviour

(7)

FP for DB Introduction 13 June 2009

foreign key (FK) R(X, Y, Z) and S (T, U, V) :

S.V ref R.X iff:

• X is identifier in R

• ∀ v ∈ V, ∃ x ∈ X : v = x

• Π S (V) = Π R (X)

X Y Z T U V

R S

behaviour

apply to a pair of relations with comparable attributes apply to a pair of union

compatible relations

UNION binary

DIFFERENCE binary INTERSECTION binary PRODUCT binary PROJECTION unary RESTRICTION unary SELECTION unary

JOIN binary

DIVISION binary conventional set-operations

complementary algebra operations

P R

P Q R

{ }

{ }

unary

binary

relational algebra

{R i } is closed under Π, σ, η, ...

operations

(8)

FP for DB Introduction 15 June 2009

relations {R

i

} with some undesirable properties

relations {S

k

} with better update properties

• Data redundancy minimised

Update transactions must not

• cause loss of information

• violate entity integrity

• carry any risk of inconsistent updating

optimisation

FD: X → Y holds for R = (..., X, Y, ...)

iff ∀ x ∈ X, [Πσ R(X=x)Y] ≤ 1 functional dependency

• BCNF

ξ → y i ⇒ ξ → y k ∀ k = 1 .. n ξ y 1 y 2 y n

optimisation

(9)

FP for DB Introduction 17 June 2009

H G F E D C B A

H G

F BCNF

F E D C B not 2NF A

F C

BCNF

D

B BCNF

E D C B not 2NF A

E C B A BCNF

The process of normalisation is

discrete

deterministic

guaranteed to terminate

when FD are found, the decomposition mechanism is detached from semantics

Though decomposition is mechanistic, the results are semantically Interpretable - when the decomposition is completed, the objects get the meaning re-assigned (akin to e.g. algebraic transformations).

observation

(10)

FP for DB Introduction 19 June 2009

All characteristics, properties, processes of RDB

• The relation (whether 1NF or not)

• Primary Key & Entity integrity

• Foreign Keys & Referential Integrity

• FD, MVD, JD, PD

• Normal Forms

• Decomposition are expressible as functions conclusion

• separation of physical & logical aspects

• data - process independence

• high level of data abstraction

• universal & uniform data structure

• global behavioural rules

• set of higher-level operations

• structure optimisation algorithm

Why relational model has been so attractive ?

(11)

FP for DB Introduction 21 June 2009

COURSE

tree

C008

C011 C012 C111

C021 C027

CODE TITLE PREQ C008 ………… none C111 ………… C008 C011 ………… C008 C012 ………… C008 C021 ………… C011 C027 ………… C011

p ::= remove C008

any q(PC(CODE, DETAILS))

has to wait until p terminates

CODE TITLE CODE PREQ

non-FD decomposition

representing intra-structures

RDB insufficient in terms of provision for recursive structures and processes

• Convoluted structures embedded in relations (tree, graph) are not directly supported in RDB

• Recursive processing not supported either

A consequence of algebraic foundations

addressed by e.g. recursive union in SQL

conclusion

(12)

FP for DB Introduction 23 June 2009

any kind of ordering (set inclusion, tree, graph, convolution) imposed on a structure contradicts relational foundations

→ evolution of RDB imminent conclusion

principles for futher development

• structural simplicity structural regularity

• separation of logical and physical aspects of database processing

• set-oriented processing algebra-oriented processing

(13)

FP for DB Introduction 25 June 2009

{ADT, procedures}

{relations, r-operations} E. Codd {nested relations, xr-operations} H. Korth at al.

{algebra (components, operations), transformations} ?

R&D progress

Referenzen

ÄHNLICHE DOKUMENTE

Discussion Seminar Everybody reads the paper carefully and sends a summary / questions to the discussion leader.. P P Guides on how to read papers can be found on the

„  One way: Fixed point operator on the type level data IntListF x = EmptyList | Cons Int x. type IntList =

• The simple prover illustrates many concepts of Isabelle/HOL’s proof system like schema variable, rule application, different arguments depending on the used method/tactic...

• The simple prover illustrates many concepts of Isabelle/HOL’s proof system like schema variable, rule application, different arguments depending on the used method/tactic. •

In the remainder of this chapter we describe the interface of the presented library, discuss how arguments of persistent predicates are stored in database tables and present a set

In particular, we show that complete strategies, like breadth-first search or iterative deepening search, are a viable alterna- tive to incomplete strategies, like depth-first

• code V e — (generates code that) computes the Value of e, stores it in the heap and returns a reference to it on top of the stack (the normal case);. • code B e — computes the

The Magnetic Tape System automatically detects, and automatically identifies, ALL housekeeping condi- tions (such as Busy, Use Lockout, Error, End of Tape, End of