473,385 Members | 1,707 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.

declare global temp table and package cache conciderations


Any thoughts on the following scenario anyone?

During a performance test I discovered that the application asked one
specific query extremely often. It turned out that this particular
query where asked 25/50/100 or 200 times from a "htmlpage", dependent
of user preferences. I figured that using a global temp table, looping
and inserting, then join would do the trick.

However, it turned out that this killed performance totally. Why,
apparently using a global temp table in the query forces a preparation
of the query each time the page is shown to a user:

.. Number of executions = 57190
Number of compilations = 55
Worst preparation time (ms) = 43265
Best preparation time (ms) = 1500
[...]
Total execution time (sec.ms) = 119286.111630

The current solution is to build a lateral clause in the code and
stuff things there as in:

[...]
sb.append("from LATERAL(VALUES");
for (int i = 0; i < codes.size(); i++) {
sb.append(" (cast(? as int), cast(? as int), cast(? as varchar(64)),
cast(? as varchar(64))) ");
if ((i + 1 ) < codes.size()) {
sb.append(", ");
}
}
sb.append(") as oc(year, period, code, educationeventid)");
[...]

and then another loop setting parameters.

The performance is ok, but I don't like the looks of the code ;-). Any
thoughts anyone? Would using a global temp table from a stored
procedure help? Any other way to avoid the preparation cost of the
query?

uname -a
Linux db2-01 2.6.9-42.ELsmp #1 SMP Wed Jul 12 23:27:17 EDT 2006 i686
i686 i386 GNU/Linux

db2level
DB21085I Instance "db2inst1" uses "32" bits and DB2 code release
"SQL08028"
with level identifier "03090106".
Informational tokens are "DB2 v8.1.2.136", "s070720", "MI00189", and
FixPak
"15".
Product is installed at "/opt/IBM/db2/V8.1".
Thanx
/Lennart
Feb 1 '08 #1
3 2425
Lennart wrote:
Any thoughts on the following scenario anyone?

During a performance test I discovered that the application asked one
specific query extremely often. It turned out that this particular
query where asked 25/50/100 or 200 times from a "htmlpage", dependent
of user preferences. I figured that using a global temp table, looping
and inserting, then join would do the trick.

However, it turned out that this killed performance totally. Why,
apparently using a global temp table in the query forces a preparation
of the query each time the page is shown to a user:

. Number of executions = 57190
Number of compilations = 55
Worst preparation time (ms) = 43265
Best preparation time (ms) = 1500
[...]
Total execution time (sec.ms) = 119286.111630

The current solution is to build a lateral clause in the code and
stuff things there as in:

[...]
sb.append("from LATERAL(VALUES");
for (int i = 0; i < codes.size(); i++) {
sb.append(" (cast(? as int), cast(? as int), cast(? as varchar(64)),
cast(? as varchar(64))) ");
if ((i + 1 ) < codes.size()) {
sb.append(", ");
}
}
sb.append(") as oc(year, period, code, educationeventid)");
[...]

and then another loop setting parameters.

The performance is ok, but I don't like the looks of the code ;-). Any
thoughts anyone? Would using a global temp table from a stored
procedure help? Any other way to avoid the preparation cost of the
query?

uname -a
Linux db2-01 2.6.9-42.ELsmp #1 SMP Wed Jul 12 23:27:17 EDT 2006 i686
i686 i386 GNU/Linux

db2level
DB21085I Instance "db2inst1" uses "32" bits and DB2 code release
"SQL08028"
with level identifier "03090106".
Informational tokens are "DB2 v8.1.2.136", "s070720", "MI00189", and
FixPak
"15".
Product is installed at "/opt/IBM/db2/V8.1".
I'm not entirely sure on what you are doing but I can provide general
background on DGTT, do's and don'ts

Any statement that depends on a DGTT needs to get recompiled next time
around if:
* The DGTT got dropped/replaced between the two invocation
* The connection is new.

Most often I have seen performance issues with DGTT when they get
defined within a stored procedure and that stored proc is called often.
Every procedure invocation causes a recompile of every statement which
has teh DGTT in it.
A better approach is to define the DGTT ONCE and then simply truncate it
(DELETE FROM SESSION.TEMP;) within the procedure instead of replacing.
The same concept hold outside of procs of course. Define once. Use many
times.

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Feb 1 '08 #2
Ian
Serge Rielau wrote:
A better approach is to define the DGTT ONCE and then simply truncate it
(DELETE FROM SESSION.TEMP;) within the procedure instead of replacing.
The same concept hold outside of procs of course. Define once. Use many
times.
Serge,

I take it that the issue where issuing DELETE FROM SESSION.TEMP does not
release the pages allocated to the table has been resolved?
Ian Bjorhovde
Feb 5 '08 #3
Ian wrote:
Serge Rielau wrote:
>A better approach is to define the DGTT ONCE and then simply truncate
it (DELETE FROM SESSION.TEMP;) within the procedure instead of replacing.
The same concept hold outside of procs of course. Define once. Use
many times.
I take it that the issue where issuing DELETE FROM SESSION.TEMP does not
release the pages allocated to the table has been resolved?
Yes.. a long time ago.

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Feb 5 '08 #4

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

Similar topics

4
by: Corrine | last post by:
Hi, I am creating a global temporary table that is session-specific. I insert a BLOB into this table, and then select the BLOB from this table into a ResultSet. The ResultSet sees this BLOB...
6
by: pb648174 | last post by:
I have a pivot table implementation, part of which is posted below. It returns no errors in query analyzer, but when profiler is run, it shows that "Error 208" is happening. I looked that up in BOL...
10
by: Ranga | last post by:
I was unable to run the statement "CREATE GLOBAL TEMPORARY TABLE" on unix version of DB2, it gave the follwing error db2 => create global temporary table temp ( OGI_SYS_NR char(8) ) DB21034E ...
0
by: gwaddell | last post by:
I have a stored procedure that is loading data into a global temp table. Here is all the code for that stored procedure. CREATE PROCEDURE AS SET NOCOUNT ON BEGIN
41
by: Miguel Dias Moura | last post by:
Hello, I am working on an ASP.NET / VB page and I created a variable "query": Sub Page_Load(sender As Object, e As System.EventArgs) Dim query as String = String.Empty ... query =...
16
by: pukivruki | last post by:
hi, I wish to create a temporary table who's name is dynamic based on the argument. ALTER PROCEDURE . @PID1 VARCHAR(50), @PID2 VARCHAR(50), @TICKET VARCHAR(20)
2
by: tejaloracle | last post by:
how to create global temporary table within procedure? CODE : create or replace procedure temp (pno varchar2) AS p_a varchar2(50); p_b varchar2(20);
0
by: cuddles | last post by:
hi all i need to declare a temporary table within a user-defined function in IBM DB2 ver 8. can someone give me the syntax for the temp table declaration. CREATE FUNCTION PEGASUS.readOrder(...
10
by: Tammy | last post by:
Hello all, I am wondering what is the best way to declare a struct to be used in other c and c++ files. Such as for a C API that will be used by others. 1. Declaring the typedef and the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.