Session: V07 Bi d d R bi d A l i Bind and Rebind Analysis · Session: V07 Bi d d R bi d A l i Mike...

79
Session: V07 Bi d dR bi dA l i Mike Bell Bind and Rebind Analysis Mike Bell HLS Technologies May 13 th , 2009 •2:45PM to 3:45PM DB2 for z/OS

Transcript of Session: V07 Bi d d R bi d A l i Bind and Rebind Analysis · Session: V07 Bi d d R bi d A l i Mike...

Session: V07 Bi d d R bi d A l i

Mike Bell

Bind and Rebind AnalysisMike Bell

HLS Technologies

May 13th, 2009 •2:45PM to 3:45PMDB2 for z/OS

What is an Access Path?What is an Access Path?

• For each SQL statement DB2 makes a choice aboutFor each SQL statement DB2 makes a choice about how to process that SQL.

• For static SQL, the access path is stored in a skeleton cursor table.

• These are stored in directory tables DSNDB01 SCT02 d DSNDB01 SPT01DSNDB01.SCT02 and DSNDB01.SPT01

• For dynamic SQL the access path is kept in the EDM pool and can be saved in DYNAMIC SQLEDM pool and can be saved in DYNAMIC SQL CACHE.

2

What is a Good Access Path?What is a Good Access Path?• Nobody complains about performance?Nobody complains about performance?• Jobs (or transactions) meet their performance goals.• Each SQL statement processes the data required in Q p q

the most cost efficient method.• DB2 chooses the access path with the lowest

estimated cost.• That cost is recorded in PROCMS and PROCSU in

DSN STATEMNT TABLE for static SQLDSN_STATEMNT_TABLE for static SQL.

3

What is a Bad Access Path?What is a Bad Access Path?• Anything that generates a midnight call.Anything that generates a midnight call.• Anything that generates a “come see me” note on

your voice mail.• The standard answer:

• Run RUNSTATS• REBIND• Repeat until solved

4

How do you get a Bad Access Path?How do you get a Bad Access Path?

Static SQL requires a BIND or REBIND• Static SQL requires a BIND or REBIND. • Dynamic SQL – it depends:

• Dynamic SQL cache active?• Dynamic SQL cache active?• Does it match an entry in the cache?• Has the cache been flushed (RUNSTATS)?• Has the cache been flushed (RUNSTATS)?

• The access path DB2 chooses is dependent on the statistics in the catalog.s a s cs e ca a og

• Both RUNSTATS and RTS.

5

How do you know the Access Path isHow do you know the Access Path is Bad?

• Examine the data in PLAN_TABLE. • Examine the data in DSN STATEMNT TABLEExamine the data in DSN_STATEMNT_TABLE.• EXPLAIN(YES)• Check SMF records for CPU used per SQLCheck SMF records for CPU used per SQL

statement.• Wait for a phone call.

6

Procedure to get your Packages g y gRebound on current DB2 Version

• REBIND COLLID(collection.*.(*))• This will attempt to rebind every version of every p y y

package. • It will include in that list packages that are no longer

valid if they exist in the collection.

7

Aid and AbetAid and Abet• SELECT DISTINCT ' REBIND PACKAGE('

CONCAT RTRIM(COLLID) CONCAT ').*.(*))' FROM SYSIBM SYSPACKAGEFROM SYSIBM.SYSPACKAGE ;

REBIND PACKAGE(ADBL).*.(*))

8

Another Aid and AbetAnother Aid and Abet

• SELECT DISTINCT ' REBIND PACKAGE(‘ CONCAT RTRIM(COLLID) CONCAT ').' CONCAT RTRIM(NAME) CONCAT '.(' CONCAT RTRIM(VERSION) CONCAT '))' FROM SYSIBM.SYSPACKAGE AWHERE CREATOR <> 'SYSIBM' AND VALID = 'Y' AND VERSION > '' AND CONTOKEN = (SELECT MAX(CONTOKEN) FROM ( ( )SYSIBM.SYSPACKAGE B WHERE A.LOCATION = B.LOCATION AND A.COLLID = B.COLLID AND A.NAME = B.NAME)

• REBIND PACKAGE(ADBL).ADB27AC.(1))

9

NOW CHECK TO SEE WHAT CHANGEDCHANGED

SELECT 'COMPARE PACKAGE ' CONCAT RTRIM(COLLID) ( )CONCAT '.' CONCAT RTRIM(NAME) CONCAT ' IN

P390H.PLAN_TABLE TO PREVIOUS' FROM SYSIBM SYSPACKAGE A WHERE CREATOR = 'P390H'SYSIBM.SYSPACKAGE A WHERE CREATOR P390H AND VALID = 'Y' AND OPERATIVE = 'Y' AND COLLID = 'TESTCOLLX'

AND CONTOKEN (SELECT MAX(CONTOKEN) FROMAND CONTOKEN = (SELECT MAX(CONTOKEN) FROM SYSIBM.SYSPACKAGE B WHERE A.LOCATION = B.LOCATION AND A.COLLID = B.COLLID AND A.NAME

B NAME)= B.NAME)ORDER BY 1

10

RESULTS OF SPUFI

COMPARE PACKAGE TESTCOLLX.TEST01 INCOMPARE PACKAGE TESTCOLLX.TEST01 IN P390H.PLAN_TABLE TO PREVIOUS

COMPARE PACKAGE TESTCOLLX.TEST02 IN P390H.PLAN_TABLE TO PREVIOUS

COMPARE PACKAGE TESTCOLLX.TEST03 IN P390H PLAN TABLE TO PREVIOUSP390H.PLAN_TABLE TO PREVIOUS

11

IS ‘HOPING TO GOODNESS’ A VALID MIGRATION STRATEGY?MIGRATION STRATEGY?

• COMPARE PACKAGE TESTCOLLX.TEST01 IN P390H.PLAN_TABLE TO PREVIOUS

• 1 ACCESS PATH FOR COLLID - TESTCOLLX .TEST01 SQL ID- OLD PLAN_TABLE -RUN DATE 2009/05/09

• PCK212I TIMESTAMP USED FOR PREVIOUS COMMAND = 2009050715502529• VERSION = 2005-04-11-18.20.42.913225• BIND TIME = 2009-05-07-15.50.25.290000_• TIMESTAMP USED FOR CURRENT = 2009050909150119• VERSION = 2005-04-11-18.20.42.913225• BIND_TIME = 2009-05-09-09.15.01.190000

• PCK206I COMPARE COMPLETE FOR PROGRAM = TEST01 VERSION = 2005-04-11-18.20.42.913225

• BIND-TIME = 2009-05-09-09.15.01.190000• PREVIOUS VERSION = 2005-04-11-18.20.42.913225• PREVIOUS BIND-TIME = 2009-05-07-15.50.25.290000

• PCK203I STATEMENTS WITH SAME ACCESS PATH 1 STATEMENTS WITH DIFFERENT ACCESS PATH 0 FOR PROGRAM TEST01

• PCK204I STATEMENTS WITH MATCHING EXPLAIN 1 STATEMENTS WITHOUT MATCHING EXPLAIN 0 FOR PROGRAM TEST01

12

What Is a Reasonable Method for Processing Rebinds?

• Identify the old binds.• Identify packages that don’t have current access path information.• Identify packages that don’t have cost information (DSN-y p g (

STATEMNT_TABLE). • Use PATH CHECK to analyze the access path data for those

packages.p g• Use PATH CHECK to create current access path data for old

packages.• Use PATH CHECK to identify safe REBIND’s.Use PATH CHECK to identify safe REBIND s.• Use PATH CHECK to create HINT’s to make REBIND safe.• Use PATH CHECK to manage ongoing REBIND activity.

13

Path CheckPath Check• Path Check has been available for 10 years.• Is a tool to compare access paths for SQL.• Has a number of features that make analyzing BIND and REBIND

activity easier.

Commands available are:• EXPLAIN DBRMEXPLAIN DBRM • TEST DBRM• COMPARE

REPORT• REPORT

14

EXPLAIN DBRMEXPLAIN DBRM• Read a DBRM.Read a DBRM.• Identify SQL that can be processed by EXPLAIN.• REPORT on the access path selected.p

15

TEST DBRMTEST DBRM

• Read a DBRM.Read a DBRM.• Identify SQL that can be process by EXPLAIN.• COMPARE the potential access path to an existing p p g

access path.

16

COMPARECOMPARE

• COMPARE two sets of access path data fromCOMPARE two sets of access path data from PLAN_TABLE and DSN_STATEMNT_TABLE.

• Identify differences.

17

REPORTREPORT

• Display the access path data from PLAN TABLEDisplay the access path data from PLAN_TABLE and DSN_STATEMNT_TABLE.

18

How old are your Packages?How old are your Packages?

• DB2 version 8 was the first release to require• DB2 version 8 was the first release to require REBIND for old packages (pre DB2 V2.3)

• Does NOT require that you recompile but you do q y p yhave to BIND or REBIND.

• OLD DBRM’s are still supported but old packages are not.

• What information is available – if the last bind was l th th h hi hseveral years ago, the access path has a high

probability of change.

19

How old are you Packages?How old are you Packages?

• SELECT BINDYEAR ,COUNT(*) AS COUNTSELECT BINDYEAR ,COUNT( ) AS COUNTFROM TABLE (SELECT COLLID, NAME, YEAR(BINDTIME) AS BINDYEAR FROM ( )SYSIBM.SYSPACKAGE T1) AS SYSPACKAGE GROUP BY BINDYEAR ;

20

SPUFI ResultsSPUFI Results

BINDYEAR COUNTBINDYEAR COUNT ---------+---------+------

2004 1 2006 448 2007 243 2008 97 2009 367

21

What does it mean?What does it mean?

• This is a fairly normal development Version 8This is a fairly normal development Version 8 subsystem.

• Majority of the BIND’s were done after the subsystem was initially started.

• Not a subsystem that was migrated from an older iversion.

• Notice the lack of activity when Version 9 became availableavailable.

• What if there were BIND’s that were 10 years old?

22

Old Bind’s are now hazardous toOld Bind s are now hazardous to your System

• Version 8 started the requirement to REBIND.• Required rebind for packages from version 2.3 or q p g

older.• Uses an internal flag from the skeleton cursor table.• Version 9 continues with rebind required for version

3.1 .

23

What next?What next?

• Depends on how you want to structure the work.Depends on how you want to structure the work.• Start with the oldest packages.• Start with packages that are missing data in p g g

PLAN_TABLE or DSN_STATEMNT_TABLE.• Work forward.

24

Check for data in Plan_Table

• SELECT SUBSTR(COLLID,1,18) AS COLLID , SUBSTR(NAME,1,8) AS NAME FROM SYSIBM SYSPACKAGE AFROM SYSIBM.SYSPACKAGE A WHERE CREATOR = 'P390H' AND VALID = 'Y' AND OPERATIVE = 'Y' AND VERSION = '' AND NOT EXISTSAND NOT EXISTS (SELECT 1 FROM P390H.PLAN_TABLE B WHERE A.COLLID = B.COLLID AND A.NAME = B.PROGNAME AND B.VERSION = '' );

25

SPUFI ResultsSPUFI Results

COLLID NAMECOLLID NAME ---------+---------+---------DSNTWR81 DSNTWR DSNUT810 DSNUGSQL DSNUTIL DSNUGSQL DSNJAR DSNX9INJ DSNJAR DSNX9RPJ

26

Check for data in Plan Table withCheck for data in Plan_Table with Version

• SELECT SUBSTR(COLLID,1,18) AS COLLID , SUBSTR(NAME,1,8) AS NAME FROM SYSIBM SYSPACKAGE AFROM SYSIBM.SYSPACKAGE A WHERE CREATOR = 'P390H' AND VALID = 'Y' AND OPERATIVE = 'Y' AND VERSION > '' AND NOT EXISTSAND NOT EXISTS (SELECT 1 FROM P390H.PLAN_TABLE B WHERE A.COLLID = B.COLLID AND A.NAME = B.PROGNAME AND A.VERSION = B.VERSION AND A.BINDTIME = B.BIND_TIME );

27

SPUFI ResultsSPUFI ResultsCOLLID NAME ---------+---------+---------+DSNWZP DSNWZP ADBL ADB27AC ADBL ADBASW DSNACC DSNACCDLDSNACC DSNACCDL DSNACC DSNACCDS DSNACC DSNACCJFDSNACC DSNACCJF DSNACC DSNACCUC DSNACC DSNACCDF

28

Use Path Check to Identify CurrentUse Path Check to Identify Current Access Path

• EXPLAIN DBRM dbrmname TO PACKAGE testcoll.* in creator.PLAN_TABLE.

• Read the DBRM.• Take explainable SQL and run EXPLAIN.• Save the results in the target name.

29

Use SPUFI to generate Path CheckUse SPUFI to generate Path Check Commands

• SELECT DISTINCT 'EXPLAIN DBRM ' CONCAT RTRIM(NAME) CONCAT ' TO PACKAGE ' CONCAT RTRIM(COLLID) CONCAT ‘ * IN P390I PLAN TABLE ‘RTRIM(COLLID) CONCAT ‘.* IN P390I.PLAN_TABLE ‘ FROM SYSIBM.SYSPACKAGE AWHERE CREATOR = 'P390H' AND VALID = 'Y' ANDWHERE CREATOR P390H AND VALID Y AND OPERATIVE = 'Y‘ AND NOT EXISTS (SELECT 1 FROM P390H.PLAN_TABLE B WHERE A.COLLID = B.COLLID AND A NAME = B PROGNAME AND A VERSION =AND A.NAME = B.PROGNAME AND A.VERSION = B.VERSION );

30

Generated CommandsGenerated Commands• EXPLAIN DBRM ADB27AC TO PACKAGE ADBL.*EXPLAIN DBRM ADB27AC TO PACKAGE ADBL.

IN P390I.PLAN_TABLE• EXPLAIN DBRM ADB27SP TO PACKAGE ADBL.*

IN P390I.PLAN_TABLE• EXPLAIN DBRM ADB2CHK TO PACKAGE ADBL.*

IN P390I PLAN TABLEIN P390I.PLAN_TABLE

31

Example RunExample Run

• //STEP1 EXEC PGM=PATHCHK //STEPLIB DD DSN=P390H.PDS.LOADX,DISP=SHR // DD DSN=DSN810.SDSNLOAD,DISP=SHR //SYSPRINT DD SYSOUT *//SYSPRINT DD SYSOUT=* //SYSEXPLN DD SYSOUT=* //SYSCHG DD SYSOUT=*//SYSCHG DD SYSOUT //DBRMIN DD DSN=P390H.DB2V8.DBRMLIB1,DISP=SHR // DD DSN=P390H.DB2V8.DBRMLIB,DISP=SHR //SYSIN DD *

32

Inputp

• OPTIONS SQLERROROPTIONS SQLERROR CONNECT TO DB8G SET CURRENT SQLID = 'P390H' QEXPLAIN DBRM TDBRM2 TO PACKAGE TESTEXP.* IN P390I.PLAN_TABLE

33

SYSPRINTSYSPRINT

PCK031I EXECUTING LICENSED PATH CHECK V3R3PCK031I EXECUTING LICENSED PATH CHECK V3R3

DEBUG LISTSQLOPTIONS SQLERRORCONNECT TO DB8GSET CURRENT SQLID = 'P390H'

EXPLAIN DBRM TDBRM2 TO PACKAGE TESTEXP.* IN P390I.PLAN_TABLE

ACCESS PATH FOR COLLID - TESTEXP .TDBRM2 SQL ID- OLD PLAN_TABLE - RUN DATE 2009/05/04

IN QRYNO M CREATOR TNAME TBNO AC MC CREATOR ACCESSNAME IO SORTUJOG LK PF FN QBNO PLNO MXSQ MJN PG JN OP

294 0 P390H SYSCOLUMNS 1 R 0 N NNNNNNNN IS S 1 1 0PCK225I DSN STATEMNT TABLE ESTIMATED COST EST SVC UNITS 209PCK225I DSN_STATEMNT_TABLE ESTIMATED COST - EST SVC UNITS 209CKP228I DSN_STATEMNT_TABLE ESTIMATED COST - EST CPU 108

34

SYSEXPLNSYSEXPLNACCESS PATH FOR COLLID - TESTEXP .TDBRM2 SQL ID- OLD PLAN_TABLE -RUN DATE 2009/05/04

DBRM TDBRM2 IS VERSION A000ADBRM TDBRM2 HAS A CONNECT TOKEN OF 0C1F0F0F00C14040DBRM TDBRM2 WAS PRECOMPILED WITH LANGUAGE IBMCOB

STATEMENT 294 THIS IS THE NEW SQL STATEMENT.

STATEMENT# 294 DECLARE SELECT-1 CURSOR FOR SELECT NAME , TBNAME , COLNO , COLTYPE , LENGTH FROM SYSCOLUMNS WHERE TBNAME = : H

STEP 1 ACCESSES TABLE P390H .SYSCOLUMNSUSING A TABLESPACE SCAN.THE ACCESS WILL USE SEQUENTIAL PREFETCHTHE TIMESTAMP FOR THIS EXPLAIN IS 2009050409431656THE TABLE HAS -1 ROWS OF 969 BYTES.THE TABLE HAS 1 ROWS OF 969 BYTES.DB2 ESTIMATES THIS QUERY WILL USE 108 MILLISECONDS OF CPU TIMEDB2 ESTIMATES THIS QUERY WILL USE 209 SERVICE UNITSDB2 WAS FORCED TO USE ESTIMATES BECAUSE OFTABLE CARDINALITY

35

SYSCHG

******************************************************PCK218I PROGRAM TEST01 HAS A NEW SQL

STATEMENTQUERYNO 333COLLECTION TESTCOLLXVERSION 2005-04-11-18.20.42.913225

36

SummarySummary

• Three basic reports.Three basic reports. • SYSPRINT has data only.• SYSEXPLN has SQL text, readable access method, Q , ,

and minimal stats for table and indexes.• SYSCHG just has access path changes• The data is saved in the PLAN_TABLE specified

using the names specified.

37

Use Path Check to Identify ChangesUse Path Check to Identify Changes

• TEST DBRM dbrmname AS PACKAGE testcoll.* inTEST DBRM dbrmname AS PACKAGE testcoll. in creator PLAN_TABLE.

• Read the DBRM.• Take explainable SQL and run EXPLAIN.• Compare the results with an existing access path.

38

How shall I build the Commands?How shall I build the Commands?

• SELECT DISTINCT 'TEST DBRM ' CONCATSELECT DISTINCT TEST DBRM CONCAT RTRIM(NAME) CONCAT ' AS PACKAGE ' CONCAT RTRIM(COLLID) CONCAT '.* IN P390H PLAN TABLE ' FROMP390H.PLAN_TABLE ' FROM SYSIBM.SYSPACKAGE A WHERE CREATOR = 'P390H' AND VALID = 'Y'WHERE CREATOR = P390H AND VALID = Y AND OPERATIVE = 'Y' AND COLLID = 'TESTCOLLX'

39

Alternate VersionAlternate Version

• SELECT 'TEST DBRM ' CONCAT RTRIM(NAME) ( )CONCAT ' AS PACKAGE ' CONCAT RTRIM(COLLID) CONCAT '.* IN P390H.PLAN_TABLE ' FROM SYSIBM SYSPACKAGE AFROM SYSIBM.SYSPACKAGE A WHERE CREATOR = 'P390H' AND VALID = 'Y' AND OPERATIVE = 'Y' AND COLLID = 'TESTCOLLX' AND CONTOKEN (SELECT MAX(CONTOKEN) FROMAND CONTOKEN = (SELECT MAX(CONTOKEN) FROM SYSIBM.SYSPACKAGE B WHERE A.LOCATION = B.LOCATION AND A.COLLID = B.COLLID AND A.NAME

B NAME)= B.NAME) ORDER BY 1

40

One of the Generated CommandsOne of the Generated Commands

• TEST DBRM TEST01 AS PACKAGE TESTCOLLX.*TEST DBRM TEST01 AS PACKAGE TESTCOLLX. IN P390H.PLAN_TABLE

41

JCL to ProcessJCL to Process• //STEP1 EXEC PGM=PATHCHK

//STEPLIB DD DSN=P390H.PDS.LOADX,DISP=SHR // DD DSN DSN810 SDSNLOAD DISP SHR// DD DSN=DSN810.SDSNLOAD,DISP=SHR //SYSPRINT DD SYSOUT=* //SYSEXPLN DD SYSOUT=*//SYSEXPLN DD SYSOUT= //SYSCHG DD SYSOUT=* //DBRMIN DD//DBRMIN DD DSN=P390H.DB2V8.DBRMLIB2,DISP=SHR //SYSIN DD *

42

CommandsCommands

CONNECT TO DB8GCONNECT TO DB8GSET CATALOG QUALIFIER = 'SYSIBM'SET CURRENT SQLID = 'PUBLIC'QTEST DBRM TEST01 AS PACKAGE TESTCOLLX.*

IN P390H.PLAN_TABLE

43

RESULTS(NOT GOOD)(NOT GOOD)

IN QRYNO M CREATOR TNAME TBNO AC MC CREATOR ACCESSNAME IO SORTUJOG LK PF FN QBNO PLNO MXSQ MJN PG JN OPSORTUJOG LK PF FN QBNO PLNO MXSQ MJN PG JN OP

* 327 0 P390H SYSCOLUMNS 1 I 2 P390H DSNDCX01 N NNNNNNNN IS L 1 1 0

PCK220I DATA CHANGE FOR COLUMN PREFETCH WASPCK221I DATA CHANGE FOR COLUMN PREFETCH IS NOW LPCK224I DSN_STATEMNT_TABLE ESTIMATED COST CHANGE - OLD EST SVC UNITS 1CKP227I DSN STATEMNT TABLE ESTIMATED COST CHANGE OLD EST CPU 1CKP227I DSN_STATEMNT_TABLE ESTIMATED COST CHANGE - OLD EST CPU 1PCK223I DSN_STATEMNT_TABLE ESTIMATED COST CHANGE - NEW EST SVC UNITS 146CKP226I DSN_STATEMNT_TABLE ESTIMATED COST CHANGE - NEW EST CPU 76

PCK206I TEST COMPLETE FOR PROGRAM = TEST01 VERSION = 2005-04-11-PCK206I TEST COMPLETE FOR PROGRAM TEST01 VERSION 2005 04 1118.34.53.754785

PREVIOUS VERSION = 2005-04-11-18.34.53.754785

PCK203I STATEMENTS WITH SAME ACCESS PATH 1 STATEMENTS WITH DIFFERENT ACCESS PATH 1 FOR PROGRAM TEST01ACCESS PATH 1 FOR PROGRAM TEST01

PCK204I STATEMENTS WITH MATCHING EXPLAIN 2 STATEMENTS WITHOUT MATCHING EXPLAIN 0 FOR PROGRAM TEST01

44

RESULTS(BETTER)(BETTER)

ACCESS PATH FOR COLLID - TESTCOLLX .TEST01 SQL ID- OLD PLAN TABLE - PLAN TABLEACCESS PATH FOR COLLID TESTCOLLX .TEST01 SQL ID OLD PLAN_TABLE PLAN_TABLE

RUN DATE 2009/05/06

PCK206I TEST COMPLETE FOR PROGRAM = TEST01 VERSION = 2006-04-24-22.45.29.330423 PREVIOUS VERSION = 2005-04-11-18.34.53.754785

PCK203I STATEMENTS WITH SAME ACCESS PATH 2 STATEMENTS WITH DIFFERENT ACCESS PATH 0 FOR PROGRAM TEST01

PCK204I STATEMENTS WITH MATCHING EXPLAIN 2 STATEMENTS WITHOUT MATCHING EXPLAIN 0 FOR PROGRAM TEST01

45

STARTING GOAL IS NO ACCESS PATH CHANGESPATH CHANGES

• New DDNAME //RBINDOUTNew DDNAME //RBINDOUTREBIND PACKAGE (TESTCOLLX.TEST01.(2006-04-

24-22.45.29.330423))-OWNER (PUBLIC)-EXPLAIN(YES)

• Generated by PATHCHECK because the access path has not changed

• Trigger is the RBINDOUT ddname

46

NEXT STEP

• Process REBIND even though there are accessProcess REBIND even though there are access path changes but depend on the estimated cost in DSN_STATEMNT_TABLE to select acceptable hchanges

• OPTIONS CPUPCT nnC if 0 th t• Can specify nn = 0 or some other percentage

47

TWO NEW DDNAMES

//STEP1 EXEC PGM=PATHCHK //STEPLIB DD DSN=P390H.PDS.LOADX,DISP=SHR // DD DSN=DSN810.SDSNLOAD,DISP=SHR //SYSPRINT DD SYSOUT=* //SYSEXPLN DD SYSOUT=*//SYSEXPLN DD SYSOUT=* //SYSCHG DD SYSOUT=* //RBINDOUT DD SYSOUT=*//PBINDOUT DD SYSOUT=*//DBRMIN DD DSN=P390H.DB2V8.DBRMLIB2,DISP=SHR //SYSIN DD *

48

OPTIONS CPUPCT nn

• RBINDOUT will have REBIND command forRBINDOUT will have REBIND command for• TEST command with no access path changes• TEST command where the estimated PROCMS

is less than the old PROCMS * (1+CPUPCT) for every changed ACCESS PATH

PBINDOUT will have REBIND commands for hazardous REBIND’shazardous REBIND’s

Every TEST command will generate a REBIND

49

SAMPLE INPUT

OPTIONS CPUPCT 10 CONNECT TO DB8G

SET CURRENT SQLID = 'PUBLIC' TEST DBRM TEST01 AS PACKAGE TESTCOLL8 * INTEST DBRM TEST01 AS PACKAGE TESTCOLL8. IN

P390H.PLAN_TABLE TEST DBRM TEST02 AS PACKAGE TESTCOLL8.* IN

P390H PLAN TABLEP390H.PLAN_TABLE TEST DBRM TEST03 AS PACKAGE TESTCOLL8.* IN

P390H.PLAN_TABLE TEST DBRM TEST04 AS PACKAGE TESTCOLL8 * INTEST DBRM TEST04 AS PACKAGE TESTCOLL8. IN

P390H.PLAN_TABLE TEST DBRM TEST05 AS PACKAGE TESTCOLL8.* IN

P390H PLAN TABLE

50

P390H.PLAN_TABLE

SAMPLE OUTPUT

IN QRYNO M CREATOR TNAME TBNO AC MC CREATOR ACCESSNAME IO SORTUJOG LK PF FN QBNO PLNO MXSQ MJN PG JN OPSORTUJOG LK PF FN QBNO PLNO MXSQ MJN PG JN OP

* 327 0 PUBLIC SYSCOLUMNS 1 I 2 PUBLIC DSNDCX01 N NNNNNNNN IS 1 1 0

PCK220I DATA CHANGE FOR COLUMN MATCHCOLS WAS 0PCK220I DATA CHANGE FOR COLUMN PREFETCH WAS SPCK221I DATA CHANGE FOR COLUMN MATCHCOLS IS NOW 2PCK221I DATA CHANGE FOR COLUMN PREFETCH IS NOWPCK224I DSN_STATEMNT_TABLE ESTIMATED COST CHANGE - OLD EST SVC UNITS 38CKP227I DSN_STATEMNT_TABLE ESTIMATED COST CHANGE - OLD EST CPU 20PCK223I DSN_STATEMNT_TABLE ESTIMATED COST CHANGE - NEW EST SVC UNITS 1CKP226I DSN_STATEMNT_TABLE ESTIMATED COST CHANGE - NEW EST CPU 1

PCK206I TEST COMPLETE FOR PROGRAM = TEST01 VERSION = 2006-04-24-22.45.29.330423

PREVIOUS VERSION = 2007-11-09-13.47.05.581274

PCK203I STATEMENTS WITH SAME ACCESS PATH 1 STATEMENTS WITH DIFFERENT ACCESS PATH 1 FOR PROGRAM TEST01

PCK204I STATEMENTS WITH MATCHING EXPLAIN 2 STATEMENTS WITHOUT MATCHING EXPLAIN 0 FOR PROGRAM TEST01

CKP219I STATEMENTS OVER CPUPCT 0

51

CKP219I STATEMENTS OVER CPUPCT 0

THE NEW ACCESS PATH HAS LOWER PROCMSLOWER PROCMS

• RBINDOUT containsRBINDOUT contains

REBIND PACKAGE (TESTCOLL8.TEST01.(2006-04-( (24-22.45.29.330423))-

OWNER (PUBLIC)-EXPLAIN(YES)

52

WHY DID DB2 CHANGE THE MATCHCOLS?MATCHCOLS?

• The test case has a different DBRM with a changedThe test case has a different DBRM with a changed SQL statement

• So REBIND would not implement that SQL change

53

NEXT POSSIBLE SOLUTIONOPTIONS CONVERTHINTOPTIONS CONVERTHINT

• OPTIONS CONVERTHINT hintnameOPTIONS CONVERTHINT hintname• If there is an access path change, then build a hint

for the old access path• HINT’s are best used as a temporary solution to let

you BIND or REBIND immediately• Long term maintenance of HINT’s is not simple

54

COMMANDS

OPTIONS CATALOGSQL NOMATCHCREATOROPTIONS CATALOGSQL NOMATCHCREATOROPTIONS CONVERTHINT MIKEHINTCONNECT TO DB8GSET CURRENT SQLID = 'PUBLIC'TEST DBRM TEST01 AS PACKAGE TESTCOLL8.*

IN P390H.PLAN_TABLE

55

RESULTS

IN QRYNO M CREATOR TNAME TBNO AC MC CREATOR ACCESSNAME IO SORTUJOG LK PF FN QBNO PLNO MXSQ MJN PG JN OP* 327 0 PUBLIC SYSCOLUMNS 1 I 2 PUBLIC DSNDCX01 N NNNNNNNN IS 1 1 0PCK220I DATA CHANGE FOR COLUMN MATCHCOLS WAS 0PCK220I DATA CHANGE FOR COLUMN MATCHCOLS WAS 0PCK220I DATA CHANGE FOR COLUMN PREFETCH WAS SPCK221I DATA CHANGE FOR COLUMN MATCHCOLS IS NOW 2PCK221I DATA CHANGE FOR COLUMN PREFETCH IS NOWPCK223I DSN_STATEMNT_TABLE ESTIMATED COST CHANGE - NEW EST SVC UNITS 1PCK226I DSN_STATEMNT_TABLE ESTIMATED COST CHANGE - NEW EST CPU 1PCK052I HINT CREATED FOR PACKAGE TESTCOLL8 PROGRAM= TEST01 MIKEHINT

IN QRYNO M CREATOR TNAME TBNO AC MC CREATOR ACCESSNAME IO SORTUJOG LK PF FN QBNO PLNO MXSQ MJN PG JN OPQ O C O O C C C O CC SS O SO UJOG Q O O SQ J G J OINS 334 0 PUBLIC SYSTABLES 1 I 1 PUBLIC DSNDTX01 N NNNNNNNN IS L 1 1 0PCK223I DSN_STATEMNT_TABLE ESTIMATED COST CHANGE - NEW EST SVC UNITS 5PCK226I DSN_STATEMNT_TABLE ESTIMATED COST CHANGE - NEW EST CPU 3

• HINT created for query 327• INS means a SQL statement was insertedWhi h th t t i t• Which means the test case is not correct

56

COMMANDSWITH CPUPCTWITH CPUPCT

OPTIONS CATALOGSQL NOMATCHCREATOROPTIONS CATALOGSQL NOMATCHCREATOROPTIONS CONVERTHINT MIKEHINTOPTIONS CPUPCT 20CONNECT TO DB8GSET CURRENT SQLID = 'PUBLIC'TEST DBRM TEST01 AS PACKAGE TESTCOLL8.*

IN P390H.PLAN_TABLE

57

Results with CPUPCT

IN QRYNO M CREATOR TNAME TBNO AC MC CREATOR ACCESSNAME IO SORTUJOG LK PF FN QBNO PLNO MXSQ MJN PG JN OP* 327 0 PUBLIC SYSCOLUMNS 1 I 2 PUBLIC DSNDCX01 N NNNNNNNN IS 1 1 0PCK220I DATA CHANGE FOR COLUMN MATCHCOLS WAS 0PCK220I DATA CHANGE FOR COLUMN MATCHCOLS WAS 0PCK220I DATA CHANGE FOR COLUMN PREFETCH WAS SPCK221I DATA CHANGE FOR COLUMN MATCHCOLS IS NOW 2PCK221I DATA CHANGE FOR COLUMN PREFETCH IS NOWPCK223I DSN_STATEMNT_TABLE ESTIMATED COST CHANGE - NEW EST SVC UNITS 1PCK226I DSN_STATEMNT_TABLE ESTIMATED COST CHANGE - NEW EST CPU 1

IN QRYNO M CREATOR TNAME TBNO AC MC CREATOR ACCESSNAME IO SORTUJOG LK PF FN QBNO PLNO MXSQ MJN PG JN OPINS 334 0 PUBLIC SYSTABLES 1 I 1 PUBLIC DSNDTX01 N NNNNNNNN IS L 1 1 0S 33 0 U C S S S U C S 0 S 0PCK223I DSN_STATEMNT_TABLE ESTIMATED COST CHANGE - NEW EST SVC UNITS 5PCK226I DSN_STATEMNT_TABLE ESTIMATED COST CHANGE - NEW EST CPU 3

• No HINT • One SQL statement didn’t exist in the old access path data

• INS means a SQL statement was inserted

58

REBINDIN PBINDOUTIN PBINDOUT

REBIND PACKAGE (TESTCOLL8.TEST01.(2005-04-REBIND PACKAGE (TESTCOLL8.TEST01.(2005 0411-18.34.53.754785))-

OWNER (PUBLIC)-EXPLAIN(YES)

59

THIS TIME USE THE CORRCT COLLECTION IDCOLLECTION ID

OPTIONS CATALOGSQL NOMATCHCREATOROPTIONS CATALOGSQL NOMATCHCREATOR OPTIONS CONVERTHINT MIKEHINT OPTIONS CPUPCT 20 CONNECT TO DB8GSET CURRENT SQLID = 'PUBLIC‘TEST DBRM TEST01 AS PACKAGE TESTCOLLX.*

IN P390H.PLAN_TABLE

60

RESULTS

IN QRYNO M CREATOR TNAME TBNO AC MC CREATOR ACCESSNAME IO SORTUJOG LK PF FN QBNOIN QRYNO M CREATOR TNAME TBNO AC MC CREATOR ACCESSNAME IO SORTUJOG LK PF FN QBNO

PLNO MXSQ MJN PG JN OP* 327 0 P390H SYSCOLUMNS 1 I 2 P390H DSNDCX01 N NNNNNNNN IS L 1

1 0PCK220I DATA CHANGE FOR COLUMN PREFETCH WASPCK221I DATA CHANGE FOR COLUMN PREFETCH IS NOW LPCK224I DSN_STATEMNT_TABLE ESTIMATED COST CHANGE - OLD EST SVC UNITS 1PCK227I DSN_STATEMNT_TABLE ESTIMATED COST CHANGE - OLD EST CPU 1PCK223I DSN_STATEMNT_TABLE ESTIMATED COST CHANGE - NEW EST SVC UNITS 146PCK226I DSN_STATEMNT_TABLE ESTIMATED COST CHANGE - NEW EST CPU 76PCK052I HINT CREATED FOR PACKAGE TESTCOLLX PROGRAM= TEST01 MIKEHINTPCK244I REBIND WRITTEN FOR DBRM WITH NEW/CHANGED SQLPCK244I REBIND WRITTEN FOR DBRM WITH NEW/CHANGED SQL

61

REBIND IN PBINDOUT

REBIND PACKAGE (TESTCOLLX.TEST01.(2005-04-REBIND PACKAGE (TESTCOLLX.TEST01.(2005 0411-18.34.53.754785))-

OWNER (P390H)-EXPLAIN(YES) -OPTHINT ('MIKEHINT')

REBIND is in PBINDOUT because it required a HINT to get access path

62

MORE NOTES

• PCK219I STATEMENTS OVER CPUPCT 2• PATHCHECK compares the cost changes even if

the access path stays the sameT h th t h• To show those cost changes

• OPTIONS REPORTCOSTGT• Will show access paths that did not change but the• Will show access paths that did not change but the

estimated cost in DSN_STATEMNT_TABLE changed

• If the cost changes more than the value allowed by CPUPCT, REBIND goes to PBINDOUT even if the access path stays the same

63

access path stays the same

RBINDOUT

• Basic is write REBIND only if all SQL access pathsBasic is write REBIND only if all SQL access paths stay the same

• IF OPTIONS CPUPCT is specified, then all SQL access paths are the same or the PROCMS estimated cost is within the specified boundry

64

PBINDOUT

• If OPTIONS CONVERTHINT specified, thenIf OPTIONS CONVERTHINT specified, then REBIND generated with OPTHINT

• If OPTIONS CPUPCT specified, any PACKAGES that had at least one SQL statement with estimated PROCMS cost increase greater than cpu percentage specifiedpercentage specified.

• Or both

65

REVIEW

• Use basic RBINDOUT to get REBIND for packagesUse basic RBINDOUT to get REBIND for packages with NO access path changes

• Use basic RBINDOUT with OPTIONS CONVERTHINT to get REBIND for packages with NO access path changes and HINT’s created for SQL with access path changesSQL with access path changes

66

REVIEW

• OPTIONS CPUPCT nn changes the rulesOPTIONS CPUPCT nn changes the rules• If the estimated cost is within the percentage

specified, then treat those access path changes as acceptable.

• One SQL statement with excess estimated cost will l th REBIND i PBINDOUTplace the REBIND in PBINDOUT

• Combine with OPTIONS CONVERTHINT means SQL with excessive estimated cost will get hint rowsSQL with excessive estimated cost will get hint rows generated but still place the REBIND in PBINDOUT

67

ANOTHER OPTION

• OPTIONS CPUPCT2 for when you only want to y yREBIND packages that will have access path changes

• Ignore packages that do not have access path• Ignore packages that do not have access path changes

• If the estimated cost for every SQL statement is less ythan the percentage specified, put the REBIND in RBINDOUT

• If the estimated cost for one SQL statement is• If the estimated cost for one SQL statement is greater than the percentage specified, put the REBIND in PBINDOUT

68

JCL IS THE SAME

//STEP1 EXEC PGM=PATHCHK //STEPLIB DD DSN=P390H.PDS.LOADX,DISP=SHR // DD DSN=DSN810.SDSNLOAD,DISP=SHR //SYSPRINT DD SYSOUT *//SYSPRINT DD SYSOUT=* //SYSEXPLN DD SYSOUT=* //SYSCHG DD SYSOUT=*//SYSCHG DD SYSOUT //RBINDOUT DD SYSOUT=* //PBINDOUT DD SYSOUT=* //DBRMIN DD DSN=P390H.DB2V8.DBRMLIB2,DISP=SHR //SYSIN DD *

69

OPTIONS CPUPCT2

OPTIONS CATALOGSQL NOMATCHCREATOR OPTIONS CPUPCT2 10 CONNECT TO DB8G SET CURRENT SQLID = 'PUBLIC' TEST DBRM TEST01 AS PACKAGE TESTCOLL8.*

IN P390H PLAN TABLEIN P390H.PLAN_TABLE TEST DBRM TEST02 AS PACKAGE TESTCOLL8.*

IN P390H.PLAN_TABLE TEST DBRM TEST03 AS PACKAGE TESTCOLL8.*

IN P390H.PLAN_TABLE

70

OUTPUT

TEST DBRM TEST04 AS PACKAGE TESTCOLL8.* IN P390H.PLAN_TABLE

ACCESS PATH FOR COLLID - TESTCOLL8 .TEST04 SQL ID- OLD PLAN TABLE - PLAN TABLE RUN DATE 2009/05/08ACCESS PATH FOR COLLID TESTCOLL8 .TEST04 SQL ID OLD PLAN_TABLE PLAN_TABLE RUN DATE 2009/05/08

IN QRYNO M CREATOR TNAME TBNO AC MC CREATOR ACCESSNAME IO SORTUJOG LK PF FN QBNO PLNO MXSQ MJN PG JN OP* 327 0 PUBLIC SYSCOLUMNS 1 I 2 PUBLIC DSNDCX01 N NNNNNNNN IS 1 1 0* 327 1 PUBLIC SYSTABLES 2 I 2 PUBLIC DSNDTX01 N NNNNNNNN IS 1 2 0PCK220I DATA CHANGE FOR COLUMN INDEXONLY WAS YPCK221I DATA CHANGE FOR COLUMN INDEXONLY IS NOW NPCK224I DSN_STATEMNT_TABLE ESTIMATED COST CHANGE - OLD EST SVC UNITS 1PCK227I DSN STATEMNT TABLE ESTIMATED COST CHANGE - OLD EST CPU 1C S _S _ S COS C G O S C UPCK223I DSN_STATEMNT_TABLE ESTIMATED COST CHANGE - NEW EST SVC UNITS 2PCK226I DSN_STATEMNT_TABLE ESTIMATED COST CHANGE - NEW EST CPU 1

PCK206I TEST COMPLETE FOR PROGRAM = TEST04 VERSION = 2006-04-07-20.37.34.203896PREVIOUS VERSION = 2007-11-09-13.47.43.720348

71

RBINDOUT

REBIND PACKAGE (TESTCOLL8.TEST04.(2006-04-REBIND PACKAGE (TESTCOLL8.TEST04.(2006 0407-20.37.34.203896))-

OWNER (PUBLIC)-EXPLAIN(YES)

• All the other TEST commands generated cost increases

• This is the only access path change with the same PROCMS estimated cost (both = 1)

72

PBINDOUT

• Has all the rest of the REBIND’sHas all the rest of the REBIND s • PBINDOUT is NOT required for CPUPCT2

• This is a safe method to keep your access paths current without automatic rebind

• Estimated cost is still susceptible to old or invalid statistics

73

A SHORT DISCUSSION OF TEST CASESCASES

• How does the presentation show consistent accessHow does the presentation show consistent access path changes

• Different DBRM libraries with SQL changes to create access path differences

• NOT what you would normally expect for REBIND

74

WHAT IF DBRM’S ARE MISSING

• Usually safe assumption the SQL in SYSSTMT orUsually safe assumption the SQL in SYSSTMT or SYSPACKSTMT is valid.

• PATHCHECK optional clause for EXPLAIN and TEST commands ‘FROM CATALOG’

• There is also a product that identifies these bl iproblems in mass.

• 3 way comparison with DBRM’s, load modules and SYSPACKAGESYSPACKAGE

75

ENOUGH ABOUT REBIND – WHAT ABOUT BIND’SABOUT BIND’S

• BIND is not usually optionalBIND is not usually optional• The program is being installed because of a

business request or legal requirement• How can BIND be made safer?

76

SAME PATHCHECK FEATURES AS BEFOREBEFORE

• EXPLAIN to review the access path before the BINDEXPLAIN to review the access path before the BIND is processed

• TEST command with OPTIONS CONVERHINT will create a HINT with the old access path even if QUERYNO has changedAft th BIND COMPARE t PREVIOUS ill• After the BIND, COMPARE to PREVIOUS will identify changes in access path even if QUERYNO is differentis different

77

Our Hint Management SolutionsOur Hint Management Solutions

• Path Check– Convert Hint will insure hints are notPath Check Convert Hint will insure hints are not lost in the bind process

• Express Hints – An ISPF interface that finds and sets the correct values and then does a test to see if the hint will take

78

Session: # V07REBIND and BIND AnalysisREBIND and BIND Analysis

Mike BellHLS TECHNOLOGIES

[email protected]@ g

www.hlstechnologies.comg

79