简体   繁体   English

对PL / SQL Developer中的SQL成本感到困惑

[英]Confused about the cost of SQL in PL/SQL Developer

Select pn.pn_level_id From phone_number pn Where pn.phone_number='15183773646'


Select pn.pn_level_id From phone_number pn Where pn.phone_number=' 15183773646'

Do you think they are the same ? 您是否认为它们相同? No. Basically they are not the same in the PL/SQL Devloper. 否。基本上,它们在PL / SQL Devloper中是不同的。

在此处输入图片说明在此处输入图片说明

I'm wondering why the latter one's cost is less than the previous sql. 我想知道为什么后一个的成本比前一个sql小。 Any help would be appreciated! 任何帮助,将不胜感激!

The cost is not the same because when cost is calculated planner takes into account available statistics. 成本不一样,因为计划者在计算成本时会考虑可用的统计信息。 Statistics among other things contains values which appear most frequently in column with their frequencies. 统计信息除其他外还包含在频率中频率最高的值。 It allows planner to better estimate number of rows which will be fetched and to decide how to better get data (eg via sequential scan or by index). 它使计划人员可以更好地估计将要提取的行数,并决定如何更好地获取数据(例如,通过顺序扫描或按索引)。

In your case value 15183773646 is probably among mostly frequently appearing and that's why planner estimation is different for the query involving it (as planner has better estimation of number of such rows) as compared to other values for which it basically guesses. 在您的情况下,值15183773646可能是最经常出现的值,这就是为什么计划程序估计与其所猜测的其他值相比,与之相关的查询的计划程序估计不同(因为计划程序对此类行数的估计更好)。

优化程序会评估所有方法来提取数据,因为您的数据库没有pn.phone_number=' 15183773646'并且该值未存储在索引中,因此Oracle跳过了一个I / O操作,这就是第二个成本较低的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM