oracle 解释计划中的成本、基数和字节数是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48732396/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the meaning of Cost, Cardinality and Bytes in Explain Plan?
提问by M.Minbashi
This is a simple query: select * from customers
这是一个简单的查询: select * from customers
When I write this query in PL/SQL Developer and press F5, I see Explain Plan, but I don't know what are Cost, Cardinality and Bytes represent.
当我在 PL/SQL Developer 中编写此查询并按 F5 时,我看到了解释计划,但我不知道成本、基数和字节代表什么。
回答by Bob Jarvis - Reinstate Monica
What is Cost?
什么是成本?
The Oracle Optimizer is a cost-based optimizer. The execution plan selected for a SQL statement is just one of the many alternative execution plans considered by the Optimizer. The Optimizer selects the execution plan with the lowest cost, where cost represents the estimated resource usage for that plan. The lower the cost the more efficient the plan is expected to be. The optimizer's cost model accounts for the IO, CPU, and network resources that will be used by the query. Figure 8: Cost is found in the fifth column of the execution plan The cost of the entire plan (indicated on line 0) and each individual operation is displayed in the execution plan. However, it is not something that can be tuned or changed. The cost is an internal unit and is only displayed to allow for plan comparisons.
Oracle Optimizer 是一个基于成本的优化器。为 SQL 语句选择的执行计划只是优化器考虑的众多替代执行计划之一。优化器选择成本最低的执行计划,其中成本代表该计划的估计资源使用量。成本越低,计划的效率就越高。优化器的成本模型考虑了查询将使用的 IO、CPU 和网络资源。图 8:成本位于执行计划的第五列 整个计划(在第 0 行指示)和每个单独操作的成本显示在执行计划中。但是,它不是可以调整或更改的。成本是一个内部单位,显示仅用于计划比较。
You can also look in the Database Performance Tuning Guide, where it says:
您还可以查看Database Performance Tuning Guide,它说:
The value of this column does not have any particular unit of measurement; it is merely a weighted value used to compare costs of execution plans. The value of this column is a function of the CPU_COST and IO_COST columns.
此列的值没有任何特定的计量单位;它只是用于比较执行计划成本的加权值。此列的值是 CPU_COST 和 IO_COST 列的函数。
So - COST is a dimensionless value which is a function of CPU and IO cost.
所以 - COST 是一个无量纲值,它是 CPU 和 IO 成本的函数。
回答by thatjeffsmith
See section 12.10 for a description of the plan table columns.
有关计划表列的说明,请参阅第 12.10 节。
https://docs.oracle.com/cd/E11882_01/server.112/e41573/ex_plan.htm#PFGRF009
https://docs.oracle.com/cd/E11882_01/server.112/e41573/ex_plan.htm#PFGRF009
Cost is the amount of work the optimizer estimates to run your query via a specific plan. The optimizer generally prefers lower cost plans.
成本是优化器估计通过特定计划运行查询的工作量。优化器通常更喜欢低成本的计划。
Cost is determined by several different factors but the table statistics are one of the largest.
成本由几个不同的因素决定,但表格统计数据是最大的因素之一。
Cardinality is the number of rows the optimizer guesses will be processed for a plan step. If the stats are old, missing, or incomplete - then this can be wildly wrong. You want to look for where the optimizer sees 5 rows (cardinality) but in reality there are 50,000 rows.
基数是优化器猜测的计划步骤将处理的行数。如果统计数据陈旧、缺失或不完整——那么这可能是非常错误的。您想查找优化器看到 5 行(基数)的位置,但实际上有 50,000 行。
Bytes are same concept as cardinality but in sheer terms of data to be processed vs rows in a table.
字节与基数的概念相同,但纯粹是指要处理的数据与表中的行。
This is an extremely deep topic that requires active learning and experience. I'm sure many can contribute ideas for places to go. I personally enjoy Maria's blog.She's the former product manager for the optimizer.
这是一个非常深刻的话题,需要积极的学习和经验。我相信很多人都可以为要去的地方提供想法。我个人喜欢玛丽亚的博客。她是优化器的前产品经理。