Professional Documents
Culture Documents
Runion du Guide DB2 pour z/OS France Jeudi 10 octobre 2013 Tour Opus, Paris-La Dfense
Thats honestly not a big deal, but maybe an nice DB2 enhancement to add in future versions could be:
ALTER INDEX IX1 ADD INCLUDE (COL3, COL4, COL5) ;
SYSIBM.SYSINDEXES contains information about all indexes in the subsystem, CREATOR, NAME, TBCREATOR, TBNAME, uniqueness, #columns, SYSIBM.SYSKEYS contains information about all keys of all indexes in the subsystem, COLNAME, COLNO, associated with a particular INDEX
!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 ;
With the result of this SQL statement, you can prepare your ALTER INDEX statements to INCLUDE non-key columns to the unique indexes listed, and get rid of the corresponding now-superfluous indexes.
Save DASD ! Save CPU !
Base TableSpace
Base TableSpace
Base TableSpace
Base TableSpace
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 (COL5LOB CLOB(1M) INLINE LEN6T! 20000) Table alter : ALTER TABLE TABLE1 ALTER COLUMN COL5LOB INLINE LEN6T! 30000 ;
C)7(8249 R/2*1 4//./. : (2)
;
Tip : Larger page size can be beneficial when turning a LOB into Inline LOB (3)
The optimal length for INLINE Lobs depends on the actual DATA, more precisely, the length of the LOBs
The question is almost philosophical, since the answer greatly depends on the LOB Lengths Distribution in the column, in other words, it depends on the type of data that are stored in the LOB. And the DBA creating the table does not necessarily know what it contains, nor what it will contain
LENGTH > 4 indicates that the LOB column uses the INLINE LOB technique, the actual Inline LOB Length is LENGTH-4 LENGTH2 reflects the maximum length of the LOB column (inline + stored in Auxiliary)
This example uses SYSIBM.SYSAIE S 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 of the LOB length distribution and visualize if the INLINE LENGTH value is properly set (next slide).
First note
the performance degradation is not visible if we are dealing with small tables (small number of rows). My tests with a 1000 rows table did not show any difference. But when I performed tests on a more realist size of table (1,000,000 rows), I did notice meaningful differences.
Test environment
Presenting here the results of a performance test (CPU time, 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.
70% overhead of CPU time 17% overhead of Elapsed time Other tests performed show similar results, overhead of SELECT * varies depending on:
the number of columns specified in the SELECT COL1, COL2, the size of the table (number of rows).
In addition to the performance impact mentioned detailed above, CA Plan Analyzer also notifies the user with the following recommendation (which makes a lot of sense, and IMHO another good reason why application developers should not use SELECT * type of SQL statements in their application) :
T38' '327B. ,/ )C28./. ,/-)7'/ 20 D*2,B/E' (3)( -)4 ,/ /4-274(/*/. F3/4 )..841 )4. */E2C841 -2B7E4' 0*2E (3/ 74./*BG841 (),B/('). Y27* )DDB8-)(824 D*21*)E 32'( C)*8),B/' F8BB 42( -2**/'D24. (2 (3/ )../.>*/E2C/. -2B7E4'.
Recommendations
If you are a DB2 application developer and you care about your applications performance : do not use SELECT * statements ! If you are a DB2 administrator, you may want to share this presentation with your application developers, and / or look for products that can detect the use of embedded SELECT * statements running in your DB2 environment.
DB2 v9 introduced a new type of stored procedures called Native SQL Procedures.
These procedures execute in DBM1 address space, and provide SQL performance improvements due to less crossmemory calls compared to external stored procedures. Several improvements were done in this area in DB2 v10. IBM however mentions that the response time improvement (up to 20% improvement) can be achieved only if the existing Native SQL Procedures are dropped and re-created. That is, if you had created Native SQL Procedures under DB2 version 9 and upgraded to DB2 version 10, you might want to DROP/CREATE those.
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 SQL Procedure Another method was suggested to me, see appendix
(4)
Locate the Native Stored Procedure, and execute the DDL command.
Benefits
Performance improvements
Appendix
Philippe Dubost
Appendix
(0) Additional indexes --> Higher insert/delete CPU time (approximately 30% for each index)
Ref. presentation: DB2 10 Performance Update (Susan Lawson)
(3) Larger page sizes can be beneficial when turning a LOB into Inline LOB
Some customers default everything to 4K pages. If youve got a LOB and most of the data fits into a smaller length than the maximum inline length (32680), which isnt uncommon, it might be worth considering making the LOB columns Inline and the Page size 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
Contact information:
www.linkedin.com/in/dubost/ www.db2forz.blogspot.com E-mail: Philippe.Dubost@ca.com