+ All Categories
Home > Documents > 10 Copyright © 2006, Oracle. All rights reserved. Managing Schema Objects.

10 Copyright © 2006, Oracle. All rights reserved. Managing Schema Objects.

Date post: 27-Dec-2015
Category:
Upload: drusilla-cox
View: 221 times
Download: 0 times
Share this document with a friend
Popular Tags:
27
10 Copyright © 2006, Oracle. All rights reserved. Managing Schema Objects
Transcript
Page 1: 10 Copyright © 2006, Oracle. All rights reserved. Managing Schema Objects.

10Copyright © 2006, Oracle. All rights reserved.

Managing Schema Objects

Page 2: 10 Copyright © 2006, Oracle. All rights reserved. Managing Schema Objects.

10-2 Copyright © 2006, Oracle. All rights reserved.

Objectives

After completing this lesson, you should be able to manage schema objects and:

• Determine appropriate table types for your requirements: heap, partition, IOT, or cluster

• Perform related DBA tasks:– Estimating the size of new tables– Analyzing growth trends– Managing optimizer statistics – Reorganizing schema objects online

Table TypesPartitionIOTClusterDBA Tasks

Page 3: 10 Copyright © 2006, Oracle. All rights reserved. Managing Schema Objects.

10-3 Copyright © 2006, Oracle. All rights reserved.

Table Types

Related data from more than one table are stored together.

Clustered table

Data (including non-key values) is sorted and stored in a B-tree index structure.

Index-organized table (IOT)

Data is divided into smaller, more manageable pieces.

Partitioned table

Data is stored as an unordered collection (heap).

Ordinary (heap-organized) table

DescriptionType

Heap

IOTPartitioned

Clustered

Page 4: 10 Copyright © 2006, Oracle. All rights reserved. Managing Schema Objects.

10-4 Copyright © 2006, Oracle. All rights reserved.

What Is a Partition and Why Use It?

A partition is:

• A piece of a “very large” table or index

• Stored in its own segment

• Used for improved performance and manageability

Table Types> Partition

IOTClusterDBA Tasks

Page 5: 10 Copyright © 2006, Oracle. All rights reserved. Managing Schema Objects.

10-5 Copyright © 2006, Oracle. All rights reserved.

Partitions

Characteristics of partitions are:

• Same logical attributes: Same columns, constraints, and indexes

• Different physical attributes: Stored in different tablespaces

• Transparent to applications

• Several partitioning methods

Page 6: 10 Copyright © 2006, Oracle. All rights reserved. Managing Schema Objects.

10-6 Copyright © 2006, Oracle. All rights reserved.

Creating a Partition

Page 7: 10 Copyright © 2006, Oracle. All rights reserved. Managing Schema Objects.

10-7 Copyright © 2006, Oracle. All rights reserved.

Partitioning Methods

• Range partitioning: Maps rows based on logical ranges of columns values—for example, months in a year

• Hash partitioning: Maps rows based on the hash value of the partitioning key

• List partitioning: Maps rows based on a discrete list of values, provided by the DBA

• Range-hash partitioning: Maps rows using the range method, and within each range partition, creates hash subpartitions

• Range-list partitioning: Maps rows first based on a range of values, then based on discrete values

Page 8: 10 Copyright © 2006, Oracle. All rights reserved. Managing Schema Objects.

10-8 Copyright © 2006, Oracle. All rights reserved.

Partition Maintenance

Page 9: 10 Copyright © 2006, Oracle. All rights reserved. Managing Schema Objects.

10-9 Copyright © 2006, Oracle. All rights reserved.

Table accessby ROWID

Index-Organized Tables

Regular table access IOT access

Non-key columns

Key column

Row header

Table TypesPartition

> IOTClusterDBA Tasks

Page 10: 10 Copyright © 2006, Oracle. All rights reserved. Managing Schema Objects.

10-10 Copyright © 2006, Oracle. All rights reserved.

Index-Organized Tablesand Heap Tables

• Compared to heap tables, IOTs:– Have faster key-based access to table data– Do not duplicate the storage of primary key values– Require less storage – Use secondary indexes and logical row IDs– Have higher availability because table

reorganization does not invalidate secondary indexes

• IOTs have the following restrictions:– Must have a primary key that is not DEFERRABLE– Cannot be clustered– Cannot use composite partitioning – Cannot contain a column of type ROWID or LONG

Page 11: 10 Copyright © 2006, Oracle. All rights reserved. Managing Schema Objects.

10-12 Copyright © 2006, Oracle. All rights reserved.

Creating Index-Organized Tables

SQL> CREATE TABLE country 2 ( country_id CHAR(2) 3 CONSTRAINT country_id_nn NOT NULL, 4 country_name VARCHAR2(40), 5 currency_name VARCHAR2(25), 6 currency_symbol VARCHAR2(3), 7 map BLOB, 8 flag BLOB, 9 CONSTRAINT country_c_id_pk 10 PRIMARY KEY (country_id)) 11 ORGANIZATION INDEX 12 TABLESPACE indx 13 PCTTHRESHOLD 20 14 OVERFLOW TABLESPACE users;

Page 12: 10 Copyright © 2006, Oracle. All rights reserved. Managing Schema Objects.

10-13 Copyright © 2006, Oracle. All rights reserved.

Clusters

Clustered orders and order_item tables

Cluster Key(ORD_NO) 101 ORD_DT CUST_CD 05-JAN-97 R01

PROD QTYA4102 20A5675 19 W0824 10

102 ORD_DT CUST_CD 07-JAN-97 N45

PROD QTYA2091 11G7830 20 N9587 26

Unclustered orders and order_item tables

ORD_NO ORD_DT CUST_CD------ ------ ------

101 05-JAN-97 R01102 07-JAN-97 N45

ORD_NO PROD QTY ...----- ------ ------

101 A4102 20102 A2091 11102 G7830 20

102 N9587 26101 A5675 19101 W0824 10

Table TypesPartitionIOT

> ClusterDBA Tasks

Page 13: 10 Copyright © 2006, Oracle. All rights reserved. Managing Schema Objects.

10-14 Copyright © 2006, Oracle. All rights reserved.

Cluster Types

Index clusterSorted hash

clusterHash

cluster

1

2

3

Hash function Hash function

Page 14: 10 Copyright © 2006, Oracle. All rights reserved. Managing Schema Objects.

10-16 Copyright © 2006, Oracle. All rights reserved.

Situations Where Clusters Are Useful

Data is retrieved in the order it was inserted

Queries using equality predicate on key

Predictable number of key values

Often joined master-detail tables

Rarely updated key

Evenly distributed key values

Uniform key distribution

Sorted hashHashIndexCriterion

Page 15: 10 Copyright © 2006, Oracle. All rights reserved. Managing Schema Objects.

10-17 Copyright © 2006, Oracle. All rights reserved.

Sorted Hash Cluster: Overview

• New data structure used to store data sorted by nonprimary key columns:– Cluster key values are hashed.– Rows corresponding to a particular cluster key

value are sorted according to the sort key.

• Used to guarantee that row order is returned by queries without sorting data:– Rows are returned in ascending or descending

order for a particular cluster key value.– ORDER BY clause is not mandatory to retrieve rows

in ascending order.

Page 16: 10 Copyright © 2006, Oracle. All rights reserved. Managing Schema Objects.

10-18 Copyright © 2006, Oracle. All rights reserved.

Sorted Hash Cluster: Example

CREATE CLUSTER calls_cluster( origin_number NUMBER, call_timestamp NUMBER SORT, call_duration NUMBER SORT)HASHKEYS 10000SINGLE TABLE HASH IS origin_numberSIZE 50;

CREATE TABLE calls( origin_number NUMBER, call_timestamp NUMBER , call_duration NUMBER , other_info VARCHAR2(30))CLUSTER calls_cluster(origin_number,call_timestamp,call_duration);

Cluster key

Sort key

Page 17: 10 Copyright © 2006, Oracle. All rights reserved. Managing Schema Objects.

10-19 Copyright © 2006, Oracle. All rights reserved.

Sorted Hash Cluster: Basic Architecture

Cluster key 2…

Cluster key 1

Cluster key n

HASHKEYS

SIZE

Block chainstarting points

Rows sorted bysort key in each

block chain

Page 18: 10 Copyright © 2006, Oracle. All rights reserved. Managing Schema Objects.

10-20 Copyright © 2006, Oracle. All rights reserved.

Schema Management Tasks

DBA tasks include:

• Estimating the size of new tables

• Analyzing growth trends

• Managing optimizer statistics

• Reorganizing schema objects online

Table TypesPartitionIOTCluster

> DBA Tasks

Page 19: 10 Copyright © 2006, Oracle. All rights reserved. Managing Schema Objects.

10-21 Copyright © 2006, Oracle. All rights reserved.

Estimating Resource Usage

Page 20: 10 Copyright © 2006, Oracle. All rights reserved. Managing Schema Objects.

10-22 Copyright © 2006, Oracle. All rights reserved.

Analyzing Growth Trends

EM growth trend report:

• Used by the Segment Advisor

• Space usage statistics collected into AWR

Page 21: 10 Copyright © 2006, Oracle. All rights reserved. Managing Schema Objects.

10-23 Copyright © 2006, Oracle. All rights reserved.

Managing Optimizer Statistics

Not analyzed1

23

Page 22: 10 Copyright © 2006, Oracle. All rights reserved. Managing Schema Objects.

10-24 Copyright © 2006, Oracle. All rights reserved.

Reorganizing Schema Objects Online

• Modifying logical or physical structure of a schema object, such as a table or index

• Transparent to users

• Space requirements

Page 23: 10 Copyright © 2006, Oracle. All rights reserved. Managing Schema Objects.

10-26 Copyright © 2006, Oracle. All rights reserved.

Reorganizing Objects:Impact Report

Page 24: 10 Copyright © 2006, Oracle. All rights reserved. Managing Schema Objects.

10-27 Copyright © 2006, Oracle. All rights reserved.

Reorganizing Objects: Review

Page 25: 10 Copyright © 2006, Oracle. All rights reserved. Managing Schema Objects.

10-28 Copyright © 2006, Oracle. All rights reserved.

Basic Steps for Manual Online Reorganization

1. Verify that the table is a candidate for online reorganization.

2. Create an interim table.

3. Start the redefinition process.

4. Copy dependent objects. (This automatically creates any triggers, indexes, grants, and constraints on the interim table.)

5. Query the DBA_REDEFINITION_ERRORS view to check for errors.

6. Optionally, synchronize the interim table.

7. Complete the redefinition.

8. Drop the interim table.

Page 26: 10 Copyright © 2006, Oracle. All rights reserved. Managing Schema Objects.

10-29 Copyright © 2006, Oracle. All rights reserved.

Summary

In this lesson, you should have learned how to manage schema objects and:

• Determine appropriate table types for your requirements

• Perform related DBA tasks:– Estimating the size of new tables– Analyzing growth trends– Managing optimizer statistics – Reorganizing schema objects online

Page 27: 10 Copyright © 2006, Oracle. All rights reserved. Managing Schema Objects.

10-30 Copyright © 2006, Oracle. All rights reserved.

Practice Overview:Managing Schema Objects

This practice covers the following topics:

• Monitoring table and index space usage

• Managing optimizer statistics

• Reorganizing table and index


Recommended