Guide DB2 DB2 10 Tips
-
Upload
vibhaw-prakash-rajan -
Category
Documents
-
view
260 -
download
0
Transcript of Guide DB2 DB2 10 Tips
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 1/45
Réunion du Guide DB2 pour z/OS FranceJeudi 10 octobre 2013Tour Opus, Paris-La Défense
par Philippe Dubost, CA technologies
DB2 10 Tips
and Other Performance Topics
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 2/45
DB2 v10 tips and other performance topics
Agenda:
Save CPU by including extra columns to an unique index
Is the length of your inline LOBs optimal ?
Impact of SELECT * versus SELECTing specific columns Improve the response time of Native SQL procedures in
DB2 v10
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 3/45
DB2 v10 tips and other performance topics
Save CPU by including extra columns to an unique index
Why do we have indexes ?
Indexes can be used to enforce uniqueness of keys
Indexes are mainly created to improve SQL performance
What’s the cost of indexes ?
Indexes consume a lot of disk space (DASD)
An index adds ~30% of CPU on INSERTs / DELETEs (0)
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 4/45
DB2 v10 tips and other performance topics
Save CPU by including extra columns to an unique index
DB2 v10 new feature :
ALTER INDEX IX ADD INCLUDE (COL)
What is it good for ?
The new INCLUDE feature in DB2 v10 allows you toreduce the number of indexes, it means:
Cost savings in DASD
Cost savings in CPU.
Potential negative impact discussed in appendix (1)
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 5/45
DB2 v10 tips and other performance topics
Save CPU by including extra columns to an unique index
ALTER INDEX IX1 ADD INCLUDE (COL2)
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 6/45
DB2 v10 tips and other performance topics
Save CPU by including extra columns to an unique index
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 7/45
DB2 v10 tips and other performance topics
Save CPU by including extra columns to an unique index
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 8/45
DB2 v10 tips and other performance topics
Save CPU by including extra columns to an unique index
A note when adding several columns to an index
You have to add them one by one …
That’s honestly not a big deal, but maybe an nice DB2
enhancement to add in future versions could be:
ALTER INDEX IX1 ADD INCLUDE (COL3) ;
ALTER INDEX IX1 ADD INCLUDE (COL4) ;
ALTER INDEX IX1 ADD INCLUDE (COL5) ;
ALTER INDEX IX1 ADD INCLUDE (COL3, COL4, COL5) ;
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 9/45
DB2 v10 tips and other performance topics
Save CPU by including extra columns to an unique index
From Theory to Practice
How to locate this scenario in your DB2 environment ?
Query the system catalog to locate indexes whose keysoverlap with the unique index !
An example next slide, when the unique index iscomposed of only 1 column.
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 10/45
DB2 v10 tips and other performance topics
Save CPU by including extra columns to an unique indexSELECT IX.CREATOR,IX.NAME,
IX.TBCREATOR,IX.TBNAME,
IX.UNIQUERULE,IX.COLCOUNT,
KEYS.IXCREATOR,KEYS.IXNAME,
KEYS.COLNAME,KEYS.COLNO,
IX2.CREATOR,IX2.NAME,
IX2.TBCREATOR,IX2.TBNAME,
IX2.UNIQUERULE,IX2.COLCOUNT,
KEYS2.IXCREATOR,KEYS2.IXNAME,
KEYS2.COLNAME,KEYS2.COLNO
FROM SYSIBM.SYSINDEXES IX,
SYSIBM.SYSKEYS KEYS,
SYSIBM.SYSINDEXES IX2,
SYSIBM.SYSKEYS KEYS2
!ERE IX.UNIQUERULE " #U#
AND IX.CREATOR " KEYS.IXCREATOR
AND IX.NAME " KEYS.IXNAME
AND IX.COLCOUNT " 1
AND IX.TBCREATOR " IX2.TBCREATOR
AND IX.TBNAME " IX2.TBNAME
AND IX2.CREATOR " KEYS2.IXCREATOR
AND IX2.NAME " KEYS2.IXNAME
AND IX2.UNIQUERULE " #D#
AND IX.TBCREATOR " IX2.TBCREATOR
AND IX.TBNAME " IX2.TBNAME
AND KEYS.COLNAME " KEYS2.COLNAME ;
SYSIBM.SYSINDEXES
SYSIBM.SYSKEYS
contains information about all indexesin the subsystem, CREATOR, NAME,TBCREATOR, TBNAME, uniqueness,#columns, …
contains information about all keys ofall indexes in the subsystem, COLNAM
COLNO, … associated with a particularINDEX
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 11/45
DB2 v10 tips and other performance topics
Save CPU by including extra columns to an unique index
With the result of this SQL statement, you can
prepare your ALTER INDEX statements to INCLUDEnon-key columns to the unique indexes listed, andget rid of the corresponding now-superfluous
indexes.
Save DASD !
Save CPU !
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 12/45
DB2 v10 tips and other performance topics
Is the length of your inline LOBs optimal ?
DB2 v10 new feature :
INLINE LOBs allow a portion of a LOB column to be stored in
the base TableSpace.
What is it good for ?
improves the performance of applications accessing LOB data,(reduces the need to access the auxiliary LOB TableSpace)
enables the creation of expression-based indexes on the inline
portion of a LOB column(improves performance of searches through a LOB column)
the Inline portion of the LOB can be compressed
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 13/45
DB2 v10 tips and other performance topics
Is the length of your inline LOBs optimal ?
COL1 COL2 COL3 LOB
000100020003
00040005000$000%000&
AAAAAAABAABB
BBBBCCCCCCDDEEEEFFFF
200220022005
200&2012201320132013
'*LOB+000+000+
--111111+//111//222+333
Base TableSpace auxiliary LOB TableSpace
R/' / LOB
+//LOB++
+
+
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 14/45
DB2 v10 tips and other performance topics
Is the length of your inline LOBs optimal ?
COL1 COL2 COL3 LOB
000100020003
00040005000$000%000&
AAAAAAABAABB
BBBBCCCCCCDDEEEEFFFF
200220022005
200&2012201320132013
'*LOB+000+000+
--111111+//111//222+333
Base TableSpace auxiliary LOB TableSpace
R/' / LOB
+//LOB++
+
+
Index on expression example
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 15/45
DB2 v10 tips and other performance topics
Is the length of your inline LOBs optimal ?
COL1 COL2 COL3 LOB
000100020003
00040005000$000%000&
AAAAAAABAABB
BBBBCCCCCCDDEEEEFFFF
200220022005
200&2012201320132013
'*LOB+000+000+
--111111+//111//222+333
Base TableSpace auxiliary LOB TableSpace
R/' / LOB
+//LOB++
+
+
Some LOBs are not entirely self-contained “inline” …
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 16/45
DB2 v10 tips and other performance topics
Is the length of your inline LOBs optimal ?
COL1 COL2 COL3 LOB
000100020003
00040005000$000%000&
AAAAAAABAABB
BBBBCCCCCCDDEEEEFFFF
200220022005
200&2012201320132013
'*LOB+000+000+
--111111+//111//222+333
Base TableSpace auxiliary LOB TableSpace
R/' / LOB
+//LOB++
+
+
… and some other are self-contained.
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 17/45
DB2 v10 tips and other performance topics
Is the length of your inline LOBs optimal ?
So what should be the length for my INLINE Lobs ?
IBM DB2 limitations: Minimum: 0 (i.e. LOB is not INLINE) Maximum: 32680
Within this range, this is up to the DBA to define the proper
length. The length is defined via DDL statements: Table creation : CREATE TABLE TABLE1 (COLLOB CLOB(1M) INLINE LEN6T! 20000) ;
Table alter : ALTER TABLE TABLE1 ALTER COLUMN COLLOB INLINE LEN6T! 30000 ;
C789 R/* /// : (2)
Tip : Larger page size can be beneficial when turning a LOB into InlineLOB (3)
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 18/45
DB2 v10 tips and other performance topics
Is the length of your inline LOBs optimal ?
The optimal length for INLINE Lobs depends on theactual DATA, more precisely, the length of the LOBs
…
The question is almost philosophical, since the answer
greatly depends on the LOB Lengths Distribution in thecolumn, in other words, it depends on the type of datathat are stored in the LOB. And the DBA creating the
table does not necessarily know what it contains, nor
what it will contain…
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 19/45
DB2 v10 tips and other performance topics
Is the length of your inline LOBs optimal ?
Various examples of LOB length distributions:
1st case: almost all LOBs data are small, limited in size,with a few exceptions.
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 20/45
DB2 v10 tips and other performance topics
Is the length of your inline LOBs optimal ?
Various examples of LOB length distributions:
2nd case: the LOBs lengths are equally distributed, fromthe minimum length to the maximum length.
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 21/45
DB2 v10 tips and other performance topics
Is the length of your inline LOBs optimal ?
Various examples of LOB length distributions:
3rd case: the LOBS lengths is are linearly distributed(ascending or descending)
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 22/45
DB2 v10 tips and other performance topics
Is the length of your inline LOBs optimal ?
Various examples of LOB length distributions:
4th case: the LOBs length follow a normal distribution(Gauss).
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 23/45
DB2 v10 tips and other performance topics
Is the length of your inline LOBs optimal ?
Various examples of LOB length distributions:
5th case: the LOBs length distribution is sinusoidal
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 24/45
DB2 v10 tips and other performance topics
Is the length of your inline LOBs optimal ?
From Theory to Practice
Identify inline LOBs in your subsystem …
SELECT TBCREATOR,TBNAME,NAME,LEN6T!,LEN6T!2,COLTY<E
FROM SYSIBM.SYSCOLUMNS
!ERE ( COLTY<E " #CLOB#
OR COLTY<E " #BLOB#
OR COLTY<E " #DBCLOB# )AND LEN6T! = 4 ;
“LENGTH” > 4 indicates that the LOB column uses the INLINE LOB technique, theactual Inline LOB Length is LENGTH-4
“LENGTH2” reflects the maximum length of the LOB column (inline + stored inAuxiliary)
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 25/45
DB2 v10 tips and other performance topics
Is the length of your inline LOBs optimal ? From Theory to Practice
Visualize the length distribution of a LOB column…
The following SQL categorizes the various lengths of the LOBs into LOBlength ranges
SELECT RAN6E, COUNT(LEN6T!) AS ROCOUNT FROM (
SELECT LEN6T!(<ARSETREE) AS LEN6T!,
(CEIL(2%$%0>100)?(1@CEIL( 100 ? LEN6T!(<ARSETREE) > 2%$%0))) AS RAN6E
FROM SYSIBM.SYSIES) AS TABLEIT!RAN6E
6ROU< BY RAN6EORDER BY RAN6E ;
This example uses SYSIBM.SYSIES that contains a LOB column<ARSETREE, a 1GB BLOB (1073741824) with Inline LENGTH 27674-4 =27670
When exported to Excel, one can make a simple graph representation ofthe LOB length distribution and visualize if the INLINE LENGTH value isproperly set (next slide).
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 26/45
DB2 v10 tips and other performance topics
Is the length of your inline LOBs optimal ?
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 27/45
DB2 v10 tips and other performance topics
Is the length of your inline LOBs optimal ?
Advantages & Benefits
The nice thing about this technique is that it is re-usableover time, meaning that the same query can be ran later,
when the LOB data values have evolved.
That can help to make sure the INLINE LENGTH value is(still) optimal !
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 28/45
DB2 v10 tips and other performance topics
Impact of SELECT * versus SELECTing specific columns
Performance impact benchmark
a simple and dirty SELECT *
… versus …
selecting only the specific columns you need
First note
the performance degradation is not visible if we are dealing
with small tables (small number of rows). My tests with a 1000rows table did not show any difference. But when I performedtests on a more realist size of table (1,000,000 rows), I didnotice meaningful differences.
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 29/45
DB2 v10 tips and other performance topics
Impact of SELECT * versus SELECTing specific columns
Test environment
Presenting here the results of a performance test (CPUtime, and Elapsed time) for a 1,000,000 rows table.
DB2 v10 New Function Mode (NFM) subsystem.
Using a fairly simple table, with 7 columns only (integer,dates, and timestamps)
Compared a SELECT * with SELECT COL1, COL2.
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 30/45
DB2 v10 tips and other performance topics
Impact of SELECT * versus SELECTing specific columns Benchmark results
70% overhead of CPU time
17% overhead of Elapsed time
Other tests performed show similar results, overhead of SELECT * variesdepending on:
the number of columns specified in the SELECT COL1, COL2, …
the size of the table (number of rows).
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 31/45
DB2 v10 tips and other performance topics
Impact of SELECT * versus SELECTing specific columns
From Theory to Practice
How to identify embedded SELECT * in existing
applications running against DB2 for z/OS ?
A few years ago, I used a product that examines embeddedSQL statement in Cobol programs: CA Plan Analyzer (it also
works for other programming languages).
Not to enter into too much details about this tool, there is arule (sort of trigger) called Expert Rule 0064 that will be
triggered if an embedded SELECT * SQL statement isdiscovered in the application / plan / package analyzed.
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 32/45
DB2 v10 tips and other performance topics
Impact of SELECT * versus SELECTing specific columns
In addition to the performance impact mentioned detailedabove, CA Plan Analyzer also notifies the user with thefollowing recommendation (which makes a lot of sense, andIMHO another good reason why application developersshould not use SELECT * type of SQL statements in their
application) :
T8' '7 / 8/ /-7'/ */' - / /-7/*/
/ 8 */8 -7' * / 7/*G8 /('). Y7*
8-8 ** ' *8/' 8 -**/' /
/>*// -7'.
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 33/45
DB2 v10 tips and other performance topics
Impact of SELECT * versus SELECTing specific columns
Recommendations
If you are a DB2 application developer and you careabout your applications performance : do not useSELECT * statements !
If you are a DB2 administrator, you may want to sharethis presentation with your application developers, and /
or look for products that can detect the use of embeddedSELECT * statements running in your DB2 environment.
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 34/45
DB2 v10 tips and other performance topics
Improve the response time of Native SQL procedures in DB2 v10 DB2 v9 introduced a new type of stored procedures
called Native SQL Procedures.
These procedures execute in DBM1 address space, andprovide SQL performance improvements due to less cross-memory calls compared to external stored procedures.
Several improvements were done in this area in DB2 v10.
IBM however mentions that the response time improvement (upto 20% improvement) can be achieved only if the existing
Native SQL Procedures are dropped and re-created. That is, ifyou had created Native SQL Procedures under DB2 version 9and upgraded to DB2 version 10, you might want toDROP/CREATE those.
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 35/45
DB2 v10 tips and other performance topics
Improve the response time of Native SQL procedures in DB2 v10
From Theory to Practice
You moved to DB2 v10, and you need to locate the Native
Stored Procedures that were created prior the migration.
As I did not know when my subsystem moved to DB2v10, I used a “trick” to discover this information:
As in every new DB2 version, the DB2 catalog containsadditional tables that are created during the migration
process. I took one of them, SYSIBM.SYSAUTOALERTS,and queried SYSIBM.SYSTABLES to get the CREATEDTSvalue.
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 36/45
DB2 v10 tips and other performance topics
Improve the response time of Native SQL procedures in DB2 v10
SQL statement used to discover the date ofmigration to DB2 v10 :
HH / ' DB2 7*/ 10 NFM
SELECT CREATEDTS
FROM SYSIBM.SYSTABLES
!ERE NAME " #SYSAUTOALERTS#AND CREATOR " #SYSIBM# ;
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 37/45
DB2 v10 tips and other performance topics Improve the response time of Native SQL procedures in DB2 v10
From Theory to Practice Listing all Native Stored Procedures created prior the upgrade to
version 10 NFM
HH L8' N8/ SQL <*-/7*/' */H-*//
SELECT CREATEDBY,ONER,NAME,ORI6IN,CREATEDTS
FROM SYSIBM.SYSROUTINES
!ERE ORI6IN " #N#
AND CREATEDTS J ( SELECT CREATEDTS
FROM SYSIBM.SYSTABLES!ERE NAME " #SYSAUTOALERTS#
AND CREATOR " #SYSIBM# );
Stored procedures are listed in SYSIBM.SYSROUTINES, and the
column ORIGIN = 'N' indicates that we deals with a Native SQLProcedure
Another method was suggested to me, see appendix (4)
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 38/45
DB2 v10 tips and other performance topics Improve the response time of Native SQL procedures in DB2 v10
From Theory to Practice
With that, you have the list of Native SQL Procedures thatyou want to DROP / RECREATE.
Hopefully, you have the DDL for these objects stored indataset, but nothing is less obvious. If not, you can use
tools to generate the DDL statements from the informationin the catalog, in this example I used CA RC/Query forDB2 for z/OS to locate a particular Native SQL Procedureand generate its DDL (next slide)
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 39/45
DB2 v10 tips and other performance topics Improve the response time of Native SQL procedures in DB2 v10
Locate the Native Stored Procedure, and executethe “DDL” command.
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 40/45
DB2 v10 tips and other performance topics Improve the response time of Native SQL procedures in DB2 v10
Result of the “DDL” command
i d h f i
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 41/45
DB2 v10 tips and other performance topics Improve the response time of Native SQL procedures in DB2 v10
From Theory to Practice
Ones you have the DDL, all what’s needed is to updatethe SQL, add the DROP syntax and a couple of
COMMITs, and the job is done!
Benefits
Performance improvements
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 42/45
Appendix
Philippe Dubost
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 43/45
Appendix(0) Additional indexes --> Higher insert/delete CPU time (approximately 30% for each index)
Ref. presentation: DB2 10 Performance Update (Susan Lawson)
(1) Potential negative impact when using INCLUDE columns
If the majority of SQL is using the columns of the unique index (not the one to include) – afteradding an additional column, you now will have less index entries per page, i.e. more GETPrequests, i.e. impact on performance.
(2) Reorg needed when implementing Inline LOBs
Add an Inline length or increase length : Advisory Status (AREO)
Decrease length : Restrictive state (REORP)
(3) Larger page sizes can be beneficial when turning a LOB into Inline LOB
Some customers default everything to 4K pages. If you’ve got a LOB and most of thedata fits into a smaller length than the maximum inline length (32680), which isn’tuncommon, it might be worth considering making the LOB columns Inline and the Pagesize larger so you can get more rows on a page. Inlining LOB columns in 4K pages
might reduce the number of rows on the page, forcing you to read more pages.
(4) (not tested) - Another way to find Native Stored Procedures create under DB2 v9
SYSROUTINES created under DB2 9 should have ‘M’ in column RELCREATED
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 44/45
DB2 v10 tips and other performance topics
Presenter’s biography:
Contact information:
www.linkedin.com/in/dubost/
www.db2forz.blogspot.com
E-mail: [email protected]
A 9-year IT professional, Philippe Dubost is Product
Manager at CA technologies. In this role, he isresponsible for products planning and strategy,presenting and representing the products portfolio tocustomers and industry analysts, collecting customerrequirements and transforming them into actionable
Agile/Scrum stories in the engineering backlog.
8/12/2019 Guide DB2 DB2 10 Tips
http://slidepdf.com/reader/full/guide-db2-db2-10-tips 45/45
DB2 10 Tips
and Other Performance Topicspar Philippe Dubost, CA technologies