sql tuning

14
SQL Tuning SQL Tuning

Upload: amalie

Post on 31-Jan-2016

61 views

Category:

Documents


0 download

DESCRIPTION

SQL Tuning. Optimizer Tasks. Oracle optimizer performs the following functions when evaluating a SQL statement: Evaluates the expressions and conditions contained in the SQL statement Transforms complex queries into an equivalent join query - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: SQL Tuning

SQL TuningSQL Tuning

Page 2: SQL Tuning

2

Optimizer TasksOptimizer Tasks• Oracle optimizer performs the following functions

when evaluating a SQL statement:• Evaluates the expressions and conditions contained in the

SQL statement

• Transforms complex queries into an equivalent join query

• Chooses an optimization goal, either the Cost-based Optimizer (CBO) or the Rule-based Optimizer (RBO)

• Determines how to access each table to retrieve data

• Determines the order of table joins for statements involving more than two tables

• Chooses the type of join to be performed for each pair

Page 3: SQL Tuning

3

Optimizer ModesOptimizer Modes

Page 4: SQL Tuning

4

Optimizer GoalOptimizer Goal

Page 5: SQL Tuning

5

Rule-based Optimizer RanksRule-based Optimizer Ranks

Page 6: SQL Tuning

6

Cost-based Optimizer ProcessCost-based Optimizer Process• CHOOSE: Oracle chooses the best and most efficient path to execute and

retrieve data. Optimizer can select a cost-access method when statistics are available or a rule-based access method if it is faster. This setting is the most common mode used.

• ALL_ROWS: Oracle uses cost based access methods regardless of statistics availability. This optimizer priority is to retrieve all rows with the minimum amount of resource consumption. This option often used in Web applications.

• FIRST_ROWS: Oracle uses a mix of cost-based access methods and heuristics to retrieve the first few rows fast. This option is often used in FORMS client/server applications.

• FIRST_ROWS_N: Where N is 1, 10, 100, or 1000. Uses the cost-based access method to retrieve rows the most efficient way.

Page 7: SQL Tuning

7

Cost-based Optimizer Process Cost-based Optimizer Process (continued)(continued)

Page 8: SQL Tuning

8

Cost-based Optimizer Access Paths Cost-based Optimizer Access Paths

Page 9: SQL Tuning

9

Cost-based Optimizer Access Paths Cost-based Optimizer Access Paths (continued)(continued)

Page 10: SQL Tuning

10

Execution Plan Interpretation Execution Plan Interpretation

Page 11: SQL Tuning

11

Optimizer ParametersOptimizer Parameters• Optimizer Performance:

• OPTIMIZER_DYNAMIC_SAMPLING

• OPTIMIZER_FEATURES_ENABLE

• OPTIMIZER_INDEX_CACHING

• OPTIMIZER_INDEX_COST_ADJ

• OPTIMIZER_MAX_PERMUTATIONS

• Optimizer Behavior:• CURSOR_SHARING

• DB_FILE_MULTIBLOCK_READ_COUNT

• HASH_AREA_SIZE

• HASH_JOIN_ENABLED

• PARTITION_VIEW_ENABLED

• QUERY_REWRITE_ENABLED

• SORT_AREA_SIZE

• STAR_TRANSFORMATION_ENABLED

Page 12: SQL Tuning

12

Optimizer HintsOptimizer HintsOPTIMIZER

HINTS

ORDERED

STAR

ALL_ROWS

FIRST_ROWS(n)

CHOOSE

RULE

PARALLEL

NOPARALLEL

PQ_DISTRIBUTE

PARALLEL_INDEX

NOPARALLEL_INDEX

USE_NL

USE_MERGE

USE_HASH

DRIVING_SITE

LEADING

HASH_AJ

MERGE_AJ

APPEND

NOAPPEND

CACHE

NOCACHE

UNNEST

NO_UNNEST

PUSH_PRED

NO_PUSH_PRED

PUSH_SUBQ

NO_PUSH_SUBQ

FULL

ROWID

CLUSTER

HASH

INDEX

INDEX_ASC

INDEX_COMBINE

INDEX_JOIN

INDEX_DESC

INDEX_FFS

NO_INDEX

AND_EQUAL

USE_CONCAT

NO_EXPAND

REWRITE

EXPAND_GSET_TO_UNION

NOREWRITE

MERGE

NO_MERGE

STAR_TRANSFORMATION

FACT

NO_FACT ORDERED_PREDICATES

CURSOR_SHARING_EXACT

DYNAMIC_SAMPLING

NL_AJ

HASH_SJ

MERGE_SJ

NL_SJ

Other Hints

Page 13: SQL Tuning

13

Optimizer Hints SyntaxOptimizer Hints Syntax

Page 14: SQL Tuning

14

Classification of V$SQL Columns Classification of V$SQL Columns