Object Relational
Object Relational
video games
product endorsements
1
ADTs: User-Defined Atomic Types
Built-in SQL types (int, float, text, etc.) are limited.
– Even these types have simple methods associated with
them (math, LIKE, etc.)
ORDBMS: User can define new atomic types (&
methods) if a type cannot be naturally defined in terms
of the built-in types:
1
Dinkey Schema Revisited
create table frames (frameno integer, image jpeg,
category integer); -- images from films
create table categories (cid integer, name text,
lease_price float, comments text); -- pricing
create type theater_t tuple(tno integer, name
text, address text, phone integer)
create table theaters theater_t; -- theaters
create table films (filmno integer, title text,
stars setof(text), director text, budget
float); -- Dinkey films
create table nowshowing (film integer, theater
ref(theater_t), start date, end date);
create table countries (name text, boundary
polygon, population integer, language text)
1
An Example Query in SQL-3
Clog cereal wants to license an image of Herbert in front
of a sunrise:
select F.frameno, thumbnail(F.image),
C.lease_price
from frames F, categories C
where F.category = C.cid
and Sunrise(F.image)
– The thumbnail method produces a small image.
and Herbert(F.image);
– The Sunrise method returns T iff there’s a sunrise in the picture.
– The Herbert method returns T iff Herbert’s in pic.
1
Another SQL-3 Example
Find theaters showing Herbert films within 100 km
of Andorra:
select N.theater->name, N.theater->address, F.name
from nowshowing N, frames F, countries C
where N.film = F.filmno
and Radius(N.theater->location, 100) || C.boundary
and C.name = ‘Andorra’
and F.stars
– theater ‘Herbert
attribute the Worm’
of nowshowing: ref to an object in
another table. Use -> as shorthand for
deref(theater).name
– Set-valued attributes get compared using set methods.
1
Example 2, cont.
select N.theater->name, n.theater->address, F.name
from nowshowing N, frames F, countries C
where N.film = F.filmno
and Radius(N.theater->location, 100) || C.boundary
and C.name = ‘Andorra’
and F.stars ‘Herbert the Worm’
1
New features in SQL-3 DML
1
Path Expressions
Can have nested row types (Emp.spouse.name)
Can have ref types and row types combined
– nested dots & arrows. (Emp->Dept->Mgr.name)
Generally, called path expressions
– Describe a “path” to the data
Path-expression queries can often be rewritten as joins.
Why is that a good idea?
select M.name
select E->Dept->Mgr.name from
What about Emp.children.hobbies? emp E, Dept D, Emp M
from emp E; where E.Dept = D.oid
and D.Mgr = M.oid;
1
User-Defined Methods
New ADTs will need methods to manipulate them:
– e.g., for jpeg images: thumbnail, crop, rotate,
smooth, etc.
– Expert user writes these methods in a language like
C and compiles them.
– Methods must be registered with ORDBMS, which
then dynamically links the functions into server.
2
Inheritance
“Collection hierarchies”: Inheritance on tables
– create table student_emp under emp (gpa
float);
– Queries on emp also return tuples from
student_emp (unless you say “emp only”)
“Type extents”:
– All objects of a given type can be selected from a
single view (e.g., select * from theater_t)
2
Modifications to support ORDBMS
Parsing
– Type-checking for methods pretty complex.
Query Rewriting
– Often useful to turn path exprs into joins!
– Collection hierarchies Unions
Optimization
– New algebra operators needed for complex types.
Must know how to integrate them into optimization.
2
Modifications (Contd.)
Execution
– New algebra operators for complex types.
– OID generation & reference handling.
– Dynamic linking.
– Support “untrusted” methods.
– Support objects bigger than 1 page.
– Method caching: much like grouping.
f(x) for each x is like AVG(major) for each major.
2
Modifications (Contd.)
Access Methods
– Indexes on methods, not just columns.
– Indexes over collection hierarchies.
– Need indexes for new WHERE clause exprs (not
just <, >, =)!
GiST can help here.
Data Layout
– Clustering of nested objects.
– Chunking of arrays.
2
Stonebraker’s Application Matrix
No Query Query
2
OO/OR-DBMS Summary
Traditional SQL is too limited for new apps.
OODBMS: Persistent OO programming.
– Difficult to use, no query language.
ORDBMS: Best (?) of both worlds:
– Catching on in industry and applications.
– Pretty easy for SQL folks to pick up.
– Still has growing pains (SQL-3 standard
still a moving target).
2
Summary (Contd.)
ORDBMS offers many new features.
– But not clear how to use them!
– Schema design techniques not well understood
– Query processing techniques still in research
phase.
A moving target for OR DBA’s!