473,385 Members | 1,396 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Dynamic statement cache on LUW

aj
DB2 LUW 8.1 fixpak 14
Red Hat EL AS 4.4

I'm trying to diagnose some nocturnal CPU pressure, and am trying to
understand the dynamic statement cache as it applies to LUW. The only
doc/redbooks I am finding are for Z/OS, which I am completely ignorant
of.

I am using only Java and JDBC in my applications. No static SQL.

How does dynamic statement cache work in LUW 8.1? Is there a local
statement cache? I think there is a global statement cache (based
upon the "get snapshot for dynamic sql on <db>" command), but how do I
control it? Is it always turned on? Can I change its size?

If I prepare a statement in a java app, will the compiled version
of the statement remain in the cache after I have closed the
PreparedStatement? Will it remain after the java program completely
exits?

Any help appreciated.

aj
Jun 27 '08 #1
3 5669
Ian
aj wrote:
DB2 LUW 8.1 fixpak 14
Red Hat EL AS 4.4

I'm trying to diagnose some nocturnal CPU pressure, and am trying to
understand the dynamic statement cache as it applies to LUW. The only
doc/redbooks I am finding are for Z/OS, which I am completely ignorant
of.

I am using only Java and JDBC in my applications. No static SQL.

How does dynamic statement cache work in LUW 8.1? Is there a local
statement cache? I think there is a global statement cache (based
upon the "get snapshot for dynamic sql on <db>" command), but how do I
control it? Is it always turned on? Can I change its size?
The package cache holds the compiled plans and its size is controlled
by the pckcachesz database config parameter. Not sure what you mean
by "local" vs. "global" statement cache (is this in relation to DPF?)

When another query is prepared, DB2 looks to see if the plan already
exists in the cache -- by using a byte-for-byte comparison of the SQL
statements. (i.e. "select * from t1" <"select * FROM t1"). If
the statements match *exactly*, DB2 will use the existing plan.

Note, many things will invalidate some/all entries in the cache, like
table changes, index changes, runstats, and "FLUSH PACKAGE CACHE
DYNAMIC"

Every statement that is executed goes into the cache. I don't know
the specific algorithm for how the cache is maintained, but it's
almost certainly LRU-based (least-recently-used).
If I prepare a statement in a java app, will the compiled version
of the statement remain in the cache after I have closed the
PreparedStatement? Will it remain after the java program completely
exits?
Yes, and yes.

Jun 27 '08 #2
"aj" <ro****@mcdonalds.comwrote in message
news:Ne******************************@supernews.co m...
DB2 LUW 8.1 fixpak 14
Red Hat EL AS 4.4

I'm trying to diagnose some nocturnal CPU pressure, and am trying to
understand the dynamic statement cache as it applies to LUW. The only
doc/redbooks I am finding are for Z/OS, which I am completely ignorant
of.

I am using only Java and JDBC in my applications. No static SQL.

How does dynamic statement cache work in LUW 8.1? Is there a local
statement cache? I think there is a global statement cache (based
upon the "get snapshot for dynamic sql on <db>" command), but how do I
control it? Is it always turned on? Can I change its size?

If I prepare a statement in a java app, will the compiled version
of the statement remain in the cache after I have closed the
PreparedStatement? Will it remain after the java program completely
exits?

Any help appreciated.

aj
Package cache is global (for the database) and packages are not flushed out
when a connection that created the package is closed. They can be used by
any application connection. If DB2 finds an (absolutely) identical SQL
statements already in cache, it will use that access plan and will not have
to calculate a new one. The text of the SQL must be identical, including
spaces, etc.

It is best to use prepared statements with parameter makers ("?") if the
predicates change from one execution to the next, so that DB2 can reuse the
package in cache. If you use literals in the predicate, each statement will
be different, and little reuse will be possible.

The size is controlled by the PCKCACHESZ parm in the database configuration
(get db config for db-name). You can monitor package cache overflow in the
application snapshot.
Jun 27 '08 #3
This goes with other answers.
At prep time, DB2 does a "lookup" in the cache to see if statement is
there. If yes execution willhappen. If not, it is compiled and then
DB2 "inserts" it in the cache, if there is room. If not, then an LRU
algorithm is used to inser it. It will stay there, even after a
connect reset, until DB2 needs the room.
If there's no room because all statements are servicing connections
then the cache will self extend. This will happen until the request
claims all available memory as defined in DATABASE_MEMORY parameter.
A snapshot, like db2mtrk command output, would show you the value
defined/value currently used/value high water mark.
I also believe but not quite sure as I haven't verified lately, that
DB2 will "park" the compiled statement in the application agent
private memory if all conditions stated above cannot make room for the
insertion. The idea being you should not get a no room available to
store your statement once compiled.
Reegards, Pierre.

On Apr 28, 2:09*pm, aj <ron...@mcdonalds.comwrote:
DB2 LUW 8.1 fixpak 14
Red Hat EL AS 4.4

I'm trying to diagnose some nocturnal CPU pressure, and am trying to
understand the dynamic statement cache as it applies to LUW. *The only
doc/redbooks I am finding are for Z/OS, which I am completely ignorant
of.

I am using only Java and JDBC in my applications. * No static SQL.

How does dynamic statement cache work in LUW 8.1? * Is there a local
statement cache? *I think there is a global statement cache (based
upon the "get snapshot for dynamic sql on <db>" command), but how do I
control it? *Is it always turned on? *Can I change its size?

If I prepare a statement in a java app, will the compiled version
of the statement remain in the cache after I have closed the
PreparedStatement? *Will it remain after the java program completely
exits?

Any help appreciated.

aj
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Ina Schmitz | last post by:
Hello, I would like to get the logical and physical reads for every sql statement executed. Thatfore, I used the command "db2 get snapshot for dynamic sql on <mydatabase>". There, I could see...
0
by: Martin | last post by:
Hi. I had a very frustrating afternoon and evening but I have got it all under control now so all of a sudden I am in a good mood. I want to share some insights on output caching with you lot. ...
3
by: PaulR | last post by:
Hi, I am trying to understand what invalidates Dynamic Packages in the Package Cache. By monitoring the Size of the Package Cache, it appears the following does 1. Performing a Runstats on...
3
by: sethwai | last post by:
Hi, I find the "snapshot for dynamic sql" a great tool for identifying the most frequently executed dynamic sql statements, most cpu used, etc. It is a great help for system tuning. My...
7
by: Ronald S. Cook | last post by:
I've always been taught that stored procedures are better than writing SQL in client code for a number of reasons: - runs faster as is compiled and lives on the database server - is the more...
0
by: lekhrajm | last post by:
Hi, I want to flush Dynamic Sql CACHE completely in db2 9.1.2 I used command "db2 FLUSH PACKAGE CACHE DYNAMIC". But it lefts some queries in cache. These are fixed queries. It creats problem...
0
by: Ian | last post by:
Patrick Finnegan wrote: Yes. It doesn't matter where you execute the statement from. Is your question of "how do I check" asking how you check whether it works when executed from a client? ...
6
by: =?ISO-8859-1?Q?Tim_B=FCthe?= | last post by:
Hi, we are building a Java webapplication using JSF, running on websphere, querying a DB2 9 on Suse Enterprise 10. The app uses JDBC and PreparedStatements only (aka dynamic SQL). Every night,...
2
by: Damir | last post by:
Hello! I have noticed that after (sucessfully) executing the command: FLUSH PACKAGE CACHE DYNAMIC the dynamic SQL statement cache is not completely cleared (some of the dynamic SQL statement...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.