计算出需要多少块访问

figuring out how many block accesses are needed

oracle 是否有办法计算出对特定 table 的直接完整扫描需要多少块访问?

执行完整 table 扫描所需的 I/Os 总数取决于 table(select blocks from user_segments where segment_name='TABLE_NAME')的大小、多块读取计数(受控通过DB_FILE_MULTIBLOCK_READ_COUNT参数),以及是否正在为操作使用并行执行。

访问的块数,本质上是 logical/consistent 获取您的查询的数量。您可以使用选项 set autotrace traceonly statistics SQL*Plus 查看此统计值:

SQL> set autotrace traceonly statistics;
SQL> select * from customers;

115005 rows selected.


Statistics
----------------------------------------------------------
          4  recursive calls
          0  db block gets
       8215  consistent gets
        580  physical reads
          0  redo size
    4689008  bytes sent via SQL*Net to client
      84826  bytes received via SQL*Net from client
       7668  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
     115005  rows processed

consistent gets是查询使用的块数(也称为"logical I/O"。physical reads是实际从硬盘中检索到的块数(因为它们不在缓冲区缓存)。