sql – 如何计算查询时间

我有很长的SQL命令,有很多JOIN和UNION语句.

我打开了解释计划窗口,但我无法分辨成本,基数或字节的含义.

有人可以解释这些条款吗?并且降低必然意味着更快的查询时间?

最佳答案 正如我在
oracle Documentation中看到的那样

CARDINALITY: Estimate by the cost-based approach of the number of rows
accessed by the operation.

BYTES: Estimate by the cost-based approach of the number of bytes
accessed by the operation.

COST: Cost of the operation as estimated by the optimizer’s cost-based
approach. For statements that use the rule-based approach, this column
is null. 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 optimizer’s cost-based approach. For statements that use the rule-based approach,
this column is null. The value of this column is proportional to the
number of machine cycles required for the operation.

*IO_COST:* I/O cost of the operation as estimated by the optimizer’s cost-based approach. For statements that use the rule-based approach,
this column is null. The value of this column is proportional to the
number of data blocks read by the operation.

点赞