Optimization profiles and guidelines

DB2 Optimization profiles and guidelines

knowledge center URL
https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.admin.perf.doc/doc/c0024522.html

selectivity clause

You can influence the optimizer by providing the expected selectivity using a selectivity clause. It can be useful in situations where you want to encourage (or discourage) DB2 to use certain indexes.

SELECT c1, c2, c3, FROM T1, T2, T3
        WHERE T1.x = T2.x AND
        T2.y=T3.y AND
        T1.x >= ? selectivity 0.00001 AND
        T2.y gt; ? selectivity 0.5 AND
        T3.z = ? selectivity 0.2 AND
        T3.w = ?

guideline clause

SELECT c1, c2, c3, FROM T1, T2, T3
        WHERE T1.x = T2.x AND
        T2.y=T3.y AND
        T1.x >= ? selectivity 0.00001 AND
        T2.y gt; ? selectivity 0.5 AND
        T3.z = ? selectivity 0.2 AND
        T3.w = ?
                /*
<OPTGUIDELINES>
     <HSJOIN>
        <HSJOIN>
           <TBSCAN   TABLE='T1' />
           <TBSCAN   TABLE='T2' />
        </HSJOIN>
        <IXSCAN  TABLE='T3' />
     </HSJOIN>   
   </OPTGUIDELINES>*/ ;

other example:
<OPTGUIDELINES><DEGREE VALUE=‘ANY’/></OPTGUIDELINES>

负面案例:

过低的selectivity 值导致优化器低估排序内存的分配,从而导致了排序溢出。
In this scenario, I found that:

  • The optimizer chooses the same access plan for the two SQL. However, the estimated returned rows for the SQL that invokes the “selectivity” clause is very low, which is about 115120, but the truly returned row count is 4812590.
  • The SQL invokes the “selectivity” clause runs for more than 5 min under 20 occurrence, however, the other one runs for 3 min under the same scenario.
  • For the SQL that invokes the “selectivity” clause, the POOL_TEMP_DATA_L_READS is 413310 and the SORT_OVERFLOWS is 1. But for the other SQL it is zero.
  • For the SQL that invokes the “selectivity” clause, the ESTIMATED_SORT_SHRHEAP_TOP is 6337, but for the other SQL it is 318072.

Base on all of above, I found that the optimizer underestimates the sort heap needed for the SQL that invokes the “selectivity” clause, so that the sort overflow occurs and performance is impacted.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值