Adobe Scan May 31, 2024
Adobe Scan May 31, 2024
Obect-Based Databases
9.1 Overview
The first obstacie faced by programmers using the relational data
ited type systen1 supported by the relational model. Complex model was the lim
require correspondingly complex data types, such as nested recordapplication domains
valued attrabutes and inheritance, which are supported by structures, multi
languages. uch features are in fact supported in the E-Rtraditional programming
and extended E-R nota
tions, buthad to be translated to simpler SQL data types. The object-relational data
modelexte:is the relational data model by providing a richer tvpe system including
Complex data tvpes and object orientation. Relational query languages, in particu
lar QL, neec to be correspondingly extended to deal with the richer tvpe svstem.
Such extensions attempt to preserve the relational foundations-in particular, the
declarativeaccess to data-while extending the modeling power. Object-relational
database systems, that is, database systems based on the object-relation model, pro
Vide a
Convenient migration path for users of relational databases who wish to use
object-oriented features.
Ihe second obstacle was the difficulty in accessing database data from programs
written in programming languages such as Ct+ or Java. Merely extending the tvpe
yStem supported by the database was not enough to solve this problem completely.
361
362
Chapter o Object-Based Databases
Differences between the type system of the database and the type system of the po.
gramming language make data storage and retrieval more complicated and need to
be minimized. Having to express database access using a language (SQL) which is
language again makes the job of the
harder. Ittrom
irterent the programming programmer
is desirable, for many applications, to have programming language on-
structs or extensions that permit direct access to datain the database. without having
tvpe svstems
Ith omper multivalued we can teptesent ER model
',attrilutes, Iattributes, generalization, and
convepts, such as com
translationto the relational
hater7, we detined first normal torm model.
speialization dinlv.
ln domins, Recall that a (INE), which eyuires that all
ito be indivisible units. domain is atoic it
elements ot the domain attributes
are
The assumption ot INF is a natural one in the bank
Howeve, t ot all applications are best modeled by INEexamples we have considered.
than
eH'.adatabase asaset ot records, users ot relations.
certain applicationsorexample, rather
obts
(orentities). These objects
mv requite several records tor view it as a setot
simple. caSV-t0-Use intertace a their
requires one-to-one Orrespondenervpresentation.
A
LUSCT'S intuitive notion of an object and the database betwen the
Consider, tor example, a librarv svstem's otion ot a data item.
tollowing intormation tor each book: application, and suppose we wish to stoe the
" Book title
title ublislher
auiliorarray (name, branci)
keyword_set
Compilers Snith, Jonesl (McGraw-Hill, NewYork) parsing, analvsis)
Networks |lones, Frick] (Oxford, Londom) {lnternet, Web}
title keyword
Compilers parsing
Compilers analysis
Networks Internet
Networks Web
keywords
fitle pub_name pub_branch
Compilers McGraw-Hill New York
Networks Oxford London
books4
books.
Figure 9.2 4NF version of the relation
simplicity we assume that the title of a book uniquely identifies the book'We
For
using the following schema:
can then represernt the same information
21tlhors(title, author position)
s keyerdsltile, keyvord)
normalized representation ot
ite ac:he saiies 4NE. iigure 9.2 shows the
Similarly, the following structured type can be used to represent a composite attribute
address:
Such types are called user-defined types in SQL. The above definition corresponds
tothe E-R diagrar: in Figure 6.4. The final and not final specifications are related to
subtyping,whi: iie describe later, in Section9.3.2.2
We can now ethese types to create composite attributes in a relation, by simply
declaring an aibute to be of oneof these types. For example, we could create a table
Customer as fo
create table customer (
name Name,
address Address,
dateOfBirth date)
2. The
final final specification for Name indicates that we cannot create subtypes for name, whereas the not
specification
for Address indicates that we can create subtypes of address.
366 Chapter 9 Object-Based Databases
Notethat the for clause indicates which type this method is for, while the keyword
instance indicates that this method executes on an instance of the Customer type.
self refers to the Customer instance on which the method is invoked.
The variable
of the method can contain procedural statements, which we saw earlier
The body
in Section
4.6. Methods can update the attributes of the instance on which they are
executed.
Methods can be invoked on instances of a type. If we had created atable customer
ftne CustomerType,we can invoke the method ageOnDate() as illustrated below, to
customer.
find the age of each
select name.lastname, ageOnDate(current date)
from customer
We can then use new Name('John','Smith') to create a valueof the type Name.
We can consiia row value by listing its attributes within parentheses. For in
stance, if we de : an attribute nane as a row type with components firstnane and
lastname we car ruct this value for it:
("Ted', 'Codd')
query usesthe table people, it will tind not onlytuples directly inserted into that llb
students and
into its subtables, namely techers.
but also
thOse
OnlySQL
tuples
permits
inserted
tindare
us tothat
attributes present in eole can be accessed by thatat query.
tuples that are in pvple but not in its subtables by ising
"only people" in place of people in a query. The only keyword can also be Usel in
tlowever,
delete,
update statements. Without the only keyword, a statement
pertable,
delete andsuch as pople, also deletes tuples that were originally inserted in subtabley
statement
(such as students); for example, a
P
delete from people where
well as its subtables students
delete all tuples from the table people, as to the above
Would only keyword is added statement,
whero tuples
teachers,that satisfy P. If the affected, even if they satisfy the
subtables are not these bm
that were inserted in supertable would continue to find
conditions. Subsequent queries on the wi
multiple inheritance is possible with tables, just as it is possible
Conceptually, table of type
TenchingAssistant:
create a
tvpes. For example, we can
create table tenchingassistants
of TncingAssistant
under students, eachers
NelICSdeOnstcted as tollows
s
niseilvompu:, datalase','SQLI
books relation as:
Tius. w'cal ceale anple o! he Ve deined bv the
Publisler('McGraw-HilI,'New York
(Compilers arravi Smith'. ]ones1, new multisetl'parsing', 'analysis')
constructor
a
Here we have created a value tor the attribute Publisher by invoking for Pul-
function for Publisler with. appoiate arguments. Note that this constructor
declaredjust
Iisher must be explicitlv created, and is not present by default; it can be
like the constructor for NaC, whichwe saw earlier in Section 9.3.
It we want to insert the preceding tuple into the relation books. we could exe
the statement
9,5 Array and Multiset Types in SQL 373
records
The with ordinality clause generates an extra attribute which the position of
the element in the array. Asimilar query, but without the with
be used to generate the keywvord relation. ordinality clause, can
9.5.3 Nesting and Unnesting
fewer (orr no)
The transformation of a nested relation into a form with
attributes relation-valued
is called unnesting. The books relation has two attributes. authorarray and
keyvord set,that are collections, and two attributes, title and publisher, that are not.
relation, with n L
Suppose that we want to convert the relation into a single flat
relations or structured types as attributes. We can use the following query to carry out
the task:
lhsstemew ie nested subqueries in the select elause tor ach tuple gener
atrd by the trou 'reelausS of theouter query.Observe that the attribute B.title
!nnm the outer Sed in the nested queries, to ensurethatonly the corretsets
saegenerated tor each title.
from deurtments
Features
9.7 Implementing0-Rbasically extensions of existing relational data
Oberelationalatabasesyvstemsare levels of the database system.
clearly required at many
Ise syslems. Chages are to the storge Svstem code (relation
storage, indices.
"iovevrto minimize changes can be translated
theomplerata tvpes supportedv object-relational svstems
) relational databaseS.
to the simpler (ype system of transltion wened only look at how some featurs
lounderstand how lo do this iustance, multivalued atributesim
theFRmodelare translated intoel:tioas or in the object-relational model.
to multis :ietribules
i 1Rnodelcorrespond wtured types. ISA
hierarchies in the
(onposile attributes roughlv O
object-relational model.
"Kodlcorrespond to table inherv, we saw in Se
convertin: 1 s totables, which
The techniques tor
slate object-relational data to rela
(iono9, can be used, with some e
lional data at the slorge level. allinherited
of
subtables can be stordin an eticNtittvithout replication
tields, in one of twoways.
parentti-
trom d
" Each tuble slores the"pimarv ker úrhwh may be inherited (otherthanthe'
ble) andthe attributesi are detined locallv. Inherited attributes meansotajoin
primary key) do not need to be slored, and can be derived bv
with the supertable, based on tlhe prinarv key. i
tupl
When a
" Fach table stores all inherited and locally detined attributes. itspreseneN
inserted, it isstoredonlv inthe table in which it is inserted,and p
l'ersistent I'ogramnming Languages 379
nos lt
s n the bibliogrrhi
ulhr detans ot inrement.tts
The |D) stadard is still at aneurly stage, and undeging nevisiOns. Sveraln
punies provideinppleentations ot|0, Hovever, it rmains to be sn it lWwill l
widely usd, unlikeMG++.
" Relational systems: Simple data types, powerful query languages, high pro
tection
These descriptions hold in general, but keep in mind that some database systems
blur the boundaries. For example, object-oriented database systems built aroundor
relational
a persistent programming language can be implemented on top of a
object-relational database system. Such systems may provide lower performance than
object-oriented database systems built directly on astorage system, but provide some
of the stronger protectionguarantees of relational systems.
9.10 Summary
The object-reiational data model extends the relational data model by provid
ing aricher typ system incl:ncing coliection types and object orientation.
" Colection types inciud postrdrelations, sets, multisets, and arrays, a
obiect-relaticnaB modei pot fits attributes of a table to be collections.
as well
" Object orientation provides ioheritance with subtypes and subtables,
as object (tuple) reierences.
" The SOI1999 standard extends the SQL data-definition and query langucs
deal with the new data typesand with object orientation.
,as
language,
" We saw a variety of features of the extended data-definition
collection-valued
well as the query language, and in particular support for pre-
attempttodata
attributes, inheritace, and tuple references. Such extensions accessto
serve the relational foundations-in particular, the declarative
-whileoxtending, the modeling power.