Вы находитесь на странице: 1из 31

Oracle Architecture 2.

2. Oracle Architecture
Major components of Oracle
architecture
Major architectural differences
between Oracle and Sybase

2002 SkillBuilders, Inc.


SKILLBUILDERS

Objectives
Sybase, and most other relational databases, calls its collection of objects and data
a database. Oracle calls its collection of objects and data a database instance.
Thats because Oracle distinguishes between the data on disk (the database) and
the memory and background processes (the instance) needed to access/update
that data.

Sybase also has a different (though related) definition of segment then Oracles
definition, which will be explained shortly.

Along with other differences, the Sybase-trained Oracle student must distinguish
between the differing Sybase and Oracle definitions for terms, so as not to get
confused by directly comparing such terms.

2002 SkillBuilders, Inc. V1.0.0


Oracle Architecture 2.2

2.2
2.2

Instance and Database...


An instance allows access to the database

COMPUTER
USERS

INSTANCE
(SGA &
DATABASE
PROCESSES)

2002 SkillBuilders, Inc.

A picture is worth a thousand words. Here we see that in order to access the
database, we must have an instance started.

Note that an instance provides access to one database (an instance cannot
access more than one database). However, a single database can be accessed
by more than one instance; this is accomplished by using the Oracle Parallel
Server (OPS) architecture in Oracle releases prior to Oracle9i and is accomplished
by using Real Application Clusters (RAC) in Oracle9i and later.

Note also that a single computer can run more than one instance, or more than
one database/instance. (A single machine running more than one instance is
typically a unit testing computer in the development environment. A production
database/instance normally runs on a dedicated machine.)

2002 SkillBuilders, Inc. V1.0.0


Oracle Architecture 2.3

2.3
2.3

...Instance and Database

2002 SkillBuilders, Inc.

Now that we have a glimmer of what an Oracle instance and an Oracle database is,
lets further define each.

The INSTANCE
An Oracle instance is the combination of background processes and memory (these
are explained later in detail). When an Oracle instance is started, Oracle reads the
init.ora file, initializes memory (and other things) based on parameter values
expressed therein, and starts the various Oracle background processes.

The instance contains shared memory areas known collectively as the SGA (System
Global Area). These areas are:
data block buffer cache (buffer cache for short)
shared pool (contains both a data dictionary cache and a library [SQL & PL/SQL]
cache
java pool (optional)
large pool (optional, created if JAVA methods/application is used)
redo log buffer

continued.

2002 SkillBuilders, Inc. V1.0.0


Oracle Architecture 2.4

The instance also contains private memory areas called the PGA or Program (some
say Private) Global Area. There is one PGA created for every session
(connection or user) to the database that contain things such as a result set for a
users query, or the values of any session-defined variables.
Finally, the instance contains processes. Often called background processes, these
are Oracle software programs (threads in Windows-speak) that create and manage
the memory areas and facilitate all requests and operations of the database. There
are various Oracle processes that run only when Oracle is configured for special
functionality like Parallel or Distributed Server; but there are five processes that MUST
be running no matter what configuration Oracle is running. These processes inter-
communicate when needed. The 5 required Oracle processes are:

1. SMON (System Monitor) performs automatic instance recovery on startup (if


necessary), and coalesces all areas of newly-freed space for reuse.

2. PMON (Process Monitor) cleans up after any aborted User process (described
later on this page) by releasing locks, user-specific memory and etc. Prevents
hanging processes.

3. LGWR (Log Writer) continuously writes transaction data from the Redo Log
buffers in memory to the Redo Log files on disk.

4. DBWR (Database Writer) writes all modified data from the Block Buffer Cache in
the SGA to physical disk.

5. CKPT (Checkpoint) performs a checkpoint, at minimum, after each redo log


group switch. Checkpoint means that the CKPT process orders DBWR to write all
modified data to disk; for all database files affected by the updated data, CKPT
updates two copies of those files headers: the one stored with the file itself, and
the copy stored in the Control file.

Continued.

2002 SkillBuilders, Inc. V1.0.0


Oracle Architecture 2.5

A 6th process, the USER process, is assigned to each and every connection (user)
when Oracle is configured as a dedicated server (the normal configuration). This
USER process handles a users connection request, then reads all data for every user
DML operation from physical disk files into the Database Block Buffer cache in the
SGA (remember that every INSERT, UPDATE and DELETE first performs a SELECT to
get the proper blocks into memory before modification occurs).

In a shared server environment (AKA Multi-Threaded server), an available dispatcher


process (from a pool of such) routes requests from a user to a pool of (shared) user
processes, one of which processes the request. The dispatcher process then takes
the results and routes them back to the user/connection. MTS will be covered in a
separate section of this course; it addresses extremely large user communities.

2002 SkillBuilders, Inc. V1.0.0


Oracle Architecture 2.6

2.6
2.6

...Instance and Database...


Instance
Oracle processes and memory (SGA) that facilitate access to the
database
The Instance is started on the server with the STARTUP command
within the SQL*Plus interface
Database
Disk Files (datafiles) that contain system and user data
Log Files for recovering a database after restore
Control Files to confirm integrity of other files during STARTUP
Cannot be accessed unless instance is running
We usually say database for database/instance in Oracle

2002 SkillBuilders, Inc.

The Database
An Oracle database is a collection of all Oracle operating system files. The major
files are divided into three types:
Datafiles - Contain table data segments, index segments, system rollback
segments, and temporary (sort) segments (NOTE that Oracles definition of
segment will be explained later, and is different though related to the Sybase
definition). A datafile is part of a tablespace, which for non-System
tablespaces, usually contain just one type of segment.
Redo Log Files - Log files maintain a record of updates made to the database
(i.e., Oracles version of a Sybase transaction log). Used by recovery
operations after the restore of backup files.
Control Files - Control information such as OS file names, locations, file
integrity information, recovery information; constantly updated by Oracle
updates to data. Oracle checks this file during startup; any Data or Redo Log
file that fails the integrity check causes Oracle to halt startup and keep out
users. Always mirrored in a production database to reduce risk of loss.
Another important file is the init.ora file, also called the parameter file. Oracle
reads this file at startup. It contains parameters used at database startup that
control and define the database environment, such as parameters that control
sizing of the different memory areas in the SGA.

2002 SkillBuilders, Inc. V1.0.0


Oracle Architecture 2.7

Database and Instance Names


Instance and database each are assigned a name. They often have the same
name (not always true; in a parallel server environment, multiple instances can
access the same database - the instances will not have the exact same name.)
The instance name is called the System Identifier (SID). It is stored in the
environment variable $ORACLE_SID (UNIX) or %ORACLE_SID%
(Windows/NT). It can also been seen by querying the dynamic performance table
v$instance. ORACLE_SID and another logical called ORACLE_HOME must be
defined for each Oracle instance. (Oracle Home is the sub-directory or directories
under which Oracle places its own directories and files during installation. Its not
recommended that ORACLE_HOME be defined as the root directory.)
When you connect to the database with the CONNECT command, the current
$ORACLE_SID determines which instance you connect to and thus what database
you are connected to. You cannot be connected to more than one database at a
time.
The database name is usually assigned with the CREATE DATABASE command; it
can instead be specified in the init.ora parameter file, and is stored in a control
file. Query data dictionary view v$database to see the database name.

2002 SkillBuilders, Inc. V1.0.0


Oracle Architecture 2.8

2.8
2.8

Oracle and Sybase


Terminology Comparisons...
Sybase Server allows multiple Sybase Databases
Direct comparison in Oracle not possible
Oracle supports similar concept with
Tablespace - Collection of related tables grouped together for
administration
Schema - Tables owner by single user

Sybase database is administration group


Can backup, delete, control placement
Oracle tablespace provides these features too

Sybase database is logical group of tables


Oracle schema provides this too via tablespaces containing a
logical group of tables
2002 SkillBuilders, Inc.

A Sybase Server installation supports many Sybase databases. The Oracle


Server does not directly support this. Lets examine this further, remembering that
exact comparisons are tough to make between Oracle and Sybase.
Its helpful to repeat that an Oracle database is a collection of all database files
under control of an Oracle server instance.
The Sybase non-master database is a logical collection of tables and other objects
- part of the same application and log space for those objects. When a database
is created, its metadata (data dictionary) is stored both in the Sybase master
database, and in user catalogs created in each non-master database. Disk space
is assigned during creation or altering of the database, in the form of Sybase
devices which map directly to areas on physical disks.
Sybase devices dont have an exact analogy in Oracle. In Oracle, when a database
is created, it consists of at least one tablespace (always named SYSTEM), and
usually many more tablespaces. Each Oracle tablespace is created with a
datafile specification: disk name, full access path, filename, and the size of the
file. Oracle works directly with the operating system to create and maintain these
tablespace files. If the file specified does not exist, Oracle creates it. (An existing
file can be re-used by specifying the REUSE parameter during creation/alteration of
the tablespace.) A tablespace can consist of one or more physical files on one or
more disks or controllers or both.
Continues

2002 SkillBuilders, Inc. V1.0.0


Oracle Architecture 2.9

Other non-application tablespaces are set up for Oracle system use, such as a
tablespace for temporary (sort) space, and a tablespace to handle multiple rollback
segments.
Finally, one or (usually) more application tablespaces are usually set up as a logical
collection of tables and other objects; so its usually a collection of tablespaces
containing objects, instead of one Sybase database containing objects, that are part
of the same application.

Indexes are usually stored in their own tablespaces. For example, all tables making
up Accounting data might be stored in a tablespace named ACCT. All of the
indexes for the ACCT tablespaces table data might be stored in another tablespace
named ACCT_IDX. Except for the special SYSTEM tablespace auto-created during
database/instance creation, DBAs add the other tablespaces for Oracle or
application use as needed.

Furthermore, the Sybase database can be managed as a unit. For example, it can
be backed up and recovered as a unit. The smallest unit that can be backed up
from or restored to an Oracle database is one datafile. However, Oracle also
supports export/import (see the export and import utilities) of all objects
within a schema (in Oracle-speak, a schema are those Oracle objects owned by
one user).

So we can say that the Sybase Database is roughly analogous to an Oracle


Schema contained in one or more tablespaces.
Oracle Schema defined:
Group of objects all owned by the same user
Single Oracle database supports many schemas
Schema, within one or more tablespaces, can reside across multiple
devices

2002 SkillBuilders, Inc. V1.0.0


Oracle Architecture 2.10

2.10
2.10

...Oracle and Sybase


Terminology Comparisons...
Oracle allows multiple tablespaces within one
Oracle Database/Instance
1 Sybase database = 1 Oracle Schema
on multiple tablespaces

2002 SkillBuilders, Inc.

Remembering that exact comparisons between Sybase and Oracle are difficult to
make, contemplate this statement:

1 Sybase schema = 1 Sybase applications objects residing within one Sybase


database

1 Oracle schema = 1 Oracle applications objects residing within multiple


Oracle tablespaces

The next few pages will break down this statement and detail each part.

2002 SkillBuilders, Inc. V1.0.0


Oracle Architecture 2.11

2.11
2.11

...Oracle and Sybase


Terminology Comparisons
Sybase Logical Device maps to a physical
disk
Oracle Tablespace maps to one or more
physical files on a physical disk or disks
Sybase Database Segment = Multiple Oracle
Data, Index, Rollback or Sort Segments
within one or more Tablespaces

2002 SkillBuilders, Inc.

What about control of object location on physical objects?


In Sybase, all individual objects reside inside of databases, which is made up of
devices, which in turn map to one or more physical areas on disk.
With Oracle, all individual objects are created inside of tablespaces, which are
made up of files, which in turn map to one or more physical areas on disk files.
The concept of a segment is worth highlighting as another term with different
meanings for Sybase and Oracle.
In Sybase, segments label space on one or more logical devices for one database.
Multiple Sybase tables or indexes can be placed on one segment.
In Oracle, as mentioned, file space is allocated for each tablespaces datafile(s).
Each table or index in Oracle is its own segment within that datafile (represented
logically, remember, by the Oracle tablespace). Additionally, there are rollback
segments and temporary (sort) segments. Except for partitioned tables and
indexes (not covered here), all tables and indexes are each considered to be a
segment, no matter how much the segment grows or shrinks for example, a table
is just one segment when it contains 10,000 rows, and its still just one segment if
all but 10 rows are deleted.
So in brief, one Sybase database segment can be made up of multiple objects such
as tables. One Oracle segment is only one object, such as a table.

2002 SkillBuilders, Inc. V1.0.0


Oracle Architecture 2.12

2.12
2.12

Understanding Tablespace
and Schema
connect system/manager
create tablespace skillbuilders
datafile d:\oracle\oradata\orcl\sb.dbf
size 10M;
connect dave/bartstarr
create table test
(c1 number )
tablespace skillbuilders;
grant select on test to steve;
connect steve/bears
select * from dave.test;

2002 SkillBuilders, Inc.

Understanding Tablespace and Schema


To help us understand the concept and relationship of tablespace, schema and
table, lets examine an example.
The example above shows user SYSTEM connecting to the database. (Of course,
the instance must be started to connect to the database.) Then the user creates a
tablespace called SKILLBUILDERS. The syntax of this command shows that the
tablespace is mapped to a 10Mb file called sb.dbf.
The example continues with user DAVE connecting to the database (this
disconnects the previous session by user SYSTEM). Then, DAVE proceeds to
create a table called TEST in tablespace SKILLBUILDERS and GRANT SELECT
privilege on TEST to user STEVE.
Finally, STEVE connects to the database and SELECTs from DAVEs table. Lets
look again at the query:
SELECT * FROM dave.test;
It is notable that the tablespace is not referenced; in Oracle it is never referenced in
a DML command. However, note that the schema is required. (The schema can
be omitted if a SYNONYM is created; more on this later.)

2002 SkillBuilders, Inc. V1.0.0


Oracle Architecture 2.13

2.13
2.13

...Oracle and Sybase


Terminology Comparisons
Sybase Master Database roughly similar to
Oracle SYSTEM Tablespace
Both contain a catalog of object information
Difference: Sybase creates USER catalogs in each
user database created
Oracle provides views that filter only a given
USERs objects:
SELECT table_name FROM user_tables;
USER_TABLES is an Oracle-supplied view that shows only
the connected USERs tables

2002 SkillBuilders, Inc.

Oracle does not support the concept of MASTER and USER databases. However, an
analogy can be made. The MASTER database is somewhat similar to the Oracle
SYSTEM tablespace. The SYSTEM tablespace contains the Oracle data dictionary -
a series of tables and views, owned by user SYS, that contain information about all
system and user objects in the database.

A notable difference is that Sybase stores some of the USER-related data dictionary
information into the USER databases themselves. So, in Oracle, how would a
logged in USER see a list of only those tables owned or accessible for one USER or
SCHEMA? Oracle supports this via Oracle-supplied views. Some of these views (all
based on underlying Oracle system tables) have a prefix of DBA_, ALL_ or
USER.

Oracle data dictionary views with the prefix of USER_ contain information about
objects owned by the current user (the connected user), such as:
USER_TABLES - Contains information about tables owned by the connected
user.
USER_OBJECTS - Contains information about all objects (including tables)
owned by the connected user.
Continues

2002 SkillBuilders, Inc. V1.0.0


Oracle Architecture 2.14

Oracle provides similar data dictionary tables for finding information about objects
not in your schema, but on which you been granted privilege(s) to access. These
always have the ALL_ prefix:
ALL_TABLES - Contains information about all tables a logged-in user
doesnt own but has been granted the privilege to query and/or update by
the tables owner.

Oracle views with the DBA_ prefix contain information about all of the specified
objects stored in the database, regardless of owner(schema), such as:
DBA_TABLES - Contains information about all tables in the database.

There are Oracle user views for many other types of objects, such as
USER_INDEXES and USER_SEQUENCES.
Oracles data dictionary is considered vast and comprehensive. Just remember, as
a new Oracle user, that you will become familiar with some of these views as you
need and use them one by one. Its very possible that you wont ever become
familiar with, much less use, the vast majority of Oracle data dictionary information.
A big chunk of Oracles data dictionary is used only by DBAs, or data modelers.
Some users new to Oracle and already somewhat dazed by Oracle concepts get
intimidated by all of the data dictionary information available; instead, new Oracle
users should consider the data dictionary a vast Oracle library where views are
books, and the user decides which views to check out (query), ignoring all other
views until the possible future day that theyre actually needed.

2002 SkillBuilders, Inc. V1.0.0


Oracle Architecture 2.15

2.15
2.15

Oracle Object-Oriented
Support
Object Constructs
Added in Oracle v8.05
User-Defined Datatypes
Allow complex datatypes
Useful with Oracle collection types
Used to create object tables
Collections
Varrays
Nested Tables
Can be used as table columns or PL/SQL variable types

2002 SkillBuilders, Inc.

Oracle8 and later added many new features for application developers to exploit.
Along with Oracle8s new support for Java applications came capabilities to use
object constructs within the Oracle RDBMS, that is, as extensions to the Oracle
relational model.

Oracle8i and later with the Objects option installed are referred to as an Object-
Relational Database Management Systems (ORDBMS). Naturally, these object
constructs lend themselves to applications using JAVA, C++ or other object-
oriented languages. But they are handy as well within Oracle relational tables and
within PL/SQL, so you neednt be using an O-O language for application
development to benefit from their use.
User-Defined Datatypes
One of Oracles new object constructs is called an object type, also called a user-
defined datatype (UDT). A UDT lets a developer or DBA create their own data
structures that are composed of standard Oracle datatypes such as NUMBER,
VARCHAR2, DATE and CHAR. You can create a UDT, then use it as a template for
columns, tables, and other constructs just like any standard datatype. Look to the
next page for an example:

2002 SkillBuilders, Inc. V1.0.0


Oracle Architecture 2.16

Create a UDT example:


/*** CREATE THE TYPE ***/

CREATE TYPE emp_name_type AS OBJECT


(first_name VARCHAR2(25),
middle_name VARCHAR2(25),
last_name VARCHAR2(25)
);

Now this type can be used as a column datatype in a table.

CREATE TABLE employee


(emp_sid NUMBER PRIMARY KEY,
emp_name EMP_NAME_TYPE NOT NULL,
job_id NUMBER,
manager_sid NUMBER REFERENCES employee(emp_sid)
) tablespace HR;

Collection Types
Varrays
A varray is an ordered array of variable-length data elements which can be stored
in a single row. Varrays share these characteristics:
If the total size of the varray is 4K bytes or less, its stored in-line with the
rest of the row. If the varray is larger than 4K bytes, it is stored out-of-line
from the rest of the row.
You must specify a maximum number of data elements that a varray can
contain.

Example usage of a varray:


Lets say the children and their birthdates of each employee at a company need to
be stored with other employee data so the company president can send them
birthday cards.
Without varrays, the parent table EMPLOYEE would have to have a foreign key
table (maybe called EMP_CHILDREN) that contains a row for each child an
employee has (with columns for child name and child birth date). A performance-
expensive table join would be needed to access employee children information.
With Oracles varray, an ordered list of data elements with each childs name and
birth date can be created within the table EMPLOYEE, with a max size of
MAX_CHILDREN determined by the employee with the most children (this max size
can be adjusted later if, for example, a new employee was hired with even more
kids than the current champ). Now a query can now retrieve employee

2002 SkillBuilders, Inc. V1.0.0


Oracle Architecture 2.17

children information without the performance penalty of a table join between


EMPLOYEE and EMP_CHILDREN.
Code example:

/*** CREATE EMP CHILD DATATYPE ***/


CREATE TYPE emp_child_type AS OBJECT
(name VARCHAR2(25),
birthdate DATE);

/*** CREATE THE VARRAY TYPE ***/

CREATE TYPE child_lst_type AS VARRAY(15) OF emp_child_type;

/*** ADD A COLUMN AS NEW DATATYPE TO EMPLOYEE TABLE ***/

ALTER TABLE employee ADD (emp_children child_lst_type);

Nested Tables
A nested table is an unordered array of data elements. It can be pictured as a sub-
table embedded within a parent table. Nested tables share these characteristics:
Nested table data is always stored out-of-line from its parent table; but it is
accessible from the parent table via a direct pointer (Oracles ROWID,
explained later) to the nested table data for each parent row selected.
Unlike varrays, the maximum number of elements in a nested table is
unlimited.
Example usage of a nested table:
Consider a company that performs a quarterly evaluation of each employees work
performance, and that this information is stored along with other employee data.
Long-term employees would have many such evaluations stored with no maximum
limit, so a nested table would be perfect: unlike a varray, there is no limit to the
number of elements in a nested table.
The same benefits described above for varrays thus hold true for nested tables:
instead of having a second table (say, named EVALS) dependent on its parent table
EMPLOYEE, the nested table is built along with the parent table. For each row of
EMPLOYEE table containing a nested table, that rows matching data in the nested
table (stored separately) is retrieved with one fetch via a pointer (Oracles ROWID).
Again a table join, or the need to INSERT into more than one table, is eliminated.
Code example:
/*** CREATE OBJECT TYPE FOR EMPLOYEE EVALUATIONS ***/

CREATE TYPE eval_type AS OBJECT


(mgr_sid NUMBER,
eval_date DATE,
this_qtr_accomp VARCHAR2(3000)
next_qtr_goals VARCHAR2 (3000)
);

2002 SkillBuilders, Inc. V1.0.0


Oracle Architecture 2.18

/*** CREATE OBJECT TYPE FOR NEW NESTED TABLE ***/

CREATE TYPE eval_tab_type AS TABLE OF eval_type;

/*** ADD NEW NESTED TABLE TO TABLE EMPLOYEE ***/

ALTER TABLE employee ADD (qtrly_evals eval_tab_type)


NESTED TABLE qtrly_evals STORE AS nest_qtrly_evals;

2002 SkillBuilders, Inc. V1.0.0


Oracle Architecture 2.19

2.19
2.19

Major Oracle Relational


Objects
TABLE
Collectionof columns and rows
Limited object-oriented support
Nested Tables
VARRAYs
Index-Organized Tables
Partitioned Tables

INDEX
Oracle supports many index types:
B-Tree, Bitmap, Function-based, Reverse Key

2002 SkillBuilders, Inc.

Since weve covered Oracles new object constructs, lets now examine the major
Oracle relational objects. Some Oracle relational objects have no counterpart in
Sybase; these will be fully explained. For those objects with similar Sybase
counterparts, well concentrate on the Oracle-specific details and capabilities.
Oracle Tables
An Oracle table, like any relational database table, is a collection of columns and
rows presented in an X-Y axis format. Oracle8 and Oracle8i allow some new
features that can be used with tables.
As described on the previous page, the Oracle RDBMS allows objects constructs
such as user-defined datatypes, and the varray and nested table collection types.
Remember, collection types allow variable-length lists of data to be stored within a
single row in a table. These collection types along with user-defined datatypes are
supported by both PL/SQL (for use in variable declarations) and the Oracle
RDBMS (as table column datatypes).
Oracle also allows a tables data to be physically ordered on disk based on one
(and only one) of the indexes created for that table. This is referred to as an index-
organized table. An example of usage is for applications with a large table of
initialization data that is read at every application startup. If the data needs to be
sorted in memory when selected (e.g., theres an ORDER BY), this can waste a lot
of time. Index-organized data will be read in directly from disk where the data is
already ordered properly.

2002 SkillBuilders, Inc. V1.0.0


Oracle Architecture 2.20

Oracle8 introduced table partitioning, which allows a large table to be physically


chopped into partitions and stored in separate tablespaces on separate disks. A
usage example: a very large table in a 24 by 7 shop could be so big it cannot be
backed up at in one night. However, each partition of a table can be backed up
separately, and at different times if needed. Queries and updates to partitioned
tables perform much faster, as Oracle can quickly narrow down which partition to
access instead of searching an entire table. Maintenance operations can be greatly
simplified using table partitions.
Oracle Index Types
Oracle supports different index types. The B-Tree index is by far the most widely-
used index type in the Oracle RDBMS. Variations of the b-tree algorithm have
been used on most major relational database types to provide fast retrieval of data.
Oracles other index types are used for special situations. The index type
descriptions:
B-Tree indexes are the standard, default index type created. Oracle traverses the
binary tree structure utilizing a binary-search algorithm until it finds the index node
containing an entry for the row(s) its searching for. This node is called the leaf
node of the index. Stored in the leaf node is an Oracle ROWID the actual physical
location of the row on disk. With one more disk head seek, Oracle retrieves the
actual row(s) of data.
Bitmap indexes are created on table columns with a low cardinality of values that
is, very few unique values. For example, a column named marital_status
might only allow S, M, 'D or W (single, married, divorced, widowed). The problem
using a b-tree index is that Oracles optimizer assumes that with only 4 distinct
values, each value represents approximately 25% of marital_status rows in a
table. Oracles threshold, where it decides a table scan (reading every record) is
cheaper than using an index, is far below 25% of the records. Thus Oracle would
always perform a table scan rather than use the b-tree index.
A bitmap index works differently. Instead of storing data for the column(s) being
indexes, Oracle stores a 0 or a 1 for each value type thats what a bitmap is.
Heres a picture of the values a bitmap index might hold for each row:

Data Row 1 SMDW


1000
0010
0100
0010
0001
0010 continues

2002 SkillBuilders, Inc. V1.0.0


Oracle Architecture 2.21

Reverse-Key Indexes store the characters of each data value from the column(s)
being indexed to be stored in reverse order, resulting in a better distribution of
values for certain applications.
For example, consider an Oracle application that has heavy update activity on a
table that uses a creation date and a sequential number as a primary key. Lets
further assume that this application adds new records to this table every day, and
deletes old records from the table more than 30 days old. During heavy activity hot
spots can cause performance degradation; that is, Oracle is pounding on a
relatively few number of the blocks in the table, inserting new blocks at one end and
deleting old blocks at the other end. With a reverse-key index, the inserts and
deletes are now spread out randomly amongst all blocks of data in the table.
Function-based indexes fix a major problem concerning Oracle index usage, and
were only added to Oracle 8i (v8.16 and later). Normally, if a function is used on an
indexed column in the WHERE clause of a SELECT, it disables use of the index; that
is, Oracle performs a table scan looking for matches rather then using the index, a
major performance killer for queries on large tables. You can now create an index
based on a columns function-computed value, rather then the column value itself,
guaranteeing that Oracle will use the index.

2002 SkillBuilders, Inc. V1.0.0


Oracle Architecture 2.22

2.22
2.22

Major Oracle Relational


Objects
TABLESPACE
Logical object composed of one or more physical
disk files
All Oracle segments (data, index, rollback,
temporary) must reside within one or more
tablespaces)
SEQUENCE
Sequential number generator
VIEW
Logical
view, presented as a table, of the results of
a SQL query 2002 SkillBuilders, Inc.

Oracle Tablespaces
Tablespaces and their storage specifications were covered earlier when we
compared Oracle schemas to Sybase databases. Lets further clarify some of their
characteristics and distinguish them from the other two major Oracle file types.
Oracle segments were described earlier. All Oracle segments must reside within a
tablespace. Almost always, each tablespace contains only one segment type. An
application may have a number of tablespaces within which tables are created.
Indexes for those tables would reside in their own tablespaces. A DBA usually
creates at least one tablespace for rollback segments (usually between 4 and 10
rollback segments are created within the rollback segment tablespace for update-
intensive applications). The maintenance of rollback segments has been greatly
enhanced in Oracle9i allowing for automated rollback (UNDO) usage. Additionally,
the Oracle DBA will create one or more tablespaces for sorting purposes, and are
used as needed by the application. Succinct definitions for the varying segment
types:
A data segment contain the rows of data from one, and only one, Oracle table.
Index segments contain index entries for the rows of data in a table, one index
segment per index.
Continues

2002 SkillBuilders, Inc. V1.0.0


Oracle Architecture 2.23

Rollback segments contain undo data blocks used by Oracle to store the
original data block(s) for the modifying transaction that fails or is rolled back.
Temporary segments are what Oracle uses for sorting data such as SELECTs
with ORDER BY clauses.

Oracle Sequence
Oracle provides a sequential number generating object called a sequence. A
typical usage for a sequence would be to generate unique, sequential numbers to
be stored in a column used for a tables primary key. Its only usage is to provide
the next number generated by the sequence, or to display the current number (the
last number generated by the sequence). Default values start with the number 1,
increment by one, and have no maximum value perfect for a primary key.
Options that can be specified when creating or altering a sequence include the
ability start with any number, increment by any number, specify a maximum value,
additionally cycle repeatedly through the same range of values, and more.
Code example:

/*** CREATE THE SEQUENCE WITH DEFAULT VALUES ***/


/*** (start with 1, increment by 1) ***/

create sequence part_seq;

/*** USE THE SEQUENCE IN THREE INSERT STATEMENTS ***/

insert into parts (part_id, part_name, qty, price)


VALUES (part_seq.NEXTVAL,Widget,39,10.99);

insert into parts (part_id, part_name, qty, price)


VALUES (part_seq.NEXTVAL,Whatsis,287,4.99);

insert into parts (part_id, part_name, qty, price)


VALUES (part_seq.NEXTVAL,Blomdoggle,6,219.99);

/*** SELECT COLUMN part_id FROM TABLE parts ***/

select part_id from parts;

PART_ID
-----------
1
2
3 Continues

2002 SkillBuilders, Inc. V1.0.0


Oracle Architecture 2.24

/*** ALTER THE SEQUENCE TO INCREMENT BY 2 INSTEAD OF 1 ***/

alter sequence part_seq increment by 2;

/*** PERFORM ANOTHER INSERT ***/

insert into parts (part_id, part_name, qty, price)


VALUES (part_seq.NEXTVAL, Gogglite, 15, 11.00);

/*** SELECT part_id AGAIN ***/

select part_id from parts;

PART_ID
-----------
1
2
3
5

Oracle Views
An Oracle view is a logical representation of the result set of rows from a query,
presented to the user in table form. Unlike a table and its data, a view is not a
physical object. Its a logical view of the data from one or more tables in a SQL
query. The view can hide complex query structures from inexperienced users, or a
view can be created to show a user some of a tables columns, but hiding other
columns of data, by limiting the columns selected by the views query.
A view can be created as read-only, or it can allow updates. An update of a view
results in the data being changed in the underlying table(s) making up the views
query since, of course, a view is not a real object.
Try to remember that a view is really just a SELECT statement with a name.

2002 SkillBuilders, Inc. V1.0.0


Oracle Architecture 2.25

2.25
2.25

ORACLE PL/SQL Objects


PL/SQL Block
Body of code for PL/SQL procedures, functions and triggers
Can contain SQL & explicit cursors along with typical
programmatic constructs like IF, WHILE, and FOR loops
Can call non-PL/SQL procedures (C, Cobol or Pascal) from
an external library
Can call JAVA methods as well

Stored Procedures & Functions


PL/SQL block with a Stored Procedure or Function header

2002 SkillBuilders, Inc.

Oracles PL/SQL allows the creation of procedures, functions and triggers called
PL/SQL objects. Below is a description of the four main objects:
PL/SQL Block
The basic PL/SQL construct is the PL/SQL block. This block structure consists of
local variable declarations (optional), the code body (mandatory), and an exception
(error) handler (optional).

These blocks are used to build PL/SQL objects. That is, a header added at the top
of a PL/SQL block defines the object as a procedure, function or trigger.
Stored Procedures and Functions
Procedures or functions can be passed parameters, as in most programming
languages. Functions in PL/SQL, as is typical, must return a value in its code body.

2002 SkillBuilders, Inc. V1.0.0


Oracle Architecture 2.26

2.26
2.26

ORACLE PL/SQL Objects


Triggers
PL/SQL block with a Trigger header
DML, Startup/Shutdown, DDL, Suspended
Transaction, and Servererror triggers available
Packages
A logical grouping of related PL/SQL objects
Can hide certain PL/SQL objects
All PL/SQL objects contained moved into memory
when one is called in one physical I/O operation

2002 SkillBuilders, Inc.

Triggers
Triggers are available on most relational databases, including Oracle, to fire
automatically on any combination of an Insert, Update or Delete to a table. That is,
the code within the triggers PL/SQL block runs whenever the header-specified
DML action occurs.
Oracle has greatly expanded its trigger functionality by adding the capability to fire a
trigger based on a DDL command, the Oracle server events Startup and Shutdown,
a suspended transaction, or any Servererror generated by code. Again, the
syntax of the triggers header determines the trigger type.
Packages
Oracle packages are a way to group related PL/SQL objects together. For
example, a package might be created by user TOM in the development
environment. This package contains all of the PL/SQL objects, like procedures and
functions, that Tom is developing for an application.
In production, a package might be created to hold all of the PL/SQL objects used by
the Accounting portion of the application software.
Besides offering a nice way to package a bunch of PL/SQL objects, what else do
packages do? For one thing, permission can be granted to execute procedures or
functions in the package by one grant on the package itself.

grant execute on account_pack to dave;

2002 SkillBuilders, Inc. V1.0.0


Oracle Architecture 2.27

Now, Dave can execute any procedure or function listed in the package header.
However, Dave can not execute any procedure or function listed in the package
body, but not in the package header. This is used by the developer to disallow calls
to those objects that are only called by other objects in the same package.
Finally, when a database is newly booted and the application restarted, Oracle will
load the entire package into the shared pool portion of the SGA (main memory)
when Daves code calls just one of the procedures or functions in the package.
This is a huge performance benefit, as it eliminates multiple physical disk seeks to
bring into memory all of a packages objects.

New PL/SQL Functionality


Oracle has added some notable new PL/SQL functionality as of version 8.05 and
later:

PL/SQL blocks can now call JAVA methods or, via external libraries, 3GL
procedures (as of this writing, for COBOL, C and PASCAL; more languages
are being added)
PL/SQL blocks can now use a package of Oracle built-in procedures (the
package is called UTL_FILE) to directly manipulate non-Oracle operating
system files
Simple and searched CASE statements
The DBMS_METADATA package that allows you to generate DDL statements
based on information in the data dictionary
In support of the Oracle9i Resumable Space Management feature, the AFTER
SUSPEND trigger has been added. Upon detection of a suspended
transaction this trigger can be used to log and/or correct the problem.

2002 SkillBuilders, Inc. V1.0.0


Oracle Architecture 2.28

2.28
2.28

Summary
There are major architectural differences
between Oracle and Sybase
Similar Oracle/Sybase terms have different
meanings
Oracle instance = memory & processes
Oracle database = Oracle files on disk
Sybase database roughly = Oracle schema
Oracle data disk space controlled by
tablespaces datafile spec

2002 SkillBuilders, Inc.

2002 SkillBuilders, Inc. V1.0.0


Oracle Architecture 2.29

2.29
2.29

Summary
User-specific data dictionary views list info for objects
owned or accessible by current user
Oracle (8i and beyond) supports object constructs
like user-defined datatypes and collection types
Oracle relational objects include tables, indexes,
tablespaces, sequences (sequential number
generators) and views
Oracles PL/SQL used to create procedures,
functions, triggers and packages

2002 SkillBuilders, Inc.

2002 SkillBuilders, Inc. V1.0.0


Oracle Architecture 2.30

Workshop 2
Class exercise Questions

2002 SkillBuilders, Inc.


SKILLBUILDERS

Workshop
1. How many databases can one Oracle instance support?

2. What is the Oracle equivalent to Sybase's:


corporate_server.personnel_database.prod_schema.dependents_table?

3. Name three features that provide Oracle scalability.

4. What is Oracle's equivalent to Sybase's USE DB?

5. What is an instance?

6. What areas of memory improve Oracles performance?

7. What is distributed database?

8. Can replication snapshots be updated?

9. What is the purpose of the Parallel Server Option?

. . . . continued . . . .

2002 SkillBuilders, Inc. V1.0.0


Oracle Architecture 2.31

10. How does Oracle provide very large database support?

11. What Oracle products allow you to store Word files directly in the database
and search them?

12. What Oracle products allow you to build dynamic web sites?

13. How many tests must you pass for your Oracle Application Developer
Certification? Which of these tests does this course prepare you for?

2002 SkillBuilders, Inc. V1.0.0

Вам также может понравиться