ohk计算机解释输出与分布统计信息收集.docx
- 文档编号:27518342
- 上传时间:2023-07-02
- 格式:DOCX
- 页数:17
- 大小:16.68KB
ohk计算机解释输出与分布统计信息收集.docx
《ohk计算机解释输出与分布统计信息收集.docx》由会员分享,可在线阅读,更多相关《ohk计算机解释输出与分布统计信息收集.docx(17页珍藏版)》请在冰豆网上搜索。
ohk计算机解释输出与分布统计信息收集
解释输出与分布统计信息收集
1.首先我们运行如下的解释语句
D:
\ProgramFiles\IBM\SQLLIB\BIN>db2expln-dsample-q"select*fromemployeewhereempno='000010'"-t-g-i
或者是:
D:
\ProgramFiles\IBM\SQLLIB\BIN>dynexpln-dsample-q"select*fromemployeewhereempno='000010'"-t-g-i
DB2UniversalDatabaseVersion9.5,5622-044(c)CopyrightIBMCorp.1991,2007
LicensedMaterial-ProgramPropertyofIBM
IBMDB2UniversalDatabaseSQLandXQUERYExplainTool
DB2UniversalDatabaseVersion9.5,5622-044(c)CopyrightIBMCorp.1991,2007
LicensedMaterial-ProgramPropertyofIBM
IBMDB2UniversalDatabaseSQLandXQUERYExplainTool
********************DYNAMIC***************************************
====================STATEMENT==========================================
IsolationLevel=CursorStability
Blocking=BlockUnambiguousCursors
QueryOptimizationClass=5
PartitionParallel=No
Intra-PartitionParallel=No
SQLPath="SYSIBM","SYSFUN","SYSPROC","SYSIBMADM",
"ZHANGRAN"
Statement:
select*
fromemployee
whereempno='000010'
SectionCodePage=1208
EstimatedCost=7.579099
EstimatedCardinality=1.000000
(2)AccessTableName=ZHANGRAN.EMPLOYEEID=2,6
|IndexScan:
Name=ZHANGRAN.PK_EMPLOYEEID=1
||RegularIndex(NotClustered)
||IndexColumns:
|||1:
EMPNO(Ascending)
|#Columns=13
|SingleRecord
|FullyQualifiedUniqueKey
|AvoidLockingCommittedData
|#KeyColumns=1
||StartKey:
InclusiveValue
||||1:
'000010'
||StopKey:
InclusiveValue
||||1:
'000010'
|DataPrefetch:
Eligible0
|IndexPrefetch:
None
|LockIntents
||Table:
IntentShare
||Row:
NextKeyShare
|SargablePredicate(s)
(2)||ReturnDatatoApplication
|||#Columns=14
(1)ReturnDataCompletion
Endofsection
OptimizerPlan:
Rows
Operator
(ID)
Cost
1
RETURN
(1)
7.5791
|
1
FETCH
(2)
7.5791
/\
174
IXSCANTable:
(3)ZHANGRAN
0.0150155EMPLOYEE
|
74
Index:
ZHANGRAN
PK_EMPLOYEE
我们注意到红字部分很奇怪,本来employee表中只有42条记录,怎么基数估计为74呢?
这主要是因为统计信息不准,所以我们进行RUNSTATS收集EMPLOYEE的统计信息(包括分布统计信息)
2.收集统计信息
D:
\ProgramFiles\IBM\SQLLIB\BIN>db2runstatsontablezhangran.employeewithdistributionandsampleddetailedindexesall
3.最后,我们再次来输出执行计划
D:
\ProgramFiles\IBM\SQLLIB\BIN>db2expln-dsample-q"select*fromemployeewhereempno='000010'"-t-g-i
DB2UniversalDatabaseVersion9.5,5622-044(c)CopyrightIBMCorp.1991,2007
LicensedMaterial-ProgramPropertyofIBM
IBMDB2UniversalDatabaseSQLandXQUERYExplainTool
DB2UniversalDatabaseVersion9.5,5622-044(c)CopyrightIBMCorp.1991,2007
LicensedMaterial-ProgramPropertyofIBM
IBMDB2UniversalDatabaseSQLandXQUERYExplainTool
********************DYNAMIC***************************************
====================STATEMENT==========================================
IsolationLevel=CursorStability
Blocking=BlockUnambiguousCursors
QueryOptimizationClass=5
PartitionParallel=No
Intra-PartitionParallel=No
SQLPath="SYSIBM","SYSFUN","SYSPROC","SYSIBMADM",
"ZHANGRAN"
Statement:
select*
fromemployee
whereempno='000010'
SectionCodePage=1208
EstimatedCost=7.577406
EstimatedCardinality=1.000000
(2)AccessTableName=ZHANGRAN.EMPLOYEEID=2,6
|IndexScan:
Name=ZHANGRAN.PK_EMPLOYEEID=1
||RegularIndex(NotClustered)
||IndexColumns:
|||1:
EMPNO(Ascending)
|#Columns=13
|SingleRecord
|FullyQualifiedUniqueKey
|AvoidLockingCommittedData
|#KeyColumns=1
||StartKey:
InclusiveValue
||||1:
'000010'
||StopKey:
InclusiveValue
||||1:
'000010'
|DataPrefetch:
Eligible0
|IndexPrefetch:
None
|LockIntents
||Table:
IntentShare
||Row:
NextKeyShare
|SargablePredicate(s)
(2)||ReturnDatatoApplication
|||#Columns=14
(1)ReturnDataCompletion
Endofsection
OptimizerPlan:
Rows
Operator
(ID)
Cost
1
RETURN
(1)
7.57741
|
1
FETCH
(2)
7.57741
/\
142
IXSCANTable:
(3)ZHANGRAN
0.0133226EMPLOYEE
|
42
Index:
ZHANGRAN
PK_EMPLOYEE
4.这时统计信息准确,执行计划可靠
我们再看一个有代表性的例子
1.假如有下面两个表
T2T3
XYY
1AB
2BB
2CD
4DD
7EF
7FF
7GH
7HH
9IJ
9JJ
2.在没有收集统计信息时,解释输出如下
D:
\ProgramFiles\IBM\SQLLIB\BIN>db2expln-deast-q"select*fromt2,t3wheret2.x=7andt2.y=t3.y"-t-g-i
DB2UniversalDatabaseVersion9.5,5622-044(c)CopyrightIBMCorp.1991,2007
LicensedMaterial-ProgramPropertyofIBM
IBMDB2UniversalDatabaseSQLandXQUERYExplainTool
DB2UniversalDatabaseVersion9.5,5622-044(c)CopyrightIBMCorp.1991,2007
LicensedMaterial-ProgramPropertyofIBM
IBMDB2UniversalDatabaseSQLandXQUERYExplainTool
********************DYNAMIC***************************************
====================STATEMENT==========================================
IsolationLevel=CursorStability
Blocking=BlockUnambiguousCursors
QueryOptimizationClass=5
PartitionParallel=No
Intra-PartitionParallel=No
SQLPath="SYSIBM","SYSFUN","SYSPROC","SYSIBMADM",
"ZHANGRAN"
Statement:
select*
fromt2,t3
wheret2.x=7andt2.y=t3.y
SectionCodePage=1208
EstimatedCost=15.159988
EstimatedCardinality=0.160000
(4)AccessTableName=ZHANGRAN.T2ID=2,5
|#Columns=1
|AvoidLockingCommittedData
|EvaluateBlock/DataPredicatesBeforeLockingCommittedRow
|RelationScan
||Prefetch:
Eligible
|LockIntents
||Table:
IntentShare
||Row:
NextKeyShare
|SargablePredicate(s)
||#Predicates=1
(4)||ProcessBuildTableforHashJoin
(2)HashJoin
|EstimatedBuildSize:
4000
|EstimatedProbeSize:
4000
|BitFilterSize:
800
(3)|AccessTableName=ZHANGRAN.T3ID=2,6
||#Columns=1
||AvoidLockingCommittedData
||RelationScan
|||Prefetch:
Eligible
||LockIntents
|||Table:
IntentShare
|||Row:
NextKeyShare
||SargablePredicate(s)
(3)|||ProcessProbeTableforHashJoin
(1)ReturnDatatoApplication
|#Columns=3
Endofsection
OptimizerPlan:
Rows
Operator
(ID)
Cost
0.16
RETURN
(1)
15.16
|
0.16
HSJOIN
(2)
15.16
/\
100.4
TBSCANTBSCAN
(3)(4)
7.579167.58039
||
1010
Table:
Table:
ZHANGRANZHANGRAN
T3T2
我们看到运用谓词T2.X=7后的估计基数为0.4,一点都不准确。
3.下面我们收集统计信息,但是不收集分布统计信息
D:
\ProgramFiles\IBM\SQLLIB\BIN>db2runstatsontablezhangran.t2
DB20000IRUNSTATS命令成功完成。
4.再次查看解释输出
D:
\ProgramFiles\IBM\SQLLIB\BIN>db2expln-deast-q"select*fromt2,t3wheret2.x=7andt2.y=t3.y"-t-g-i
DB2UniversalDatabaseVersion9.5,5622-044(c)CopyrightIBMCorp.1991,2007
LicensedMaterial-ProgramPropertyofIBM
IBMDB2UniversalDatabaseSQLandXQUERYExplainTool
DB2UniversalDatabaseVersion9.5,5622-044(c)CopyrightIBMCorp.1991,2007
LicensedMaterial-ProgramPropertyofIBM
IBMDB2UniversalDatabaseSQLandXQUERYExplainTool
********************DYNAMIC***************************************
====================STATEMENT==========================================
IsolationLevel=CursorStability
Blocking=BlockUnambiguousCursors
QueryOptimizationClass=5
PartitionParallel=No
Intra-PartitionParallel=No
SQLPath="SYSIBM","SYSFUN","SYSPROC","SYSIBMADM",
"ZHANGRAN"
Statement:
select*
fromt2,t3
wheret2.x=7andt2.y=t3.y
SectionCodePage=1208
EstimatedCost=15.160070
EstimatedCardinality=0.800000
(4)AccessTableName=ZHANGRAN.T2ID=2,5
|#Columns=1
|AvoidLockingCommittedData
|EvaluateBlock/DataPredicatesBeforeLockingCommittedRow
|RelationScan
||Prefetch:
Eligible
|LockIntents
||Table:
IntentShare
||Row:
NextKeyShare
|SargablePredicate(s)
||#Predicates=1
(4)||ProcessBuildTableforHashJoin
(2)HashJoin
|EstimatedBuildSize:
4000
|EstimatedProbeSize:
4000
(3)|AccessTableName=ZHANGRAN.T3ID=2,6
||#Columns=1
||AvoidLockingCommittedData
||RelationScan
|||Prefetch:
Eligible
||LockIntents
|||Table:
IntentShare
|||Row:
NextKeyShare
||SargablePredicate(s)
(3)|||ProcessProbeTableforHashJoin
(1)ReturnDatatoApplication
|#Columns=3
Endofsection
OptimizerPlan:
Rows
Operator
(ID)
Cost
0.8
RETURN
(1)
15.1601
|
0.8
HSJOIN
(2)
15.1601
/\
102
TBSCANTBSCAN
(3)(4)
7.579167.58039
||
1010
Table:
Table:
ZHANGRANZHANGRAN
T3T2
我们可以看到,优化器认为数据分布均匀,利用1/DISTINCTCARDINALITY=1/5=0.2算出其选择性,从而得到估计基数为10*0.2=2。
实际基数为4
5.我们收集分布统计信息
D:
\ProgramFiles\IBM\SQLLIB\BIN>db2runstatsontablezhangran.t2withdistributionandsampleddetailedindexesall
6.再次查看解释输出数据
D:
\ProgramFiles\IBM\SQLLIB\BIN>db2expln-deast-q"select*fromt2,t3wheret2.x=7andt2.y=t3.y"-t-g-i
DB2UniversalDatabaseVersion9.5,5622-044(c)CopyrightIBMCorp.1991,2007
LicensedMaterial-ProgramPropertyofIBM
IBMDB2UniversalDatabaseSQLandXQUERYExplainTool
DB2UniversalDatabaseVersion9.5,5622-044(c)CopyrightIBMCorp.1991,2007
LicensedMaterial-ProgramPropertyofIBM
IBMDB2UniversalDatabaseSQLandXQUERYExplainTool
********************DYNAMIC***************************************
====================STATEMENT==========================================
IsolationLevel=CursorStability
Blocking=BlockUnambiguousCursors
QueryOptimizationClass=5
PartitionParallel=No
Intra-PartitionParallel=No
SQLPath="SYSIBM","SYSFUN","SYSPROC","SYSIBMADM",
"ZHANGRAN"
Statement:
select*
fromt2,t3
wheret2.x=7andt2.y=t3.y
SectionCodePage=1208
Estimate
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- ohk 计算机 解释 输出 分布 统计 信息 收集
