Skip to content
Advertisement

How can I see the contents of an Oracle index?

Is it possible to have a look at what is there inside an index using SQL*Plus?

If I have a table like this:

Table A
------------------------
rowid  |  id   name
123    |  1    A
124    |  4    G
125    |  2    R
126    |  3    P

where id is the primary key, I expect the index to be something like this

index on A.id
-------------
id  rowid
1   123
2   125
3   126
4   124

Is there some SQL query using which I can actually see the contents of an index?

Advertisement

Answer

There’s not a simple query – you can dump table or index blocks to trace files, but you have to identify the block you’re interested in. Dion Cho has an example of how you can process this block dump with SQL, but it’s not for the faint of heart.

However, you can do this:

select /* index_ffs (a [name of index]) */
       id, rowid 
  from a
 where id is not null
 order by id, rowid;

Oracle doesn’t write index entries where all of the values being indexed are null, so if id is nullable, we need to filter those out. The index_ffs hint forces Oracle to satisfy the query reading the index blocks, not the data blocks. This “solution” doesn’t show the data which would be in root or branch blocks, whereas a block dump can.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement