The CPU Costing Model: A Few Thoughts Part IV (Map of the Problematique)

It’s called the CPU Costing model because among other things, it includes the time associated with performing CPU operations.
 
The CPU Costing model formula once again:
 
(sum of all the single block I/Os x average wait time for a single block I/O +
 sum of all the multiblock I/Os x average wait time for a multiblock I/O +
 sum of all the required CPU cycles / CPU cycles per second)
/
average wait time for a single block I/O
 

So the portion detailing the sum of all required CPU cycles divided by the CPU cycles per second can potentially contribute a significant proportion of the overall costs.
 
When I previously discussed the costs associated with the CPU model between using an index and a FTS, the FTS example I used had an overall cost of 70 but I calculated that the I/O component costs were only 67. Therefore the costs directly related to CPU operations with the FTS example was 3.
 
However, these CPU specific costs in this example may vary from database to database, although the FTS might be identical as might the required CPU cycles. However, a variable in all this is the CPU cycles per second system statistic (CPUSPEED) associated with a particular database environment.
 
Obviously, the faster the CPUs, the quicker it can perform the necessary CPU operations associated with the FTS (or any operation for that matter). Conversely, the slower the CPUs, the longer it will take to complete the necessary CPU related operations. The CPU costing model formula automatically takes all this into consideration.
 
In the previous example, the CPUSPEED system statistic was 1745.
 
Let’s now run the identical FTS but this time with a faster and a slower CPU and see how this might adjust the overall related costs when using the CPU costing model.
 
One can simulate a “faster” CPU by simply adjusting the CPUSPEED system statistic. Let’s make the CPUs appear 10 times faster:
 

SQL> exec dbms_stats.set_system_stats(pname=>’cpuspeed’, pvalue=>17450);
 
PL/SQL procedure successfully completed.
 

OK, let’s now see how this impacts the cost of the FTS:
 
SQL> SELECT * FROM bowie_stuff WHERE id = 420;
 
1000 rows selected.
 

Execution Plan
———————————————————-
Plan hash value: 910563088
 
——————————————————————-
|Id|Operation         |Name       |Rows|Bytes|Cost (%CPU)|Time    |
——————————————————————-
| 0|SELECT STATEMENT  |           |1000|18000|   67   (0)|00:00:01|
|*1| TABLE ACCESS FULL|BOWIE_STUFF|1000|18000|   67   (0)|00:00:01|
——————————————————————-
 

We notice that the overall cost has reduced from 70 down to 67. The cost of 3 that was previously attributed to just the CPU related costs have all disappeared and the costs are now just the 67 in relation to the I/O component.
 
The CPU is now so fast that it can effectively perform all the necessary operations in a negligible amount of time. An even faster CPU will not further improve the costs associated with this FTS as the costs now only include the I/O related components.

The (%CPU) value of (0) gives us this information if you didn’t follow how I derived the I/O cost of 67 in my previous post.

If we go the other way and now make the CPU about 1/10 the speed of the original example:
 
 
SQL> exec dbms_stats.set_system_stats(pname=>’cpuspeed’, pvalue=>175);
 
PL/SQL procedure successfully completed.
 
SQL> SELECT * FROM bowie_stuff WHERE id = 420;
 
1000 rows selected.
 

Execution Plan
———————————————————-
Plan hash value: 910563088
 
——————————————————————-
|Id|Operation         |Name       |Rows|Bytes|Cost (%CPU)|Time    |
——————————————————————-
| 0|SELECT STATEMENT  |           |1000|18000|   93  (28)|00:00:01|
|*1| TABLE ACCESS FULL|BOWIE_STUFF|1000|18000|   93  (28)|00:00:01|
——————————————————————-
 

We now notice the overall costs have jumped up considerably up from 70 up 93.
 
The costs associated directly with CPU activities have now increased up from 3 to 26. The CPU component is in the ballpark of 10 times as expensive/significant when you take into account rounding errors (the original 3 value was rounded accordingly). Remember also that these figures are times expressed in units of time it takes to perform a single block I/O.
 
The CPUs are now so slow that it takes a considerable amount of time to complete all the required CPU operations.
 
Note that the (%CPU) value is now a significant (28%) of the overall costs as derived from the following formula:

round(cpu related cost/total cost) x 100 = round(26/93 x 100) = 28.
 
So having a faster (or possibly slower) CPU when performing a hardware upgrade/change can result in potentially different execution plan costings (and as such different execution plans) when using the CPU CBO costing model.
 
It’s called the CPU costing model for a reason and as one would indeed hope, the speed of said CPU(s) can directly impact the associated costs and decisions made by the CBO.

 

参考至:http://richardfoote.wordpress.com/2010/01/07/the-cpu-costing-model-a-few-thoughts-part-iv-map-of-the-problematique/

如有错误,欢迎指正

邮箱:czmcj@163.com

作者:czmmiao  文章出处:http://czmmiao.iteye.com/blog/2086252

时间: 2024-09-17 03:46:15

The CPU Costing Model: A Few Thoughts Part IV (Map of the Problematique)的相关文章

查询linux,HP-UX的cpu信息

在平时的工作中,需要了解服务器的硬件配置信息,对于cpu的信息查询,在Linux,unix中可能会有一些不同. 对于hp-ux来说,有现成的命令machinfo可以直接得到cpu的一些明细信息. 对于Linux来说,可能就需要自己去做一些解析了.解析的文件位于/proc/cpuinfo中. 可以使用如下的脚本来进行cpu信息的读取. os_type=`uname` if [[ $os_type = "HP-UX" ]]; then machinfo else echo "**

The Query Optimizer

The Query Optimizer This chapter discusses SQL processing, optimization methods, and how the query optimizer (usually called the optimizer) chooses a specific plan to execute SQL. The chapter contains the following sections: Overview of the Query Opt

PostgreSQL 10.0 preview 多核并行增强 - 并行hash join支持shared hashdata, 节约哈希表内存提高效率

标签 PostgreSQL , 10.0 , 多核并行增强 , shared hash表 , hash join 背景 PostgreSQL 9.6支持哈希JOIN并行,但是每个worker进程都需要复制一份哈希表,所以会造成内存的浪费,小表无妨,但是大表的浪费是非常大的. 因此10.0做了一个改进,使用共享的哈希表. Hi hackers, In PostgreSQL 9.6, hash joins can be parallelised under certain conditions, b

转载大师的读书笔记 1

http://www.heysky.net/archives/2006/08/9iperformancetuningguide.html Introduction to the Optimizer Overview of SQL Processing  1. parser 进行语意和语法分析  2. Optimizer 利用RBO,CBO等方法决定产生查询结果的最有效路径  3. Row Source Generator 从2中接受优化后的方案,并产生SQL的Execution Plan  4.

Oracle中常数复合索引的应用案例

从一个客户的真实优化案例引申的问题. 客户的一个数据库需要进行优化,不过由于程序开发方没有介入,因此这次优化无法对SQL进行修改. 仅对数据库级的调整一般来说收效不大,不过发现客户数据库中个别的SQL存在性能问题,且这个性能问题已经影响到整个数据库.如果可以将这个SQL优化,那么可以解决目前数据库的性能问题.幸运的是,这个问题可以通过添加索引来进行优化. 模拟问题SQL如下: SQL> select * from v$version; BANNER -----------------------

Oracle优化器的两种优化方式

Oracle的优化器有两种优化方式: 基于规则的优化方式:Rule-Based Optimization(RBO) 基于成本或者统计信息的优化方式(Cost-Based Optimization:CBO) RBO方式:优化器在分析SQL语句时,所遵循的是Oracle内部预定的一些规则.比如我们常见的,当一个where子句中的一列有索引时去走索引. CBO方式:CBO是在ORACLE7 引入,但到ORACLE8i 中才成熟.ORACLE 已经声明在ORACLE9i之后的版本中,RBO将不再支持.它

oracle中复合索引的创建剖析—包含in的三个条件SQL语句复合索引的创建

之前文章中提过复合索引的创建思路: 1 前导列尽可能让更多的核心业务SQL能够使用 2 单个SQL语句索引的前导列尽量选择等值条件做为索引的前导列 这里我们如果在对in的谓词.三个条件的SQL语句复合索引的创建做一些更深入的分析,详细的例子如下: SQL> select * from v$version; BANNER -------------------------------------------------------------------------------- Oracle D

CBO学习笔记(转)

Query Transformation 在继续研究SQL的其他操作(比如Join)对CBO的影响之前,我们来讨论一下Oracle优化器的Query Transformation特性.我们都习惯于根据我们的SQL结构来判断SQL的效率,但是我们必须要知道,对于我们写好的SQL,Oracle的优化器会进行改写,或者说是进行转化.转化的目的是是要把我们的SQL转化成oracle认为更简单,更有效率的结构,需要注意的是,有些时候(主要取决的版本),CBO的的某些转化似乎不是基于cost的,而是基于ru

volatile限定符{C}

PS: ...Newbie love coding-  Linux_c一站式编程(volatile限定符介绍) linux_c的volatile限定符 现在探讨一下编译器优化会对生成的指令产生什么影响,在此基础上介绍C语言的volatile限定符.看下面的例子: 我们用recv和send这两个全局变量来模拟设备寄存器.假设某种平台采用内存映射I/O,串口发送寄存器和串口接收寄存器位于固定的内存地址,而recv和send这两个全局变量也有固定的内存地址,所以在这个例子中把它们假想成串口接收寄存器和