哪一个计划更好?

邮件列表中有人询问如何判定两个SQL执行计划哪个更好,COST能否作为判断依据。有人赞同根据响应时间判断,有人认为应关注估计基数。多位专家对此各有观点,最后得出实践是检验标准,CBO不够完美,期待其完善。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

邮件列表中有人问:如果有两个执行计划,如何判定哪一个更好?COST 能作为判断的依据么?

有人赞同 Thomas Kyte 的观点,根据响应时间来判断.
有人引用了Hotsos Symposium 2004 的 How To Forecast Tuning Results:

As cost is always a result of cardinality we should focus only on the
estimated cardinality. A developer, when writing the text of a SQL
statement, knows the purpose of the statement and also knows what he
wants to get as the result. Also the cardinality of the result set is
known – or at least he/she has an idea about that. Thus comparing the
estimated cardinality with the expected cardinality would be good
practice for timely elimination of performance problems. When those
two cardinalities differ by orders of magnitude performance problems
are almost inevitable. If the CBO were to correctly estimate the
cardinality of final or intermediate result sets, the cost would be very different and some other plan with a lower cost would be selected.
Most likely this plan would be the optimal one.”

Connor McDonald认为:这是个充满哲学意味的争论.如果优化器是完美的,那么最低开销的就应该是最快的查询.但优化器总是不那么完美,只是试图告诉我你哪一个执行计划可能是最优化的而已.Cary Millsap
指出:CBO 在一个查询执行之前,只能用一个模型来评估开销(can only estimate a cost using a model.),而该模型不够完美是问题所在.所以在执行该计划之后CBO才可以知道真正的estimated cost .10g 的优化器做了改进,可能有能力评估响应时间.Jonathan Lewis自信的认为:

the cost of a query IS and always
has been the optimizer’s estimate of the actual
run time of a query

不过争论来争论去,还有应了那句老话,"实践是检验真理的唯一标准",实际的执行一下,哪一个快就哪一个好吧! CBO 远远不够完美,期待完美的那一天…

延伸阅读:

Google+
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值