Identify SQL Tuning Opportunities


Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Identify SQL Tuning Opportunities

  1. 1. TECHNICAL WHITE PAPERUsing SQL Performance for DB2:Identify SQL Tuning Opportunitiesthru Object Analysis
  2. 2. IntroductionObject Analysis Reports are one feature that differentiates APPTUNE for DB2 from other SQL tuning products –other vendors require a separate product to provide the same information as the Object Analysis report.In most cases, I/O time is the single largest component of an SQL statement’s elapsed time. We generallyfocus on fixing SQL Statements with high getpage counts or statements that use tablespace scans. We focuson increasing the number of Matching Columns, strive to reach Index Only access path and apply differenttechniques to improve the access strategy.There are other performance metrics to identify potential tuning candidate SQL Statements. For example ifyou focus on the “Most Used Object” in the system, you are likely to address the most frequently used SQLstatements or programs in the DB2 Subsystem. The advantage of focusing your best tuning techniques on thisSQL statement is that even a minor improvement of a few milliseconds or a few getpages can provide a totalsavings much larger than you would expect. It’s quite possible that the SQL statement might already executein subseconds or do just a few getpages. But having a better access strategy for that SQL statement that isexecuted millions of times would save the most CPU. Let’s go in depth for a specific case.DETAILS...The Database Analysis section of the Object Analysis report is a good place to start. It gives you the most usedDatabases for the collector interval as shown below. In this example, DBTIB is responsible for 80% of the Getpages.When we drill down one more level to Table Level, the most accessed object is is VP_CUSTOMER_LIMITS tablewith 485155 getpages. 1
  3. 3. The next step is to find the most used SQL Statement and Program on that table. There are 2 options here, usingeither option R ( Program ) or S ( Statement ). Either way you end up with the most frequently used SQL statementto target your tuning efforts. I prefer the (S)tatement option. In one screen you are able to see both the SQLStatement and Program info at the same time.This is one of the most useful reports for your the tuning process. In one screen, we have the name of the mostheavily used program (GET_DAIL) and the most heavily used SQL statement in that program. Drilling downfurther we can see that the Statement is accessing the Table directly much more frequently than it’s associatedIndex. 2
  4. 4. Before going into the Explain feature we could hypothesize that either the Filter Factors of Index columns orthe order of key columns may not be optimal, the number of Matching Columns is not as high as it could beand the access path is almost certainly not Index Only because most of the getpages are against the table.These are just guesses based on the report above. Additionally we can also see that the Index is using BP0which is normally reserved for the DB2 Catalog and Directory.If we can decrease the number of table touches by increasing index usage (increase the number of matchingcolumns or index screening) and ideally turn to access path to Index Only, then the average number ofgetpages might even decrease from 14.The screen shot shows the SQL statement we need to improve. Upon further examination of the Explainresults, the index used for this SQL has only two columns and has 0.12 Cluster ratio. Having “Equal” and“IS” operators in the WHERE clause makes this SQL a perfect candidate for 5 column match and Index Onlyaccess. Adding the other 3 columns in the WHERE clause plus two columns in SELECT section into the indexmakes this an “SQL Index Only” access with less than 10 getpages average.This is an example where tweaking the most used SQL and saving a few getpages, even if the Statementmight look relatively efficient at first glance, can make a huge difference in overall CPU utilization. 3
  5. 5. About the Author IBM Champion Cuneyt Goksu is an independent DB2 specialist and IBM Gold Consultant since 2009. His main activity is linked to DB2 for z/OS and LUW Installation, Migration, Administration and Performance Tuning. He has presented papers at several conferences, local events and writing articles for IT magazines. Cuneyt is currently a member IDUG Board of Directors, he is the leader of Turkish DB2 Users Group and IBM Authorized DB2 Training Partner. Cuneyt can be reached at 4
  6. 6. Business Runs on I.T. I.T. Runs on BMC SoftwareBusiness runs better when IT runs at its best. Tens of thousands of IT organizations around the world -- fromsmall and mid-market businesses to the Global 100 -- rely on BMC Software (NASDAQ: BMC) to manage theirbusiness services and applications across distributed, mainframe, virtual and cloud environments. BMC helpscustomers cut costs, reduce risk and achieve business objectives with the broadest choice of IT managementsolutions, including industry-leading Business Service Management and Cloud Management offerings. For thefour fiscal quarters ended September 30, 2012, BMC revenue was approximately $2.2 billion. www.bmc.comBMC, BMC Software, and the BMC Software logo are the exclusive properties of BMC Software, Inc., are registered with the U.S. Patent and Trademark Office, and may beregistered or pending registration in other countries. All other BMC trademarks, service marks, and logos may be registered or pending registration in the U.S. or in othercountries. Linux is the registered trademark of Linus Torvalds. All other trademarks or registered trademarks are the property of their respective owners.© 2012 BMC Software, Inc. All rights reserved. Origin date: 1/13 *357594*