SlideShare a Scribd company logo
Introduction to
Oracle Optimizer
Heribertus Bramundito
Agenda
 Our Environment
 Heap Table

 Histogram

 Oracle Optimizer
 Cost
 Selectivity & Cardinality
 Clustering Factor

 Access Method
 Partitioning
 Join Method
 Sub-query
 Hint
Our Environment
Heap Table
 This is default table when we issue the CREATE TABLE

statement
 Data is stored in random fashion, no specific sort of order
(best fit algorithm)

3
Our Environment
Heap Table (result from table access)

4
Our Environment
Heap Table (result from index access)

5
Our Environment
IOT Table (a comparison)

6
Our Environment
Histogram
 Collection of information about data distribution in

specific column
 Oracle maintains 2 types of histogram: frequency and
height-balanced
 Oracle use histogram as additional information when
deciding whether to use index scan or table scan

7
Our Environment
Histogram (column without histogram)

8
Our Environment
Histogram (create histogram)

9
Our Environment
Histogram (column with histogram)

10
Agenda
 Our Environment
 Heap Table

 Histogram

 Oracle Optimizer
 Cost
 Selectivity & Cardinality
 Clustering Factor

 Access Method
 Partitioning
 Join Method
 Sub-query
 Hint
Cost
 Jonathan Lewis: “The cost represents the optimizer‟s best estimate of the

time it will take to execute the statement”
 A result of the calculation performed by optimizer
 Few conditions that make CBO produces wrong result”
 No statistics on the underlying objects or statistics are obsolete
 Performance characteristics of hardware or current workloads are not known
 Bug

 From Oracle Performance Tuning Guide and Reference

Cost = (#SRds * sreadtim + #MRds * mreadtim +
#CPUCycles / cpuspeed) / sreadtim
#SRds: number of single data block reads
#MRds: number of multi data block reads
#CPUCycle: number of CPU cycles
sreadtim: single block read time
mreadtim: multi block read time
cpuspeed: CPU cycles per second
12
Cost (the calculation)
 #SRds = blevel + #leaf_block * idx_sel + clustering_factor * tbl_sel (index





scan)
#MRds = #tbl_blocks under HWM / mbrc (full table/ index scan)
sreadtim = ioseektim + block_size * iotfrspeed (SREADTIM)
mreadtim = ioseektim + mbrc * block_size * iotfrspeed (MREADTIM)
mbrc = db_file_multiblock_read_count (MBRC)

 Going back to slide #4 (let‟s try to calculate cost of table

scan)
 Cost = (24 / 16) * (10 + 16 * 8192 / 4092) / (10 + 8192 / 4092) = 1.5 * 42 /

12 = 5.25

 Slide #5 (index scan only)
 Cost = 0 + ceil(1 * 0.0588) = ceil(0.0588) = 1

 Slide #10 (index scan with access to the table)
 Cost = 0 + 1 + ceil((4 / 17) * 20) = 1 + ceil(4.705) = 1 + 5 = 6
13
Selectivity & Cardinality
 Selectivity is what fraction of row the predicate is supposed to fetch/ return

Selectivity = 1 / num_distinct (no histogram)

Selectivity = density (histogram)
 Cardinality is total number of row the predicate is supposed to return

Cardinality = num_rows * density
 Going back to slide #4


Cardinality = num_rows = 20

 Slide #5


Selectivity = (number of bucket with data / number of total bucket) = 17 / 17 = 1



Cardinality = selectivity * num_rows = 1 * 20 = 20

 Slide #10


14

Selectivity = 4 / 17 = 0.235



Cardinality = 0.235 * 20 = 4.7
Clustering Factor
 Represents the degree to which data is randomly

distributed through a table
 Number of blocks <= clustering factor <= number of rows
 Index has better selectivity if clustering factor is close to
number of data block, means Oracle can do multi block
read on the table for several index‟s key

15
Clustering Factor (block_id from rowid)
 Going back to NORMAL_HASH table example, due to

the anomaly configuration of pctfree and pctused, every
block contains single row only

16
Access Method
 There are 2 access methods: table and index

access
 Index access can be: Fast Full Scan, Full Scan,
Unique Scan, Range Scan, Range Scan
(MIN/MAX) and Skip Scan

17
Access Method
Full Table Scan
 Oracle is reading all rows from the table
 Not suitable for OLTP system with high volume of

transaction and usually only access small fraction of data
 Suitable for DSS system with batch reporting query
 Not good for Nested Loop (NL) for the outer table (huge
table)
 Usually we see it in Hash Join (HJ)

18
Access Method
Index Fast Full Scan

 Oracle is reading all rows from the index to get the

result (doesn‟t required table access since the index
contains all columns required to resolve the query)
 To be able to use Index FFS, the column should be
defined as NOT NULL or at least one column in a
composite index is NOT NULL, the reason is that
NULL values are not included in the index creation,
so when the column is defined as NOT NULL Oracle
knows that all values are available in the index
 Index FFS will be available as an option if we put “IS
NOT NULL” in the WHERE clause explicitly
 Cost will be only for accessing the index
19
Access Method
Index Fast Full Scan (forced by hint)

20
Access Method
Index Fast Full Scan (cost calculation)
 If we remove the HINT, we will have Index Full Scan
 Cost for Index Fast Full Scan
 Cost = (8 / 16) * (10 + 16 * 8192 / 4092) / (10 + 8192 / 4092) = 0.5 * 32 / 12 =

ceil(1.333) = 2
 Cost for Index Full Scan
 Cost = 0 + ceil(1 * 1 / 14) = ceil(0.0714) = 1

21
Access Method
Index Fast Full Scan (building the example)

 Another figure from index with more leaf block

(another anomaly configuration in the pctfree of
the index)

22
Access Method
Index Fast Full Scan (the result)

23
Access Method
Index Full Scan

 Oracle is reading all rows from the index, and

may be accessing these rows in the underlying
table
Without table
access

24
Access Method
Index Full Scan (with table access)
Unique index

25
Access Method
Index Unique Scan
 Oracle is reading 0 or 1 rows from the index, only on

unique index
 Equality operator in the predicate (=), ay be seen in AND,
OR, IS NULL operator

26
Access Method
Index Unique Scan (the result)

27
Access Method
Index Range Scan

 Oracle is reading 0 or more contiguous rows

from the index
 Non unique index with range operator in the
predicate (>, <, >=, <=)

28
Access Method
Index Range Scan (MIN/MAX)

 Oracle is identifying 0 or more contiguous rows

in the index, but is reading only one (the first or
the last) in order to satisfy a MIN or MAX
aggregate function

29
Access Method
Index Skip Scan

 Oracle is reading 0 or more rows from different

parts of the index (composite index), and may be
accessing these rows in the underlying table
 Skip Scan will be happened when we access a
composite index with second column in the
index‟s order. It will not be happened for the third
column, forth, etc.
 It will works only if first column in the index has
low cardinality (few distinct value) otherwise full
table scan will be better in most of the case
30
Access Method
Index Skip Scan (building the example)

31
Access Method
Index Skip Scan (the result)
First index‟s
column with low
cardinality

32
Access Method
Index Skip Scan (a comparison)

First index‟s
column with high
cardinality

33
Partitioning
 There are some consideration when we are

working with partition table. One of its is
regarding access path. We introduce partitioning
on the table usually to reduce the number of
rows which will affected by any query, since we
know that not all of those rows are being used in
the query.
 There are 4 kinds of access method for
partitioned table: Partition Range Single,
Partition Range Iterator, Partition Range All and
Partition Range Sub-query
34
Partitioning (building the example)

35
Partitioning
Partition Range Single

 Exactly only single partition of the table involves

in the query. Access path on this partition
depends on the query, can be Table Scan or any
Index Scan

36
Partitioning
Partition Range Iterator

 We will see this kind of access path whenever

we have several partitions in the query

37
Partitioning
Partition Range All
 In this kind of access method, all partitions in the table

will be scanned. This is a bad example of table design 
(create a partition table without taking any benefit of it)

38
Partitioning
Partition Range Sub-query (building an example)

 This method is new in 10g. If the partitioned table

is bigger compare to the other join table and the
expected number of the records (result) is
significantly less, Oracle will perform dynamic
partition pruning using sub-query
 The partitioned table will be having 200,000
blocks and the other join only 200 blocks

39
Partitioning
Partition Range Sub-query (the result)

Only 7 rows compare
to 1000 rows from
partitioned table

40
Partitioning
Partition Range Sub-query (a comparison)

41
Join Method
 There are 3 join methods: Nested Loop (NL),

Hash Join (HJ) and Sort Merge Join (SM)
 Most of the time we see only „standard‟ join
between 2 tables, but in rare case we will see
Anti-Join and Semi-Join variation for all above 3
methods. Anti-Join will be appear when we are
working with NOT IN clause while Semi-Join will
be appear when we are working with EXISTS
clause

42
Join Method
Nested Loop

 The Nested means an iteration. Pseudo-code for

this kind of join will be like below:
for x in (select [col] from outer_table) loop
for y in (select [col] from inner_table where outer_table.join_col =
inner_table.join_col) loop
return the rows from outer and inner table
end loop;
end loop;

 Suitable for small “size” for the outer (driving)

table. For the inner table, it should be accessed
using index scan
 Starting from 9i, Oracle introduces new „table
prefetching‟ method which will reduce logical I/O
43
Join Method
Nested Loop (building the example)

44
Join Method
Nested Loop (table prefetching method)

note down the
logical I/O

45
Join Method
Nested Loop (legacy method)

recreate with
UNIQUE index
46
Join Method
Nested Loop (the result)

47
Join Method
Hash Join

 In this method, first Oracle will choose 1 dataset

(build table – this is outer table in Nested Loop), and
then create hash table in memory using generated
hash-key from join column. Once completed, second
table (probe table – this is inner table in Nested
Loop) will be scanned using the same hash function
(probing the hash table)
 Applicable for join with equality operator (=)
 There are 3 level of effectiveness: optimal, one-pass
and multi-pass. Optimal when the size of tables is
matched with hash_area_size. One-pass or Multipass when the tables is not enough to be hash-ed in
the memory (requires disk operation)
 Event 10104 for tracing Hash Join operation
48
Join Method
Hash Join (cont.)

 Check hash_area_size and

workarea_size_policy database parameter
 Check v$sysstat for relevant system statistics
SELECT name, value, case when sum(value) over() = 0 then 0
else round(value*100/sum(value) over(),2) end as pct
FROM v$sysstat

WHERE name LIKE 'workarea executions%'

49
Join Method
Hash Join (components)

50
Join Method
Hash Join (build the example)

51
Join Method
Hash Join (the result – optimal)

workarea_size_policy = AUTO
test on SMALL table

52
Join Method
Hash Join (the result – optimal, part 2)

workarea_size_policy = AUTO
test on BIG table

53
Join Method
Hash Join (with index scan on the tables)

54
Join Method
Hash Join (event 10104)

55
Join Method
Sort Merge
 There are 2 operation in this method: sort and merge. So






56

it is application for any query which requires sorting (on
the join column): Order By clause, Group By clause, Set
operation, Distinct operator, Analytical function, Index
creation, Connect By query and etc
Similar to Hash Join, there are 3 level of effectiveness for
sorting operation: optimal, one-pass and multi-pass.
Optimal when the size sort_area_size is enough to
handle sort operation. One-pass or Multi-pass when
Oracle requires disk operation for the sorting
Event 10032 for tracing sort operation and 10033 for
tracing sort I/O operation
Check sort_area_size and workarea_size_policy
database parameter
Check v$sysstat for relevant system statistics and
v$tempstat for sorting statistics
Join Method
Sort Merge (cont.)

 Merging part can be one of the following

possibilities:

57
Join Method
Sort Merge (build the example)

58
Join Method
Sort Merge (sorting only example)

59
Join Method
Sort Merge (sorting only example – cont.)

60
Join Method
Sort Merge (the example)

61
Join Method
Sort Merge (Merge Join Cartesian)

62
Join Method
Sort Merge (event 10032)

63
Sub-query
 There 2 main types of sub-query: Nested Sub-

query and Correlated Sub-query
 Nested sub-query when the sub-query (inner
query) need to be completed first and then the
result will be passed to the main query
 Correlated sub-query when the main query
should be executed first in order to execute the
inner query
 In some cases we can rewrite sub-query into join
form for performance improvement
64
Sub-query (building the example)

65
Sub-query
Nested

 The select statement against “sub_q” is executed

first and the outputs will be used by main query

66
Sub-query
Correlated

 We can see from Predicate Information,

“sub_q” is executed for every value from
“main_q”

67
Sub-query
Correlated – rewrite into join

68
Sub-query
Correlated – comparing the statistics

Check
logical I/O
69
Hint
 Some of famous Oracle hints
 PARALLEL, PARALLEL_INDEX
 FULL
 INDEX, INDEX_SS, INDEX_FFS
 LEADING
 ORDERED
 DRIVING_SITE
 USE_NL, USE_HASH, USE_MERGE
 APPEND
 USE_CONCAT

 Other hints
 MERGE_AJ, HASH_AJ
 MERGE_SJ, HASH_SJ
 UNNEST, NO_UNNEST

70
References
 Jonathan Lewis, Cost-Based Oracle






71



Fundamentals
Thomas Kyte, Expert Oracle Database
Architecture – 9i and 10g Programming
Techniques and Solutions
http://www.orafaq.com/tuningguide/
http://oraclerandolf.blogspot.com/2011/10/paralleldowngrade.html
http://asktom.oracle.com/pls/asktom/f?p=100:1:0::
NO::
http://jonathanlewis.wordpress.com/

More Related Content

What's hot

linked list
linked list linked list
linked list
Mohaimin Rahat
 
Linked lists a
Linked lists aLinked lists a
Linked lists a
Khuram Shahzad
 
Linked List
Linked ListLinked List
Linked List
Ashim Lamichhane
 
Data Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListData Structure and Algorithms Linked List
Data Structure and Algorithms Linked List
ManishPrajapati78
 
linked list
linked listlinked list
linked list
Shaista Qadir
 
Unit ii(dsc++)
Unit ii(dsc++)Unit ii(dsc++)
Unit ii(dsc++)
Durga Devi
 
Sql Queries
Sql QueriesSql Queries
Sql Queries
webicon
 
IBM Informix Database SQL Set operators and ANSI Hash Join
IBM Informix Database SQL Set operators and ANSI Hash JoinIBM Informix Database SQL Set operators and ANSI Hash Join
IBM Informix Database SQL Set operators and ANSI Hash Join
Ajay Gupte
 
Migration
MigrationMigration
Migration
oracle documents
 
Linklist
LinklistLinklist
Deletion from single way linked list and search
Deletion from single way linked list and searchDeletion from single way linked list and search
Deletion from single way linked list and search
Estiak Khan
 
Discover the power of Recursive SQL and query transformation with Informix da...
Discover the power of Recursive SQL and query transformation with Informix da...Discover the power of Recursive SQL and query transformation with Informix da...
Discover the power of Recursive SQL and query transformation with Informix da...
Ajay Gupte
 
Linked List Static and Dynamic Memory Allocation
Linked List Static and Dynamic Memory AllocationLinked List Static and Dynamic Memory Allocation
Linked List Static and Dynamic Memory Allocation
Prof Ansari
 
linked list (c#)
 linked list (c#) linked list (c#)
linked list (c#)
swajahatr
 
MySQL index optimization techniques
MySQL index optimization techniquesMySQL index optimization techniques
MySQL index optimization techniques
kumar gaurav
 
MYSQL join
MYSQL joinMYSQL join
MYSQL join
Ahmed Farag
 
Doubly & Circular Linked Lists
Doubly & Circular Linked ListsDoubly & Circular Linked Lists
Doubly & Circular Linked Lists
Afaq Mansoor Khan
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
dchuynh
 
single linked list
single linked listsingle linked list
single linked list
Sathasivam Rangasamy
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
maamir farooq
 

What's hot (20)

linked list
linked list linked list
linked list
 
Linked lists a
Linked lists aLinked lists a
Linked lists a
 
Linked List
Linked ListLinked List
Linked List
 
Data Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListData Structure and Algorithms Linked List
Data Structure and Algorithms Linked List
 
linked list
linked listlinked list
linked list
 
Unit ii(dsc++)
Unit ii(dsc++)Unit ii(dsc++)
Unit ii(dsc++)
 
Sql Queries
Sql QueriesSql Queries
Sql Queries
 
IBM Informix Database SQL Set operators and ANSI Hash Join
IBM Informix Database SQL Set operators and ANSI Hash JoinIBM Informix Database SQL Set operators and ANSI Hash Join
IBM Informix Database SQL Set operators and ANSI Hash Join
 
Migration
MigrationMigration
Migration
 
Linklist
LinklistLinklist
Linklist
 
Deletion from single way linked list and search
Deletion from single way linked list and searchDeletion from single way linked list and search
Deletion from single way linked list and search
 
Discover the power of Recursive SQL and query transformation with Informix da...
Discover the power of Recursive SQL and query transformation with Informix da...Discover the power of Recursive SQL and query transformation with Informix da...
Discover the power of Recursive SQL and query transformation with Informix da...
 
Linked List Static and Dynamic Memory Allocation
Linked List Static and Dynamic Memory AllocationLinked List Static and Dynamic Memory Allocation
Linked List Static and Dynamic Memory Allocation
 
linked list (c#)
 linked list (c#) linked list (c#)
linked list (c#)
 
MySQL index optimization techniques
MySQL index optimization techniquesMySQL index optimization techniques
MySQL index optimization techniques
 
MYSQL join
MYSQL joinMYSQL join
MYSQL join
 
Doubly & Circular Linked Lists
Doubly & Circular Linked ListsDoubly & Circular Linked Lists
Doubly & Circular Linked Lists
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 
single linked list
single linked listsingle linked list
single linked list
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 

Similar to Introduction to oracle optimizer

hashing.pdf
hashing.pdfhashing.pdf
hashing.pdf
Yuvraj919347
 
Application sql issues_and_tuning
Application sql issues_and_tuningApplication sql issues_and_tuning
Application sql issues_and_tuning
Anil Pandey
 
Ora faq
Ora faqOra faq
Ora faq
vishpoola
 
Ora faq
Ora faqOra faq
Ora faq
vishpoola
 
Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007
paulguerin
 
Database Performance
Database PerformanceDatabase Performance
Database Performance
Boris Hristov
 
Advanced MySQL Query Optimizations
Advanced MySQL Query OptimizationsAdvanced MySQL Query Optimizations
Advanced MySQL Query Optimizations
Dave Stokes
 
Database index
Database indexDatabase index
Database index
Riteshkiit
 
Oracle Join Methods and 12c Adaptive Plans
Oracle Join Methods and 12c Adaptive PlansOracle Join Methods and 12c Adaptive Plans
Oracle Join Methods and 12c Adaptive Plans
Franck Pachot
 
Bo4301369372
Bo4301369372Bo4301369372
Bo4301369372
IJERA Editor
 
Hashing Technique In Data Structures
Hashing Technique In Data StructuresHashing Technique In Data Structures
Hashing Technique In Data Structures
SHAKOOR AB
 
Top 10 sap abap faqs-www.bigclasses.com
Top 10 sap abap faqs-www.bigclasses.comTop 10 sap abap faqs-www.bigclasses.com
Top 10 sap abap faqs-www.bigclasses.com
bigclasses.com
 
Optimizing MySQL queries
Optimizing MySQL queriesOptimizing MySQL queries
Optimizing MySQL queries
GMO-Z.com Vietnam Lab Center
 
Interview Questions.pdf
Interview Questions.pdfInterview Questions.pdf
Interview Questions.pdf
TarunKumar893717
 
Hash join
Hash joinHash join
Mysql Optimization
Mysql OptimizationMysql Optimization
Mysql Optimization
KLabCyscorpions-TechBlog
 
Maryna Popova "Deep dive AWS Redshift"
Maryna Popova "Deep dive AWS Redshift"Maryna Popova "Deep dive AWS Redshift"
Maryna Popova "Deep dive AWS Redshift"
Lviv Startup Club
 
MySQL Indexes
MySQL IndexesMySQL Indexes
MySQL Indexes
Anton Zhukov
 
Etl2
Etl2Etl2
Indexing Strategies
Indexing StrategiesIndexing Strategies
Indexing Strategies
jlaspada
 

Similar to Introduction to oracle optimizer (20)

hashing.pdf
hashing.pdfhashing.pdf
hashing.pdf
 
Application sql issues_and_tuning
Application sql issues_and_tuningApplication sql issues_and_tuning
Application sql issues_and_tuning
 
Ora faq
Ora faqOra faq
Ora faq
 
Ora faq
Ora faqOra faq
Ora faq
 
Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007
 
Database Performance
Database PerformanceDatabase Performance
Database Performance
 
Advanced MySQL Query Optimizations
Advanced MySQL Query OptimizationsAdvanced MySQL Query Optimizations
Advanced MySQL Query Optimizations
 
Database index
Database indexDatabase index
Database index
 
Oracle Join Methods and 12c Adaptive Plans
Oracle Join Methods and 12c Adaptive PlansOracle Join Methods and 12c Adaptive Plans
Oracle Join Methods and 12c Adaptive Plans
 
Bo4301369372
Bo4301369372Bo4301369372
Bo4301369372
 
Hashing Technique In Data Structures
Hashing Technique In Data StructuresHashing Technique In Data Structures
Hashing Technique In Data Structures
 
Top 10 sap abap faqs-www.bigclasses.com
Top 10 sap abap faqs-www.bigclasses.comTop 10 sap abap faqs-www.bigclasses.com
Top 10 sap abap faqs-www.bigclasses.com
 
Optimizing MySQL queries
Optimizing MySQL queriesOptimizing MySQL queries
Optimizing MySQL queries
 
Interview Questions.pdf
Interview Questions.pdfInterview Questions.pdf
Interview Questions.pdf
 
Hash join
Hash joinHash join
Hash join
 
Mysql Optimization
Mysql OptimizationMysql Optimization
Mysql Optimization
 
Maryna Popova "Deep dive AWS Redshift"
Maryna Popova "Deep dive AWS Redshift"Maryna Popova "Deep dive AWS Redshift"
Maryna Popova "Deep dive AWS Redshift"
 
MySQL Indexes
MySQL IndexesMySQL Indexes
MySQL Indexes
 
Etl2
Etl2Etl2
Etl2
 
Indexing Strategies
Indexing StrategiesIndexing Strategies
Indexing Strategies
 

Recently uploaded

Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
Zilliz
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 

Recently uploaded (20)

Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 

Introduction to oracle optimizer

  • 2. Agenda  Our Environment  Heap Table  Histogram  Oracle Optimizer  Cost  Selectivity & Cardinality  Clustering Factor  Access Method  Partitioning  Join Method  Sub-query  Hint
  • 3. Our Environment Heap Table  This is default table when we issue the CREATE TABLE statement  Data is stored in random fashion, no specific sort of order (best fit algorithm) 3
  • 4. Our Environment Heap Table (result from table access) 4
  • 5. Our Environment Heap Table (result from index access) 5
  • 6. Our Environment IOT Table (a comparison) 6
  • 7. Our Environment Histogram  Collection of information about data distribution in specific column  Oracle maintains 2 types of histogram: frequency and height-balanced  Oracle use histogram as additional information when deciding whether to use index scan or table scan 7
  • 8. Our Environment Histogram (column without histogram) 8
  • 10. Our Environment Histogram (column with histogram) 10
  • 11. Agenda  Our Environment  Heap Table  Histogram  Oracle Optimizer  Cost  Selectivity & Cardinality  Clustering Factor  Access Method  Partitioning  Join Method  Sub-query  Hint
  • 12. Cost  Jonathan Lewis: “The cost represents the optimizer‟s best estimate of the time it will take to execute the statement”  A result of the calculation performed by optimizer  Few conditions that make CBO produces wrong result”  No statistics on the underlying objects or statistics are obsolete  Performance characteristics of hardware or current workloads are not known  Bug  From Oracle Performance Tuning Guide and Reference Cost = (#SRds * sreadtim + #MRds * mreadtim + #CPUCycles / cpuspeed) / sreadtim #SRds: number of single data block reads #MRds: number of multi data block reads #CPUCycle: number of CPU cycles sreadtim: single block read time mreadtim: multi block read time cpuspeed: CPU cycles per second 12
  • 13. Cost (the calculation)  #SRds = blevel + #leaf_block * idx_sel + clustering_factor * tbl_sel (index     scan) #MRds = #tbl_blocks under HWM / mbrc (full table/ index scan) sreadtim = ioseektim + block_size * iotfrspeed (SREADTIM) mreadtim = ioseektim + mbrc * block_size * iotfrspeed (MREADTIM) mbrc = db_file_multiblock_read_count (MBRC)  Going back to slide #4 (let‟s try to calculate cost of table scan)  Cost = (24 / 16) * (10 + 16 * 8192 / 4092) / (10 + 8192 / 4092) = 1.5 * 42 / 12 = 5.25  Slide #5 (index scan only)  Cost = 0 + ceil(1 * 0.0588) = ceil(0.0588) = 1  Slide #10 (index scan with access to the table)  Cost = 0 + 1 + ceil((4 / 17) * 20) = 1 + ceil(4.705) = 1 + 5 = 6 13
  • 14. Selectivity & Cardinality  Selectivity is what fraction of row the predicate is supposed to fetch/ return Selectivity = 1 / num_distinct (no histogram) Selectivity = density (histogram)  Cardinality is total number of row the predicate is supposed to return Cardinality = num_rows * density  Going back to slide #4  Cardinality = num_rows = 20  Slide #5  Selectivity = (number of bucket with data / number of total bucket) = 17 / 17 = 1  Cardinality = selectivity * num_rows = 1 * 20 = 20  Slide #10  14 Selectivity = 4 / 17 = 0.235  Cardinality = 0.235 * 20 = 4.7
  • 15. Clustering Factor  Represents the degree to which data is randomly distributed through a table  Number of blocks <= clustering factor <= number of rows  Index has better selectivity if clustering factor is close to number of data block, means Oracle can do multi block read on the table for several index‟s key 15
  • 16. Clustering Factor (block_id from rowid)  Going back to NORMAL_HASH table example, due to the anomaly configuration of pctfree and pctused, every block contains single row only 16
  • 17. Access Method  There are 2 access methods: table and index access  Index access can be: Fast Full Scan, Full Scan, Unique Scan, Range Scan, Range Scan (MIN/MAX) and Skip Scan 17
  • 18. Access Method Full Table Scan  Oracle is reading all rows from the table  Not suitable for OLTP system with high volume of transaction and usually only access small fraction of data  Suitable for DSS system with batch reporting query  Not good for Nested Loop (NL) for the outer table (huge table)  Usually we see it in Hash Join (HJ) 18
  • 19. Access Method Index Fast Full Scan  Oracle is reading all rows from the index to get the result (doesn‟t required table access since the index contains all columns required to resolve the query)  To be able to use Index FFS, the column should be defined as NOT NULL or at least one column in a composite index is NOT NULL, the reason is that NULL values are not included in the index creation, so when the column is defined as NOT NULL Oracle knows that all values are available in the index  Index FFS will be available as an option if we put “IS NOT NULL” in the WHERE clause explicitly  Cost will be only for accessing the index 19
  • 20. Access Method Index Fast Full Scan (forced by hint) 20
  • 21. Access Method Index Fast Full Scan (cost calculation)  If we remove the HINT, we will have Index Full Scan  Cost for Index Fast Full Scan  Cost = (8 / 16) * (10 + 16 * 8192 / 4092) / (10 + 8192 / 4092) = 0.5 * 32 / 12 = ceil(1.333) = 2  Cost for Index Full Scan  Cost = 0 + ceil(1 * 1 / 14) = ceil(0.0714) = 1 21
  • 22. Access Method Index Fast Full Scan (building the example)  Another figure from index with more leaf block (another anomaly configuration in the pctfree of the index) 22
  • 23. Access Method Index Fast Full Scan (the result) 23
  • 24. Access Method Index Full Scan  Oracle is reading all rows from the index, and may be accessing these rows in the underlying table Without table access 24
  • 25. Access Method Index Full Scan (with table access) Unique index 25
  • 26. Access Method Index Unique Scan  Oracle is reading 0 or 1 rows from the index, only on unique index  Equality operator in the predicate (=), ay be seen in AND, OR, IS NULL operator 26
  • 27. Access Method Index Unique Scan (the result) 27
  • 28. Access Method Index Range Scan  Oracle is reading 0 or more contiguous rows from the index  Non unique index with range operator in the predicate (>, <, >=, <=) 28
  • 29. Access Method Index Range Scan (MIN/MAX)  Oracle is identifying 0 or more contiguous rows in the index, but is reading only one (the first or the last) in order to satisfy a MIN or MAX aggregate function 29
  • 30. Access Method Index Skip Scan  Oracle is reading 0 or more rows from different parts of the index (composite index), and may be accessing these rows in the underlying table  Skip Scan will be happened when we access a composite index with second column in the index‟s order. It will not be happened for the third column, forth, etc.  It will works only if first column in the index has low cardinality (few distinct value) otherwise full table scan will be better in most of the case 30
  • 31. Access Method Index Skip Scan (building the example) 31
  • 32. Access Method Index Skip Scan (the result) First index‟s column with low cardinality 32
  • 33. Access Method Index Skip Scan (a comparison) First index‟s column with high cardinality 33
  • 34. Partitioning  There are some consideration when we are working with partition table. One of its is regarding access path. We introduce partitioning on the table usually to reduce the number of rows which will affected by any query, since we know that not all of those rows are being used in the query.  There are 4 kinds of access method for partitioned table: Partition Range Single, Partition Range Iterator, Partition Range All and Partition Range Sub-query 34
  • 36. Partitioning Partition Range Single  Exactly only single partition of the table involves in the query. Access path on this partition depends on the query, can be Table Scan or any Index Scan 36
  • 37. Partitioning Partition Range Iterator  We will see this kind of access path whenever we have several partitions in the query 37
  • 38. Partitioning Partition Range All  In this kind of access method, all partitions in the table will be scanned. This is a bad example of table design  (create a partition table without taking any benefit of it) 38
  • 39. Partitioning Partition Range Sub-query (building an example)  This method is new in 10g. If the partitioned table is bigger compare to the other join table and the expected number of the records (result) is significantly less, Oracle will perform dynamic partition pruning using sub-query  The partitioned table will be having 200,000 blocks and the other join only 200 blocks 39
  • 40. Partitioning Partition Range Sub-query (the result) Only 7 rows compare to 1000 rows from partitioned table 40
  • 42. Join Method  There are 3 join methods: Nested Loop (NL), Hash Join (HJ) and Sort Merge Join (SM)  Most of the time we see only „standard‟ join between 2 tables, but in rare case we will see Anti-Join and Semi-Join variation for all above 3 methods. Anti-Join will be appear when we are working with NOT IN clause while Semi-Join will be appear when we are working with EXISTS clause 42
  • 43. Join Method Nested Loop  The Nested means an iteration. Pseudo-code for this kind of join will be like below: for x in (select [col] from outer_table) loop for y in (select [col] from inner_table where outer_table.join_col = inner_table.join_col) loop return the rows from outer and inner table end loop; end loop;  Suitable for small “size” for the outer (driving) table. For the inner table, it should be accessed using index scan  Starting from 9i, Oracle introduces new „table prefetching‟ method which will reduce logical I/O 43
  • 44. Join Method Nested Loop (building the example) 44
  • 45. Join Method Nested Loop (table prefetching method) note down the logical I/O 45
  • 46. Join Method Nested Loop (legacy method) recreate with UNIQUE index 46
  • 47. Join Method Nested Loop (the result) 47
  • 48. Join Method Hash Join  In this method, first Oracle will choose 1 dataset (build table – this is outer table in Nested Loop), and then create hash table in memory using generated hash-key from join column. Once completed, second table (probe table – this is inner table in Nested Loop) will be scanned using the same hash function (probing the hash table)  Applicable for join with equality operator (=)  There are 3 level of effectiveness: optimal, one-pass and multi-pass. Optimal when the size of tables is matched with hash_area_size. One-pass or Multipass when the tables is not enough to be hash-ed in the memory (requires disk operation)  Event 10104 for tracing Hash Join operation 48
  • 49. Join Method Hash Join (cont.)  Check hash_area_size and workarea_size_policy database parameter  Check v$sysstat for relevant system statistics SELECT name, value, case when sum(value) over() = 0 then 0 else round(value*100/sum(value) over(),2) end as pct FROM v$sysstat WHERE name LIKE 'workarea executions%' 49
  • 50. Join Method Hash Join (components) 50
  • 51. Join Method Hash Join (build the example) 51
  • 52. Join Method Hash Join (the result – optimal) workarea_size_policy = AUTO test on SMALL table 52
  • 53. Join Method Hash Join (the result – optimal, part 2) workarea_size_policy = AUTO test on BIG table 53
  • 54. Join Method Hash Join (with index scan on the tables) 54
  • 55. Join Method Hash Join (event 10104) 55
  • 56. Join Method Sort Merge  There are 2 operation in this method: sort and merge. So     56 it is application for any query which requires sorting (on the join column): Order By clause, Group By clause, Set operation, Distinct operator, Analytical function, Index creation, Connect By query and etc Similar to Hash Join, there are 3 level of effectiveness for sorting operation: optimal, one-pass and multi-pass. Optimal when the size sort_area_size is enough to handle sort operation. One-pass or Multi-pass when Oracle requires disk operation for the sorting Event 10032 for tracing sort operation and 10033 for tracing sort I/O operation Check sort_area_size and workarea_size_policy database parameter Check v$sysstat for relevant system statistics and v$tempstat for sorting statistics
  • 57. Join Method Sort Merge (cont.)  Merging part can be one of the following possibilities: 57
  • 58. Join Method Sort Merge (build the example) 58
  • 59. Join Method Sort Merge (sorting only example) 59
  • 60. Join Method Sort Merge (sorting only example – cont.) 60
  • 61. Join Method Sort Merge (the example) 61
  • 62. Join Method Sort Merge (Merge Join Cartesian) 62
  • 63. Join Method Sort Merge (event 10032) 63
  • 64. Sub-query  There 2 main types of sub-query: Nested Sub- query and Correlated Sub-query  Nested sub-query when the sub-query (inner query) need to be completed first and then the result will be passed to the main query  Correlated sub-query when the main query should be executed first in order to execute the inner query  In some cases we can rewrite sub-query into join form for performance improvement 64
  • 65. Sub-query (building the example) 65
  • 66. Sub-query Nested  The select statement against “sub_q” is executed first and the outputs will be used by main query 66
  • 67. Sub-query Correlated  We can see from Predicate Information, “sub_q” is executed for every value from “main_q” 67
  • 69. Sub-query Correlated – comparing the statistics Check logical I/O 69
  • 70. Hint  Some of famous Oracle hints  PARALLEL, PARALLEL_INDEX  FULL  INDEX, INDEX_SS, INDEX_FFS  LEADING  ORDERED  DRIVING_SITE  USE_NL, USE_HASH, USE_MERGE  APPEND  USE_CONCAT  Other hints  MERGE_AJ, HASH_AJ  MERGE_SJ, HASH_SJ  UNNEST, NO_UNNEST 70
  • 71. References  Jonathan Lewis, Cost-Based Oracle     71  Fundamentals Thomas Kyte, Expert Oracle Database Architecture – 9i and 10g Programming Techniques and Solutions http://www.orafaq.com/tuningguide/ http://oraclerandolf.blogspot.com/2011/10/paralleldowngrade.html http://asktom.oracle.com/pls/asktom/f?p=100:1:0:: NO:: http://jonathanlewis.wordpress.com/