CPU成本高而IO成本低的原因是什么?
What is the reason of high CPU cost but low IO cost?
我是 运行 对 table 的查询,它只有 283 条记录。由于没有在谓词中传递索引列值,因此查询将进行完整 table 扫描。
成本仅为 12,但 CPU 成本非常高 - 4,75,189。
尽管 table 的记录数很少,但 CPU 成本高的原因是什么?
成本和 CPU 成本有什么区别?
PL SQL 开发者被用作 IDE.
查询-:
SELECT qmh_client, qmh_ip_timestamp, qmh_plant, qmh_key_tsklst_grp,
qmh_grp_cntr, qmh_valid_dt, qmh_tdc_desc, qmh_cert_std,
qmh_tsklst_usage, qmh_statu, qmh_lot_size_from, qmh_lot_size_to,
qmh_tl_usage_uom, qmh_ctyp, qmh_cp_no, qmh_cp_version, qmh_tdform,
qmh_ref_tdc, qmh_licn_no, qmh_guege_len, qmh_ip_activity,
qmh_cp_activity, qmh_ip_sts_code, qmh_cp_sts_code, qmh_ltext_act,
qmh_ltxt_sts_code, qph_ip_id, qmh_ip_mess, qmh_cp_id, qmh_cp_mess,
qmh_rfd, qmh_smtp_addr, qmh_crt_time, qmh_crt_date, qmh_crt_by,
qmh_ip_upd_time, qmh_ip_upd_date, qmh_ip_upd_by, qmh_cp_upd_time,
qmh_upd_date, qmh_cp_upd_by, qmh_clas_sts_code, qmh_clas_id,
qmh_clas_mess, qmh_clas_upd_time, qmh_clas_upd_date,
qmh_clas_upd_by, qmh_prd_ind, qmh_tdc_type, qmh_pi_status
FROM ipdmdm.t_qm_insp_hdr
WHERE qmh_pi_status = 'N'
FOR UPDATE
勾选this
COST: Cost of the operation as estimated by the optimizer’s query
approach. Cost is not determined for table access operations. 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: CPU cost of the operation as estimated by the query
optimizer’s approach. The value of this column is proportional to the
number of machine cycles required for the operation. For statements
that use the rule-based approach, this column is null.
您可以参考这篇文章了解What is the cost column in an explain plan?
Depending on your release and setting for the hidden parameter
_optimizer_cost_model (cpu or io), the cost is taken from the cpu_cost and io_cost columns in the plan table (, in turn, estimates from
sys.aux_stats$. The "cost" column is not any particular unit of
measurement, it is a weighted average of the costs derived from the
cost-based decision tree generated when the SQL statement is bring
processed. The cost column is essentially an estimate of the run-time
for a given operation.
根据the manual,CPU_COST 和IO_COST 是以不同的方式测量的。 IO_COST 是 "proportional to the number of data blocks read by the operation",CPU_COST 是 "proportional to the number of machine cycles required for the operation"。
成本之间的差异应该不会太令人惊讶,因为许多数据库操作需要比磁盘读取多 CPU 个数量级的周期。在我的 PC 上进行的简单测试产生了类似的结果:
create table test1(a char(1000));
insert into test1 select level from dual connect by level <= 283;
begin
dbms_stats.gather_table_stats(user, 'TEST1');
end;
/
explain plan set statement_id = 'cost test' for select * from test1 for update;
select cpu_cost, io_cost from plan_table where statement_id = 'cost test' and id = 0;
CPU_COST IO_COST
-------- -------
348672 13
尽管它被称为基于 成本 的优化器,但在评估执行计划时,成本通常不是一个有用的指标。 "Operation" 和 "Rows" 列更有用。
此外,如果您对解释计划感兴趣,请停止使用 IDE 的残缺视图并使用 Oracle 提供的文本版本。使用 explain plan for select ...
和 select * from table(dbms_xplan.display);
。 PL/SQL Developer 是一个很棒的工具,但它的解释计划 window 缺少关键信息(注释部分)并且有一些错误(它不包括会话设置)。
我是 运行 对 table 的查询,它只有 283 条记录。由于没有在谓词中传递索引列值,因此查询将进行完整 table 扫描。
成本仅为 12,但 CPU 成本非常高 - 4,75,189。
尽管 table 的记录数很少,但 CPU 成本高的原因是什么?
成本和 CPU 成本有什么区别?
PL SQL 开发者被用作 IDE.
查询-:
SELECT qmh_client, qmh_ip_timestamp, qmh_plant, qmh_key_tsklst_grp,
qmh_grp_cntr, qmh_valid_dt, qmh_tdc_desc, qmh_cert_std,
qmh_tsklst_usage, qmh_statu, qmh_lot_size_from, qmh_lot_size_to,
qmh_tl_usage_uom, qmh_ctyp, qmh_cp_no, qmh_cp_version, qmh_tdform,
qmh_ref_tdc, qmh_licn_no, qmh_guege_len, qmh_ip_activity,
qmh_cp_activity, qmh_ip_sts_code, qmh_cp_sts_code, qmh_ltext_act,
qmh_ltxt_sts_code, qph_ip_id, qmh_ip_mess, qmh_cp_id, qmh_cp_mess,
qmh_rfd, qmh_smtp_addr, qmh_crt_time, qmh_crt_date, qmh_crt_by,
qmh_ip_upd_time, qmh_ip_upd_date, qmh_ip_upd_by, qmh_cp_upd_time,
qmh_upd_date, qmh_cp_upd_by, qmh_clas_sts_code, qmh_clas_id,
qmh_clas_mess, qmh_clas_upd_time, qmh_clas_upd_date,
qmh_clas_upd_by, qmh_prd_ind, qmh_tdc_type, qmh_pi_status
FROM ipdmdm.t_qm_insp_hdr
WHERE qmh_pi_status = 'N'
FOR UPDATE
勾选this
COST: Cost of the operation as estimated by the optimizer’s query approach. Cost is not determined for table access operations. 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: CPU cost of the operation as estimated by the query optimizer’s approach. The value of this column is proportional to the number of machine cycles required for the operation. For statements that use the rule-based approach, this column is null.
您可以参考这篇文章了解What is the cost column in an explain plan?
Depending on your release and setting for the hidden parameter _optimizer_cost_model (cpu or io), the cost is taken from the cpu_cost and io_cost columns in the plan table (, in turn, estimates from sys.aux_stats$. The "cost" column is not any particular unit of measurement, it is a weighted average of the costs derived from the cost-based decision tree generated when the SQL statement is bring processed. The cost column is essentially an estimate of the run-time for a given operation.
根据the manual,CPU_COST 和IO_COST 是以不同的方式测量的。 IO_COST 是 "proportional to the number of data blocks read by the operation",CPU_COST 是 "proportional to the number of machine cycles required for the operation"。
成本之间的差异应该不会太令人惊讶,因为许多数据库操作需要比磁盘读取多 CPU 个数量级的周期。在我的 PC 上进行的简单测试产生了类似的结果:
create table test1(a char(1000));
insert into test1 select level from dual connect by level <= 283;
begin
dbms_stats.gather_table_stats(user, 'TEST1');
end;
/
explain plan set statement_id = 'cost test' for select * from test1 for update;
select cpu_cost, io_cost from plan_table where statement_id = 'cost test' and id = 0;
CPU_COST IO_COST
-------- -------
348672 13
尽管它被称为基于 成本 的优化器,但在评估执行计划时,成本通常不是一个有用的指标。 "Operation" 和 "Rows" 列更有用。
此外,如果您对解释计划感兴趣,请停止使用 IDE 的残缺视图并使用 Oracle 提供的文本版本。使用 explain plan for select ...
和 select * from table(dbms_xplan.display);
。 PL/SQL Developer 是一个很棒的工具,但它的解释计划 window 缺少关键信息(注释部分)并且有一些错误(它不包括会话设置)。