Unit 4 Oracle
Unit 4 Oracle
UNIT 4 ORACLE
Structure Page Nos.
4.0 Introduction 51
4.1 Objectives 52
4.2 Database Application Development Features 52
4.2.1 Database Programming
4.2.2 Database Extensibility
4.3 Database Design and Querying Tools 57
4.4 Overview of Oracle Architecture 50
4.4.1 Physical Database Structures
4.4.2 Logical Database Structures
4.4.3 Schemas and Common Schema Objects
4.4.4 Oracle Data Dictionary
4.4.5 Oracle Instance
4.4.6 Oracle Background Processes
4.4.7 How Oracle Works?
4.5 Query Processing and Optimisation 71
4.6 Distributed Oracle 75
4.6.1 Distributed Queries and Transactions
4.6.2 Heterogenous Services
4.7 Data Movement in Oracle 76
4.7.1 Basic Replication
4.7.2 Advanced Replication
4.7.3 Transportable Tablespaces
4.7.4 Advanced Queuing and Streams
4.7.5 Extraction, Transformation and Loading
4.8 Database Administration Tools 77
4.9 Backup and Recovery in Oracle 78
4.10 Oracle Lite 79
4.11 Scalability and Performance Features of Oracle 79
4.11.1 Concurrency
4.11.2 Read Consistency
4.11.3 Locking Mechanisms
4.11.4 Real Application Clusters
4.11.5 Portability
4.12 Oracle DataWarehousing 83
4.12.1 Extraction, Transformation and Loading (ETL)
4.12.2 Materialised Views
4.12.3 Bitmap Indexes
4.12.4 Table Compression
4.12.5 Parallel Execution
4.12.6 Analytic SQL
4.12.7 OLAP Capabilities
4.12.8 Data Mining
4.12.9 Partitioning
4.13 Security Features of Oracle 85
4.14 Data Integrity and Triggers in Oracle 86
4.15 Transactions in Oracle 87
4.16 SQL Variations and Extensions in Oracle 88
4.17 Summary 90
4.18 Solutions/Answers 91
4.0 INTRODUCTION
The relational database concept was first described by Dr. Edgar F. Codd in an IBM
research publication titled “System R4 Relational” which in 1970. Initially, it was
unclear whether any system based on this concept could achieve commercial success.
However, if we look back there have been many products, which support most of the
features of relational database models and much more. Oracle is one such product
51
Emerging Trends and that was created by Relational Software Incorporated (RSI) in 1977. They released
Example DBMS Oracle V.2 as the world’s first relational database within a couple of years. In 1983,
Architecture RSI was renamed Oracle Corporation to avoid confusion with a competitor named
RTI. During this time, Oracle developers made a critical decision to create a portable
version of Oracle (Version 3) that could run not only on Digital VAX/VMS systems,
but also on Unix and other platforms. Since the mid-1980s, the database deployment
model has evolved from dedicated database application servers to client/servers to
Internet computing implemented with PCs and thin clients accessing database
applications via browsers – and, to the grid with Oracle Database 10g.
4.1 OBJECTIVES
After going through this unit, you should be able to:
Year Feature
Oracle Release 2—the first commercially available relational database
1979
to use SQL.
Single code base for Oracle across multiple platforms, Portable toolset,
1980-1990 Client/server Oracle relational database, CASE and 4GL toolset, Oracle
Financial Applications built on relational database.
Oracle Parallel Server on massively parallel platform, cost-based
optimiser, parallel operations including query, load, and create index,
Universal database with extended SQL via cartridges, thin client, and
application server, Oracle 8 with inclusion of object-relational and Very
Large Database (VLDB) features, Oracle8i added a new twist to the
1991-2000
Oracle database – a combination of enhancements that made the
Oracle8i database the focal point of the world of Internet (the i in 8i)
computing.
Java Virtual Machine (JVM) was added into the database and Oracle
52
Oracle
Year Feature
tools were integrated in the middle tier.
Oracle9i Database Server is generally available: Real Application
2001
Clusters; OLAP and data mining API in the database.
However, in this section we will concentrate on the tools that are used to create
applications. We have divided the discussion in this section into two categories:
database programming and database extensibility options. Later in this unit, we will
describe the Oracle Developer Suite, a set of optional tools used in Oracle Database
Server and Oracle Application Server development.
SQL
All operations on the information in an Oracle database are performed using SQL
statements. A statement must be the equivalent of a complete SQL sentence, as in:
SELECT last_name, department_id FROM employees;
Only a complete SQL statement can run successfully. A SQL statement can be
thought of as a very simple, but powerful, computer instruction. SQL statements of
Oracle are divided into the following categories.
53
Emerging Trends and Session Control Statements: These statements let a user control the properties of the
Example DBMS current session, including enabling and disabling roles and changing language
Architecture settings. The two session control statements are ALTER SESSION and SET ROLE.
System Control Statements: These statements change the properties of the Oracle
database instance. The only system control statement is ALTER SYSTEM. It lets
users change settings, such as the minimum number of shared servers, kill a session,
and perform other tasks.
Datatypes
Each attribute and constant in a SQL statement has a datatype, which is associated
with a specific storage format, constraints, and a valid range of values. When you
create a table, you must specify a datatype for each of its columns.
An object type differs from native SQL datatypes in that it is user-defined, and it
specifies both the underlying persistent data (attributes) and the related behaviours
(methods). Object types are abstractions of real-world entities, for example, purchase
orders.
Object types and related object-oriented features, such as variable-length arrays and
nested tables, provide higher-level ways to organise and access data in the database.
Underneath the object layer, data is still stored in columns and tables, but you can
work with the data in terms of real-world entities – customers and purchase orders,
that make the data meaningful. Instead of thinking in terms of columns and tables
when you query the database, you can simply select a customer.
PL/SQL
PL/SQL is Oracle’s procedural language extension to SQL. PL/SQL combines the
ease and flexibility of SQL with the procedural functionality of a structured
programming language, such as IF, THEN, WHILE, and LOOP.
54
• Data access can be controlled by stored PL/SQL code. In this case, PL/SQL Oracle
users can access data only as intended by application developers, unless another
access route is granted.
• Oracle supports PL/SQL Server Pages, so the application logic can be invoked
directly from your Web pages.
The PL/SQL program units can be defined and stored centrally in a database. Program
units are stored procedures, functions, packages, triggers, and anonymous
transactions.
Procedures and functions are sets of SQL and PL/SQL statements grouped together as
a unit to solve a specific problem or to perform a set of related tasks. They are created
and stored in compiled form in the database and can be run by a user or a database
application. Procedures and functions are identical, except that all functions always
return a single value to the user. Procedures do not return values.
Packages encapsulate and store related procedures, functions, variables, and other
constructs together as a unit in the database. They offer increased functionality (for
example, global package variables can be declared and used by any procedure in the
package). They also improve performance (for example, all objects of the package are
parsed, compiled, and loaded into memory once).
Large Objects
Interest in the use of large objects (LOBs) continues to grow, particularly for storing
non-traditional data types such as images. The Oracle database has been able to store
large objects for some time. Oracle8 added the capability to store multiple LOB
columns in each table. Oracle Database 10g essentially removes the space limitation
on large objects.
Object-Oriented Programming
Support of object structures has been included since Oracle8i to allow an object-
oriented approach to programming. For example, programmers can create user-
defined data types, complete with their own methods and attributes. Oracle’s object
support includes a feature called Object Views through which object-oriented
programs can make use of relational data already stored in the database. You can also
store objects in the database as varying arrays (VARRAYs), nested tables, or index
organised tables (IOTs).
55
Emerging Trends and Third-Generation Languages (3GLs)
Example DBMS
Architecture Programmers can interact with the Oracle database from C, C++, Java, COBOL, or
FORTRAN applications by embedding SQL in those applications. Prior to compiling
applications using a platform’s native compilers, you must run the embedded SQL
code through a precompiler. The precompiler replaces SQL statements with library
calls the native compiler can accept. Oracle provides support for this capability
through optional “programmer” precompilers for languages such as C and C++
(Pro*C) and COBOL (Pro*COBOL). More recently, Oracle added SQLJ, a
precompiler for Java that replaces SQL statements embedded in Java with calls to a
SQLJ runtime library, also written in Java.
Database Drivers
All versions of Oracle include database drivers that allow applications to access
Oracle via ODBC (the Open DataBase Connectivity standard) or JDBC (the Java
DataBase Connectivity open standard). Also available are data providers for OLE DB
and for .NET.
56
Oracle interMedia bundles additional image, audio, video, and locator functions and is Oracle
included in the database license. Oracle interMedia offer the following capabilities:
• The image portion of interMedia can store and retrieve images.
• The audio and video portions of interMedia can store and retrieve audio and
video clips, respectively.
• The locator portion of interMedia can retrieve data that includes spatial
coordinate information.
XML
Oracle added native XML data type support to the Oracle9i database and XML and
SQL interchangeability for searching. The structured XML object is held natively in
object relational storage meeting the W3C DOM specification. The XPath syntax for
searching in SQL is based on the SQLX group specifications.
SQL*Plus
SQL*Plus is an interactive and batch query tool that is installed with every Oracle
Database Server or Client installation. It has a command-line user interface, a
Windows Graphical User Interface (GUI) and the iSQL*Plus web-based user
interface.
SQL*Plus has its own commands and environment, and it provides access to the
Oracle Database. It enables you to enter and execute SQL, PL/SQL, SQL*Plus and
operating system commands to perform the following:
• format, perform calculations on, store, and print from query results,
• examine table and object definitions,
• develop and run batch scripts, and
• perform database administration.
You can use SQL*Plus to generate reports interactively, to generate reports as batch
processes, and to output the results to text file, to screen, or to HTML file for
browsing on the Internet. You can generate reports dynamically using the HTML
output facility of SQL*Plus, or using the dynamic reporting capability of iSQL*Plus
to run a script from a web page.
Oracle JDeveloper
Oracle Designer
The designer also include generators for creating applications for Oracle Developer,
HTML clients using Oracle’s Application Server, and C++. Designer can generate
applications and reverse-engineer existing applications or applications that have been
modified by developers. This capability enables a process called round-trip
engineering, in which a developer uses Designer to generate an application, modifies
the generated application, and reverse-engineers the changes back into the Designer
repository.
Oracle Discoverer
58
Oracle Discoverer Administration Edition enables administrators to set up and Oracle
maintain the Discoverer End User Layer (EUL). The purpose of this layer is to shield
business analysts using Discoverer as an ad hoc query or ROLAP tool from SQL
complexity. Wizards guide the administrator through the process of building the EUL.
In addition, administrators can put limits on resources available to analysts monitored
by the Discoverer query governor.
Oracle Portal
Oracle Portal, introduced as WebDB in 1999, provides an HTML-based tool for
developing web-enabled applications and content-driven web sites. Portal application
systems are developed and deployed in a simple browser environment. Portal includes
wizards for developing application components incorporating “servlets” and access to
other HTTP web sites. For example, Oracle Reports and Discoverer may be accessed
as servlets. Portals can be designed to be user-customisable. They are deployed to the
middle-tier Oracle Application Server.
Oracle Portal has enhanced the WebDB, with the ability to create and use portlets,
which allow a single web page to be divided into different areas that can
independently display information and interact with the user.
Datafiles
Every Oracle database has one or more physical datafiles. The datafiles contain all the
database data. The data of logical database structures, such as tables and indexes, is
physically stored in the datafiles allocated for a database.
The characteristics of datafiles are:
• a datafile can be associated with only one database,
60
• datafiles can have certain characteristics set to let them automatically extend Oracle
when the database runs out of space,
• one or more datafiles form a logical unit of database storage called a tablespace.
Data in a datafile is read, as needed, during normal database operation and stored in
the memory cache of Oracle. For example, assume that a user wants to access some
data in a table of a database. If the requested information is not already in the memory
cache for the database, then it is read from the appropriate datafiles and stored in the
memory.
Control Files
Every Oracle database has a control file. A control file contains entries that specify the
physical structure of the database. For example, it contains the following information:
• database name,
• names and locations of datafiles and redo log files, and
• time stamp of database creation.
Oracle can multiplex the control file, that is, simultaneously maintain a number of
identical control file copies, to protect against failure involving the control file.
Every time an instance of an Oracle database is started, its control file identifies the
database and redo log files that must be opened for database operation to proceed. If
the physical makeup of the database is altered (for example, if a new datafile or redo
log file is created), then the control file is automatically modified by Oracle to reflect
the change. A control file is also used in database recovery.
The primary function of the redo log is to record all changes made to the data. If a
failure prevents modified data from being permanently written to the datafiles, then
the changes can be obtained from the redo log, so work is never lost. To protect
against a failure involving the redo log itself, Oracle allows a multiplexed redo log so
that two or more copies of the redo log can be maintained on different disks.
The information in a redo log file is used only to recover the database from a system
or media failure that prevents database data from being written to the datafiles. For
example, if an unexpected power shortage terminates database operation, then the data
in the memory cannot be written to the datafiles, and the data is lost. However, lost
data can be recovered when the database is opened, after power is restored. By
applying the information in the most recent redo log files to the database datafiles,
Oracle restores the database to the time when the power failure had occurred. The
process of applying the redo log during a recovery operation is called rolling forward.
Parameter Files
61
Emerging Trends and Parameter files contain a list of configuration parameters for that instance and
Example DBMS database.
Architecture
Oracle recommends that you create a server parameter file (SPFILE) as a dynamic
means of maintaining initialisation parameters. A server parameter file lets you store
and manage your initialisation parameters persistently in a server-side disk file.
The alert file, or alert log, is a special trace file. The alert file of a database is a
chronological log of messages and errors.
Backup Files
To restore a file is to replace it with a backup file. Typically, you restore a file when a
media failure or user error has damaged or deleted the original file.
User-managed backup and recovery requires you to actually restore backup files
before a trial recovery of the backups can be attempted/performed.
Tablespaces
A database is divided into logical storage units called tablespaces, which group related
logical structures together. For example, tablespaces commonly group together all
application objects to simplify administrative operations.
Each database is logically divided into one or more tablespaces. One or more datafiles
are explicitly created for each tablespace to physically store the data of all logical
structures in a tablespace. The combined size of the datafiles in a tablespace is the
total storage capacity of the tablespace. Every Oracle database contains a SYSTEM
tablespace and a SYSAUX tablespace. Oracle creates them automatically when the
database is created. The system default is to create a smallfile tablespace, which is the
traditional type of Oracle tablespace. The SYSTEM and SYSAUX tablespaces are
created as smallfile tablespaces.
Oracle also lets you create bigfile tablespaces up to 8 exabytes (8 million terabytes) in
size. With Oracle-managed files, bigfile tablespaces make datafiles completely
transparent for users. In other words, you can perform operations on tablespaces,
rather than on the underlying datafiles.
62
sometimes a tablespace is offline, in order to make a portion of the database Oracle
unavailable while allowing normal access to the remainder of the database. This
makes many administrative tasks easier to perform.
Extents
The next level of logical database space is an extent. An extent is a specific number of
contiguous data blocks, obtained in a single allocation, used to store a specific type of
information.
Segments
Next, is the segment, or the level of logical database storage. A segment is a set of
extents allocated for a certain logical structure. The following table describes the
different types of segments.
Segment Description
Data Each non-clustered table has a data segment. All table data is stored in
segment the extents of the data segment.
For a partitioned table, each partition has a data segment.
Each cluster has a data segment. The data of every table in the cluster is
stored in the cluster’s data segment.
Index Each index has an index segment that stores all of its data.
segment For a partitioned index, each partition has an index segment.
Temporary Temporary segments are created by Oracle when a SQL statement needs
segment a temporary database area to complete execution. When the statement
has been executed, the extents in the temporary segment are returned to
the system for future use.
Rollback If you are operating in automatic undo management mode, then the
segment database server manages undo space-using tablespaces. Oracle
recommends that you use automatic undo management.
Space management for these rollback segments was complex, and not
done that way. Oracle uses the undo tablespace method of managing
undo; this eliminates the complexities of managing rollback segment
space.
63
Emerging Trends and Segment Description
Example DBMS
Architecture transactions. There is only one SYSTEM rollback segment and it is
created automatically at CREATE DATABASE time and is always
brought online at instance startup. You are not required to perform any
operation to manage the SYSTEM rollback segment.
Oracle dynamically allocates space when the existing extents of a segment become
full. In other words, when the extents of a segment are full, Oracle allocates another
extent for that segment. Because extents are allocated as needed, the extents of a
segment may or may not be contiguous on a disk.
Tables
Tables are the basic unit of data storage in an Oracle database. Database tables hold all
user-accessible data. Each table has columns and rows.
Indexes
Indexes are optional structures associated with tables. Indexes can be created to
increase the performance of data retrieval. An index provides an access path to table
data.
When processing a request, Oracle may use some or all of the available indexes in
order to locate, the requested rows efficiently. Indexes are useful when applications
frequently query a table for a range of rows (for example, all employees with salaries
greater than 1000 dollars) or a specific row.
An index is automatically maintained and used by the DBMS. Changes to table data
(such as adding new rows, updating rows, or deleting rows) are automatically
incorporated into all relevant indexes with complete transparency to the users. Oracle
uses B-trees to store indexes in order to speed up data access.
An index in Oracle can be considered as an ordered list of the values divided into
block-wide ranges (leaf blocks). The end points of the ranges along with pointers to
the blocks can be stored in a search tree and a value in log(n) time for n entries could
be found. This is the basic principle behind Oracle indexes.
The following Figure 2 illustrates the structure of a B-tree index.
64
Oracle
The upper blocks (branch blocks) of a B-tree index contain index data that points to
lower-level index blocks. The lowest level index blocks (leaf blocks) contains every
indexed data value and a corresponding rowid used to locate the actual row. The leaf
blocks are doubly linked. Indexes in columns containing character data are based on
the binary values of the characters in the database character set.
If the blocks have n keys then they have n+1 pointers. The number of keys and
pointers is limited by the block size.
Leaf Blocks: All leaf blocks are at the same depth from the root branch block. Leaf
blocks store the following:
• the complete key value for every row, and
• ROWIDs of the table rows
All key and ROWID pairs are linked to their left and right siblings. They are sorted by
(key, ROWID).
Views
Views are customised presentations of data in one or more tables or other views. A
view can also be considered as a stored query. Views do not actually contain data.
Rather, they derive their data from the tables on which they are based, (referred to as
the base tables of the views). Views can be queried, updated, inserted into, and deleted
from, with some restrictions.
65
Emerging Trends and
Example DBMS Views provide an additional level of table security by restricting access to a pre-
Architecture determined set of rows and columns of a table. They also hide data complexity and
store complex queries.
Clusters
Clusters are groups of one or more tables physically stored together because they
share common columns and are often used together. Since related rows are physically
stored together, disk access time improves.
Like indexes, clusters do not affect application design. Whether a table is part of a
cluster is transparent to users and to applications. Data stored in a clustered table is
accessed by SQL in the same way as data stored in a non-clustered table.
Synonyms
A synonym is an alias for any table, view, materialised view, sequence, procedure,
function, package, type, Java class schema object, user-defined object type, or another
synonym. Because a synonym is simply an alias, it requires no storage other than its
definition in the data dictionary.
A data dictionary is created when a database is created. To accurately reflect the status
of the database at all times, the data dictionary is automatically updated by Oracle in
response to specific actions, (such as, when the structure of the database is altered).
The database relies on the data dictionary to record, verify, and conduct on-going
work. For example, during database operation, Oracle reads the data dictionary to
verify that schema objects exist and that users have proper access to them.
66
Oracle creates and uses memory structures to complete several jobs. For example, Oracle
memory stores program code being run and data shared among users. Two basic
memory structures associated with Oracle are: the system global area and the program
global area. The following subsections explain each in detail.
Users currently connected to an Oracle database share the data in the SGA. For
optimal performance, the entire SGA should be as large as possible (while still fitting
in to the real memory) to store as much data in memory as possible and to minimise
disk I/O.
The information stored in the SGA is divided into several types of memory structures,
including the database buffers, redo log buffer, and the shared pool.
67
Emerging Trends and The Program Global Area (PGA) is a memory buffer that contains data and control
Example DBMS information for a server process. A PGA is created by Oracle when a server process is
Architecture started. The information in a PGA depends on the configuration of Oracle.
The architectural features discussed in this section enables the Oracle database to
support:
• many users concurrently accessing a single database, and
• the high performance required by concurrent multiuser, multiapplication
database systems.
Oracle creates a set of background processes for each instance. The background
processes consolidate functions that would otherwise be handled by multiple Oracle
programs running for each user process. They asynchronously perform I/O and
monitor other Oracle processes to provide increased parallelism for better
performance and reliability. There are numerous background processes, and each
Oracle instance can use several background processes.
Process Architecture
A process is a “thread of control” or a mechanism in an operating system that can run
a series of steps. Some operating systems use the terms job or task. A process
generally has its own private memory area in which it runs. An Oracle database server
has two general types of processes: user processes and Oracle processes.
Oracle Processes
Oracle processes are invoked by other processes to perform functions on behalf of the
invoking process. Oracle creates server processes to handle requests from connected
user processes. A server process communicates with the user process and interacts
with Oracle to carry out requests from the associated user process. For example, if a
user queries some data not already in the database buffers of the SGA, then the
associated server process reads the proper data blocks from the datafiles into the SGA.
Oracle can be configured to vary the number of user processes for each server process.
In a dedicated server configuration, a server process handles requests for a single user
process. A shared server configuration lets many user processes share a small number
of server processes, minimising the number of server processes and maximising the
use of available system resources.
On some systems, the user and server processes are separate, while on others they are
combined into a single process. If a system uses the shared server or if the user and
server processes run on different machines, then the user and server processes must be
separate. Client/server systems separate the user and server processes and run them on
different machines.
68
Oracle
Let us discuss a few important process briefly next.
• If Oracle needs to read blocks requested by users into the cache and there is no
free space in the buffer cache. The blocks written out are the least recently used
blocks. Writing blocks in this order minimises the performance impact of losing
them from the buffer cache.
The Process Monitor process watches over the user processes that access the database.
If a user process terminates abnormally, PMON is responsible for cleaning up any of
the resources left behind (such as memory) and for releasing any locks held by the
failed process.
Archiver (ARC)
The Archiver process reads the redo log files once Oracle has filled them and writes a
copy of the used redo log files to the specified archive log destination(s).
69
Emerging Trends and The Checkpoint process works with DBWR to perform checkpoints. CKPT updates
Example DBMS the control file and database file headers to update the checkpoint data when the
Architecture checkpoint is complete.
Recover (RECO)
The Recover process automatically cleans up failed or suspended distributed
transactions.
1) An instance has started on the computer running Oracle (often called the host or
database server).
3) The server is running the proper Oracle Net Services driver. The server detects
the connection request from the application and creates a dedicated server
process on behalf of the user process.
4) The user runs a SQL statement and commits the transaction. For example, the
user changes a name in a row of a table.
5) The server process receives the statement and checks the shared pool for any
shared SQL area that contains a similar SQL statement. If a shared SQL area is
found, then the server process checks the user’s access privileges to the
requested data, and the previously existing shared SQL area is used to process
the statement. If not, then a new shared SQL area is allocated for the statement,
so it can be parsed and processed.
6) The server process retrieves any necessary data values from the actual datafile
(table) or those stored in the SGA.
7) The server process modifies data in the system global area. The DBWn process
writes modified blocks permanently to the disk when doing so is efficient.
Since, the transaction is committed, the LGWR process immediately records the
transaction in the redo log file.
8) If the transaction is successful, then the server process sends a message across
the network to the application. If it is not successful, then an error message is
transmitted.
9) Throughout this entire procedure, the other background processes run, watching
for conditions that require intervention. In addition, the database server manages
other users’ transactions and prevents contention between transactions that
request the same data.
70
Oracle
4.5 QUERY PROCESSING AND OPTIMISATION
This section provides the various stages of the execution of a SQL statement in each
stage of DML statement processing. The following stages are necessary for each type
of statement processing:
71
Emerging Trends and
Example DBMS
Architecture
Oracle parses a SQL statement only if a shared SQL area for a similar SQL statement
does not exist in the shared pool. In this case, a new-shared SQL area is allocated, and
the statement is parsed.
The parse stage includes processing requirements that need to be done only once, no
matter, how many times the statement is executed. Oracle translates each SQL
statement only once, re-executing that parsed statement during subsequent references
to the statement.
Although parsing a SQL statement validates that statement, parsing only identifies
errors that can be found before the execution of the statement. Thus, some errors
cannot be caught by parsing. For example, errors in data conversion or errors in data
(such as an attempt to enter duplicate values in a primary key) and deadlocks are all
errors or situations that can be encountered and reported only during the execution
stage.
Note: Queries are different from other types of SQL statements because, if successful,
they return data as results. Whereas, other statements simply return success or failure,
for instance, a query can return one row or thousands of rows. The results of a query
are always in tabular format, and the rows of the result are fetched (retrieved), either a
row at a time or in groups.
Several issues are related only to query processing. Queries include not only explicit
SELECT statements but also the implicit queries (subqueries) in other SQL
statements. For example, each of the following statements, require a query as a part of
its execution:
INSERT INTO table SELECT...
73
Emerging Trends and In the define stage of a query, you specify the location, size, and datatype of variables
Example DBMS defined to receive each fetched value. Oracle performs datatype conversion if
Architecture necessary.
Stage 5: Bind any Variables
At this point, Oracle knows the meaning of the SQL statement but still does not have
enough information to execute the statement. Oracle needs values for any variables
listed in the statement; for example, Oracle needs a value for DEPT_NUMBER. The
process of obtaining these values is called binding variables.
A program must specify the location (memory address) of the value. End users of
applications may be unaware that they are specifying bind variables, because the
Oracle utility can simply prompt them for a new value.
Because you specify the location (binding by reference), you need not rebind the
variable before re-execution. You can change its value and Oracle will look up the
value on each execution, using the memory address.
You must also specify a datatype and length for each value (unless they are implied or
defaulted) in order for Oracle to perform datatype conversions.
For some statements you can specify a number of executions to be performed. This is
called array processing. Given n number of executions, the bind and define locations
are assumed to be the beginning of an array of size n.
Stage 8: Fetch Rows of a Query
In the fetch stage, rows are selected and ordered (if requested by the query), and each
successive fetch retrieves another row of the result until the last row has been fetched.
Stage 9: Close the Cursor
The final stage of processing a SQL statement is closing the cursor.
Query Optimisation
An important facet of database system performance tuning is the tuning of SQL
statements. SQL tuning involves three basic steps:
• Identifying high load or top SQL statements that are responsible for a large
share of the application workload and system resources, by reviewing past SQL
execution history available in the system.
• Verifying that the execution plans produced by the query optimiser for these
statements perform reasonably.
74
• Implementing corrective actions to generate better execution plans for poorly Oracle
performing SQL statements.
These three steps are repeated until the system performance reaches a satisfactory
level or no more statements can be tuned.
A SQL statement can be executed in many different ways, such as full table scans,
index scans, nested loops, and hash joins. The Oracle query optimiser determines the
most efficient way to execute a SQL statement after considering many factors related
to the objects referenced and the conditions specified in the query. This determination
is an important step in the processing of any SQL statement and can greatly affect
execution time.
The query optimiser determines most efficient execution plan by considering available
access paths and by factoring in information based on statistics for the schema objects
(tables or indexes) accessed by the SQL statement. The query optimiser also considers
hints, which are optimisation suggestions placed in a comment in the statement.
2) The optimiser estimates the cost of each plan based on statistics in the data
dictionary for data distribution and storage characteristics of the tables, indexes,
and partitions accessed by the statement.
The cost is an estimated value proportional to the expected resource use needed
to execute the statement with a particular plan. The optimiser calculates the cost
of access paths and join orders based on the estimated computer resources,
which includes I/O, CPU, and memory.
Serial plans with higher costs take more time to execute than those with lesser
costs. When using a parallel plan, however, resource use is not directly related
to elapsed time.
3) The optimiser compares the costs of the plans and chooses the one with the
lowest cost.
76
4.7.3 Transportable Tablespaces Oracle
Oracle messaging adds the capability to develop and deploy a content-based publish
and subscribe solution using the rules engine to determine relevant subscribing
applications. As new content is published to a subscriber list, the rules on the list
determine which subscribers should receive the content. This approach means that a
single list can efficiently serve the needs of different subscriber communities.
In the first release of Oracle9i, AQ added XML support and Oracle Internet Directory
(OID) integration. This technology is leveraged in Oracle Application Interconnect
(OAI), which includes adapters to non-Oracle applications, messaging products, and
databases.
The second release of Oracle9i introduced Streams. Streams have three major
components: log-based replication for data capture, queuing for data staging, and user-
defined rules for data consumption. Oracle Database 10g includes support for change
data capture and file transfer solutions via Streams.
77
Emerging Trends and information about the Oracle environment. EM can also manage Oracle’s Application
Example DBMS Server, Collaboration Suite, and E-Business Suite.
Architecture
Prior to the Oracle8i database, the EM software was installed on Windows-based
systems. Each repository was accessible only by a single database manager at a time.
EM evolved to a Java release providing access from a browser or Windows-based
system. Multiple database administrators could then access the EM repository at the
same time.
More recently, an EM HTML console was released with Oracle9iAS. This console has
important new application performance management and configuration management
features. The HTML version supplemented the Java-based Enterprise Manager earlier
available. Enterprise Manager 10g, released with Oracle Database 10g, also comes in
Java and HTML versions. EM can be deployed in several ways: as a central console
for monitoring multiple databases leveraging agents, as a “product console” (easily
installed with each individual database), or through remote access, also known as
“studio mode”. The HTML-based console includes advanced management capabilities
for rapid installation, deployment across grids of computers, provisioning, upgrades,
and automated patching.
Oracle Enterprise Manager 10g has several additional options (sometimes called
packs) for managing the Oracle Enterprise Edition database. These options, which are
available for the HTML-based console, the Java-based console, or both, include:
• Database Diagnostics Option
• Application Server Diagnostics Option
• Database Tuning Option
• Database Change Management Option
• Database Configuration Management Option
• Application Server Configuration Management Option.
Standard management pack functionality for managing the Standard Edition is now
also available for the HTML-based console.
Recovery Manager
Typical backups include complete database backups (the most common type),
tablespace backups, datafile backups, control file backups, and archived redo log
backups. Oracle8 introduced the Recovery Manager (RMAN) for server-managed
backup and recovery of the database. Previously, Oracle’s Enterprise Backup Utility
(EBU) provided a similar solution on some platforms. However, RMAN, with its
Recovery Catalogue we stored in an Oracle database, provides a much more complete
solution. RMAN can automatically locate, back up, restore, and recover datafiles,
control files, and archived redo logs. RMAN, since Oracle9i, can restart backups,
restore and implement recovery window policies when backups expire. The Oracle
Enterprise Manager Backup Manager provides a GUI-based interface to RMAN.
Oracle Enterprise Manager 10g introduces a new improved job scheduler that can be
used with RMAN and other scripts, and that can manage automatic backups to disk.
78
Incremental Backup and Recovery Oracle
Oracle Storage Manager and Automated Disk Based Backup and Recovery
Various media-management software vendors support RMAN. Since Oracle8i, a
Storage Manager has been developed with Oracle to provide media-management
services, including the tracking of tape volumes, for up to four devices. RMAN
interfaces automatically with the media-management software to request the mounting
of tapes as needed for backup and recovery operations.
Oracle Database 10g introduces Automated Disk Based Backup and Recovery. The
disk acts as a cache, and archives and backups can then be copied to tape. The disk
“cache” can also serve as a staging area for recovery.
Although the Oracle Lite Database engine runs on a much smaller platform than other
Oracle implementations (it requires a 50K to 1 MB footprint depending on the
platform), Mobile SQL, C++, and Java-based applications can run against the
database. ODBC is therefore, supported. Java support includes Java stored procedures
and JDBC. The database is self-tuning and self-administering. In addition to
Windows-based laptops, Oracle Lite also supports for handheld devices running on
WindowsCE, Palm’s Computing Platform, and Symbian EPOC.
• Data must be read and modified in a consistent fashion. The data a user is
viewing or changing is not changed (by other users) until the user is finished
with the data.
• High performance is required for maximum productivity from the many users
of the database system.
4.11.1 Concurrency
A primary concern of a multiuser database management system is controlling
concurrency, which is the simultaneous access of the same data by many users.
Without adequate concurrency controls, data could be updated or changed improperly,
compromising data integrity.
79
Emerging Trends and One way to manage data concurrency is to make each user wait for a turn. The goal of
Example DBMS a database management system is to reduce that wait so it is either nonexistent or
Architecture negligible to each user. All data manipulation language statements should proceed
with as little interference as possible, and undesirable interactions among concurrent
transactions must be prevented. Neither performance nor data integrity can be
compromised.
Oracle resolves such issues by using various types of locks and a multiversion
consistency model. These features are based on the concept of a transaction. It is the
application designer’s responsibility to ensure that transactions fully exploit these
concurrency and consistency features.
• Guarantees that the set of data seen by a statement is consistent with respect to a
single point in time and does not change during statement execution (statement-
level read consistency).
• Ensures that readers of database data do not wait for writers or other readers of
the same data.
• Ensures that writers of database data do not wait for readers of the same data.
• Ensures that writers only wait for other writers if they attempt to update
identical rows in concurrent transactions.
Only when a transaction is committed are the changes of the transaction made
permanent. Statements that start after the user’s transaction is committed only see the
changes made by the committed transaction.
Transaction is the key to Oracle’s strategy for providing read consistency. This unit of
committed (or uncommitted) SQL statements dictates the start point for read-
consistent views generated on behalf of readers and controls modified data can be
seen by other transactions of the time span when, database for reading or updating.
80
Oracle also uses locks to control concurrent access to data. When updating Oracle
information, the data server holds that information with a lock, until, the update is
submitted or committed. Until that happens, no one else can make changes to the
locked information. This ensures the data integrity of the system.
Oracle provides unique non-escalating row-level locking. Unlike other data servers
that “escalate” locks to cover entire groups of rows or even the entire table, Oracle
always locks only the row of information being updated. Because Oracle includes the
locking information with the actual rows themselves, Oracle can lock an unlimited
number of rows so users can work concurrently without unnecessary delays.
Automatic Locking
Oracle locking is performed automatically and requires no user action. Implicit
locking occurs for SQL statements as necessary, depending on the action requested.
Oracle’s lock manager automatically locks table data at the row level. By locking
table data at the row level, contention for the same data is minimised.
Oracle’s lock manager maintains several different types of row locks, depending on
the type of operation that established the lock. The two general types of locks are:
exclusive locks and share locks. Only one exclusive lock can be placed on a resource
(such as a row or a table); however, many share locks can be placed on a single
resource. Both exclusive and share locks always allow queries on the locked resource
but prohibit other activity on the resource (such as updates and deletes).
Manual Locking
Under some circumstances, a user might want to override default locking. Oracle
allows manual override of automatic locking features at both the row level (by first
querying for the rows that will be updated in a subsequent statement) and the table
level.
You can scale applications in RAC environments to meet increasing data processing
demands without changing the application code. As you add resources such as nodes
or storage, RAC extends the processing powers of these resources beyond the limits of
the individual components.
4.11.5 Portability
Oracle provides unique portability across all major platforms and ensures that your
applications run without modification after changing platforms. This is because the
Oracle code base is identical across platforms, so you have identical feature
functionality across all platforms, for complete application transparency. Because of
this portability, you can easily upgrade to a more powerful server as your
requirements change.
82
In addition to a relational database, a data warehouse environment includes an Oracle
extraction, transportation, transformation, and loading (ETL) solution, an online
analytical processing (OLAP) engine, client analysis tools, and other applications that
manage the process of gathering data and delivering it to business users.
Materialised views are stored in the same database as their base tables can improve
query performance through query rewrites. Query rewrites are particularly useful in a
data warehouse environment.
Fully indexing a large table with a traditional B-tree index can be prohibitively
expensive in terms of space because the indexes can be several times larger than the
data in the table. Bitmap indexes are typically only a fraction of the size of the
indexed data in the table.
Oracle OLAP provides the query performance and calculation capability, previously
found only in multidimensional databases to Oracle’s relational platform. In addition,
it provides a Java OLAP API that is appropriate for the development of internet-ready
analytical applications. Unlike other combinations of OLAP and RDBMS technology,
Oracle OLAP is not a multidimensional database using bridges to move data from the
relational data store to a multidimensional data store. Instead, it is truly an OLAP-
enabled relational database. As a result, Oracle provides the benefits of a
multidimensional database along with the scalability, accessibility, security,
manageability, and high availability of the Oracle database. The Java OLAP API,
which is specifically designed for internet-based analytical applications, offers
productive data access.
4.12.9 Partitioning
Partitioning addresses key issues in supporting very large tables and indexes by letting
you decompose them into smaller and more manageable pieces called partitions. SQL
queries and DML statements do not need to be modified in order to access partitioned
tables. However, after partitions are defined, DDL statements can access and
manipulate individual partitions rather than entire tables or indexes. This is how
partitioning can simplify the manageability of large database objects. Also,
partitioning is entirely transparent to applications.
Associated with each database user is a schema by the same name. By default, each
database user creates and has access to all objects in the corresponding schema.
Database security can be classified into two categories: system security and data
security.
System security includes mechanisms that control the access and use of the database
at the system level. For example, system security includes:
• valid user name/password combinations,
• the amount of disk space available to a user’s schema objects, and
• the resource limits for a user.
Data security includes mechanisms that control the access and use of the database at
the schema object level. For example, data security includes:
• users with access to a specific schema object and the specific types of actions
permitted to each user on the schema object (for example, user MOHAN can
issue SELECT and INSERT statements but not DELETE statements using the
employees table),
• the actions, if any, that are audited for each schema object, and
• data encryption to prevent unauthorised users from bypassing Oracle and
accessing the data.
Security Mechanisms
The Oracle database provides discretionary access control, which is a means of
restricting access to information based on privileges. The appropriate privilege must
be assigned to a user in order for that user to access a schema object. Appropriately
privileged users can grant other users privileges at their discretion.
85
Emerging Trends and application. Oracle provides integrity constraints and database triggers to manage data
Example DBMS integrity rules.
Architecture
Database triggers let you define and enforce integrity rules, but a database trigger is
not the same as an integrity constraint. Among other things, a database trigger does
not check data already loaded into a table. Therefore, it is strongly recommended that
you use database triggers only when the integrity rule cannot be enforced by integrity
constraints.
Integrity Constraints
An integrity constraint is a declarative way to define a business rule for a column of a
table. An integrity constraint is a statement about table data that is always true and
that follows these rules:
• If an integrity constraint is created for a table and some existing table data does
not satisfy the constraint, then the constraint cannot be enforced.
Keys
Key is used to define several types of integrity constraints. A key is the column or set
of columns included in the definition of certain types of integrity constraints. Keys
describe the relationships between the different tables and columns of a relational
database. Individual values in a key are called key values.
The different types of keys include:
• Primary key: The column or set of columns included in the definition of a
table’s PRIMARY KEY constraint. A primary key’s value uniquely identifies
the rows in a table. Only one primary key can be defined for each table.
• Referenced key: The unique key or primary key of the same or a different table
referenced by a foreign key.
86
Triggers Oracle
Triggers are procedures written in PL/SQL, Java, or C that run (fire) implicitly,
whenever a table or view is modified or when some user actions or database system
action occurs.
Transactions let users guarantee consistent changes to data, as long as the SQL
statements within a transaction are grouped logically. A transaction should consist of
all necessary parts for one logical unit of work – no more and no less. Data in all
referenced tables are in a consistent state before the transaction begins and after it
ends. Transactions should consist of only SQL statements that make one consistent
change to the data.
Consider a banking database. When a bank customer transfers money from a savings
account to a checking account, the transaction can consist of three separate operations:
decrease in the savings account, increase in the checking account, and recording the
transaction in the transaction journal.
The transfer of funds (the transaction) includes increasing one account (one SQL
statement), decreasing another account (one SQL statement), and recording the
transaction in the journal (one SQL statement). All actions should either fail or
succeed together; the credit should not be committed without the debit. Other non-
related actions, such as a new deposit to one account, should not be included in the
transfer of funds transaction. Such statements should be in other transactions.
Oracle must guarantee that all three SQL statements are performed to maintain
accounts accurately. When something prevents one of the statements in the transaction
from running (such as a hardware failure), then the other statements of the transaction
must be undone. This is called rolling back. If an error occurs in making any of the
updates, then no updates are made.
To commit, a transaction makes permanent the changes resulting from all SQL
statements in the transaction. The changes made by the SQL statements of a
transaction become visible to other user sessions’ transactions that start only after the
transaction is committed.
To undo a transaction, retracts, any of the changes resulting from the SQL statements
in the transaction. After a transaction is rolled back, the affected data is left
unchanged, as if the SQL statements in the transaction were never run.
Savepoints
87
Emerging Trends and Savepoints divide a long transaction with many SQL statements into smaller parts.
Example DBMS With savepoints, you can arbitrarily mark your work at any point within a long
Architecture transaction. This gives you the option of later rolling back all work performed from
the current point in the transaction to a declared savepoint within the transaction.
• RETURN statement.
Oracle’s triggers differ from the standard as follows:
• Oracle does not provide the optional syntax FOR EACH STATEMENT for the
default case, the statement trigger.
• Oracle does not support OLD TABLE and NEW TABLE; the transition tables
specified in the standard (the multiset of before and after images of affected
rows) are not available.
• The trigger body is written in PL/SQL, which is functionally equivalent to the
standard’s procedural language PSM, but not the same.
88
• In the trigger body, the new and old transition variables are referenced Oracle
beginning with a colon.
• Oracle’s row triggers are executed as the row is processed, instead of buffering
them and executing all of them after processing all rows. The standard’s
semantics are deterministic, but Oracle’s in-flight row triggers are more
performant.
• Oracle’s before row and before-statement triggers may perform DML
statements, which is forbidden in the standard. On the other hand, Oracle’s
after-row statements may not perform DML, while it is permitted in the
standard.
• When multiple triggers apply, the standard says they are executed in order of
definition; in Oracle the execution order is non-deterministic.
In addition to traditional structured data, Oracle is capable of storing, retrieving, and
processing more complex data.
• Object types, collection types, and REF types provide support for complex
structured data. A number of standard-compliant multiset operators are now
supported by the nested table collection type.
• Large objects (LOBs) provide support for both character and binary
unstructured data. A single LOB reach a size of 8 to 128 terabytes, depending
on the size of the database block.
• The XML datatype provides support for semistructured XML data.
89