Académique Documents
Professionnel Documents
Culture Documents
Transportable Tablespaces
Here comes another wonderful feature in the new release of Oracle 8.1.5.
Transportable tablespaces are a lot like cutting a piece of the database and pasting it
to another database. Well, you don't need to actually cut it, you can always make a
copy of the part of the database and add it to another database.
The concept is to just copy the datafiles and move the dictionary information to the
new server. Since you are exporting only the data dictionary information, the time
required to move data between databases is much faster than using the regular
import/export. Remember to connect as sys or sysdba while exporting or importing
the data dictionary information.
The granularity, at which we can move pieces of a database, using this concept, is a
tablespace. You can move as many tablespaces as you want in one shot. But the
tablespaces must meet certain criteria.
DBMS_TTS.TRANSPORT_SET_CHECK('TSP1,TSP2', TRUE);
where TSP1, TSP2 are the tablespace names and TRUE specifies that the oracle
server also take the constraints, foreign keys etc., into consideration. If it is FALSE
the procedure does not bother about the constraints, and raises an error whenever
you refer these objects in the destination database.
Now query the view TRANSPORT_SET_VIOLATIONS. This view lists all the objects
and tablespace which is not self-contained. If there is no such tablespace, this view
will be empty.
Now export the tablespaces using the export utility that is provided with the oracle
server. This exports only metadata info pertaining to the tablespaces. Other options
like Triggers=y, Grants=y and constraints=y can be used to copy the respective
objects.
set the tablespaces on the source database back to read write after the export.
Copy the export.dmp and the data files for these tablespaces into the destination
server using any OS utility. On the destination database invoke the import utility to
add the tablespaces to the new database. Once the files have been added, set the
tablespaces to read write.
If you want to change the ownership of the the objects, you can mention TOUSER
and FROMUSER options. If you don't specify these options, imp tries to create the
objects under the same user from the source database. If the user doesn't exists on
the destination database, import will fail.
One of the many new features in Oracle 8i is the Function-Based Index (we will
refrain from using FBI, but only just). This allows the DBA to create indexes on
functions or expressions; these functions can be user generated pl/sql functions,
standard SQL functions (non-aggregate only) or even a C callout.
A classic problem the DBA faces in SQL Tuning is how to tune those queries that use
function calls in the where clause, and result in indexes created on these columns
not to be used.
Example
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=3 Card=1 Bytes=17)
1 0 SORT (AGGREGATE)
2 1 TABLE ACCESS (FULL) OF 'SALES_CONTACTS' (Cost=3 Card=16 Bytes=272)
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=2 Card=1 Bytes=17)
1 0 SORT (AGGREGATE)
2 1 INDEX (RANGE SCAN) OF 'FBI' (NON-UNIQUE) (Cost=2 Card=381 Bytes=6477)
The function-based index has forced the optimizer to use index range scans
(retuning zero or more rowids) on the surname column rather than doing a full table
scan (non-index lookup). Optimal performance does vary depending on table size,
uniqueness and selectivity of columns, use of fast full table scans etc. Therefore try
both methods to gain optimal performance in your database.
It is important to remember that the function-based B*Tree index does not store the
expression results in the index but uses an "expression tree". The optimizer performs
expression matching by parsing the expression used in the SQL statement and
comparing the results against the expression-tree values in the function-based
index. This comparison IS case sensitive (ignores spaces) and therefore your
function-based index expressions should match expressions used in the SQL
statement where clauses.
Init.ora Parameters
Grants
Grants To create function-based indexes the user must be granted CREATE INDEX
and QUERY REWRITE, or alternatively be granted CREATE ANY INDEX and GLOBAL
QUERY REWRITE. The index owner must have EXECUTE access on the function used
for the index. If execute access is revoked then the function-based index will be
"disabled" (see dba_indexes).
Disabled Indexes
Queries on a DISABLED index fail if the optimizer chooses to use the index.Here is an
example ORA error:
ERROR at line 1: ORA-30554: function-based index MYUSER.FBI is disabled.
All DML operations on a DISABLED index also fail unless the index is also marked
UNUSABLE and the initialization parameter SKIP_UNUSABLE_INDEXES is set to true.
The following restrictions apply to function based indexes. You may not index:
a) LOB columns
b) REF
c) Nested table column
d) Objects types with any of the above data types.
When you create an index on a table, a separate storage area is allocated to store
the B-Tree Structure, another B-Tree object is created related to the table. In an
index-organized table the data for the table is held in its associated index.
Rather than having a row's rowid as the second element of the index entry, the
actual data row is stored in the B*-tree index. Changes to the table data, such as
adding new rows, updating rows, or deleting rows, result only in updating the index.
You can use the CREATE TABLE statement, but you have to provide certain other
parameters.
Benefits of IOT
1. Since you are not storing the index keys separately the space required is less.
2. Optimizer does not need to read two locations. The data can be found in one
structure.
3. Since the data is organized based on the primary key, applications that use
primary key to fetch the data performs well.
Like any other object, the data dictionary manages space allocation to a tablespace.
That means Oracle updates the appropriate tables in the data dictionary whenever
an extent is allocated or freed for reuse. Oracle also stores rollback information
about each update of the dictionary tables. Because dictionary tables and rollback
segments are part of the database, the space that they occupy is subject to the
same space management operations as all other data. This method of space
management is called extent management by the data dictionary. These tablespaces
are also called as Dictionary managed tablespaces. This was the only option available
prior to release 8.1. In Oracle release 8.1 and above you have an option to manage
the space allocation called extent management by the tablespace
A tablespace that can manage extent allocation by itself is called locally managed
tablespace. These tablespaces maintain a bitmap in each datafile to keep track of the
freed or used status of blocks in that datafile. Each bit in the bitmap corresponds to a
block or a group of blocks. When an extent is allocated or freed for reuse, Oracle
changes the bitmap values to show the new status of the blocks. These changes do
not generate rollback information because they do not update tables in the data
dictionary (except for special cases such as tablespace quota information).
Extent Allocation
Locally managed tablespaces can have uniform extent sizes or variable extent sizes
that are determined by the system. Any of the options, UNIFORM or AUTOALLOCATE
can be mentioned while creating the tablespace. For UNIFORM extents you can
specify an extent size. The default size is 1MB. For AUTOALLOCATE extents you can
specify the size of the initial extent and Oracle determines the optimal size of the
additional extents, with a minimum extent size of 64KB. That is why these are called
system-managed extents.
Oracle looks for free space to allocate to a new extent by first determining a
candidate datafile in the tablespace and then searching the datafile's bitmap for the
required number of adjacent free blocks. If that datafile does not have enough
adjacent free space, Oracle looks in another datafile. When extents are deallocated,
Oracle modifies the bitmap in the datafile.
Advantages
Notes
1.Temporary tablespaces that manage their extents locally can only use UNIFORM
extent allocation.
2.For permanent tablespaces the default extent size for system managed extents is
64KB.
Materialized Views
This article deals with Materialized views and helps you realize the potential of Oracle
8i in Data Warehousing and DSS Solutions. These views work by pre-calculating the
aggregate operations and the optimizer will transparently rewrite the query to use
these views.
Introduction
Example 1 :
The fact table stores the actual data about the sales by month and state, time table
has the day,month, year dimenstions and geog stores the state names. This view is
built and populated with data immediately.
Lets asssume that you asked oracle to calculate the same values in a query and if
query_rewrite is allowed on your server, the optimizer will automatically use the
values in the above precomputed view.
NOTES:
RESTRICTIONS:
2. There cannot be any set functions like UNION, MINUS in the underlying query for
materialized views.
Temporary Tables
Here is another feature I found interesting that was introduced in Oracle 8i.
Temporary tables, yep temporary tables. You may say, whats the big deal, I was
creating temporary tables from before, whats new now. These temporary tables have
a global definition. When a user inserts rows in a session, those rows are only visible
to that session and the rows are only available until the transaction or the session is
ended based on how the table has been defined. Confused....Read On...
Temporary Tables
The above statement creates a table whose definition is visible to all the sessions but
the data is visible to only the session that has created it. Temporary tables can be
used by developers to store session / transaction specific data that can be discarded
as soon as the session/transaction ends. When a truncate is issued on this table,
only data related to that particular session is truncated.
The above code creates a table named dbatest. When data is inserted into this table
the data persists either at the session or transaction level based on how "On
Commit" parameter is specified. On commit can be specified as "delete rows" or
"preserve rows". Delete Rows seems to be the default.
In the above table, as soon as the user ends the transaction by issuing a commit
statement, the data in the temporary table is deleted ( truncated ).
The above statement causes the creation of a table that will keep its rows even after
the transaction is committed. If the user inserts rows into the above table and then
commits the data, the data that was inserted will exist until the session is ended.
Restrictions
Temporary tables cannot contain nested tables or varray types or they cannot be
partitioned, index-organized or clustered. They cannot be used in parallel DML or
parallel queries and distributed transactions are not supported on these tables.