0% found this document useful (0 votes)
80 views20 pages

Be A Hero in SQL Tuning

V.Hariharaputhran is an Oracle expert who gives presentations on optimizing SQL performance. The document discusses how SQL queries can suddenly run slow and provides tips on troubleshooting issues like hard parsing. It explains how using bind variables instead of literals in SQL statements can avoid library cache contention and improve scalability by allowing query plans to be shared between statements. The document also covers Oracle database optimizer features over different versions like adaptive cursor sharing that help it detect parameter sensitivity and choose better execution plans for SQL statements with bind variables.

Uploaded by

pavan0927
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views20 pages

Be A Hero in SQL Tuning

V.Hariharaputhran is an Oracle expert who gives presentations on optimizing SQL performance. The document discusses how SQL queries can suddenly run slow and provides tips on troubleshooting issues like hard parsing. It explains how using bind variables instead of literals in SQL statements can avoid library cache contention and improve scalability by allowing query plans to be shared between statements. The document also covers Oracle database optimizer features over different versions like adaptive cursor sharing that help it detect parameter sensitivity and choose better execution plans for SQL statements with bind variables.

Uploaded by

pavan0927
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Be a Hero in SQL Tuning

V.Hariharaputhran
www.puthranv.com

V.Hariharaputhran
o Twelve years in Oracle Development / DBA / Big Data /
Cloud Technologies
o All India Oracle Users Group (AIOUG) Evangelist
o Passion to learn and share
o Blog: www.puthranv.com
www.puthranv.com
o Twitter: @puthranv

All of a sudden my SQL is running slow

How to start
What should I know
What tool to use when
www.puthranv.com

Cursor Sharing Bind Aware Index Rebuild


SQL Baselines
Query
Execution Plan
Transformation
Stats Gathering
ACS

Cardinality
Feedback

Histograms
Clustering Factor
Outlines

SQL Profiles
Hints

SQL Plan Mgmt

In-memory
Index

Partitions

www.puthranv.com

All of a sudden SQL is running slow /


slow for one user/job
Thank you for
fixing it
Well can you
explain how you
fixed it ?
www.puthranv.com

Same Query with different execution timestamp

10:00 SQL - A
10:05 SQL - A

INDEX

06 ms
02.82 s

Flush Shared Pool / Enable Hard Parse

11:19 SQL - A
11:17 SQL - A

FTS

21 ms
85 ms
www.puthranv.com

Hard Parse
Select * from tbl where col = 22

Select * from tbl where col = 20

Select * from tbl where col = 10

Select * from tbl where col = 2

Select * from tbl where col = 2

4
3
Memory
2 (Library Cache)
1
Library Cache Contention
library cache: mute x
Lath: shared pool

www.puthranv.com

Literals
Select * from tbl where col = 22
Select * from tbl where col = 20
Select * from tbl where col = 10
Select * from tbl where col = 2
Select * from tbl where col = 2

Binds

Avoid Latch Contention

Select * from tbl


where col = :v1
Parameter - cursor_sharing If Application code
cannot be re-written

Issue Resolved ?
www.puthranv.com

Literals - BAD
Select * from tbl where col = 22

SQL - Cursor is not Shared


Optimizer has to perform all the
costly
operations again
Leads to high utilization of CPU
and Library Cache
Application is Not Scalable

Binds - Good
Select * from tbl where col = :v1

Soft Parse
Cursor is Sharable
Avoid Library Cache
Contention
Hit on CPU is minimized
Application is Scalable

www.puthranv.com

www.puthranv.com

What should I know


What is wrong with soft parse ?

www.puthranv.com

Bind Peeking First


Time
www.puthranv.com

If it would have done Bind Peeking

www.puthranv.com

Order of Execution Impact of Access Path


22

10:00 SQL - A
10:05 SQL - A

20000

INDEX

06 ms
02.82 s

Flush Shared Pool / Enable Hard Parse

22
20000

11:19 SQL - A
11:17 SQL - A

FTS

21 ms
85 ms

www.puthranv.com

Literals
Select * from tbl where col = 22
1. Hard Parse
1. Execution Plan No Shared
2. Cardinality Estimate based
on Literals
3. Cardinality Feedback is
used
4. Histograms info are Visible

Binds
Select * from tbl where col = :v1
1. Soft Parse
1. Execution Plan Shared
2. Cardinality Estimate on binds
ONLY FIRST TIME (until 10g)
3. Cardinality Feedback feature
does not work with binds
4. Binds and Histograms does not
go well

www.puthranv.com

Adaptive Cursor Sharing

www.puthranv.com

Optimizer - ACS

22

10

Select * from sale where


product_id = :v1

Run

Sensitive

Aware

Parse

SQL ID

Child No

Access

Hard

ASQL1

Index

Run

Sensitive

Aware

Parse

SQL ID

Child No

Access

Soft

ASQL1

Index

Product_id = :v1

20000
Run

Sensitive

Aware

Parse

SQL ID

Child No

Access

Hard

ASQL1

FTS
www.puthranv.com

With Adaptive Cursor Sharing


22

20000

20000

10:00 SQL - A
10:05 SQL - A
10:15 SQL - A
10:20 SQL - A

INDEX

FTS

06 ms
02.82 s
04 ms
85 ms
www.puthranv.com

12c

Optimizer Evolution
11g
10g

Adaptive Joins/ SQL


Plan Directives
Adaptive Cursor
Sharing/ SQL Baselines

9i
SQL Profiles
8i

Bind Peeking
Cursor Sharing
No Bind Peeking

www.puthranv.com

Thanks
www.puthranv.com

You might also like