I am trying to figure out a query that will tell me which indexes need to be rebuilt based on how many deleted rows are present in the index. From what I have read, I need to use the INDEX_STATS view after the index as been analyzed.
However, I am running into inconsistencies in the data being reported by INDEX_STATS. For example:
ops$jeffh@ibdev1.us> drop table jh_index_stat
2 /
Table dropped.
ops$jeffh@ibdev1.us> create table jh_index_stat (
2 run_ts date,
3 HEIGHT NUMBER,
4 BLOCKS NUMBER,
5 NAME VARCHAR2(30),
6 PARTITION_NAME VARCHAR2(30),
7 LF_ROWS NUMBER,
8 LF_BLKS NUMBER,
9 LF_ROWS_LEN NUMBER,
10 LF_BLK_LEN NUMBER,
11 BR_ROWS NUMBER,
12 BR_BLKS NUMBER,
13 BR_ROWS_LEN NUMBER,
14 BR_BLK_LEN NUMBER,
15 DEL_LF_ROWS NUMBER,
16 DEL_LF_ROWS_LEN NUMBER,
17 DISTINCT_KEYS NUMBER,
18 MOST_REPEATED_KEY NUMBER,
19 BTREE_SPACE NUMBER,
20 USED_SPACE NUMBER,
21 PCT_USED NUMBER,
22 ROWS_PER_KEY NUMBER,
23 BLKS_GETS_PER_ACCESS NUMBER,
24 PRE_ROWS NUMBER,
25 PRE_ROWS_LEN NUMBER
26 )
27 /
Table created.
ops$jeffh@ibdev1.us> drop table test1
2 /
Table dropped.
ops$jeffh@ibdev1.us> create table test1 (id number(10) , data_val varchar2(60))
2 /
Table created.
ops$jeffh@ibdev1.us> create unique index test1_pk on test1 (id)
2 /
Index created.
ops$jeffh@ibdev1.us> insert into test1 select rownum, column_name from all_tab_columns
2 /
26512 rows created.
ops$jeffh@ibdev1.us> commit;
Commit complete.
ops$jeffh@ibdev1.us> select min(id) min_id, max(id) max_id, count(id) count_id from test1
2 /
MIN_ID MAX_ID COUNT_ID
---------- ---------- ----------
1 26512 26512
ops$jeffh@ibdev1.us> analyze index test1_pk validate structure
2 /
Index analyzed.
ops$jeffh@ibdev1.us> insert into jh_index_stat
2 select sysdate,
3 HEIGHT,
4 BLOCKS,
5 NAME,
6 PARTITION_NAME,
7 LF_ROWS,
8 LF_BLKS,
9 LF_ROWS_LEN,
10 LF_BLK_LEN,
11 BR_ROWS,
12 BR_BLKS,
13 BR_ROWS_LEN,
14 BR_BLK_LEN,
15 DEL_LF_ROWS,
16 DEL_LF_ROWS_LEN,
17 DISTINCT_KEYS,
18 MOST_REPEATED_KEY,
19 BTREE_SPACE,
20 USED_SPACE,
21 PCT_USED,
22 ROWS_PER_KEY,
23 BLKS_GETS_PER_ACCESS,
24 PRE_ROWS,
25 PRE_ROWS_LEN
26 from index_stats
27 /
1 row created.
ops$jeffh@ibdev1.us> commit;
Commit complete.
ops$jeffh@ibdev1.us> delete from test1 where data_val < 'N'
2 /
13450 rows deleted.
ops$jeffh@ibdev1.us> commit;
Commit complete.
ops$jeffh@ibdev1.us> select min(id) min_id, max(id) max_id, count(id) count_id from test1
2 /
MIN_ID MAX_ID COUNT_ID
---------- ---------- ----------
1 26511 13062
ops$jeffh@ibdev1.us> analyze index test1_pk validate structure
2 /
Index analyzed.
ops$jeffh@ibdev1.us> insert into jh_index_stat
2 select sysdate,
3 HEIGHT,
4 BLOCKS,
5 NAME,
6 PARTITION_NAME,
7 LF_ROWS,
8 LF_BLKS,
9 LF_ROWS_LEN,
10 LF_BLK_LEN,
11 BR_ROWS,
12 BR_BLKS,
13 BR_ROWS_LEN,
14 BR_BLK_LEN,
15 DEL_LF_ROWS,
16 DEL_LF_ROWS_LEN,
17 DISTINCT_KEYS,
18 MOST_REPEATED_KEY,
19 BTREE_SPACE,
20 USED_SPACE,
21 PCT_USED,
22 ROWS_PER_KEY,
23 BLKS_GETS_PER_ACCESS,
24 PRE_ROWS,
25 PRE_ROWS_LEN
26 from index_stats
27 /
1 row created.
ops$jeffh@ibdev1.us> commit;
Commit complete.
ops$jeffh@ibdev1.us> select run_ts, lf_rows, br_rows, del_lf_rows
2 from jh_index_stat
3 /
RUN_TS LF_ROWS BR_ROWS DEL_LF_ROWS
-------- ---------- ---------- -----------
13:32:41 26512 209 0
13:32:42 26512 209 13450
At this point, The data looks right. However, when more data gets put into the table and subsequently deleted, things get all screwed up...
ops$jeffh@ibdev1.us> insert into test1 select rownum+40000, column_name from all_tab_columns
2 /
26512 rows created.
ops$jeffh@ibdev1.us> commit;
Commit complete.
ops$jeffh@ibdev1.us> select min(id) min_id, max(id) max_id, count(id) count_id from test1
2 /
MIN_ID MAX_ID COUNT_ID
---------- ---------- ----------
1 66512 39574
ops$jeffh@ibdev1.us> delete from test1 where data_val < 'N'
2 /
13450 rows deleted.
ops$jeffh@ibdev1.us> commit;
Commit complete.
ops$jeffh@ibdev1.us> select min(id) min_id, max(id) max_id, count(id) count_id from test1
2 /
MIN_ID MAX_ID COUNT_ID
---------- ---------- ----------
1 66511 26124
ops$jeffh@ibdev1.us> analyze index test1_pk validate structure
2 /
Index analyzed.
ops$jeffh@ibdev1.us> insert into jh_index_stat
2 select sysdate,
3 HEIGHT,
4 BLOCKS,
5 NAME,
6 PARTITION_NAME,
7 LF_ROWS,
8 LF_BLKS,
9 LF_ROWS_LEN,
10 LF_BLK_LEN,
11 BR_ROWS,
12 BR_BLKS,
13 BR_ROWS_LEN,
14 BR_BLK_LEN,
15 DEL_LF_ROWS,
16 DEL_LF_ROWS_LEN,
17 DISTINCT_KEYS,
18 MOST_REPEATED_KEY,
19 BTREE_SPACE,
20 USED_SPACE,
21 PCT_USED,
22 ROWS_PER_KEY,
23 BLKS_GETS_PER_ACCESS,
24 PRE_ROWS,
25 PRE_ROWS_LEN
26 from index_stats
27 /
1 row created.
ops$jeffh@ibdev1.us> commit;
Commit complete.
ops$jeffh@ibdev1.us> select run_ts, lf_rows, br_rows, del_lf_rows
2 from jh_index_stat
3 /
RUN_TS LF_ROWS BR_ROWS DEL_LF_ROWS
-------- ---------- ---------- -----------
13:32:41 26512 209 0
13:32:42 26512 209 13450
13:32:59 43292 424 17168
Since all the entries in this index are unique and distinct, I expected 53024 for LF_ROWS and 26900 for the DEL_LF_ROWS for the third entry. What am I misunderstanding?
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width
Bookmarks