Docsity

Object-Relational Systems - Database Systems I | CMPS 180, Study notes of Database Management Systems (DBMS)

Toggle sidebar
bg1
Winter 2002 Arthur Keller – CS 180 12–1
Schedule
•Today: Feb. 19 (T)
◆Object-Relational Systems.
◆Read Sections 4.5, 9.4-9.5. Assignment 5 due.
•Feb. 21 (TH)
◆Transactions, Authorization.
◆Read Sections 8.6-8.7. Project Part 5 due.
•Feb. 26 (T)
◆Datalog.
◆Read Sections 10.1-10.2. Assignment 6 due.
•Feb. 28 (TH)
◆Datalog and SQL Recursion, ODL.
◆Read Sections 10.3-10.4, 4.1-4.4. Project Part 6 due.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17

Partial preview of the text

Download Object-Relational Systems - Database Systems I | CMPS 180 and more Study notes Database Management Systems (DBMS) in PDF only on Docsity!

Winter 2002

Arthur Keller – CS 180

Schedule

•^ Today: Feb. 19 (T)

◆^ Object-Relational Systems. ◆^ Read Sections 4.5, 9.4-9.5. Assignment 5 due.

•^ Feb. 21 (TH)

◆^ Transactions, Authorization. ◆^ Read Sections 8.6-8.7. Project Part 5 due.

•^ Feb. 26 (T)

◆^ Datalog. ◆^ Read Sections 10.1-10.2. Assignment 6 due.

•^ Feb. 28 (TH)

◆^ Datalog and SQL Recursion, ODL. ◆^ Read Sections 10.3-10.4, 4.1-4.4. Project Part 6 due.

Winter 2002

Arthur Keller – CS 180

Object-Relational Systems

•^ Object-oriented ideas enter the relational world.

◆^ Keep relation as the fundamental abstraction.

•^ Compare with “object-oriented DBMS,” whichuses the class as the fundamental abstraction andtacks on relations as one of many types.Motivations•^ Allow DBMS’s to deal with specialized types –maps, signals, images, etc. – with their ownspecialized methods.•^ Supports specialized methods even onconventional relational data.•^ Supports structure more complex than “flat files.”

Winter 2002

Arthur Keller – CS 180

User-Defined Types

SQL allows

UDT

’s that play a dual role:

1.^

They can be the types of relations; i.e., thetype of their tuple. ◆^ Sometimes called a

row type

2.^

They can be the type of an attribute in arelation.

Winter 2002

Arthur Keller – CS 180

Defining UDT’s – Example in Oracle Syntax

CREATE

TYPE

BarType

AS

OBJECT

name

CHAR(20)

UNIQUE,

addr

CHAR(20)

);/ CREATE

TYPE

BeerType

AS

OBJECT

name

CHAR(20)

UNIQUE,

manf

CHAR(20)

);/ CREATE

TYPE

MenuType

AS

OBJECT

bar

REF

BarType, beer

REF

BeerType,

price

FLOAT

Winter 2002

Arthur Keller – CS 180

Creating Tables

Type declarations do not create tables.• They are used in place of element lists in^ CREATE

TABLE

statements.

Example

CREATE TABLE Bars OF BarType;CREATE TABLE Beers OF BeerType;CREATE TABLE Sells OF MenuType;

Winter 2002

Arthur Keller – CS 180

Values of User-Defined Types –

Oracle Approach

• Each UDT has a type constructor of the samename.• Values of that type are the values of its fieldswrapped in the constructor.Example

SELECT * FROM Bars;

produces values such as

BarType('Joe''s Bar', 'Maple St.')

Winter 2002

Arthur Keller – CS 180

Inserting Values – Oracle ApproachWe can use the standard

INSERT

in Oracle,

but we must wrap the inserted object in itstype-constructor.Example^ INSERT INTO Bars VALUES(

BarType('Joe''s Bar', 'Maple St.')

• SQL standard involves generator and mutatormethods; see text.

Winter 2002

Arthur Keller – CS 180

Types for Columns

A UDT can also be the type of a column.Example – Oracle SyntaxLet’s create an address type for use with bars and drinkers.

CREATE

TYPE

AddrType

AS

OBJECT

street

CHAR(30),

city

CHAR(20),

zip

INT

We can then create a table of drinkers that includes their name,address, and favorite beer.•^ The beer is included as a beer object, which “unnormalizes”the relation but is legal.

CREATE

TABLE

Drinker

name

CHAR(30),

addr

AddrType, favBeer

BeerType

);

Winter 2002

Arthur Keller – CS 180

References

UDT’s can have

references

• If

T^

is a UDT, then REF(

T ) is the type of a

reference to a

T^

object.

• Unlike OO systems, refs are values that canbe seen by queries.

Winter 2002

Arthur Keller – CS 180

Dereferencing in SQL

A^ →

B^

= the

B^

attribute of the object referred

to by reference

A.

ExampleFind the beers served by Joe.

SELECT beer -> nameFROM SellsWHERE bar -> name = 'Joe''s Bar';

Winter 2002

Arthur Keller – CS 180

Oracle’s

DEREF

Operator

If we wanted the entire

BeerType

object, we

might try to write^ SELECT ss.beerFROM Sells

ss

WHERE

ss.bar.name =

'Joe''s Bar';

That is legal, but

ss.beer

is a reference, and

we’d get a gibberish value.• To see the whole beer object, use:^ SELECT DEREF(ss.beer)FROM Sells

ss

WHERE

ss.bar.name =

'Joe''s Bar';

Winter 2002

Arthur Keller – CS 180

Methods

Real reason object-relational isn’t just nestedstructures in relations.• We’ll follow Oracle syntax.• Declared in a

CREATE

TYPE

statement,

defined in a

CREATE

TYPE

BODY

statement.

• Methods are functions or procedures; in Oraclethey are defined like any PL/SQL procedure orfunction.

◆^ But, there is a special tuple variable

SELF

that refers

to that object to which the method is applied.

Winter 2002

Arthur Keller – CS 180

Some Points to Remember

•^ The pragma is needed to allow

priceInYen

to

be used in queries.^ ◆^

WNDS

= “write no database state.”

•^ In the declaration, function/procedure argumentsneed a mode,

IN

,^ OUT

, or

IN OUT

, just like

PL/SQL procedures.^ ◆^

But the mode does not appear in the definition.

•^ Many methods will take no arguments (relying onthe built-in “self”).

◆^ In that case, do not use parentheses after the functionname.

•^ The body can have any number of functiondeclarations, separated by semicolons.

Winter 2002

Arthur Keller – CS 180

Example of Method Use

Follow a designator for the object to whichyou want to apply the method by a dot, thename of the method, and argument(s).

SELECT ss.beer.name,

ss.priceInYen(120.0)

FROM Sells

ss

WHERE

ss.bar.name =

'Joe''s Bar';