1. Trang chủ
  2. » Công Nghệ Thông Tin

Oracle 8 Database Administration volume 2 instruction guide phần 4 potx

34 260 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Using Clusters and Index-Organized Tables
Trường học University of Oracle Technology
Chuyên ngành Database Administration
Thể loại Sổ tay hướng dẫn
Năm xuất bản 1998
Thành phố Unknown
Định dạng
Số trang 34
Dung lượng 336,21 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Oracle8: Database Administration 15-25 ......Index-Organized Tables An index-organized table differs from a regular table in the following respects: • ROWID can uniquely identify a row i

Trang 1

Oracle8: Database Administration 15-23

Retrieving Information About Clusters

Note

If you need to use a join on three or more data dictionary views it may be

preferable to use temporary tables based on the views and then use the tables

in a join

Trang 2

15-24 Oracle8: Database Administration

Index-Organized Tables

Storage Structure

An index-organized table keeps all data for a table within a B-tree structure

The B-tree index, which is based on the primary key of the table, is

organized like an index The leaf blocks in this structure contain the nonkey

columns, instead of the ROWID, as the second element of the index leaf

entry Therefore, the use of an index-organized table eliminates the need to

have two separate segments, the table and the index

Accessing an Index-Organized Table

Index access to a regular table requires that one or more index blocks are

read to retrieve the ROWID and the I/O on the table based on the ROWID In

contrast, reading an index-organized table requires only index

block reads because the whole row is available in the leaf node

An index-organized table can be accessed using either the primary key or a

combination of columns that constitute the leading part of the primary key

Changes to the table data, such as adding new rows, updating rows, or

deleting rows, result only in updating the index

15-15 Copyright  Oracle Corporation, 1998 All rights reserved.

index-Non-key columns Key column Row header

Trang 3

Oracle8: Database Administration 15-25

Index-Organized Tables

An index-organized table differs from a regular table in the following

respects:

• ROWID can uniquely identify a row in a regular table, while the rows in

an index-organized table are identified by their primary key

• A regular table can have many indexes that store the ROWID

corresponding to the index key values Because an index-organized table

has no ROWID, secondary indexes cannot be created on this type of

table Any SQL statement that attempts to retrieve the ROWID of an

index-organized table receives the following error:

ORA-02031: no ROWID for fixed tables or for index-organized

tables

• When a full table scan is made on a regular table, the order in which

rows are returned is unpredictable Full scans on an index-organized

table return rows in a primary key sequence

• An index-organized table supports all constraints except unique

constraints

• An index-organized table cannot participate in a distributed transaction

It cannot be partitioned or replicated

15-16 Copyright  Oracle Corporation, 1998 All rights reserved.

Index-Organized Table

Identified by primary key

No ROWID

No secondary indexes Full index scans return rows in PK order

No support for unique constraints Distribution, replication, and partitioning not supported

Index-Organized Tables Compared with Regular Tables

Regular Table

Unique identifier—ROWID

ROWID implicit

Supports several indexes

FTS returns rows in no specific

order

Unique constraints allowed

Distribution, replication, and

partitioning supported

Trang 4

15-26 Oracle8: Database Administration

Using Index-Organized Tables

An index-organized table is useful for:

• Information retrieval applications

• Spatial applications

• Online analytical processing (OLAP) applications

Index organization is useful for a table that is frequently accessed using the

primary key and has only a few, relatively short nonkey columns

Syntax

Use the following command to define an index-organized table:

CREATE TABLE [ schema ] table

(column-definition [, column-definition ]

[, out-of-line-constraint [, out-of-line-constraint ] ] ) ORGANIZATION INDEX

15-17 Copyright  Oracle Corporation, 1998 All rights reserved.

Creating Index-Organized Tables

CREATE TABLE scott.sales

Trang 5

Oracle8: Database Administration 15-27

Using Index-Organized Tables

where: schema is the owner of the cluster

INCLUDING clause are moved to theoverflow segment If OVERFLOW is notspecified, then rows exceeding thethreshold are rejected PCTTHRESHOLDdefaults to 50 and must be a value from 0

to 50.)

INCLUDING column

specifies a column at which to divide anindex-organized table row into index andoverflow portions (All columns that follow

column are stored in the overflow data

segment If this is not specified and a rowsize exceeds PCTTHRESHOLD, allcolumns except the primary key columnswill be moved to the overflow area Thecolumn is either the name of the lastprimary key column or any nonprimary keycolumn.)

OVERFLOW specifies that index-organized table data

rows exceeding the specified threshold areplaced in the data segment defined by

segment_attributes_clause, which

specifies the tablespace, storage, and blockutilization parameters

Trang 6

15-28 Oracle8: Database Administration

Restrictions

A primary key must be specified for an index-organized table If an attempt

is made to create an index-organized table without the primary key, the

following error is generated:

ORA-25175: no PRIMARY KEY constraint found

If PCTTHRESHOLD is defined and an overflow segment is not specified,

rows exceeding the threshold are rejected with the following error:

ORA-01429: Index-Organized Table: no data segment to store

overflow row-pieces

Trang 7

Oracle8: Database Administration 15-29

Using Index-Organized Tables

A large row in an index-organized table might destroy the dense storage of

rows in the index This problem is overcome by the use of an overflow area

Segments Created for an Index-Organized Table

When an index-organized table is created specifying the OVERFLOW

clause, the following are created:

• A “logical” table with the name defined in the CREATE TABLE clause

Because all the rows are stored in the index, there is no segment that

corresponds to this table

• An index with the same name as the primary key constraint, in the

tablespace defined in the CREATE TABLE statement, using the storage

and block utilization parameters specified

• A table to accommodate the overflow row pieces The name of this table

is SYS_IOT_OVER_n, where n is the OBJECT_ID of the

index-organized table as seen from DBA_OBJECTS

15-18 Copyright  Oracle Corporation, 1998 All rights reserved.

Rows within PCTTHRESHOLD IOT tablespace Overflow tablespace

Trang 8

15-30 Oracle8: Database Administration

Index-Organized Table Operations

An index-organized table can be used like any other table All the commands, such

as ALTER TABLE, ANALYZE TABLE, TRUNCATE TABLE, and DROP TABLE,and all the DML commands, are supported against an index-organized table

Trang 9

Oracle8: Database Administration 15-31

Retrieving Information About Index-Organized Tables

Retrieving Information About Index-Organized Tables

Use the following query to list the index-organized tables and information

related to their structure:

SVRMGR> SELECT t.table_name AS "IOT", o.table_name AS

7> AND t.table_name = o.iot_name

8> AND t.owner = i.owner

9> AND t.table_name = i.table_name

10> AND t.owner= 'SCOTT';

Overflow TS -

Index TS -

PCT_THRESHOLD -

15-19 Copyright  Oracle Corporation, 1998 All rights reserved.

Retrieving IOT Information from

Data Dictionary

DBA_INDEXES

OWNER TABLE_NAME INDEX_NAME INDEX_TYPE PCT_THRESHOLD INCLUDE_COLUMN

DBA_TABLES

OWNER TABLE_NAME IOT_TYPE IOT_NAME TABLESPACE_NAME

Trang 10

15-32 Oracle8: Database Administration

Trang 11

Oracle8: Database Administration 15-33

Summary

Quick Reference

Initialization parameters None

Dynamic performance views None

Data dictionary views DBA_CLUSTERS

DBA_TAB_COLUMNS DBA_CLU_COLUMNS DBA_CLUSTER_HASH_EXPRESSIONS DBA_TABLES

DBA_INDEXES

CREATE INDEX ON CLUSTER CREATE CLUSTER HASHKEYS HASH IS ALTER CLUSTER

TRUNCATE CLUSTER DROP CLUSTER CREATE TABLE ORGANIZATION INDEX

Trang 12

15-34 Oracle8: Database Administration

Trang 13

16

Loading and Reorganizing Data

Trang 14

16-2 Oracle8: Database Administration

Trang 15

Oracle8: Database Administration 16-3

Objectives

Objectives

16-2 Copyright  Oracle Corporation, 1998 All rights reserved.

Objectives

Loading data using direct-load insert

Loading data into Oracle tables using

SQL*Loader conventional and direct

paths

Reorganizing data using export and

import

Trang 16

16-4 Oracle8: Database Administration

Overview

Several methods are available for loading data into tables in an Oracle

database The methods that will be discussed here are:

• Direct-load insert

• SQL*Loader

• Export and Import utilities

Direct-Load Insert

Direct-load inserts can be used to copy data from one table to another table

within the same database It speeds up the insert operation, by passing the

buffer cache, and writing data directly into the data files

SQL*Loader

SQL*Loader is a utility that is used to load data from external files into

Oracle tables It provides a means of migration from other systems to

Oracle database Export

Import

Direct-load insert

Trang 17

Oracle8: Database Administration 16-5

Overview

Export and Import Utilities

Export utility enables users to extract dictionary information and data from

an Oracle database and move them into an operating system file in

Oracle-binary format The files generated by export can be read by the

Import utility into the same Oracle database or a different database The

Export and Import utilities have several uses that will be discussed in a

subsequent section in this lesson

Trang 18

16-6 Oracle8: Database Administration

Loading Data Using Direct-Load Insert

where: schema is the owner of the table

sub-query is the subquery used to select the required

columns and rows for insertDirect-Load inserts are only available when the INSERT INTO SELECT

command is used This option is not available when INSERT INTO

VALUES command is used The direct-load insert can be used both on

nonpartitioned and partitioned tables This operation maintains indexes and

also enforces all enabled constraints It also enables other users to

concurrently modify other rows in the table

16-4 Copyright  Oracle Corporation, 1998 All rights reserved.

Free space after delete Blocks used by inserted rows

High water mark Used block

Using Direct-Load Inserts

Trang 19

Oracle8: Database Administration 16-7

Loading Data Using Direct-Load Insert

Logging Mode

When inserting using the LOGGING option, which is the default, the

operation generates redo log entries, making complete recovery possible in

case of failures

If the NOLOGGING option is used, changes to data are not recorded in the

redo log buffer Some minimal logging is still carried out, for operations

such as extent allocation The NOLOGGING mode is used if this attribute

has been set for the table

If several online modifications to the data in the table are likely to occur

subsequently, it might be advisable to set the NOLOGGING attribute before

the load and reset it to LOGGING once the load completes

Other Considerations

Direct-load inserts allow other transactions to concurrently make changes to

the table

All data inserted using this method is loaded above the high water mark If

the table contains many blocks where rows have been deleted, space may be

wasted, and full table scans may be slower

Instructor Note

You may want to inform the participants that hints are suggestions that

they give the optimizer for optimizing a SQL statements They are always

specified after the first keyword in a statement block, preceded by a “+”

sign, delimited by “/*” and “*/.” You may want to refer interested

participants to the lesson “Optimization Modes and Hints” in the manual

Oracle8 Server Tuning.

Trang 20

16-8 Oracle8: Database Administration

Direct-load inserts can be made in parallel using one of the following

methods:

• Using a PARALLEL hint in the INSERT statement as in the example

• Creating the table or altering it to specify the PARALLEL clause

When parallel direct-load inserts are made, the Oracle server uses several

processes, known as parallel query slaves, to insert data into the table

Temporary segments are allocated to store the data inserted by each slave

process When the transaction commits, the extents in these individual

segments become a part of the table in which records are inserted

Note

• The ALTER SESSION ENABLE PARALLEL DML command must be

executed at the beginning of a transaction

• An object that is modified using parallel direct-load insert cannot be

queried or modified again within the same transaction

• For a detailed discussion of parallel direct-load inserts, see the chapter

“Parallel Execution” in Oracle8 Server Reference manual.

Instructor Note

You can demonstrate the use of parallel direct-load insert using the scripts

dli_set.sql and dli_par.sql.

16-5 Copyright  Oracle Corporation, 1998 All rights reserved.

Free space after delete Temporary segments

High water mark Used block

Parallel Direct-Load Insert

Slave process

Trang 21

Oracle8: Database Administration 16-9

Loading Data Using SQL*Loader

Loading Data Using SQL*Loader

SQL*Loader loads data from external files into tables in an Oracle database

SQL*Loader Features

SQL*Loader has the following features:

• One or more input files can be used

• Several input records can be combined into one logical record for

loading

• Input fields can be fixed or variable length

• Input data can be in any format—character, binary, packed decimal, date,

and zoned decimal

• Data can be loaded from different types of media such as disk, tape, or

named pipes

• Data can be loaded into several tables in one run

• Options are available to either replace or to append to existing data in the

Trang 22

16-10 Oracle8: Database Administration

• Column values can be autogenerated based on rules For example, a

sequential key value can be generated and stored in a column

• Data can be loaded directly into the table, bypassing the database buffer

cache

Files Used by SQL*Loader

SQL*Loader uses the following files:

Control file: specifies the input format, output tables, and optional

conditions that may be used to load only part of the records found in the

input data files

Data files: contain the data in the format defined in the control file

Parameter file: is an optional file that can be used to define the command

line parameters for the load

Bad file: is used by the utility to write the records that are rejected during

the load (This can occur during input record validation by the utility or

during record insertion by the Oracle server.)

Log file: is created by SQL*Loader and contains a record of the load

Discard file: is a file that can be created, if necessary, to store all records

that did not satisfy the selection criteria

Trang 23

Oracle8: Database Administration 16-11

Loading Data Using SQL*Loader

SQL*Loader provides two methods for loading data:

• Conventional path

• Direct path

Conventional Path Load

Conventional path load builds an array of rows to be inserted and uses the

SQL INSERT statement to load the data During conventional path loads,

input records are parsed based on field specifications, and an array of records

is built and inserted into the table specified in the control file Records that

do not conform to the field specifications are rejected and those records that

do not satisfy the selection criteria are discarded

Conventional path loads can be used to load data into both clustered and

unclustered tables Redo log generation is controlled by the logging attribute

for the table being loaded

16-7 Copyright  Oracle Corporation, 1998 All rights reserved.

Conventional and Direct Loads

Conventional

Direct path

Array

management

Data save Table

High water mark Space used only by conventional load

A A A A A

AAAA AAAA AAAA AAAA AAAA AAAA

A A A A A A

Instance SGA Shared pool

Ngày đăng: 08/08/2014, 20:21

TỪ KHÓA LIÊN QUAN