表和索引真实使用量分析

简介: 1、表的使用分析 参考文章:How to Determine Real Space used by a Table (Below the High Water Mark) (Doc ID 77635.

1、表的使用分析

参考文章:How to Determine Real Space used by a Table (Below the High Water Mark) (Doc ID 77635.1)

**Checked for relevance on 31-Oct-2011*** 

PURPOSE
This article describes how to find out how many blocks are really being used within a table ie. are not empty. Please note that this article does
not cover what to do when chaining is taking place.


SCOPE & APPLICATION
For DBA's needing to determine how many blocks within a table are  empty blocks.

How many blocks contain data (are not empty)
--------------------------------------------
Each row in the table has pseudocolumn called ROWID.This pseudo contains information about physical location of the row in format ————block_number.row.file

If the table is stored in a tablespace which has one datafile, all we have to do is to get DISTINCT  number of block_number from ROWID column of this table.But if the table is stored in a tablespace with more than onedatafile then you can have the same block_number but in different datafiles so we have to get DISTINCT number of block_number+file from ROWID.

(如果表示存在一个只有一个数据文件的的表空间内,我们只要从ROWID中找出distinct的数量,就得到了数据块使用的个数;

但是,对于一个表存储在多个数据文件里的,就会有相同的block numner,但是数据文件号是不同的,所以这个时候可以distinct ROWID  block_number+file)

SQL> create table tab_test4 as select * from dba_objects;
Table created.

SQL> select count(*) from tab_test4;
  COUNT(*)
----------
     74491

SQL> ANALYZE TABLE TAB_TEST4 ESTIMATE STATISTICS;  (这样统计信息就可以存入usr_tables表中了)
Table analyzed.

通过如下命令,查看使用block的数量:

  SELECT COUNT (DISTINCT 
         DBMS_ROWID.ROWID_BLOCK_NUMBER(rowid)||
         DBMS_ROWID.ROWID_RELATIVE_FNO(rowid)) "Used"
    FROM user_test1.tab_test4;


      Used
------------
      1010

也就是说,有1010个数据块被使用。


执行truncate表:

SQL> TRUNCATE TABLE tab_test4;

Table truncated.

SQL>  ANALYZE TABLE TAB_TEST4 ESTIMATE STATISTICS;

Table analyzed.

再次查看:

    SELECT  table_name, num_rows,blocks,empty_blocks
  FROM dba_tables
  WHERE table_name='TAB_TEST4';



2、索引使用分析

参考文章:How to Find Out How Much Space an Index is Using (Doc ID 33343.1)








相关文章
|
8月前
如何查询当前年最新的数据以及这条数据的上一年的最新数据?
如何查询当前年最新的数据以及这条数据的上一年的最新数据
36 0
|
8月前
|
SQL 分布式计算 MaxCompute
一次性查询一张表所有字段的空值率
一次性查询一张表所有字段的空值率
751 2
|
11月前
|
关系型数据库 MySQL 索引
一个表中索引的数量是不是越多越好?
往InnoDB表新增数据时,都会基于主键给自动建立聚簇索引。 随着我们不停的在表里插入数据,会不停的在数据页里插入数据。一个数据页放满后,就会分裂成多个数据页,这时就需要索引页去指向各个数据页。
96 0
|
SQL 存储 监控
为什么我建议需要定期重建数据量大但是性能关键的表
为什么我建议需要定期重建数据量大但是性能关键的表
为什么我建议需要定期重建数据量大但是性能关键的表
|
存储 缓存 分布式计算
指定表和分区来预先缓存,查询分析更高效 | 学习笔记
快速学习指定表和分区来预先缓存,查询分析更高效。
135 0
|
SQL 存储 缓存
|
SQL 索引 Go
通过手动创建统计信息优化sql查询性能案例
原文:通过手动创建统计信息优化sql查询性能案例 本质原因在于:SQL Server 统计信息只包含复合索引的第一个列的信息,而不包含复合索引数据组合的信息   来源于工作中的一个实际问题, 这里是组合列数据不均匀导致查询无法预估数据行数,从而导致无法选择合理的执行计划导致性能低下的情况 我...
804 0

相关实验场景

更多