If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Question Marks in Logs?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-12-08, 01:48
Dracofrank Dracofrank is offline
Registered User
 
Join Date: Jan 2008
Posts: 3
Question Marks in Logs?

Hello and thanks in advance,

I am trying to log queries of my app by using an event monitor. The app works fine without errors and producing correct results. Unfortunately, my event monitor only gives queries with question marks, like "select * from address where addr_id = ?" instead of replacing with placeholder. Using a dynamic sql snapshop also gives the same result. Why??
Reply With Quote
  #2 (permalink)  
Old 01-12-08, 04:41
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
The question mark is a parameter marker/place holder. I'd say that it is often not a good idea to put the specific values in there because (a) this may be dynamic SQL and those values may not be know at statement compilation time, and (b) the values may contain sensitive information.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #3 (permalink)  
Old 01-12-08, 11:54
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Quote:
Originally Posted by Dracofrank
Hello and thanks in advance,

I am trying to log queries of my app by using an event monitor. The app works fine without errors and producing correct results. Unfortunately, my event monitor only gives queries with question marks, like "select * from address where addr_id = ?" instead of replacing with placeholder. Using a dynamic sql snapshop also gives the same result. Why??
These are prepared statements. That is the way your applicaiton submits them. There is a big advantage to this in that the statement is compiled only once and the access plan (package) is stored in package cache for reuse over and over again without recompiling.

If your application did not use prepared statements, then the SQL would have to be compiled each time it is submitted (assuming the predicate values are different for each query), probably resulting in longer execution times.

You can do an explain using the parmater markers, so there is usually no serious limitation in their use in analyzing the system performance. Sometimes a query may run faster if DB2 knows the exact value of a predicate at compile time (when the package is created) but a good DBA can figure out ways to solve these problems.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #4 (permalink)  
Old 01-15-08, 13:26
Dracofrank Dracofrank is offline
Registered User
 
Join Date: Jan 2008
Posts: 3
Prepared Statements

Quote:
Originally Posted by Marcus_A
These are prepared statements. That is the way your applicaiton submits them. There is a big advantage to this in that the statement is compiled only once and the access plan (package) is stored in package cache for reuse over and over again without recompiling.

If your application did not use prepared statements, then the SQL would have to be compiled each time it is submitted (assuming the predicate values are different for each query), probably resulting in longer execution times.

You can do an explain using the parmater markers, so there is usually no serious limitation in their use in analyzing the system performance. Sometimes a query may run faster if DB2 knows the exact value of a predicate at compile time (when the package is created) but a good DBA can figure out ways to solve these problems.
Yes, the queries that I am looking at are prepared statements, but when they are executed their placeholders have actual values. Do you know why the actual values aren't replaced in the TEXT when the event monitor or get snapshot is used? Thanks.
Reply With Quote
  #5 (permalink)  
Old 01-15-08, 15:53
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Quote:
Originally Posted by Dracofrank
Yes, the queries that I am looking at are prepared statements, but when they are executed their placeholders have actual values. Do you know why the actual values aren't replaced in the TEXT when the event monitor or get snapshot is used? Thanks.
The SQL snapshot gets the data from the package cache, which only has the prepared statement.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #6 (permalink)  
Old 01-15-08, 21:14
Dracofrank Dracofrank is offline
Registered User
 
Join Date: Jan 2008
Posts: 3
Quote:
Originally Posted by Marcus_A
The SQL snapshot gets the data from the package cache, which only has the prepared statement.
So is there any way to get the executed statement? Thanks.
Reply With Quote
  #7 (permalink)  
Old 01-16-08, 02:51
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
What gets executed is the access plan (also called "section"). A section is something like a function in any other programming language, and the DB2 runtime takes the section and interprets it like /usr/bin/perl is doing it for perl scripts. That being said, a function can take parameters that influence the function result. Exactly the same applies to SQL statements with parameter markers: the SQL statement (section) is "programmed" once you compile the SQL statement and bind it to the database (or execute it for the first time in case of dynamic SQL so that it is kept in the DB2 statement cache). Thus, the SQL statement that's being executed is what can be found in the snapshots.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On