Connecting Tech Pros Worldwide Forums | Help | Site Map

SQL Functions & the Package cache...

Paul Reddin
Guest
 
Posts: n/a
#1: Nov 12 '05
Hi,

V8.1 fp4a

We have been performing some performance measurements on SQL functions
and have observed the following and need to verify if this is expected
behaviour.

Our SQL Functions contain SEVERAL select statements, and it appears that the
prep time for statements where the functions are referenced, consume
a couple of seconds prep time EVERY time they are run. i.e they are clearly not
utilising the package cache.

Note, the query containing the reference to the function is identical
each time it is run, so why isn't the whole query still in the package cache?

Is this because the queries in the functions have to be recompiled everytime
they are run because there are multiple of them?

This is costing us dearly in performance and we really need to these queries to
fully utilise the package cache for online performance.

Many Thanks.

Paul.
Serge Rielau
Guest
 
Posts: n/a
#2: Nov 12 '05

re: SQL Functions & the Package cache...


Paul,
SQL Functions are macro expanded into the invoking query.
There is no such concept as preping the body of an SQL Function in DB2
UDB for Multiplatforms.
If all goes right you should get caching.
Have you checked the snapshots? Cpould be be you're thrashing the cache?
Any changes to the underlying schema or environment (SET PATH, SET
SCHEMA, ....)

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Paul Reddin
Guest
 
Posts: n/a
#3: Nov 12 '05

re: SQL Functions & the Package cache...


Serge,

Thanks again for your reposnse.

I think all is becoming clear now...

Today we actually looked at the "optimiser rewritten" SQL of one of
our SQL functions, from within Visual Explain. This also made it all
much clearer.

The optimiser rewrites all the conditional logic into pure SQL, i.e
union'd selects etc..., and so what we thought was being processed
with conditional logic around multiple statements, is actually one big
select internally.

So, now we fully understand the implications on the function simply
becoming part of the calling statement.

As a result, I also looked a bit more deeply into the package snapshot
information (As you suggested) and actually saw something very
confusing...

If I execute a query and perform
db2 "get snapshot for dynamic sql on jbsukd17"
I see the query, and if I run it multiple times, I see the "number of
executions" increment and "number of compilations" remain at 1 -
exactly the behaviour I would expect.

However, if I now execute
db2 "flush package cache dynamic"

I would expect a couple of things to happen, (neither of which does)
1. The snapshot to maybe return nothing - it doesn't, everything is as
before
the flush ??
and/or
2. The "number of compilations" to be incremented on the next running
- it isn't.

So, it appears that the flush isn't actually flushing anything,
because no
recompilation is taking place and nothing is disappearing from the
snapshot
information ?? any ideas?

Thanks.

Paul.
Serge Rielau
Guest
 
Posts: n/a
#4: Nov 12 '05

re: SQL Functions & the Package cache...


Paul,

Beats me. There is a safe way to verify the statement got flushed
however (and for some reason the snapshot doesn't shot what you expect).
flip on db2trc after the flush and rerun the query.
If you see functions starting with sqln.... you reentered the compiler.
If you don't, DB2 didn't flush.

Cheers
Serge

PS: If you see union'ed selects that means you are on FP4(a) and you
benefit from TPC-C. The union represents the BEGIN .. END :-)

--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Closed Thread