Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Database Server Software > Oracle Database > Oracle Miscellaneous

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-17-2008, 04:09 PM
Andreas Mosmann
 
Posts: n/a
Default HowTo find out used (useful) and unused (usesless) indexes?

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-17-2008, 04:09 PM
fitzjarrell@cox.net
 
Posts: n/a
Default Re: HowTo find out used (useful) and unused (usesless) indexes?

On Apr 17, 4:38*am, Andreas Mosmann <mosm...@expires-30-04-2008.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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-17-2008, 05:23 PM
DA Morgan
 
Posts: n/a
Default Re: HowTo find out used (useful) and unused (usesless) indexes?

fitzjarrell@cox.net wrote:
> On Apr 17, 4:38 am, Andreas Mosmann <mosm...@expires-30-04-2008.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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-19-2008, 06:20 AM
Andreas Mosmann
 
Posts: n/a
Default Re: HowTo find out used (useful) and unused (usesless) indexes?

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-19-2008, 06:20 AM
joel garry
 
Posts: n/a
Default Re: HowTo find out used (useful) and unused (usesless) indexes?

On Apr 18, 2:29*am, Andreas Mosmann <mosm...@expires-30-04-2008.news-
group.org> wrote:
> 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


I do believe that is the downside of deleting indices based on usage.
It only shows what's been used during the observation. That implies a
bad assumption that the usage is completely stable. To me, this seems
worse than just dropping an index and seeing who screams, since when
there is a problem in the future, you have to go through an entire
performance tuning workup because the linkage to the act of dropping
the index is obscured. Maybe I'm missing the concept. What about an
index that would be used when you pass some tipping point or boundary
condition or upgrade or change a session parameter?

I just don't get it. This looks like a feature capriciously useful
for poorly implemented systems.

jg
--
@home.com is bogus.
22 innings of baseball. Yikes!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-19-2008, 06:20 AM
Malcolm Dew-Jones
 
Posts: n/a
Default Re: HowTo find out used (useful) and unused (usesless) indexes?

joel garry (joel-garry@home.com) wrote:
: On Apr 18, 2:29=A0am, Andreas Mosmann <mosm...@expires-30-04-2008.news-
: group.org> wrote:
: > 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

: I do believe that is the downside of deleting indices based on usage.
: It only shows what's been used during the observation. That implies a
: bad assumption that the usage is completely stable. To me, this seems
: worse than just dropping an index and seeing who screams, since when
: there is a problem in the future, you have to go through an entire
: performance tuning workup because the linkage to the act of dropping
: the index is obscured. Maybe I'm missing the concept. What about an
: index that would be used when you pass some tipping point or boundary
: condition or upgrade or change a session parameter?

You can disable an index. That way the definition exists but the index is
never used or maintained (i.e. no overhead). If you decide it is needed
you simply enable it.

"when you pass some tipping point"

If an index is enabled then presumably it will only be used when the CBO
decides it is useful for a query.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-19-2008, 02:49 PM
Shakespeare
 
Posts: n/a
Default Re: HowTo find out used (useful) and unused (usesless) indexes?


"Malcolm Dew-Jones" <yf110@vtn1.victoria.tc.ca> schreef in bericht
news:48091a22$1@news.victoria.tc.ca...
> joel garry (joel-garry@home.com) wrote:
> : On Apr 18, 2:29=A0am, Andreas Mosmann <mosm...@expires-30-04-2008.news-
> : group.org> wrote:
> : > 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
>
> : I do believe that is the downside of deleting indices based on usage.
> : It only shows what's been used during the observation. That implies a
> : bad assumption that the usage is completely stable. To me, this seems
> : worse than just dropping an index and seeing who screams, since when
> : there is a problem in the future, you have to go through an entire
> : performance tuning workup because the linkage to the act of dropping
> : the index is obscured. Maybe I'm missing the concept. What about an
> : index that would be used when you pass some tipping point or boundary
> : condition or upgrade or change a session parameter?
>
> You can disable an index. That way the definition exists but the index is
> never used or maintained (i.e. no overhead). If you decide it is needed
> you simply enable it.
>
> "when you pass some tipping point"
>
> If an index is enabled then presumably it will only be used when the CBO
> decides it is useful for a query.
>


But an index may become useful over time, true?

Shakespeare


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-19-2008, 05:41 PM
DA Morgan
 
Posts: n/a
Default Re: HowTo find out used (useful) and unused (usesless) indexes?

joel garry wrote:

> I just don't get it. This looks like a feature capriciously useful
> for poorly implemented systems.
>
> jg


In many cases you are correct. But that does not decrease the value
of the tool. It is just that the tool, like all tools, requires some
application of a synapse or two.
--
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 04-19-2008, 05:41 PM
DA Morgan
 
Posts: n/a
Default Re: HowTo find out used (useful) and unused (usesless) indexes?

Shakespeare wrote:

> But an index may become useful over time, true?
>
> Shakespeare


On that basis alone one could justify putting an index on every
column of every table so I will respectfully disagree unless you
write a very broad definition of "may."

You need to understand your data and how it is being accessed.
The extra overhead of an unused index is not value added.

My recommendation would be to use the DBMS_STATS.SET.... procedures
to see how queries will react to the expected future growth of both
tables and indexes.
--
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 04-20-2008, 02:49 PM
Shakespeare
 
Posts: n/a
Default Re: HowTo find out used (useful) and unused (usesless) indexes?


"DA Morgan" <damorgan@psoug.org> schreef in bericht
news:1208624947.696580@bubbleator.drizzle.com...
> Shakespeare wrote:
>
>> But an index may become useful over time, true?
>>
>> Shakespeare

>
> On that basis alone one could justify putting an index on every
> column of every table so I will respectfully disagree unless you
> write a very broad definition of "may."
>
> You need to understand your data and how it is being accessed.
> The extra overhead of an unused index is not value added.
>
> My recommendation would be to use the DBMS_STATS.SET.... procedures
> to see how queries will react to the expected future growth of both
> tables and indexes.
> --
> 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


I was aiming at data with for example a 'year' column. This column could be
indexed by design, but in the first year (all records same value) this index
is not useful and won't be used. But on the first entry in the second year
it is useful to find entries of that year and so on. A script to remove or
disable unused indexes would remove/disable this index in the first year.

Shakespeare


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
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
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:31 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
UnixAdminTalk.com

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460