ADB - Chapter 1-3
ADB - Chapter 1-3
Chapter One
Concepts for Object Oriented Databases
Introduction
Database technology has concentrated on the static aspects of information storage. With the
arrival of the third generation of Database Management Systems, namely Object-Oriented
Database Management Systems (OODBMSs) and Object-Relational Database Management
Systems (ORDBMSs), the two disciplines have been combined to allow the concurrent
modelling of both data and the processes acting upon the data. In database systems, we have
seen the widespread acceptance of RDBMSs for traditional business applications, such as order
processing, inventory control, banking, and airline reservations. However, existing RDBMSs
have proven inadequate for applications whose needs are quite different from those of
traditional business database applications. These applications include: computer-aided design
(CAD), computer-aided manufacturing (CAM), computer-aided software engineering (CASE),
network management systems, digital publishing, geographic information systems (GIS),
office information systems (OIS) and multimedia systems, interactive and dynamic Web sites.
Strengths of the relational model are its simplicity, its suitability for Online Transaction
Processing (OLTP), symmetric structure and its support for data independence. However, the
relational data model, and relational DBMSs, possess significant weaknesses as they are poor
in representing real world entities, Semantic overloading, poor support for integrity and general
constraints, homogeneous data structure, limited operations, difficulty handling recursive
queries and impedance mismatch. Furthermore, in RDBMS, Transactions in business
processing are generally short-lived and the concurrency control primitives and protocols such
as two-phase locking are not particularly suited for long-duration transactions, Schema changes
are difficult and RDBMSs were designed to use content-based associative access (that is,
declarative statements with selection based on one or more predicates) and are poor at
navigational access (that is, access based on movement between individual records).
These limitations of early data models and the need for more complex applications, need for
additional data modeling features and increased use of object-oriented programming languages
resulted in the creation of object oriented databases.
Advanced Database Systems Handout
upon. An Object is a uniquely identifiable entity that contains both the attributes that describe
the state of a ‘real world’ object and the actions that are associated with it. (Simula 1960s). An
object, similar to program variable in programming language, is composed of two components:
state (value) and behaviour (operations), except that it will typically have a complex data
structure as well as specific operations defined by the programmer. In OO databases, objects
may have an object structure of arbitrary complexity in order to contain all of the necessary
information that describes the object. In contrast, in traditional database systems, information
about a complex object is often scattered over many relations or records, leading to loss of
direct correspondence between a real-world object and its database representation.
The internal structure of an object in OOPLs includes the specification of instance variables,
which hold the values that define the internal state of the object. An instance variable is similar
to the concept of an attribute, except that instance variables may be encapsulated within the
object and thus are not necessarily visible to external users. Some OO models insist that all
operations a user can apply to an object must be predefined. This forces a complete
encapsulation of objects. To encourage encapsulation, an operation is defined in two parts:
Signature or interface of the operation, specifies the operation name and arguments
(or parameters).
Method or body, specifies the implementation of the operation.
The object type definition includes an operation signature for each operation that specifies the
name of the operation, the names and types of each argument, the names of any exceptions that
can be raised, and the types of the values returned, if any. Operations can be invoked by passing
a message to an object, which includes the operation name and the parameters. The object then
executes the method for that operation. This encapsulation permits modification of the internal
structure of an object, as well as the implementation of its operations, without the need to
disturb the external programs that invoke these operations
Some OO systems provide capabilities for dealing with multiple versions of the same object (a
feature that is essential in design and engineering applications). For example, an old version of
an object that represents a tested and verified design should be retained until the new version
is tested and verified which is very crucial for designs in manufacturing process control,
architecture and software systems.
Operator polymorphism/ operator overloading: This refers to an operation’s ability to be
applied to different types of objects; in such a situation, an operation name may refer to several
distinct implementations, depending on the type of objects it is applied to.
Advanced Database Systems Handout
Type Constructors
A type constructor is a feature of a typed formal language that builds new types from old ones.
Basic types are considered to be built using nullary type constructors. Complex objects are
built from simpler ones by applying constructors to them. Attributes can be classified as simple
or complex. A simple attribute can be a primitive type such as integer, string, real, and so on,
which takes on literal values. The simplest objects are objects such as integers, characters,
byte strings of any length, Booleans and floats. Basic type constructors are atom, tuple, and
set; can also include list, bag, and array.
The atom constructor is used to represent all basic atomic values, such as integers, real
numbers, character strings, booleans, and any other basic data types that the system
supports directly.
Sets are critical because they are a natural way of representing collections from the real
world.
Tuples are critical because they are a natural way of representing properties of an entity.
Lists or arrays are important because they capture order
Figure: Specifying the object types EMPLOYEE, DATE, and DEPARTMENT using type constructors.
Advanced Database Systems Handout
query the value of selected attributes. In general, the implementation of an operation can be
specified in a general-purpose programming language that provides flexibility and power in
defining the operations.
A method consists of a name and a body that performs the behaviour associated with the
method name. In an object-oriented language, the body consists of a block of code that carries
out the required functionality. For example, the next code represents the method to update a
member of staff’s salary. The name of the method is updateSalary, with an input parameter
increment, which is added to the instance variable salary to produce a new salary.
Messages are the means by which objects communicate. A message is simply a request from
one object (the sender) to another object (the receiver) asking the second object to execute one
of its methods. The sender and receiver may be the same object.
Classes are blueprints for defining a set of similar objects. Thus, objects that have the same
attributes and respond to the same messages can be grouped together to form a class. The
attributes and associated methods are defined once for the class rather than separately for each
object. A class is also an object and has its own attributes and methods, referred to as class
attributes and class methods, respectively. Class attributes describe the general characteristics
of the class, such as totals or averages. For database applications, the requirement that all
objects be completely encapsulated is too stringent. One way of relaxing this requirement is to
divide the structure of an object into visible and hidden attributes (instance variables).
Advanced Database Systems Handout
Naming Mechanism: Assign an object a unique persistent name through which it can
be retrieved by this and other programs.
Reachability Mechanism: Make the object reachable from some persistent object. An
object B is said to be reachable from an object A if a sequence of references in the
object graph lead from object A to object B.
1.4 Type Hierarchies and Inheritance
An entity type represents a set of entities of the same type such as Staff, Branch, and
PropertyForRent. We can also form entity types into a hierarchy containing superclasses and
subclasses.
Superclass: An entity type that includes one or more distinct subgroupings of its
occurrences, which require to be represented in a data model.
Subclass: A distinct subgrouping of occurrences of an entity type, which require to be
represented in a data model.
Entity types that have distinct subclasses are called superclasses. For example, the entities that
are members of the Staff entity type may be classified as Manager, SalesPersonnel, and
Advanced Database Systems Handout
Secretary. In other words, the Staff entity is referred to as the superclass of the Manager,
SalesPersonnel, and Secretary subclasses. The relationship between a superclass and any one
of its subclasses is called a superclass/subclass relationship. For example, Staff/Manager has
a superclass/subclass relationship.
Inheritance allows one class to be defined as a special case of a more general class. These
special cases are known as subclasses and the more general cases are known as superclasses.
The process of forming a superclass is referred to as generalization; forming a subclass is
specialization. Generalization is the process of minimizing the differences between entities by
identifying their common characteristics. The process of generalization is a bottom-up
approach, which results in the identification of a generalized superclass from the original entity
types. Specialization is the process of maximizing the differences between members of an
entity by identifying their distinguishing characteristics. Specialization is a top-down approach
to defining a set of superclasses and their related subclasses. The set of subclasses is defined
on the basis of some distinguishing characteristics of the entities in the superclass.
A subclass inherits all the properties of its superclass and additionally defines its own unique
properties (attributes and methods). All instances of the subclass are also instances of the
superclass. The principle of substitutability states that an instance of the subclass can be used
whenever a method or a construct expects an instance of the superclass.
Superclass/Subclass Relationships
Each member of a subclass is also a member of the superclass. In other words, the entity in the
subclass is the same entity in the superclass, but has a distinct role. The relationship between a
superclass and a subclass is one-to-one (1:1) and is called a superclass/subclass relationship.
Advanced Database Systems Handout
Chapter Two
Query Processing and Optimization
A query means a request for information. A query based on a set of pre-defined code, so
your database understands the instruction. We refer to this code as the query language. The
standard for database management is Structured Query Language (SQL).
Query Processing is the process of choosing a suitable execution strategy for processing a
query. The activities implemented by query processing are the activities involved in parsing,
validating, optimizing, and executing a query. The aims of query processing are to transform a
query written in a high-level language, typically SQL, into a correct and efficient execution
strategy expressed in a low-level language (procedural). A low-level programming language is
a programming language that provides little or no abstraction from a computer's instruction set
architecture—commands or functions in the language map closely to processor instructions.
When the relational model was first launched commercially, one of the major criticisms often
cited was inadequate performance of queries. Since then, a significant amount of research has
been devoted to developing highly efficient algorithms for processing queries. There are many
ways in which a complex query can be performed, and one of the aims of query processing is
to determine which one is the most cost effective.
Query decomposition is the first phase of query processing which involves scanning, parsing,
and validating a given query. The aims of query decomposition are to transform a high-level
query into a relational algebra query and checks that it is syntactically and semantically correct.
A relational algebra query: is a procedural query language, which takes instances of relations
as input and yields instances of relations as output. It uses operators (unary or binary) to
perform queries. They accept relations as their input and yield relations as their output.
The relational algebra is very important for several reasons:
It provides a formal foundation for relational model operations.
It is used as a basis for implementing and optimizing queries in the query processing
and optimization modules that are integral parts of relational database management
systems (RDBMSs)
Some of its concepts are incorporated into the SQL standard query language for
RDBMSs.
The fundamental operations of relational algebra are: Select, Project, Union, Set difference,
Cartesian product, and Rename.
Select Operation (σ): It selects tuples that satisfy the given predicate from a relation.
Advanced Database Systems Handout
Notation − σp(r)
Where σ stands for selection predicate and r stands for relation. p is prepositional logic
formula which may use connectors like and, or, and not. These terms may use
relational operators like − =, ≠, ≥, <, >, ≤.
Example: σsubject = "database"(Books)
Project Operation (∏): It projects column(s) that satisfy a given predicate.
Notation − ∏A1, A2, An (r)
Where A1, A2 , An are attribute names of relation r.
Duplicate rows are automatically eliminated, as relation is a set.
Example: ∏subject, author (Books)
Union Operation (∪): It performs binary union between two given relations and is defined as
r ∪ s = { t | t ∈ r or t ∈ s}.
Notation − r U s
Where r and s are either database relations or relation result set (temporary relation).
Example: ∏ author (Books) ∪ ∏ author (Articles)
For a union operation to be valid, the following conditions must hold −
r and s must have the same number of attributes.
Attribute domains must be compatible.
Duplicate tuples are automatically eliminated.
Set Difference (−): The result of set difference operation is tuples, which are present in one
relation but are not in the second relation.
Notation − r − s
Finds all the tuples that are present in r but not in s.
Example: ∏ author (Books) − ∏ author (Articles)
Cartesian Product (Χ): Combines information of two different relations into one.
Notation − r Χ s
Where r and s are relations and their output will be defined as −
r Χ s = { q t | q ∈ r and t ∈ s}
Example: σauthor = ‘Jonathan’(Books Χ Articles)
Rename Operation (ρ)(rho): The results of relational algebra are also relations but without
any name. The rename operation allows us to rename the output relation.
Notation − ρ x (E)
Where the result of expression E is saved with name of x.
Advanced Database Systems Handout
Example: the following is an example of translating a given nested SQL query into an
equivalent relational algebra expression.
Query Optimization
In first generation network and hierarchical database systems, the low-level procedural query
language is generally embedded in a high-level programming language such as COBOL, and
it is the programmer’s responsibility to select the most appropriate execution strategy. In
contrast, with declarative languages such as SQL, the user specifies what data is required rather
than how it is to be retrieved. This relieves the user of the responsibility of determining, or
even knowing, what constitutes a good execution strategy and makes the language more
universally usable. Additionally, giving the DBMS the responsibility for selecting the best
Advanced Database Systems Handout
strategy prevents users from choosing strategies that are known to be inefficient and gives the
DBMS more control over system performance.
An important aspect of query processing is query optimization. As there are many equivalent
transformations of the same high-level query, the aim of query optimization is to choose the
one that minimizes resource usage. Generally, we try to reduce the total execution time of the
query, which is the sum of the execution times of all individual operations that make up the
query. However, resource usage may also be viewed as the response time of the query, in which
case we concentrate on maximizing the number of parallel operations. Since the problem is
computationally intractable with a large number of relations, the strategy adopted is generally
reduced to finding a near optimum solution.
Query optimization is the process of choosing a suitable execution strategy for processing a
query. An internal representation (query tree or query graph) of the query is created after
scanning, parsing, and validating. The aim of query optimization is to choose the one that
minimizes resource usage. Generally, we try to reduce the total execution time of the query,
which is the sum of the execution times of all individual operations that make up the query
The disadvantages arise from the fact that the execution strategy that is chosen as being
optimal when the query is compiled may no longer be optimal when the query is run.
However, a hybrid approach could be used to overcome this disadvantage, where the query is
re-optimized if the system detects that the database statistics have changed significantly since
the query was last compiled.
The main heuristic is to apply first the operations that reduce the size of intermediate results.
E.g., Apply SELECT and PROJECT operations before applying the JOIN or other
binary operations.
Query tree
A query tree is tree data structure that corresponds to a relational algebra expression. It
represents the input relations of the query as leaf nodes of the tree, and represents the relational
algebra operations as internal nodes. An execution of the query tree consists of executing an
internal node operation whenever its operands are available and then replacing that internal
node by the relation that results from executing the operation.
Query graph
A graph data structure that corresponds to a relational calculus expression. It does not indicate
an order on which operations to perform first. There is only a single graph corresponding to
each query.
Example:
For every project located in ‘Stafford’, retrieve the project number, the controlling department
number and the department manager’s last name, address and birthdate.
SQL query:
Relation algebra:
Figure 2.3: (a) Query tree for the relational algebra, (b) Query tree for SQL query
3. Cascade of : In a cascade (sequence) of operations, all but the last one can be
ignored:
4. Commuting with : If the selection condition c involves only the attributes A1, ...,
An in the projection list, the two operations can be commuted:
6. Commuting with (or x ): If all the attributes in the selection condition c involve
only the attributes of one of the relations being joined—say, R—the two operations can
be commuted as follows:
Alternatively, if the selection condition c can be written as (c1 and c2), where
condition c1 involves only the attributes of R and condition c2 involves only the
attributes of S, the operations commute as follows:
7. Commuting with (or x): Suppose that the projection list is L = {A1, ..., An, B1, ...,
Bm}, where A1, ..., An are attributes of R and B1, ..., Bm are attributes of S. If the join
condition c involves only attributes in L, the two operations can be commuted as
follows:
If the join condition C contains additional attributes not in L, these must be added
to the projection list, and a final operation is needed.
8. Commutativity of set operations: The set operations υ and ∩ are commutative but “–
” is not.
10. Commuting with set operations: The operation commutes with υ, ∩, and –. If
stands for any one of these three operations, we have
Explanation:
Suppose that we had a constraint on the database schema that stated that no
employee can earn more than his or her direct supervisor. If the semantic query
optimizer checks for the existence of this constraint, it need not execute the
query at all because it knows that the result of the query will be empty.
Techniques known as theorem proving can be used for this purpose.
Advanced Database Systems Handout
Chapter Three
Transaction Processing Concepts
Introduction
Database management system (DBMS) is a software package/system to facilitate creation and
maintenance of database. DBMS Support different types of databases. Databases can be
classified according to the number of users: database locations: and expected type and
extent of use. Depending on the number of users databases are classified into single user
databases and multiuser databases.
Single user databases: At most one user at a time can use the system
Multiuser databases: Many users can access the system concurrently.
A transaction should always transform the database from one consistent state to another,
although we accept that consistency may be violated while the transaction is in progress. A
transaction can have one of two outcomes. If it completes successfully, the transaction is said
to have committed and the database reaches a new consistent state. On the other hand, if the
transaction does not execute successfully, the transaction is aborted. If a transaction is aborted,
the database must be restored to the consistent state it was in before the transaction started.
Such a transaction is rolled back or undone. A committed transaction cannot be aborted. If we
decide that the committed transaction was a mistake, we must perform another compensating
transaction to reverse its effects. However, an aborted transaction that is rolled back can be
restarted later and, depending on the cause of the failure, may successfully execute and commit
at that time.
ii. Concurrency Control
Many DBMSs allow users to undertake simultaneous operations on the database. If these
operations are not controlled, the accesses may interfere with one another and the database can
become inconsistent. To overcome this, the DBMS implements a concurrency control protocol
that prevents database accesses from interfering with one another. Concurrency control is the
process of managing simultaneous operations on the database without having them interfere
with one another.
The Need for Concurrency Control
A major objective in developing a database is to enable many users to access shared data
concurrently. Concurrent access is relatively easy if all users are only reading data, as there is
no way that they can interfere with one another. However, when two or more users are
accessing the database simultaneously and at least one is updating data, there may be
interference that can result in inconsistencies. Therefore, we examine three potential problems
caused by concurrency: the lost update problem, the uncommitted dependency problem, and
the inconsistent analysis problem.
The Lost Update Problem: An apparently successfully completed update operation by one user
can be overridden by another user. This occurs when two transactions that access the same
database items have their operations interleaved in a way that makes the value of some database
item incorrect.
Advanced Database Systems Handout
The uncommitted dependency problem: also known as the Temporary Update (or Dirty Read)
Problem occurs when one transaction is allowed to see the intermediate results of another
transaction before it has committed. This means that when one transaction updates a database
item and then the transaction fails for some reason. However, the updated item is accessed by
another transaction before it is changed back to its original value.
The inconsistent analysis problem: also known as The Incorrect Summary Problem occurs
when a transaction reads several values from the database but a second transaction updates
some of them during the execution of the first. For example, a transaction that is summarizing
data in a database (for example, totalling balances) will obtain inaccurate results if, while it is
executing, other transactions are updating the database. Another example is if one transaction
is calculating an aggregate summary function on a number of records while other transactions
are updating some of these records, the aggregate function may calculate some values before
they are updated and others after they are updated.
Advanced Database Systems Handout
Database recovery is the process of restoring the database to a correct state following a failure.
The failure may be the result of a system crash due to hardware or software errors, a media
failure, such as a head crash, or a software error in the application, such as a logical error in the
program that is accessing the database. It may also be the result of unintentional or intentional
corruption or destruction of data or facilities by system administrators or users. Whatever the
underlying cause of the failure, the DBMS must be able to recover from the failure and restore
the database to a consistent state.
Figure 3.4: State transition diagram illustrating the states for transaction execution
Recovery Manager
If a failure occurs during the transaction, then the database could be inconsistent. It is the task
of the recovery manager to ensure that the database is restored to the state it was in before the
start of the transaction, and therefore a consistent state. Recovery manager keeps track of the
following operations for recovery purposes:
begin_transaction: This marks the beginning of transaction execution.
read or write: These specify read or write operations on the database items that are
executed as part of a transaction.
End_transaction: This specifies that read and write transaction operations have ended
and marks the end limit of transaction execution.
commit_transaction: This signals a successful end of the transaction so that any
changes (updates) executed by the transaction can be safely committed to the database
and will not be undone.
rollback (or abort): This signals that the transaction has ended unsuccessfully, so that
any changes or effects that the transaction may have applied to the database must be
undone.
serializable schedule orders any conflicting operations in the same way as some serial
execution.
Being serializable is not the same as being serial. Being serializable implies that the schedule
is a correct schedule.
It will leave the database in a consistent state.
The interleaving is appropriate and will result in a state as if the transactions were
serially executed, yet will achieve efficiency due to concurrent execution.
The algorithm looks at only the read_item and write_item operations in a schedule to
construct a precedence graph (or serialization graph), which is a directed graph G = (N, E)
that consists of a set of nodes N = {T1, T2, ..., Tn } and a set of directed edges E = {e1, e2, ...,
em }. There is one node in the graph for each transaction Ti in the schedule. Each edge ei in
the graph is of the form (Tj → Tk ), 1 ≤ j ≤ n, 1 ≤ k f n, where Tj is the starting node of ei and
Tk is the ending node of ei. Such an edge from node Tj to node Tk is created by the algorithm
if one of the operations in Tj appears in the schedule before some conflicting operation in Tk.
Algorithm: Testing Conflict Serializability of a Schedule S
For each transaction Ti participating in schedule S, create a node labeled Ti in the
precedence graph.
For each case in S where Tj executes a read_item(X) after Ti executes a write_item(X),
create an edge (Ti → Tj) in the precedence graph.
For each case in S where Tj executes a write_item(X) after Ti executes a read_item(X),
create an edge (Ti → Tj) in the precedence graph.
For each case in S where Tj executes a write_item(X) after Ti executes a write_item(X),
create an edge (Ti → Tj) in the precedence graph.
The schedule S is serializable if and only if the precedence graph has no cycles; if there is no
cycle, S is serializable.
Advanced Database Systems Handout
Figure 3.5: (a) Precedence graph for serial schedule A; (b) Precedence graph for serial schedule B. (c)
Precedence graph for schedule C (not serializable). (d) Precedence graph for schedule D (serializable,
equivalent to schedule A).
The idea behind view equivalence is that, as long as each read operation of a trans-action reads
the result of the same write operation in both schedules, the write operations of each transaction
must produce the same results. The read operations are hence said to see the same view in both
schedules. A schedule S is said to be view serializable if it is view equivalent to a serial
schedule.
The definitions of conflict serializability and view serializability are similar if a condition
known as the constrained write assumption (or no blind writes) holds on all transactions in
the schedule. This condition states that any write operation wi(X) in Ti is preceded by a ri(X)
in Ti and that the value written by wi(X) in Ti depends only on the value of X read by ri(X).
This assumes that computation of the new value of X is a function f(X) based on the old value
of X read from the database. A blind write is a write operation in a transaction T on an item X
Advanced Database Systems Handout
that is not dependent on the value of X, so it is not preceded by a read of X in the transaction
T.
Conflict serializability is stricter than view serializability. With unconstrained write (or blind
write), a schedule that is view serializable is not necessarily conflict serializable. Any conflict
serializable schedule is also view serializable, but not vice versa.
The semantics of debit-credit operations is that they update the value of a data item X by
either subtracting from or adding to the value of the data item. Because addition and subtraction
operations are commutative—that is, they can be applied in any order—it is possible to produce
correct schedules that are not serializable.
The diagnostic area size option, DIAGNOSTIC SIZE n, specifies an integer value n,
which indicates the number of conditions that can be held simultaneously in the
diagnostic area. These conditions supply feedback information (errors or exceptions) to
the user or program on the n most recently executed SQL statement.
The isolation level option is specified using the statement: <isolation>, where the value
for <isolation> can be READ UNCOMMITTED, READ COMMITTED,
REPEATABLE READ, or SERIALIZABLE. The default isolation level is
SERIALIZABLE, although some systems use READ COMMITTED as their default.
The use of the term SERIALIZABLE here is based on not allowing violations that cause
dirty read, unrepeatable read, and phantoms.
Dirty read: A transaction T1 may read the update of a transaction T2, which has not yet
committed. If T2 fails and is aborted, then T1 would have read a value that does not exist and
is incorrect.
Nonrepeatable read: A transaction T1 may read a given value from a table. If another
transaction T2 later updates that value and T1 reads that value again, T1 will see a different
value.
Phantoms: A transaction T1 may read a set of rows from a table, perhaps based on some
condition specified in the SQL WHERE-clause. Now suppose that a transaction T2 inserts a
new row that also satisfies the WHERE-clause condition used in T1, into the table used by T1.
If T1 is repeated, then T1 will see a phantom, a row that previously did not exist.
Advanced Database Systems Handout