|
原帖由 Yong Huang 于 2009-3-30 05:39 发表 ![]()
If you think about the plan, it makes perfect sense. The CBO cost is the number of I/O blocks Oracle has to read (slightly modified by a factor involving CPU time). In table access preceeded by an index range scan, Oracle has to go through the branch block(s) (including root block) of the index to get to the leaf blocks, scan all the leaf blocks needed (i.e. those picked based on the index selectivity), and read all table blocks pointed to by the rowid's stored in the index leaf blocks (i.e. table blocks times table selectivity). You only have a global index. There's no ambiguity there. Now, you may ask why not full table, the entire table, not just a partition? Think about it. The where clause tells Oracle which single partition it needs to read. Why would Oracle still need to read the whole table? The table selectivity is also about the single partition, because even this selectivity calculation does not need to be based on the whole table (the partition is already clearly identified early on).
Yong Huang
1. 我并是说oracle需要读整个表(做FTS),因为数据可以只在一个分区内得到,所以只用单个分区的选择率计算基数是没有问题的。
2. 在计算代价公式的第三部分中CF*(table selectivity),
2.1 CF是针对整个索引,因为索引是非分区的,根据CF的定义,它是针对表中的所有记录而得到
2.2 表选择率是基于单个分区的,假设我选出分区中的所有记录,即selectivity=1时,此时得到的代价是CF,即为根据rowid获取整个表的代价。(但实际上我们只需要根据rowid获取单个分区的记录)
2.3 根据上面两点,我认为在计算代价时的第三部分是不合适的。 |
|