lunes, 30 de julio de 2007

Database Algebra

Explanation

x = variable

X = defined name

x -> y = given x find y

= set of x

{} = empty set

{x} = a set with one element called x

{x,y,z} = a set with x, y and z

[x] = list of x

(x..y) = range from x to y

(x, y) = vector of x and y

y : = y belongs to set of x

<: = is a strict subset of

<=: = is a subset of

x y = x or y

s1 U: s2 = union of set s1 and set s2

s1 I: s2 = intersection of set s1 and set s2

x # x : = x so that x belongs to set of y

x => y = if x is true then y is true

x = (y,z) => x.y = if x is composed of (y,z), you can address x.y

PrimitiveType = ( int, float, date, string, string[n], blob )

Once the notation is defined (or should we call them axioms?), we can define some properties that we can prove to be true.

Algebra

(x..y) -> z == x -> z

(x, y, z) == ((x, y), z)

(x) == x

x -> y == (, f(x)=y)

Not very impressive, huh?

Well, the devil is in the details, and therefore the paradise is also in the details, if you know how to find and exorcise those devils ;-)


Database

Type = PrimitiveType

Fielddef = (name, Type)

Field = (name, value, Fielddef) # (value : fielddef.type)

Tabledef = (, pk) # pk <=:

Row =

Rowtx = ( tx, Row ) # tx : int

Rowdata = ( (lowertx..higher) -> Rowtx ) # ( lowertx : int && highertx : int )

Tabledata = ( TabvleDef, pk -> rowdata) # pk <=: Tabledef && row.. = tabledef.

Table = (Tabledef, Tabledata) # ( Tabledata.pk <=: Tabledef && Tabledata.Tabledef == Tabledef )

Database = (

, lowertx, highertx ) # (lowertx : int && highertx : int)

What is the point of having an algebra to define a database? If this algebra is correct, and I know for sure it is not, since I was transcribing it from notepad and I found several bugs, but let us assume we can write a correct database algebra. And then let us assume that we have an interpreter for this algebra.

We would have a database.

So what? I hear you say. Databases have existed for 50 years, so why are you trying to reinvent the wheel?

First, current database technology is dated. Also it does not implement the relational algebra nor the relational model properly. And the most important thing: it is full of hacks. Unmaintainable. Unable to grow.

I want this to be a vehicle for thought.


And now let us have some fun...


Table operations

table.insert(Row) # table.tabledef. = row..

table.update(updaterow, matchrow) # updaterow : Row && matchrow : Row

table.project( ) # <=: table.tabledef. // sql select stmt

table.select( matchrow) # matchrow : Row // sql where stmt

No hay comentarios: