dbTalk Databases Forums  

HowTo find out used (useful) and unused (usesless) indexes?

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss HowTo find out used (useful) and unused (usesless) indexes? in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Andreas Mosmann
 
Posts: n/a

Default HowTo find out used (useful) and unused (usesless) indexes? - 04-17-2008 , 05:38 AM






Hi,

Is there a way to find out what indexes are used(useful)/unused(useless)
while the last few days/weeks?
If possible so tell me a way via data dictionary without using any
external tools.

Andreas Mosmann

--
wenn email, dann AndreasMosmann <bei> web <punkt> de

Reply With Quote
  #2  
Old   
fitzjarrell@cox.net
 
Posts: n/a

Default Re: HowTo find out used (useful) and unused (usesless) indexes? - 04-17-2008 , 08:45 AM






On Apr 17, 4:38*am, Andreas Mosmann <mosm... (AT) expires-30-04-2008 (DOT) news-
group.org> wrote:
Quote:
Hi,

Is there a way to find out what indexes are used(useful)/unused(useless)
while the last few days/weeks?
If possible so tell me a way via data dictionary without using any
external tools.

Andreas Mosmann

--
wenn email, dann AndreasMosmann <bei> web <punkt> de
Let Oracle do that for you:

SQL> create index emp_eno_idx
2 on emp(empno);

Index created.

SQL>
SQL> alter index emp_eno_idx monitoring usage;

Index altered.

SQL>
SQL> select * from emp;

EMPNO ENAME JOB MGR HIREDATE SAL
COMM DEPTNO
---------- ---------- --------- ---------- --------- ----------
---------- ----------
7369 SMITH CLERK 7902 17-DEC-80
800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600
300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250
500 30
7566 JONES MANAGER 7839 02-APR-81
2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250
1400 30
7698 BLAKE MANAGER 7839 01-MAY-81
2850 30
7782 CLARK MANAGER 7839 09-JUN-81
2450 10
7788 SCOTT ANALYST 7566 09-DEC-82
3000 20
7839 KING PRESIDENT 17-NOV-81
5000 10
7844 TURNER SALESMAN 7698 08-SEP-81
1500 0 30
7876 ADAMS CLERK 7788 12-JAN-83
1100 20

EMPNO ENAME JOB MGR HIREDATE SAL
COMM DEPTNO
---------- ---------- --------- ---------- --------- ----------
---------- ----------
7900 JAMES CLERK 7698 03-DEC-81
950 30
7902 FORD ANALYST 7566 03-DEC-81
3000 20
7934 MILLER CLERK 7782 23-JAN-82
1300 10

14 rows selected.

SQL>
SQL> select index_name, table_name, used from v$object_usage;

INDEX_NAME TABLE_NAME USE
------------------------------ ------------------------------ ---
EMP_ENO_IDX EMP NO

SQL>
SQL> select * from emp where deptno = 30;

EMPNO ENAME JOB MGR HIREDATE SAL
COMM DEPTNO
---------- ---------- --------- ---------- --------- ----------
---------- ----------
7499 ALLEN SALESMAN 7698 20-FEB-81 1600
300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250
500 30
7654 MARTIN SALESMAN 7698 28-SEP-81 1250
1400 30
7698 BLAKE MANAGER 7839 01-MAY-81
2850 30
7844 TURNER SALESMAN 7698 08-SEP-81
1500 0 30
7900 JAMES CLERK 7698 03-DEC-81
950 30

6 rows selected.

SQL>
SQL> select index_name, table_name, used from v$object_usage;

INDEX_NAME TABLE_NAME USE
------------------------------ ------------------------------ ---
EMP_ENO_IDX EMP NO

SQL>
SQL> select * from emp where empno < 7400;

EMPNO ENAME JOB MGR HIREDATE SAL
COMM DEPTNO
---------- ---------- --------- ---------- --------- ----------
---------- ----------
7369 SMITH CLERK 7902 17-DEC-80
800 20

SQL>
SQL> select index_name, table_name, used from v$object_usage;

INDEX_NAME TABLE_NAME USE
------------------------------ ------------------------------ ---
EMP_ENO_IDX EMP YES

SQL>

Using the 'alter index <indexname> monitoring usage;' directive
Oracle will keep track of whether or not an index is actually used and
will do so until you issue an 'alter index <indexname> nomonitoring
usage;' command. A simple query of V$OBJECT_USAGE will reveal which
indexes are and are not used. After an 'alter index <indexname>
nomonitoring usage;' directive is issued the collected data remains in
the V$OBJECT_USAGE view; it isn't removed for the objects in question
until another 'alter index ... monitoring usage;' command is called:

SQL> alter index emp_eno_idx nomonitoring usage;

Index altered.

SQL> select index_name, table_name,used from v$object_usage;

INDEX_NAME TABLE_NAME USE
------------------------------ ------------------------------ ---
EMP_ENO_IDX EMP YES

SQL>


David Fitzjarrell


Reply With Quote
  #3  
Old   
fitzjarrell@cox.net
 
Posts: n/a

Default Re: HowTo find out used (useful) and unused (usesless) indexes? - 04-17-2008 , 08:45 AM



On Apr 17, 4:38*am, Andreas Mosmann <mosm... (AT) expires-30-04-2008 (DOT) news-
group.org> wrote:
Quote:
Hi,

Is there a way to find out what indexes are used(useful)/unused(useless)
while the last few days/weeks?
If possible so tell me a way via data dictionary without using any
external tools.

Andreas Mosmann

--
wenn email, dann AndreasMosmann <bei> web <punkt> de
Let Oracle do that for you:

SQL> create index emp_eno_idx
2 on emp(empno);

Index created.

SQL>
SQL> alter index emp_eno_idx monitoring usage;

Index altered.

SQL>
SQL> select * from emp;

EMPNO ENAME JOB MGR HIREDATE SAL
COMM DEPTNO
---------- ---------- --------- ---------- --------- ----------
---------- ----------
7369 SMITH CLERK 7902 17-DEC-80
800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600
300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250
500 30
7566 JONES MANAGER 7839 02-APR-81
2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250
1400 30
7698 BLAKE MANAGER 7839 01-MAY-81
2850 30
7782 CLARK MANAGER 7839 09-JUN-81
2450 10
7788 SCOTT ANALYST 7566 09-DEC-82
3000 20
7839 KING PRESIDENT 17-NOV-81
5000 10
7844 TURNER SALESMAN 7698 08-SEP-81
1500 0 30
7876 ADAMS CLERK 7788 12-JAN-83
1100 20

EMPNO ENAME JOB MGR HIREDATE SAL
COMM DEPTNO
---------- ---------- --------- ---------- --------- ----------
---------- ----------
7900 JAMES CLERK 7698 03-DEC-81
950 30
7902 FORD ANALYST 7566 03-DEC-81
3000 20
7934 MILLER CLERK 7782 23-JAN-82
1300 10

14 rows selected.

SQL>
SQL> select index_name, table_name, used from v$object_usage;

INDEX_NAME TABLE_NAME USE
------------------------------ ------------------------------ ---
EMP_ENO_IDX EMP NO

SQL>
SQL> select * from emp where deptno = 30;

EMPNO ENAME JOB MGR HIREDATE SAL
COMM DEPTNO
---------- ---------- --------- ---------- --------- ----------
---------- ----------
7499 ALLEN SALESMAN 7698 20-FEB-81 1600
300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250
500 30
7654 MARTIN SALESMAN 7698 28-SEP-81 1250
1400 30
7698 BLAKE MANAGER 7839 01-MAY-81
2850 30
7844 TURNER SALESMAN 7698 08-SEP-81
1500 0 30
7900 JAMES CLERK 7698 03-DEC-81
950 30

6 rows selected.

SQL>
SQL> select index_name, table_name, used from v$object_usage;

INDEX_NAME TABLE_NAME USE
------------------------------ ------------------------------ ---
EMP_ENO_IDX EMP NO

SQL>
SQL> select * from emp where empno < 7400;

EMPNO ENAME JOB MGR HIREDATE SAL
COMM DEPTNO
---------- ---------- --------- ---------- --------- ----------
---------- ----------
7369 SMITH CLERK 7902 17-DEC-80
800 20

SQL>
SQL> select index_name, table_name, used from v$object_usage;

INDEX_NAME TABLE_NAME USE
------------------------------ ------------------------------ ---
EMP_ENO_IDX EMP YES

SQL>

Using the 'alter index <indexname> monitoring usage;' directive
Oracle will keep track of whether or not an index is actually used and
will do so until you issue an 'alter index <indexname> nomonitoring
usage;' command. A simple query of V$OBJECT_USAGE will reveal which
indexes are and are not used. After an 'alter index <indexname>
nomonitoring usage;' directive is issued the collected data remains in
the V$OBJECT_USAGE view; it isn't removed for the objects in question
until another 'alter index ... monitoring usage;' command is called:

SQL> alter index emp_eno_idx nomonitoring usage;

Index altered.

SQL> select index_name, table_name,used from v$object_usage;

INDEX_NAME TABLE_NAME USE
------------------------------ ------------------------------ ---
EMP_ENO_IDX EMP YES

SQL>


David Fitzjarrell


Reply With Quote
  #4  
Old   
fitzjarrell@cox.net
 
Posts: n/a

Default Re: HowTo find out used (useful) and unused (usesless) indexes? - 04-17-2008 , 08:45 AM



On Apr 17, 4:38*am, Andreas Mosmann <mosm... (AT) expires-30-04-2008 (DOT) news-
group.org> wrote:
Quote:
Hi,

Is there a way to find out what indexes are used(useful)/unused(useless)
while the last few days/weeks?
If possible so tell me a way via data dictionary without using any
external tools.

Andreas Mosmann

--
wenn email, dann AndreasMosmann <bei> web <punkt> de
Let Oracle do that for you:

SQL> create index emp_eno_idx
2 on emp(empno);

Index created.

SQL>
SQL> alter index emp_eno_idx monitoring usage;

Index altered.

SQL>
SQL> select * from emp;

EMPNO ENAME JOB MGR HIREDATE SAL
COMM DEPTNO
---------- ---------- --------- ---------- --------- ----------
---------- ----------
7369 SMITH CLERK 7902 17-DEC-80
800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600
300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250
500 30
7566 JONES MANAGER 7839 02-APR-81
2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250
1400 30
7698 BLAKE MANAGER 7839 01-MAY-81
2850 30
7782 CLARK MANAGER 7839 09-JUN-81
2450 10
7788 SCOTT ANALYST 7566 09-DEC-82
3000 20
7839 KING PRESIDENT 17-NOV-81
5000 10
7844 TURNER SALESMAN 7698 08-SEP-81
1500 0 30
7876 ADAMS CLERK 7788 12-JAN-83
1100 20

EMPNO ENAME JOB MGR HIREDATE SAL
COMM DEPTNO
---------- ---------- --------- ---------- --------- ----------
---------- ----------
7900 JAMES CLERK 7698 03-DEC-81
950 30
7902 FORD ANALYST 7566 03-DEC-81
3000 20
7934 MILLER CLERK 7782 23-JAN-82
1300 10

14 rows selected.

SQL>
SQL> select index_name, table_name, used from v$object_usage;

INDEX_NAME TABLE_NAME USE
------------------------------ ------------------------------ ---
EMP_ENO_IDX EMP NO

SQL>
SQL> select * from emp where deptno = 30;

EMPNO ENAME JOB MGR HIREDATE SAL
COMM DEPTNO
---------- ---------- --------- ---------- --------- ----------
---------- ----------
7499 ALLEN SALESMAN 7698 20-FEB-81 1600
300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250
500 30
7654 MARTIN SALESMAN 7698 28-SEP-81 1250
1400 30
7698 BLAKE MANAGER 7839 01-MAY-81
2850 30
7844 TURNER SALESMAN 7698 08-SEP-81
1500 0 30
7900 JAMES CLERK 7698 03-DEC-81
950 30

6 rows selected.

SQL>
SQL> select index_name, table_name, used from v$object_usage;

INDEX_NAME TABLE_NAME USE
------------------------------ ------------------------------ ---
EMP_ENO_IDX EMP NO

SQL>
SQL> select * from emp where empno < 7400;

EMPNO ENAME JOB MGR HIREDATE SAL
COMM DEPTNO
---------- ---------- --------- ---------- --------- ----------
---------- ----------
7369 SMITH CLERK 7902 17-DEC-80
800 20

SQL>
SQL> select index_name, table_name, used from v$object_usage;

INDEX_NAME TABLE_NAME USE
------------------------------ ------------------------------ ---
EMP_ENO_IDX EMP YES

SQL>

Using the 'alter index <indexname> monitoring usage;' directive
Oracle will keep track of whether or not an index is actually used and
will do so until you issue an 'alter index <indexname> nomonitoring
usage;' command. A simple query of V$OBJECT_USAGE will reveal which
indexes are and are not used. After an 'alter index <indexname>
nomonitoring usage;' directive is issued the collected data remains in
the V$OBJECT_USAGE view; it isn't removed for the objects in question
until another 'alter index ... monitoring usage;' command is called:

SQL> alter index emp_eno_idx nomonitoring usage;

Index altered.

SQL> select index_name, table_name,used from v$object_usage;

INDEX_NAME TABLE_NAME USE
------------------------------ ------------------------------ ---
EMP_ENO_IDX EMP YES

SQL>


David Fitzjarrell


Reply With Quote
  #5  
Old   
fitzjarrell@cox.net
 
Posts: n/a

Default Re: HowTo find out used (useful) and unused (usesless) indexes? - 04-17-2008 , 08:45 AM



On Apr 17, 4:38*am, Andreas Mosmann <mosm... (AT) expires-30-04-2008 (DOT) news-
group.org> wrote:
Quote:
Hi,

Is there a way to find out what indexes are used(useful)/unused(useless)
while the last few days/weeks?
If possible so tell me a way via data dictionary without using any
external tools.

Andreas Mosmann

--
wenn email, dann AndreasMosmann <bei> web <punkt> de
Let Oracle do that for you:

SQL> create index emp_eno_idx
2 on emp(empno);

Index created.

SQL>
SQL> alter index emp_eno_idx monitoring usage;

Index altered.

SQL>
SQL> select * from emp;

EMPNO ENAME JOB MGR HIREDATE SAL
COMM DEPTNO
---------- ---------- --------- ---------- --------- ----------
---------- ----------
7369 SMITH CLERK 7902 17-DEC-80
800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600
300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250
500 30
7566 JONES MANAGER 7839 02-APR-81
2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250
1400 30
7698 BLAKE MANAGER 7839 01-MAY-81
2850 30
7782 CLARK MANAGER 7839 09-JUN-81
2450 10
7788 SCOTT ANALYST 7566 09-DEC-82
3000 20
7839 KING PRESIDENT 17-NOV-81
5000 10
7844 TURNER SALESMAN 7698 08-SEP-81
1500 0 30
7876 ADAMS CLERK 7788 12-JAN-83
1100 20

EMPNO ENAME JOB MGR HIREDATE SAL
COMM DEPTNO
---------- ---------- --------- ---------- --------- ----------
---------- ----------
7900 JAMES CLERK 7698 03-DEC-81
950 30
7902 FORD ANALYST 7566 03-DEC-81
3000 20
7934 MILLER CLERK 7782 23-JAN-82
1300 10

14 rows selected.

SQL>
SQL> select index_name, table_name, used from v$object_usage;

INDEX_NAME TABLE_NAME USE
------------------------------ ------------------------------ ---
EMP_ENO_IDX EMP NO

SQL>
SQL> select * from emp where deptno = 30;

EMPNO ENAME JOB MGR HIREDATE SAL
COMM DEPTNO
---------- ---------- --------- ---------- --------- ----------
---------- ----------
7499 ALLEN SALESMAN 7698 20-FEB-81 1600
300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250
500 30
7654 MARTIN SALESMAN 7698 28-SEP-81 1250
1400 30
7698 BLAKE MANAGER 7839 01-MAY-81
2850 30
7844 TURNER SALESMAN 7698 08-SEP-81
1500 0 30
7900 JAMES CLERK 7698 03-DEC-81
950 30

6 rows selected.

SQL>
SQL> select index_name, table_name, used from v$object_usage;

INDEX_NAME TABLE_NAME USE
------------------------------ ------------------------------ ---
EMP_ENO_IDX EMP NO

SQL>
SQL> select * from emp where empno < 7400;

EMPNO ENAME JOB MGR HIREDATE SAL
COMM DEPTNO
---------- ---------- --------- ---------- --------- ----------
---------- ----------
7369 SMITH CLERK 7902 17-DEC-80
800 20

SQL>
SQL> select index_name, table_name, used from v$object_usage;

INDEX_NAME TABLE_NAME USE
------------------------------ ------------------------------ ---
EMP_ENO_IDX EMP YES

SQL>

Using the 'alter index <indexname> monitoring usage;' directive
Oracle will keep track of whether or not an index is actually used and
will do so until you issue an 'alter index <indexname> nomonitoring
usage;' command. A simple query of V$OBJECT_USAGE will reveal which
indexes are and are not used. After an 'alter index <indexname>
nomonitoring usage;' directive is issued the collected data remains in
the V$OBJECT_USAGE view; it isn't removed for the objects in question
until another 'alter index ... monitoring usage;' command is called:

SQL> alter index emp_eno_idx nomonitoring usage;

Index altered.

SQL> select index_name, table_name,used from v$object_usage;

INDEX_NAME TABLE_NAME USE
------------------------------ ------------------------------ ---
EMP_ENO_IDX EMP YES

SQL>


David Fitzjarrell


Reply With Quote
  #6  
Old   
DA Morgan
 
Posts: n/a

Default Re: HowTo find out used (useful) and unused (usesless) indexes? - 04-17-2008 , 01:02 PM



fitzjarrell (AT) cox (DOT) net wrote:
Quote:
On Apr 17, 4:38 am, Andreas Mosmann <mosm... (AT) expires-30-04-2008 (DOT) news-
group.org> wrote:
Hi,

Is there a way to find out what indexes are used(useful)/unused(useless)
while the last few days/weeks?
If possible so tell me a way via data dictionary without using any
external tools.

Andreas Mosmann

--
wenn email, dann AndreasMosmann <bei> web <punkt> de

Let Oracle do that for you:

SQL> create index emp_eno_idx
2 on emp(empno);

Index created.

SQL
SQL> alter index emp_eno_idx monitoring usage;

Index altered.

SQL
SQL> select * from emp;

EMPNO ENAME JOB MGR HIREDATE SAL
COMM DEPTNO
---------- ---------- --------- ---------- --------- ----------
---------- ----------
7369 SMITH CLERK 7902 17-DEC-80
800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600
300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250
500 30
7566 JONES MANAGER 7839 02-APR-81
2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250
1400 30
7698 BLAKE MANAGER 7839 01-MAY-81
2850 30
7782 CLARK MANAGER 7839 09-JUN-81
2450 10
7788 SCOTT ANALYST 7566 09-DEC-82
3000 20
7839 KING PRESIDENT 17-NOV-81
5000 10
7844 TURNER SALESMAN 7698 08-SEP-81
1500 0 30
7876 ADAMS CLERK 7788 12-JAN-83
1100 20

EMPNO ENAME JOB MGR HIREDATE SAL
COMM DEPTNO
---------- ---------- --------- ---------- --------- ----------
---------- ----------
7900 JAMES CLERK 7698 03-DEC-81
950 30
7902 FORD ANALYST 7566 03-DEC-81
3000 20
7934 MILLER CLERK 7782 23-JAN-82
1300 10

14 rows selected.

SQL
SQL> select index_name, table_name, used from v$object_usage;

INDEX_NAME TABLE_NAME USE
------------------------------ ------------------------------ ---
EMP_ENO_IDX EMP NO

SQL
SQL> select * from emp where deptno = 30;

EMPNO ENAME JOB MGR HIREDATE SAL
COMM DEPTNO
---------- ---------- --------- ---------- --------- ----------
---------- ----------
7499 ALLEN SALESMAN 7698 20-FEB-81 1600
300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250
500 30
7654 MARTIN SALESMAN 7698 28-SEP-81 1250
1400 30
7698 BLAKE MANAGER 7839 01-MAY-81
2850 30
7844 TURNER SALESMAN 7698 08-SEP-81
1500 0 30
7900 JAMES CLERK 7698 03-DEC-81
950 30

6 rows selected.

SQL
SQL> select index_name, table_name, used from v$object_usage;

INDEX_NAME TABLE_NAME USE
------------------------------ ------------------------------ ---
EMP_ENO_IDX EMP NO

SQL
SQL> select * from emp where empno < 7400;

EMPNO ENAME JOB MGR HIREDATE SAL
COMM DEPTNO
---------- ---------- --------- ---------- --------- ----------
---------- ----------
7369 SMITH CLERK 7902 17-DEC-80
800 20

SQL
SQL> select index_name, table_name, used from v$object_usage;

INDEX_NAME TABLE_NAME USE
------------------------------ ------------------------------ ---
EMP_ENO_IDX EMP YES

SQL

Using the 'alter index <indexname> monitoring usage;' directive
Oracle will keep track of whether or not an index is actually used and
will do so until you issue an 'alter index <indexname> nomonitoring
usage;' command. A simple query of V$OBJECT_USAGE will reveal which
indexes are and are not used. After an 'alter index <indexname
nomonitoring usage;' directive is issued the collected data remains in
the V$OBJECT_USAGE view; it isn't removed for the objects in question
until another 'alter index ... monitoring usage;' command is called:

SQL> alter index emp_eno_idx nomonitoring usage;

Index altered.

SQL> select index_name, table_name,used from v$object_usage;

INDEX_NAME TABLE_NAME USE
------------------------------ ------------------------------ ---
EMP_ENO_IDX EMP YES

SQL


David Fitzjarrell
One small addendum to David's excellent response.

Sometimes Oracle uses the statistics collected for an index but does
not use the index itself.

Thus it is possible to drop an unused index and have performance
affected. If you see this happen then rebuild the index and note
what is happening for future reference.
--
Daniel A. Morgan
Oracle Ace Director & Instructor
University of Washington
damorgan@x.washington.edu (replace x with u to respond)
Puget Sound Oracle Users Group
www.psoug.org


Reply With Quote
  #7  
Old   
DA Morgan
 
Posts: n/a

Default Re: HowTo find out used (useful) and unused (usesless) indexes? - 04-17-2008 , 01:02 PM



fitzjarrell (AT) cox (DOT) net wrote:
Quote:
On Apr 17, 4:38 am, Andreas Mosmann <mosm... (AT) expires-30-04-2008 (DOT) news-
group.org> wrote:
Hi,

Is there a way to find out what indexes are used(useful)/unused(useless)
while the last few days/weeks?
If possible so tell me a way via data dictionary without using any
external tools.

Andreas Mosmann

--
wenn email, dann AndreasMosmann <bei> web <punkt> de

Let Oracle do that for you:

SQL> create index emp_eno_idx
2 on emp(empno);

Index created.

SQL
SQL> alter index emp_eno_idx monitoring usage;

Index altered.

SQL
SQL> select * from emp;

EMPNO ENAME JOB MGR HIREDATE SAL
COMM DEPTNO
---------- ---------- --------- ---------- --------- ----------
---------- ----------
7369 SMITH CLERK 7902 17-DEC-80
800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600
300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250
500 30
7566 JONES MANAGER 7839 02-APR-81
2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250
1400 30
7698 BLAKE MANAGER 7839 01-MAY-81
2850 30
7782 CLARK MANAGER 7839 09-JUN-81
2450 10
7788 SCOTT ANALYST 7566 09-DEC-82
3000 20
7839 KING PRESIDENT 17-NOV-81
5000 10
7844 TURNER SALESMAN 7698 08-SEP-81
1500 0 30
7876 ADAMS CLERK 7788 12-JAN-83
1100 20

EMPNO ENAME JOB MGR HIREDATE SAL
COMM DEPTNO
---------- ---------- --------- ---------- --------- ----------
---------- ----------
7900 JAMES CLERK 7698 03-DEC-81
950 30
7902 FORD ANALYST 7566 03-DEC-81
3000 20
7934 MILLER CLERK 7782 23-JAN-82
1300 10

14 rows selected.

SQL
SQL> select index_name, table_name, used from v$object_usage;

INDEX_NAME TABLE_NAME USE
------------------------------ ------------------------------ ---
EMP_ENO_IDX EMP NO

SQL
SQL> select * from emp where deptno = 30;

EMPNO ENAME JOB MGR HIREDATE SAL
COMM DEPTNO
---------- ---------- --------- ---------- --------- ----------
---------- ----------
7499 ALLEN SALESMAN 7698 20-FEB-81 1600
300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250
500 30
7654 MARTIN SALESMAN 7698 28-SEP-81 1250
1400 30
7698 BLAKE MANAGER 7839 01-MAY-81
2850 30
7844 TURNER SALESMAN 7698 08-SEP-81
1500 0 30
7900 JAMES CLERK 7698 03-DEC-81
950 30

6 rows selected.

SQL
SQL> select index_name, table_name, used from v$object_usage;

INDEX_NAME TABLE_NAME USE
------------------------------ ------------------------------ ---
EMP_ENO_IDX EMP NO

SQL
SQL> select * from emp where empno < 7400;

EMPNO ENAME JOB MGR HIREDATE SAL
COMM DEPTNO
---------- ---------- --------- ---------- --------- ----------
---------- ----------
7369 SMITH CLERK 7902 17-DEC-80
800 20

SQL
SQL> select index_name, table_name, used from v$object_usage;

INDEX_NAME TABLE_NAME USE
------------------------------ ------------------------------ ---
EMP_ENO_IDX EMP YES

SQL

Using the 'alter index <indexname> monitoring usage;' directive
Oracle will keep track of whether or not an index is actually used and
will do so until you issue an 'alter index <indexname> nomonitoring
usage;' command. A simple query of V$OBJECT_USAGE will reveal which
indexes are and are not used. After an 'alter index <indexname
nomonitoring usage;' directive is issued the collected data remains in
the V$OBJECT_USAGE view; it isn't removed for the objects in question
until another 'alter index ... monitoring usage;' command is called:

SQL> alter index emp_eno_idx nomonitoring usage;

Index altered.

SQL> select index_name, table_name,used from v$object_usage;

INDEX_NAME TABLE_NAME USE
------------------------------ ------------------------------ ---
EMP_ENO_IDX EMP YES

SQL


David Fitzjarrell
One small addendum to David's excellent response.

Sometimes Oracle uses the statistics collected for an index but does
not use the index itself.

Thus it is possible to drop an unused index and have performance
affected. If you see this happen then rebuild the index and note
what is happening for future reference.
--
Daniel A. Morgan
Oracle Ace Director & Instructor
University of Washington
damorgan@x.washington.edu (replace x with u to respond)
Puget Sound Oracle Users Group
www.psoug.org


Reply With Quote
  #8  
Old   
DA Morgan
 
Posts: n/a

Default Re: HowTo find out used (useful) and unused (usesless) indexes? - 04-17-2008 , 01:02 PM



fitzjarrell (AT) cox (DOT) net wrote:
Quote:
On Apr 17, 4:38 am, Andreas Mosmann <mosm... (AT) expires-30-04-2008 (DOT) news-
group.org> wrote:
Hi,

Is there a way to find out what indexes are used(useful)/unused(useless)
while the last few days/weeks?
If possible so tell me a way via data dictionary without using any
external tools.

Andreas Mosmann

--
wenn email, dann AndreasMosmann <bei> web <punkt> de

Let Oracle do that for you:

SQL> create index emp_eno_idx
2 on emp(empno);

Index created.

SQL
SQL> alter index emp_eno_idx monitoring usage;

Index altered.

SQL
SQL> select * from emp;

EMPNO ENAME JOB MGR HIREDATE SAL
COMM DEPTNO
---------- ---------- --------- ---------- --------- ----------
---------- ----------
7369 SMITH CLERK 7902 17-DEC-80
800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600
300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250
500 30
7566 JONES MANAGER 7839 02-APR-81
2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250
1400 30
7698 BLAKE MANAGER 7839 01-MAY-81
2850 30
7782 CLARK MANAGER 7839 09-JUN-81
2450 10
7788 SCOTT ANALYST 7566 09-DEC-82
3000 20
7839 KING PRESIDENT 17-NOV-81
5000 10
7844 TURNER SALESMAN 7698 08-SEP-81
1500 0 30
7876 ADAMS CLERK 7788 12-JAN-83
1100 20

EMPNO ENAME JOB MGR HIREDATE SAL
COMM DEPTNO
---------- ---------- --------- ---------- --------- ----------
---------- ----------
7900 JAMES CLERK 7698 03-DEC-81
950 30
7902 FORD ANALYST 7566 03-DEC-81
3000 20
7934 MILLER CLERK 7782 23-JAN-82
1300 10

14 rows selected.

SQL
SQL> select index_name, table_name, used from v$object_usage;

INDEX_NAME TABLE_NAME USE
------------------------------ ------------------------------ ---
EMP_ENO_IDX EMP NO

SQL
SQL> select * from emp where deptno = 30;

EMPNO ENAME JOB MGR HIREDATE SAL
COMM DEPTNO
---------- ---------- --------- ---------- --------- ----------
---------- ----------
7499 ALLEN SALESMAN 7698 20-FEB-81 1600
300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250
500 30
7654 MARTIN SALESMAN 7698 28-SEP-81 1250
1400 30
7698 BLAKE MANAGER 7839 01-MAY-81
2850 30
7844 TURNER SALESMAN 7698 08-SEP-81
1500 0 30
7900 JAMES CLERK 7698 03-DEC-81
950 30

6 rows selected.

SQL
SQL> select index_name, table_name, used from v$object_usage;

INDEX_NAME TABLE_NAME USE
------------------------------ ------------------------------ ---
EMP_ENO_IDX EMP NO

SQL
SQL> select * from emp where empno < 7400;

EMPNO ENAME JOB MGR HIREDATE SAL
COMM DEPTNO
---------- ---------- --------- ---------- --------- ----------
---------- ----------
7369 SMITH CLERK 7902 17-DEC-80
800 20

SQL
SQL> select index_name, table_name, used from v$object_usage;

INDEX_NAME TABLE_NAME USE
------------------------------ ------------------------------ ---
EMP_ENO_IDX EMP YES

SQL

Using the 'alter index <indexname> monitoring usage;' directive
Oracle will keep track of whether or not an index is actually used and
will do so until you issue an 'alter index <indexname> nomonitoring
usage;' command. A simple query of V$OBJECT_USAGE will reveal which
indexes are and are not used. After an 'alter index <indexname
nomonitoring usage;' directive is issued the collected data remains in
the V$OBJECT_USAGE view; it isn't removed for the objects in question
until another 'alter index ... monitoring usage;' command is called:

SQL> alter index emp_eno_idx nomonitoring usage;

Index altered.

SQL> select index_name, table_name,used from v$object_usage;

INDEX_NAME TABLE_NAME USE
------------------------------ ------------------------------ ---
EMP_ENO_IDX EMP YES

SQL


David Fitzjarrell
One small addendum to David's excellent response.

Sometimes Oracle uses the statistics collected for an index but does
not use the index itself.

Thus it is possible to drop an unused index and have performance
affected. If you see this happen then rebuild the index and note
what is happening for future reference.
--
Daniel A. Morgan
Oracle Ace Director & Instructor
University of Washington
damorgan@x.washington.edu (replace x with u to respond)
Puget Sound Oracle Users Group
www.psoug.org


Reply With Quote
  #9  
Old   
DA Morgan
 
Posts: n/a

Default Re: HowTo find out used (useful) and unused (usesless) indexes? - 04-17-2008 , 01:02 PM



fitzjarrell (AT) cox (DOT) net wrote:
Quote:
On Apr 17, 4:38 am, Andreas Mosmann <mosm... (AT) expires-30-04-2008 (DOT) news-
group.org> wrote:
Hi,

Is there a way to find out what indexes are used(useful)/unused(useless)
while the last few days/weeks?
If possible so tell me a way via data dictionary without using any
external tools.

Andreas Mosmann

--
wenn email, dann AndreasMosmann <bei> web <punkt> de

Let Oracle do that for you:

SQL> create index emp_eno_idx
2 on emp(empno);

Index created.

SQL
SQL> alter index emp_eno_idx monitoring usage;

Index altered.

SQL
SQL> select * from emp;

EMPNO ENAME JOB MGR HIREDATE SAL
COMM DEPTNO
---------- ---------- --------- ---------- --------- ----------
---------- ----------
7369 SMITH CLERK 7902 17-DEC-80
800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600
300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250
500 30
7566 JONES MANAGER 7839 02-APR-81
2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250
1400 30
7698 BLAKE MANAGER 7839 01-MAY-81
2850 30
7782 CLARK MANAGER 7839 09-JUN-81
2450 10
7788 SCOTT ANALYST 7566 09-DEC-82
3000 20
7839 KING PRESIDENT 17-NOV-81
5000 10
7844 TURNER SALESMAN 7698 08-SEP-81
1500 0 30
7876 ADAMS CLERK 7788 12-JAN-83
1100 20

EMPNO ENAME JOB MGR HIREDATE SAL
COMM DEPTNO
---------- ---------- --------- ---------- --------- ----------
---------- ----------
7900 JAMES CLERK 7698 03-DEC-81
950 30
7902 FORD ANALYST 7566 03-DEC-81
3000 20
7934 MILLER CLERK 7782 23-JAN-82
1300 10

14 rows selected.

SQL
SQL> select index_name, table_name, used from v$object_usage;

INDEX_NAME TABLE_NAME USE
------------------------------ ------------------------------ ---
EMP_ENO_IDX EMP NO

SQL
SQL> select * from emp where deptno = 30;

EMPNO ENAME JOB MGR HIREDATE SAL
COMM DEPTNO
---------- ---------- --------- ---------- --------- ----------
---------- ----------
7499 ALLEN SALESMAN 7698 20-FEB-81 1600
300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250
500 30
7654 MARTIN SALESMAN 7698 28-SEP-81 1250
1400 30
7698 BLAKE MANAGER 7839 01-MAY-81
2850 30
7844 TURNER SALESMAN 7698 08-SEP-81
1500 0 30
7900 JAMES CLERK 7698 03-DEC-81
950 30

6 rows selected.

SQL
SQL> select index_name, table_name, used from v$object_usage;

INDEX_NAME TABLE_NAME USE
------------------------------ ------------------------------ ---
EMP_ENO_IDX EMP NO

SQL
SQL> select * from emp where empno < 7400;

EMPNO ENAME JOB MGR HIREDATE SAL
COMM DEPTNO
---------- ---------- --------- ---------- --------- ----------
---------- ----------
7369 SMITH CLERK 7902 17-DEC-80
800 20

SQL
SQL> select index_name, table_name, used from v$object_usage;

INDEX_NAME TABLE_NAME USE
------------------------------ ------------------------------ ---
EMP_ENO_IDX EMP YES

SQL

Using the 'alter index <indexname> monitoring usage;' directive
Oracle will keep track of whether or not an index is actually used and
will do so until you issue an 'alter index <indexname> nomonitoring
usage;' command. A simple query of V$OBJECT_USAGE will reveal which
indexes are and are not used. After an 'alter index <indexname
nomonitoring usage;' directive is issued the collected data remains in
the V$OBJECT_USAGE view; it isn't removed for the objects in question
until another 'alter index ... monitoring usage;' command is called:

SQL> alter index emp_eno_idx nomonitoring usage;

Index altered.

SQL> select index_name, table_name,used from v$object_usage;

INDEX_NAME TABLE_NAME USE
------------------------------ ------------------------------ ---
EMP_ENO_IDX EMP YES

SQL


David Fitzjarrell
One small addendum to David's excellent response.

Sometimes Oracle uses the statistics collected for an index but does
not use the index itself.

Thus it is possible to drop an unused index and have performance
affected. If you see this happen then rebuild the index and note
what is happening for future reference.
--
Daniel A. Morgan
Oracle Ace Director & Instructor
University of Washington
damorgan@x.washington.edu (replace x with u to respond)
Puget Sound Oracle Users Group
www.psoug.org


Reply With Quote
  #10  
Old   
Andreas Mosmann
 
Posts: n/a

Default Re: HowTo find out used (useful) and unused (usesless) indexes? - 04-18-2008 , 05:29 AM



Thank both of you,

I will try it out.
Is there also a way to determine what index is still needed/useful for a
special query?

Andreas Mosmann

--
wenn email, dann AndreasMosmann <bei> web <punkt> de

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.