1
Database Administration
& Management
Lecture 11
Chapter 4 – Additional Data Structures and Query
Optimization
2
Partitioning
Divide the information in tables or indexes among multiple
physical storage areas.
Data is divided based on column values.
• Range of values (usually date and numbers)
• List of values
• Hash Function
Partition Advisor can recommend a partitioning strategy for
a table(s) that can help to improve the performance of
Oracle Database.
3
Partitioning
Interval partitioning
• Automatic generation of a new partition after a fixed interval
or range when data to be inserted does not fit into existing
partition ranges.
Composite partitioning
• Defines two levels of partitions using a combination of list,
range and hash partitioning.
Equipartitioning
• Partition a table and an index identically.
• Automatic implementation by specifying an index for the
partitioned table as LOCAL index.
4
Partitioning - Benefits
Faster SQL
• Oracle won’t access partitions that do not contain any data to
satisfy the query.
Reduce scope of maintenance operations.
Increased data availability.
Data partitions based on the time span are specially useful
in a data warehouse environment.
5
Additional Data Structures
Sequences
Synonyms
Clusters
Hash Clusters
6
Sequences
 Sequence object is used to generate unique numbers for use as keys
or identifiers.
 Whenever a value is requested from a sequence, it returns a value
and increments its internal value.
 Sequence numbers are defined with a name, an incremental value,
and some additional information about the sequence.
 Sequences exist independently of any particular table, so more than
one table can use the same sequence number.
 Syntax:
CREATE SEQUENCE sequence_name
MINVALUE value
MAXVALUE value
START WITH value
INCREMENT BY value
7
Synonyms
Synonym is an alternative name for a table, view, sequence,
procedure, stored function, package, materialized view, Java
class schema object, user-defined object type, or another
synonym.
Qualified names for objects can get confusing, synonym can
be created for any table or view to make name simpler and
more readable.
Synonyms simplify user access to a data structure.
Public synonym - all users of a database can use it.
Private synonym - only the user whose schema contains the
synonym can use it.
8
Clusters
 Cluster is a data structure that improves retrieval performance by
storing related data values together on disk.
 Storing related values together reduces the number of I/O
operations needed to retrieve related values.
 A cluster is composed of one or more tables.
 The cluster includes a cluster index, which stores all the values for
the corresponding cluster key.
 Each value in the cluster index points to a data block that contains
only rows with the same value for the cluster key.
 Clusters may not be appropriate for tables that regularly require
full table scans.
9
Hash Clusters
Each request for data in a clustered table involves at least
two I/O operations, one for the cluster index and one for the
data.
A hash cluster stores related data rows together, but groups
the rows according to a hash value for the cluster key.
Each retrieval operation starts with a calculation of the hash
value and then goes directly to the data block that contains
the relevant rows.
A hash-clustered table is faster for retrieving data than a
clustered table.
10
Query Optimization
The process of determining the best way to access the data
requested by query.
Execution path - optimal way to retrieve data by Oracle.
Approaches to retrive data:
• Use index to find ROWIDs and retrieve relevant rows.
– ORDER BY can be automatically implementes in presorted index.
• Full table scan
– Bypass the index for small table to avoid additional I/O step.
Complexity in selecting the right execution path can grow rapidly.
Two different Oracle query optimizers:
1. Rule-based optimizer
2. Cost-based optimizer
11
Rule-Based Optimization
Uses a set of predefined rules for query optimization decisions.
No longer supported from version 10g and onwards.
Oracle rule-based optimizer had about 20 rules.
• The rule-based optimizer assigns an optimization score to each
potential execution path and then takes the path with the best
optimization score.
• When two paths have the same optimization score, the rule-
based optimizer selects the execution path based on the order in
which the tables occurred in the SQL statement.
Simple set of rules cannot deal with complex queries effectively.
12
Figure 4-4. The effect of optimization choices
13
Cost-Based Optimization
Introducted with Oracle version 7.
Selects the execution path that requires the least number of
logical I/O operations.
Uses statistics about the composition of the relevant data
structures.
Use of statistics enables cost-based optimizer to make a much
more well-informed choice of the optimal execution plan.
Automatic Workload Repository (AWR) automatically gathers
the statistics by default.
• Database access and usage statistics, system and session
statistics, SQL statements that produce the greatest loads...
14
CBO - How statistics are used
Optimal execution plan is determined by assigning an
optimization score for each of the potential execution plan
using internal rules and logic along with statistics.
These statistics relate to the tables, columns, and indexes
involved in the execution plan.
Overall system statistics collected in Data Dictionary Tables,
also determine the overall cost of the I/O required by an
execution plan.
• I/O and CPU performance and utilization
Oracle database 10g and onwards, default cost basis is
calculated on the CPU cost plus the I/O cost for a plan.
15
Table 4-1. Database statistics

1606802425-dba-w7 database management.pptx

  • 1.
    1 Database Administration & Management Lecture11 Chapter 4 – Additional Data Structures and Query Optimization
  • 2.
    2 Partitioning Divide the informationin tables or indexes among multiple physical storage areas. Data is divided based on column values. • Range of values (usually date and numbers) • List of values • Hash Function Partition Advisor can recommend a partitioning strategy for a table(s) that can help to improve the performance of Oracle Database.
  • 3.
    3 Partitioning Interval partitioning • Automaticgeneration of a new partition after a fixed interval or range when data to be inserted does not fit into existing partition ranges. Composite partitioning • Defines two levels of partitions using a combination of list, range and hash partitioning. Equipartitioning • Partition a table and an index identically. • Automatic implementation by specifying an index for the partitioned table as LOCAL index.
  • 4.
    4 Partitioning - Benefits FasterSQL • Oracle won’t access partitions that do not contain any data to satisfy the query. Reduce scope of maintenance operations. Increased data availability. Data partitions based on the time span are specially useful in a data warehouse environment.
  • 5.
  • 6.
    6 Sequences  Sequence objectis used to generate unique numbers for use as keys or identifiers.  Whenever a value is requested from a sequence, it returns a value and increments its internal value.  Sequence numbers are defined with a name, an incremental value, and some additional information about the sequence.  Sequences exist independently of any particular table, so more than one table can use the same sequence number.  Syntax: CREATE SEQUENCE sequence_name MINVALUE value MAXVALUE value START WITH value INCREMENT BY value
  • 7.
    7 Synonyms Synonym is analternative name for a table, view, sequence, procedure, stored function, package, materialized view, Java class schema object, user-defined object type, or another synonym. Qualified names for objects can get confusing, synonym can be created for any table or view to make name simpler and more readable. Synonyms simplify user access to a data structure. Public synonym - all users of a database can use it. Private synonym - only the user whose schema contains the synonym can use it.
  • 8.
    8 Clusters  Cluster isa data structure that improves retrieval performance by storing related data values together on disk.  Storing related values together reduces the number of I/O operations needed to retrieve related values.  A cluster is composed of one or more tables.  The cluster includes a cluster index, which stores all the values for the corresponding cluster key.  Each value in the cluster index points to a data block that contains only rows with the same value for the cluster key.  Clusters may not be appropriate for tables that regularly require full table scans.
  • 9.
    9 Hash Clusters Each requestfor data in a clustered table involves at least two I/O operations, one for the cluster index and one for the data. A hash cluster stores related data rows together, but groups the rows according to a hash value for the cluster key. Each retrieval operation starts with a calculation of the hash value and then goes directly to the data block that contains the relevant rows. A hash-clustered table is faster for retrieving data than a clustered table.
  • 10.
    10 Query Optimization The processof determining the best way to access the data requested by query. Execution path - optimal way to retrieve data by Oracle. Approaches to retrive data: • Use index to find ROWIDs and retrieve relevant rows. – ORDER BY can be automatically implementes in presorted index. • Full table scan – Bypass the index for small table to avoid additional I/O step. Complexity in selecting the right execution path can grow rapidly. Two different Oracle query optimizers: 1. Rule-based optimizer 2. Cost-based optimizer
  • 11.
    11 Rule-Based Optimization Uses aset of predefined rules for query optimization decisions. No longer supported from version 10g and onwards. Oracle rule-based optimizer had about 20 rules. • The rule-based optimizer assigns an optimization score to each potential execution path and then takes the path with the best optimization score. • When two paths have the same optimization score, the rule- based optimizer selects the execution path based on the order in which the tables occurred in the SQL statement. Simple set of rules cannot deal with complex queries effectively.
  • 12.
    12 Figure 4-4. Theeffect of optimization choices
  • 13.
    13 Cost-Based Optimization Introducted withOracle version 7. Selects the execution path that requires the least number of logical I/O operations. Uses statistics about the composition of the relevant data structures. Use of statistics enables cost-based optimizer to make a much more well-informed choice of the optimal execution plan. Automatic Workload Repository (AWR) automatically gathers the statistics by default. • Database access and usage statistics, system and session statistics, SQL statements that produce the greatest loads...
  • 14.
    14 CBO - Howstatistics are used Optimal execution plan is determined by assigning an optimization score for each of the potential execution plan using internal rules and logic along with statistics. These statistics relate to the tables, columns, and indexes involved in the execution plan. Overall system statistics collected in Data Dictionary Tables, also determine the overall cost of the I/O required by an execution plan. • I/O and CPU performance and utilization Oracle database 10g and onwards, default cost basis is calculated on the CPU cost plus the I/O cost for a plan.
  • 15.

Editor's Notes

  • #14 cost basis is calculated on the CPU cost plus the I/O cost for a plan