bioffeexplain

advertisement
Example how to make EXPLAIN readable for non DBA:
Select from system catalog is clumsy but workable.
I made the results as narrow as possible to fit mainframe screen.
DELETE FROM PLAN_TABLE ;
EXPLAIN ALL SET QUERYNO = 1 FOR
SQI1
;
…………
…………
EXPLAIN ALL SET QUERYNO = 3 FOR
SQI2
;
SELECT CASE WHEN COLSEQ = 1 OR COLSEQ IS NULL THEN
SUBSTR(CHAR(QUERYNO),1,2) ||'|'||
SUBSTR(CHAR(QBLOCKNO),1,2) ||'|'||
SUBSTR(CHAR(PLANNO),1,2) ||'|'||
SUBSTR(CHAR(METHOD),1,2) ||'|'||
SUBSTR(TNAME,1,15)
||'|'||
ACCESSTYPE
||'|'||
SUBSTR(CHAR(MATCHCOLS),1,2)||'|'||
SUBSTR(ACCESSNAME,1,08) ||'|'||
PREFETCH
||'|'||
INDEXONLY
||'|'||
SUBSTR(CHAR(MIXOPSEQ),1,1) ||'|'||
CASE WHEN CARDF IS NULL OR QUERYNO IS NULL THEN '
'
ELSE SUBSTR(CHAR(DEC(CARDF)),8,09) END
ELSE ' ' ||'|'||' '||'|'|| ' '||'|'||' '||'|'||
'
'||'|'||' '||'|'||' '||'|'||
'
'||'|'||' '||'|'||' '||'|'||' '||'|'||
'
' END||'|'||
CASE WHEN FULLKEYCARD IS NULL OR COLSEQ <> 1 THEN
'
' ELSE SUBSTR(DIGITS(FULLKEYCARD),2,9) END ||'|'||
CASE WHEN COLSEQ IS NULL THEN '
' ELSE COLNAME END
,'
',' ',COLSEQ,QUERYNO,QBLOCKNO,PLANNO,ACCESSNAME
FROM ( PLAN_TABLE A LEFT OUTER JOIN SYSIBM.SYSKEYS B
ON IXNAME=ACCESSNAME AND IXCREATOR= Put creator there in Quotas)
LEFT OUTER JOIN SYSIBM.SYSTABLES C ON C.NAME=TNAME
AND A.CREATOR=C.CREATOR
LEFT OUTER JOIN SYSIBM.SYSINDEXES I ON I.NAME=ACCESSNAME
AND A.CREATOR=I.CREATOR UNION ALL
SELECT 'QN'
||'|'|| 'BL'
||'|'||
'PL'||'|'||'MT'||'|'|| 'TBL NAME
' ||'|'||
'TY'||'|'||'MC'||'|'||'ACCESSNM'||'|'||'P' ||'|'||
'I'||'|'||'M' ||'|'||'STATROWS '||'|'||'IDISTROWS' ||'|'||
'INDCOLNM' , ' ' , ' ', 0 COLSEQ ,-1 QUERYNO , 0 QBLOCKNO
, 0 PLANNO ,' ' ACCESSNAME FROM PLAN_TABLE UNION
SELECT '--' ||'|'||'--' ||'|'||'--' ||'|'||'--' ||'|'||
'---------------'||'|'||'--' ||'|'||'--' ||'|'||
'--------'||'|'||'-'||'|'||'-'||'|'||
'-|'||'---------'||'|'|| '---------|', ' ', ' ',0 COLSEQ
,0 QUERYNO, 0 QBLOCKNO , 0 PLANNO ,' ' ACCESSNAME FROM PLAN_TABLE
ORDER BY QUERYNO,QBLOCKNO,PLANNO, ACCESSNAME, COLSEQ
WITH UR ;
Where:
SQL1 and SQL2 are SQL statements to explain.
Red field MUST to be coded – most important to put correct creator id - otherwise (if omitted) – SQL will run forever.
Results:
QN|BL|PL|MT|TBL NAME
|TY|MC|ACCESSNM|P|I|M|STATROWS |IDISTROWS|INDCOLNM
--|--|--|--|---------------|--|--|--------|-|-|-|---------|---------|
1 |1 |1 |3 |
| |0 |
| | |0|
|
|
1 |2 |1 |0 |CBA_CI_CTCOV
|I |1 |XMBD0331| |N|0|033999167|017881860|CTHLD_ID
| | | |
| | |
| | | |
|
|INT_CNTR_ID
| | | |
| | |
| | | |
|
|CI_ID
1 |2 |2 |1 |CBA_CI
|I |1 |XMBD030C| |N|0|011183167|011183167|CI_ID
1 |3 |1 |0 |CBA_CI_CTCOV
|I |1 |XMBD0331| |N|0|033999167|017881860|CTHLD_ID
| | | |
| | |
| | | |
|
|INT_CNTR_ID
| | | |
| | |
| | | |
|
|CI_ID
1 |3 |2 |1 |CBA_CTCOV
|I |1 |XMBD037C| |Y|0|000652547|000652547|INT_CNTR_ID
| | | |
| | |
| | | |
|
|INS_LIN_C
1 |4 |1 |0 |CBA_CI_CTCOV
|I |1 |XMBD0331| |N|0|033999167|017881860|CTHLD_ID
| | | |
| | |
| | | |
|
|INT_CNTR_ID
| | | |
| | |
| | | |
|
|CI_ID
1 |4 |2 |1 |CBA_CI
|I |1 |XMBD030C| |N|0|011183167|011183167|CI_ID
1 |4 |3 |3 |
| |0 |
| |N|0|
|
|
……………………………………………………………………………
…………………………………………………………………………………
3 |1 |1 |3 |
| |0 |
| | |0|
|
|
3 |2 |1 |0 |CBA_CI_CTCOV
|I |1 |XMBD0331| |N|0|033999167|017881860|CTHLD_ID
| | | |
| | |
| | | |
|
|INT_CNTR_ID
| | | |
| | |
| | | |
|
|CI_ID
3 |2 |2 |1 |CBA_CI
|I |1 |XMBD030C| |N|0|011183167|011183167|CI_ID
3 |3 |1 |0 |CBA_CI_CTCOV
|I |1 |XMBD0331| |N|0|033999167|017881860|CTHLD_ID
| | | |
| | |
| | | |
|
|INT_CNTR_ID
| | | |
| | |
| | | |
|
|CI_ID
3 |3 |2 |1 |CBA_CTCOV
|I |1 |XMBD037C| |Y|0|000652547|000652547|INT_CNTR_ID
| | | |
| | |
| | | |
|
|INS_LIN_C
3 |4 |1 |0 |CBA_CI_CTCOV
|I |1 |XMBD0331| |N|0|033999167|017881860|CTHLD_ID
| | | |
| | |
| | | |
|
|INT_CNTR_ID
| | | |
| | |
| | | |
|
|CI_ID
3 |4 |2 |1 |CBA_CI
|I |1 |XMBD030C| |N|0|011183167|011183167|CI_ID
3 |4 |3 |3 |
| |0 |
| |N|0|
|
|
Where
QN
QUERYNO
BL
Block number
PL
Plan number
MT
Method
TBL NAME
Table name
TY
Type of access
MC
Matching columns number
ACCESSNM
Access name (index name)
P
Prefetch (S/L or none)
I
Index only Y/N
M
MIXOPSEQ
STATROWS Number of rows in the table according to statistics
IDISTROWS Actual number of rows in the index ACCESSNM
INDCOLNM Index column in there sequence.
Download