Oracle段统计信息查询

时间:2012-06-28 16:42:25

标签: sql oracle

以下查询输出过去7天内表的总逻辑读数:

SELECT owner as schema, object_name AS table_name,
     sum(logical_reads_delta) AS total_logical_reads
FROM dba_hist_seg_stat a, dba_hist_seg_stat_obj b
WHERE     owner != 'SYS'
     and owner!= 'SYSTEM'
     AND a.obj# = b.obj#
     AND a.dataobj# = b.dataobj#
     AND object_type = 'TABLE'
GROUP BY owner, object_name
order by sum(logical_reads_delta) desc;

如果它不在输出中,则没有逻辑读取。

我实际上正在寻找一种方法来连接数据库中的所有表(即使没有逻辑读取的表)与上面的输出。外联?

结果有望成为数据库上最近活动的列表,列出所有具有逻辑读取的表(以及一些具有空值的表)

想法怎么做?

1 个答案:

答案 0 :(得分:1)

我不确定我是否误解了这个问题,但是这个问题会在某种程度上解决你的问题吗?

我已将您的查询链接到DBA_TABLES(使用外部联接),因此它可以检索数据库中可用的所有表,这些表首先列出具有逻辑读取的表。

SELECT t.owner AS schema_name,
       t.table_name,
       q.total_logical_reads
  FROM dba_tables t
  LEFT JOIN
      (SELECT b.owner AS schema,
              b.object_name AS table_name,
              SUM (a.logical_reads_delta) AS total_logical_reads
         FROM dba_hist_seg_stat a
         JOIN dba_hist_seg_stat_obj b USING (obj#, dataobj#)
        WHERE b.owner NOT IN ('SYS', 'SYSTEM')
          AND b.object_type = 'TABLE'
        GROUP BY b.owner, b.object_name) q
   ON (t.owner = q.schema AND t.table_name = q.table_name)
ORDER BY q.total_logical_reads DESC NULLS LAST;

锄头有帮助......