a closer look at parsing

27
A Closer Look at Parsing: Possible Application Optimizations Mark J. Bobak Michigan Oracle Users Summit, 9/24/09

Upload: 311ybb

Post on 06-Apr-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

8/3/2019 A Closer Look at Parsing

http://slidepdf.com/reader/full/a-closer-look-at-parsing 1/27

A Closer Look at Parsing:

Possible Application Optimizations

Mark J. BobakMichigan Oracle Users Summit, 9/24/09

8/3/2019 A Closer Look at Parsing

http://slidepdf.com/reader/full/a-closer-look-at-parsing 2/27

FixePGA

FixePGA固定

PGA

程序

全局

区 

在MTS

模式

下每

个会话有

一个uga

FixedPGA CGAUGA UGA-1 其他 

可变PGA

PGA

UGA

话内存 

Private SQL area

久区

域 

Runtime area

Workarea

8/3/2019 A Closer Look at Parsing

http://slidepdf.com/reader/full/a-closer-look-at-parsing 3/27

Logbuffer

Javapool

largepool

streamspool

Buffercache

字典缓

存 

存 

SGA Shared pool

Server进程1

Server进程2

PGA1 PGA2

8/3/2019 A Closer Look at Parsing

http://slidepdf.com/reader/full/a-closer-look-at-parsing 4/27

Introduction

• Working as Oracle DBA since 2000• Employed by ProQuest Company, Ann Arbor, MI, since

1997

• Frequent presenter at national and international

conferences; Hotsos, UKOUG, Oracle OpenWorld• Member of Southeast Michigan Oracle Professionals

• Member of the OakTable Network since December,2002

8/3/2019 A Closer Look at Parsing

http://slidepdf.com/reader/full/a-closer-look-at-parsing 5/27

Objectives

• A closer look at parsing – Hard parse/Soft parse/Cursor cache hit

 – Parameters which affect parsing?

• cursor_sharing/session_cached_cursors/cursor_space_for_time

• Application design considerations

 – How can better parsing practices improve scalability?

 – What changes can be implemented at applicationlevel?

8/3/2019 A Closer Look at Parsing

http://slidepdf.com/reader/full/a-closer-look-at-parsing 6/27

8/3/2019 A Closer Look at Parsing

http://slidepdf.com/reader/full/a-closer-look-at-parsing 7/27

What is Parsing?

According to Wikipedia:

“In computer science and linguistics, parsing, or, moreformally, syntactic analysis, is the process of analyzinga text, made of a sequence of tokens (for example,words), to determine its grammatical structure with

respect to a given (more or less) formal grammar.” 

8/3/2019 A Closer Look at Parsing

http://slidepdf.com/reader/full/a-closer-look-at-parsing 8/27

8/3/2019 A Closer Look at Parsing

http://slidepdf.com/reader/full/a-closer-look-at-parsing 9/27

Hard Parse

• Most expensive – Shared pool latch

• Allocate memory from shared pool

 – Library cache latch

• Define parent and child cursor areas

 – Syntax check

 – Semantic check

• Object resolution• Permissions

 – Execution plan generation

8/3/2019 A Closer Look at Parsing

http://slidepdf.com/reader/full/a-closer-look-at-parsing 10/27

Cursor Authentication

• Most expensive – Shared pool latch

• Allocate memory from shared pool

 – Library cache latch• Define parent and child cursor area

 – Syntax check

 – Semantic check• Object resolution

• Permissions

 – Execution plan generation

8/3/2019 A Closer Look at Parsing

http://slidepdf.com/reader/full/a-closer-look-at-parsing 11/27

Soft Parse

• Most expensive – Shared pool latch

• Allocate memory from shared pool

 – Library cache latch• Define parent and child cursor areas

 – Syntax check

 – Semantic check• Object resolution

• Permissions

 – Execution plan generation

8/3/2019 A Closer Look at Parsing

http://slidepdf.com/reader/full/a-closer-look-at-parsing 12/27

Session Cursor Cache Hit

• Most expensive – Shared pool latch

• Allocate memory from shared pool

 – Library cache latch• Define parent and child cursor areas

 – Syntax check

 – Semantic check• Object resolution

• Permissions

 – Execution plan generation

8/3/2019 A Closer Look at Parsing

http://slidepdf.com/reader/full/a-closer-look-at-parsing 13/27

What’s the difference? 

How Do Soft Parse and Session Cursor Cache Hitdiffer?

In the event of a session cursor cache hit, thesession cursor cache has cached the librarycache lock structure, so your session does notneed to re-create it.

In the case of a soft parse, the library cache lockobject (your session’s handle to the SQLstatement) needs to be created.

8/3/2019 A Closer Look at Parsing

http://slidepdf.com/reader/full/a-closer-look-at-parsing 14/27

session_cached_cursors

This parameter should be set to a positive integer,and defines the size of the session cursor cache.In recent versions of Oracle, the default is 50.

The session cursor cache allows your session tocache the library cache lock object for any SQLstatement that has been executed three times.This allows for the user’s session to avoid

searching the library cache for frequentlyparsed SQL.

8/3/2019 A Closer Look at Parsing

http://slidepdf.com/reader/full/a-closer-look-at-parsing 15/27

cursor_space_for_time

cursor_space_for_time is a boolean,defaults to false. If you do not have a well-controlled, well-defined set of SQL,

do NOT set this parameter to true.Setting this parameter to true caches thelibrary cache pin structure. This effectively

prevents any cursor from being aged outof the cache, as long as an application isholding the cursor open.

8/3/2019 A Closer Look at Parsing

http://slidepdf.com/reader/full/a-closer-look-at-parsing 16/27

Shareable SQL

• SQL with literal values cannot share parentcursor

• SQL whose text matches exactly can share

parent cursor, but may not be able to share childcursor (execution plan)

• There are lots of reasons why Oracle maydecide not to share a child cursor

• Complete list is visible inV$SQL_SHARED_CURSOR

8/3/2019 A Closer Look at Parsing

http://slidepdf.com/reader/full/a-closer-look-at-parsing 17/27

cursor_sharing

When you have a poorly designed application, that useslots of literals, you may consider setting cursor_sharing.

• Three possible values:

 – exact : SQL must be an exact text match to beshared. This is the default.

 – force : SQL which is similar, except for literal valuesis shared and so is the execution plan. There is apotential for degraded execution plans.

 – similar : SQL which is similar, except for literalvalues is shared, but allows for differing executionplans.

8/3/2019 A Closer Look at Parsing

http://slidepdf.com/reader/full/a-closer-look-at-parsing 18/27

Parsing and Scalability

Every application will fall into one of three broadcategories, with respect to parsing and the levelof scalability.

• Category 1 – Literal SQL, no bind variables, onehard parse per execution

• Category 2 – Bind variables, one soft parse perexecution

• Category 3 – Bind variables, one parse, manyexecutions

8/3/2019 A Closer Look at Parsing

http://slidepdf.com/reader/full/a-closer-look-at-parsing 19/27

Category 1

• Is characterized by lack of bind variables

• One hard parse per execution

• Every SQL statement is unique and mustbe hard parsed

• Inherently non-scalable

• cursor_sharing may be helpful• cursor_sharing is a band aid not a

panacea. Fix the application! 

8/3/2019 A Closer Look at Parsing

http://slidepdf.com/reader/full/a-closer-look-at-parsing 20/27

Exceptions to the Rule

• Data Warehouse

• Decision Support Systems

• Other systems where the query executiontime far exceeds the parse time. In thiscase, it may be more beneficial for thedatabase to have access to the literalvalues.

8/3/2019 A Closer Look at Parsing

http://slidepdf.com/reader/full/a-closer-look-at-parsing 21/27

Category 2

• No literal values, bind variables are in use

• Still one parse per execution, but sincebind variables are in use, parses are soft

• Many applications fall into this category

8/3/2019 A Closer Look at Parsing

http://slidepdf.com/reader/full/a-closer-look-at-parsing 22/27

Category 3

• Parse once, execute many times

• This is the holy grail

• Highly scalable, CPU efficient• Don’t change a thing! 

8/3/2019 A Closer Look at Parsing

http://slidepdf.com/reader/full/a-closer-look-at-parsing 23/27

Which parameters apply?

• For category 1 (SQL w/ literal values),cursor_sharing may help. (Not a panacea, atbest, it’s a band aid.) Also, some benefit from

session_cached_cursors.• For category 2, session_cached_cursors, will be

a benefit, possibly cursor_space_for_time (onlyif app is well-behaved)

• For category 3, no need to do anything, life isgood!

8/3/2019 A Closer Look at Parsing

http://slidepdf.com/reader/full/a-closer-look-at-parsing 24/27

How to reduce parse calls?

• Only one way to reduce the number of parse calls.

• That is to reduce the number of PARSE db calls

• All the server side tuning in the world (fiddling with

system parameters, changing size of shared pool,etc) will NEVER reduce the number of parse calls.

• May be able to minimize the impact of a parse call,but only application code changes can reduce the

number of parse calls.

8/3/2019 A Closer Look at Parsing

http://slidepdf.com/reader/full/a-closer-look-at-parsing 25/27

Conclusion

• We’ve covered some basic concepts of 

parsing in Oracle

• Discussed the system parameters thatmay have an effect on the parse load onyour system

• Covered the basics of application designconsiderations that will improve bothsystem scalability and parse performance.

8/3/2019 A Closer Look at Parsing

http://slidepdf.com/reader/full/a-closer-look-at-parsing 26/27

References

• Designing applications for performance andscalability – Oracle Whitepaper by Bjorn Engsig,Lex De Haan, Graham Wood and John Rees

(available on OTN)• Oracle Database Reference Manual for

description of statistics

• Oracle Database Performance Tuning Guide

8/3/2019 A Closer Look at Parsing

http://slidepdf.com/reader/full/a-closer-look-at-parsing 27/27

Q/A?

• Questions?

• Comments?

• Complaints?