Query to find indexes bigger in size than tables sizes

Team -
I am looking for a query to find the list of indexes in a schema or in a entire database which are bigger in size than the respective tables size .
Db version : Any
Thanks
Venkat

results are the same in my case
  1  select di.owner, di.index_name, di.table_name
  2  from dba_indexes di, dba_segments ds
  3  where ds.blocks > (select dt.blocks
  4               from dba_tables dt
  5               where di.owner = dt.owner
  6               and  di.leaf_blocks > dt.blocks
  7               and   di.table_name = dt.table_name)
  8*  and ds.segment_name = di.index_name
SQL> /
OWNER                      INDEX_NAME                TABLE_NAME
SYS                      I_CON1                     CON$
SYS                      I_OBJAUTH1                OBJAUTH$
SYS                      I_OBJAUTH2                OBJAUTH$
SYS                      I_PROCEDUREINFO1            PROCEDUREINFO$
SYS                      I_DEPENDENCY1                DEPENDENCY$
SYS                      I_ACCESS1                ACCESS$
SYS                      I_OID1                     OID$
SYS                      I_PROCEDUREC$                PROCEDUREC$
SYS                      I_PROCEDUREPLSQL$           PROCEDUREPLSQL$
SYS                      I_WARNING_SETTINGS           WARNING_SETTINGS$
SYS                      I_WRI$_OPTSTAT_TAB_OBJ#_ST     WRI$_OPTSTAT_TAB_HISTORY
SYS                      I_WRI$_OPTSTAT_H_OBJ#_ICOL#_ST WRI$_OPTSTAT_HISTGRM_HISTORY
SYS                      WRH$_PGASTAT_PK                WRH$_PGASTAT
SYSMAN                      MGMT_STRING_METRIC_HISTORY_PK  MGMT_STRING_METRIC_HISTORY
DBADMIN                  TSTNDX                     TSTTBL
15 rows selected

Similar Messages

  • Why Index size is bigger than table size?

    Dear All,
    I found in my database my tables sizes is coming around 30TB (All Tables in Database). and my index size for the same is 60TB. This is data ware housing environment.
    How the index size and table size are differing?
    Why they are differing? why index size is bigger than table size?
    How to manage the size?
    Please give me clear explanation and required information on the above.
    Regards
    Suresh

    There are many reasons why the total space allocated indexes could be larger than the total space allocated to tables. Sometimes it's a mark of good design, sometimes it indicates a problem. In your position your first move is to spend as little time as possible in deciding whether your high-level summary is indicative of a problem, so you need to look at a little more detail.
    As someone else pointed out - are you looking at the sizes because you are running out of space, or because you have a perceived performance problem. If not, then your question is one of curiosity.
    If it's about performance then you should be looking for code (either through statspack/AWR or sql_trace) that is performing badly and use the analysis of that code to help you identify suspect indexes.
    If it's about space, then you need to do some simple investigations aimed at finding a few indexes that can be "shrunk" or dropped. Pointers for this are:
    select
            table_owner, table_name, count(*)
    from
            dba_indexes
    group by
            table_owner, table_name
    having
            count(*) > 2   -- adjust to keep the output short
    order by
            count(*) desc;This tells you which tables have the most indexes - check the sizes of the tables and indexes and then check the index definitions for the larger tables with lots of indexes.
    Second quick check - join dba_tables to dba_indexes by table_name, and report the table blocks and index leaf blocks in desending order of leaf block count. Look for indexes which are very big, and also bigger than their underlying tables. There are special cases (and bugs) that can cause indexes to be much bigger than they need to be ... this report may identify a couple of anomalies that could benefit from an emergency fix followed (possibly) by a strategic fix.
    Regards
    Jonathan Lewis

  • Index size greater than table size

    HI ,
    While checking the large segments , I came to know that index HZ_PARAM_TAB_N1 is larger than table HZ_PARAM_TAB . I think it's highly fragmented and requires defragmentation . Need your suggestion on the same that how can I collect more information on the same . Providing you more information .
    1.
    select sum(bytes)/1024/1024/1024,segment_name from dba_segments group by segment_name having sum(bytes)/1024/1024/1024 > 1 order by 1 desc;
    SUM(BYTES)/1024/1024/1024 SEGMENT_NAME
    81.2941895 HZ_PARAM_TAB_N1
    72.1064453 SYS_LOB0000066009C00004$$
    52.7703857 HZ_PARAM_TAB
    2. Index code
    <pre>
    COLUMN_NAME COLUMN_POSITION
    ITEM_KEY 1
    PARAM_NAME 2
    </pre>
    Regards
    Rahul

    Hi ,
    Thanks . I know that rebuild will defragment it . But as I'm on my new site , I was looking for some more supporting information before drafting the mail on the same that it requires re org activity .It's not possible for an index to have the size greater than tables as it contains only 2 columns values + rowid . Whereas tables contains 6 columns .
    <pre>
    Name      Datatype      Length      Mandatory      Comments
    ITEM_KEY      VARCHAR2      (240)      Yes      Unique identifier for the event raised
    PARAM_NAME      VARCHAR2      (2000)      Yes      Name of the parameter
    PARAM_CHAR      VARCHAR2      (4000)      
         Value of the parameter only if its data type is VARCHAR2.
    PARAM_NUM      NUMBER      
         Value of the parameter only if its data type is NUM.
    PARAM_DATE      DATE      
         Value of the parameter only if its data type is DATE.
    PARAM_INDICATOR      VARCHAR2      (3)      Yes      Indicates if the parameter contains existing, new or >replacement values. OLD values currently exist. NEW values create initial values or replace existing values.</pre>
    Regds
    Rahul

  • Index size increases than table size

    Hi All,
    Let me know what are the possible reasons for index size greater than the table size and in some cases index size smaller than table size . ASAP
    Thanks in advance
    sherief

    hi,
    The size of a index depends how inserts and deletes occur.
    With sequential indexes, when records are deleted randomly the space will not be reused as all inserts are in the leading leaf block.
    When all the records in a leaf blocks have been deleted then leaf block is freed (put on index freelist) for reuse reducing the overall percentage of free space.
    This means that if you are deleting aged sequence records at the same rate as you are inserting, then the number of leaf blocks will stay approx constant with a constant low percentage of free space. In this case it is most probably hardly ever worth rebuilding the index.
    With records being deleted randomly then, the inefficiency of the index depends on how the index is used.
    If numerous full index (or range) scans are being done then it should be re-built to reduce the leaf blocks read. This should be done before it significantly affects the performance of the system.
    If index access’s are being done then it only needs to be rebuilt to stop the branch depth increasing or to recover the unused space
    here is a exemple how index size can become larger than table size:
    Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.3.0
    Connected as admin
    SQL> create table rich as select rownum c1,'Verde' c2 from all_objects;
    Table created
    SQL> create index rich_i on rich(c1);
    Index created
    SQL> select segment_type,bytes,blocks,extents from user_segments where segment_name like 'RICH%';
    SEGMENT_TYPE BYTES BLOCKS EXTENTS
    TABLE 1179648 144 9
    INDEX 1179648 144 9
    SQL> delete from rich where mod(c1,2)=0;
    29475 rows deleted
    SQL> commit;
    Commit complete
    SQL> select segment_type,bytes,blocks,extents from user_segments where segment_name like 'RICH%';
    SEGMENT_TYPE BYTES BLOCKS EXTENTS
    TABLE 1179648 144 9
    INDEX 1179648 144 9
    SQL> insert into rich select rownum+100000, 'qq' from all_objects;
    58952 rows inserted
    SQL> commit;
    Commit complete
    SQL> select segment_type,bytes,blocks,extents from user_segments where segment_name like 'RICH%';
    SEGMENT_TYPE BYTES BLOCKS EXTENTS
    TABLE 1703936 208 13
    INDEX 2097152 256 16
    SQL> insert into rich select rownum+200000, 'aa' from all_objects;
    58952 rows inserted
    SQL> select segment_type,bytes,blocks,extents from user_segments where segment_name like 'RICH%';
    SEGMENT_TYPE BYTES BLOCKS EXTENTS
    TABLE 2752512 336 21
    INDEX 3014656 368 23
    SQL> delete from rich where mod(c1,2)=0;
    58952 rows deleted
    SQL> commit;
    Commit complete
    SQL> select segment_type,bytes,blocks,extents from user_segments where segment_name like 'RICH%';
    SEGMENT_TYPE BYTES BLOCKS EXTENTS
    TABLE 2752512 336 21
    INDEX 3014656 368 23
    SQL> insert into rich select rownum+300000, 'hh' from all_objects;
    58952 rows inserted
    SQL> commit;
    Commit complete
    SQL> select segment_type,bytes,blocks,extents from user_segments where segment_name like 'RICH%';
    SEGMENT_TYPE BYTES BLOCKS EXTENTS
    TABLE 3014656 368 23
    INDEX 4063232 496 31
    SQL> alter index rich_i rebuild;
    Index altered
    SQL> select segment_type,bytes,blocks,extents from user_segments where segment_name like 'RICH%';
    SEGMENT_TYPE BYTES BLOCKS EXTENTS
    TABLE 3014656 368 23
    INDEX 2752512 336 21
    SQL>

  • Query to find all the view name and their size in GB

    Hi,
    What is the query to find all the view name and their size in GB.I am aware of joining all_views and user_segments but this is not serving the purpose.is there any table i need to join to get the desired result
    Thanks

    You could of course be thinking of views as they are stored in other RDBMS' as some of them actually create the view as a table on the database with a copy of the data in it and maintain that data as the base tables are updated.
    As already mentioned, Oracle just stores the SQL of the View and executes that SQL when the view is queried.
    Alternatively, Oracle also has "materialized views" which are created as snapshots of the data and will have a size. This data is updated (refreshed) based on the parameters used when creating the materialized view which means that it will either be, commonly, when a commit is issued or when a refresh is explicitly requested (refresh on demand).

  • Do we need any precautions while creating index in MV rather than tables?

    Do we need any precautions while creating index in MV rather than tables?
    Could you please someone tell me is there we need specifically follows while creation on MVs

    MV is a seprate object. You might need to create an indexes on MViews based on how you are accessing that MV. You need to take a same preacutions what you take to create an index on the table,
    I do not know what you mean by your 2nd questions. Read this for better understanding
    http://docs.oracle.com/cd/B28359_01/server.111/b28326/repmview.htm

  • DB Size and TAble size Estimation

    Hi all
    Please tell mehelp link or spredsheet to estimation DB Size and TAble size Estimate
    Regards

    Please tell mehelp link or spredsheet to estimation
    DB Size and TAble size EstimateWhat size are you looking for?
    1) Estimate of physical disk space used by an existing database schema?
    2) Estimate of how much physical disk space will be required for some arbitrary data in order to create a new database?
    Something else?
    You need to be clear with your requirements

  • SQL Query to find out similar names in two tables

    Hi,
    I want to write a query which will return the records by matching the two table with the similar name.
    that is I have two tables table1 and table2, and in table1 the column1 is having data like
    ABC INC
    The international Company
    and in the table2 has the column1 which has the data like
    ABC Corp
    The Financials Corporation
    So as per the requirement now my select query should return 1 row as ABC INC and ABC Corp are similer.
    and both the tables have around 50,000 reords so I cannot just take the first word by using substring and tryto match both, this will work only for names like ABC INC and ABC Corp but it will not return the names like
    "Instruments International Company" and "International Instruments Company"
    Please can any one help me?
    Regards,
    Chanda

    I don't have access to text here so I can't check.Almost. Better to use OR than AND:
    SQL> CREATE TABLE t (ID INTEGER, text VARCHAR2(2000))
      2  /
    Table created.
    SQL> INSERT INTO t
      2       VALUES (1, 'The international Company')
      3  /
    1 row created.
    SQL> INSERT INTO t
      2       VALUES (2, 'ABC INC')
      3  /
    1 row created.
    SQL> CREATE INDEX t_txt_idx ON t
      2  (text)
      3  INDEXTYPE IS ctxsys.CONTEXT
      4  /
    Index created.
    SQL> SELECT *
      2    FROM t
      3   WHERE contains (text,
      4                   REPLACE ('International Instruments Company', ' ', ' & ')
      5                  ) > 0
      6  /
    no rows selected
    SQL> SELECT *
      2    FROM t
      3   WHERE contains (text,
      4                   REPLACE ('International Instruments Company', ' ', ' | ')
      5                  ) > 0
      6  /
    ID TEXT
      1 The international Company
    BUT than also :(
    SQL> SELECT *
      2    FROM t
      3   WHERE contains (text,
      4                   REPLACE ('Company Instruments', ' ', ' | ')
      5                  ) > 0
      6  /
    ID TEXT
      1 The international Company

  • Index size and table size

    Hi,
    I have 3 user tables spaces that the os is reporting as 33 GB, 7 GB, and 5 GB.
    Just from a gut feeling I know we don't have that much data in our tables but I can't seem to find out where the space is allocated. I checked the internet and found various queries.
    The first one (found at ask Uncle Tom), breaks the space for table by table:
    select table_name,blocks, empty_blocks,
    avg_space as avg_space_free_K, num_freelist_blocks, blocks + empty_blocks + num_freelist_blocks as
    total_blocks_allocated,
    ((blocks + empty_blocks + num_freelist_blocks) * 8192) /1048576
    from dba_tables
    order by ((blocks + empty_blocks + num_freelist_blocks) * 8192) /1048576 desc
    This gives a total of just over 8096 MB for all tables on all table spaces.
    I then found a query on this forum.
    SELECT
    SUM(BYTES) / 1048576 as mb_allocated
    FROM
    dba_SEGMENTS
    WHERE
    SEGMENT_TYPE = 'TABLE'
    This gives me around 38,372 MB.
    What is the difference between query 1 and 2?. Can I modifiy query 2 to break down the space allocated by table?
    Thanks in advance.
    Regards,
    Ned

    Tom's query is using information gathered for the cost-based optimizer (CBO). If you have not gathered sttaistics on the tables recently, those values may be way off.
    If you want to see a breakdown of the space used by different objects, you could use something like
    select owner, segment_name, sum(bytes)/1024/1024 MB
      from dba_segments
    where owner NOT IN ('SYS', 'SYSTEM')
    group by owner, segment_nameFrom the operating system, however, you would be looking at the size of the data files allocated to the tablespace. If you allocate 10 GB to the tablespace but only have 1 GB of space from that tablespace allocated to actual objects, you still have 10 GB allocated to Oracle at the operating system level.
    select tablespace_name, sum(bytes)/1024/1024 "MB"
      from dba_data_files
    group by tablespace_nameshould match the values reported at the operating system level.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • How to find index of row in dynamic table?

    Our form has a table to which the user can add rows.  We want to be able to edit the custom help text of each field in the row to add the row number for accessibility.  But need the index number of the row to reference the row of the fields. And we can't figure out how to get it.
    We have tried both the field initialize and field layout events, but our property for index is not being recognized. For the initialize event of one of the fields in the row, we wrote this code:
    xfa.host.messageBox("We are in the initialize event for this field.");
    var thisRow = this.parent.index;
    xfa.host.messageBox(thisRow);
    We have the table set up with 8 intial rows. The first message pops up 8 times, but the second doesn't appear at all.  How can we get the number of the row we are addressing?
    Thanks.

    Not sure what's going on there but messageBox() is throwing an error for some reason (use CTRL-J in Acrobat to open the Console):
    GeneralError: Operation failed.
    XFAObject.messageBox:3:XFA:form1[0]:subMain[0]:Table1[0]:Row1[1]:TextField1[0]:ready
    Argument mismatch in property or function argument
    It works if you add some text:
    xfa.host.messageBox("Row Number: " + thisRow);
    app.alert() works: app.alert(thisRow);
    And console.println() works (less annoying for testing than popups - open the Console window to see the results):
    console.println(thisRow);
    Ah, just figured it out - messageBox() doesn't seem to like a number first, it's expecting a string. The following works with your original script:
    var thisRow = this.parent.index.toString();

  • Recursive query for finding parents and children against two tables

    Hi I have two tables where the data is stored hierarchially.
    I have found using connect_by, level and other oracle functions doing its job when the data is in one table.
    Can I traverse against two tables by using the same oracle functions.
    My Table A can go 2 levels deep in my hierarchy and level 3 and so forth has to be done against a different table.
    Appreciate your insight..
    Thanks in advance

    The number of levels that I can traverse in the first table is dynamic (sometimes 2 levels and sometimes 3 levels and actually no level limit) and then has to dynamically start looking at second table for finding any more levels in the other table.
    I was able to implement them seperately and union them.
    I was more looking for a comprehensive solution to reduce the number of lines that I have to maintain...
    Thanks in advance
    Edited by: user566193 on Jan 15, 2010 1:58 PM

  • Query to find 1:N relation from a table

    Hi,
    I have a table where Material# & Item# are stored. Now Material# & Item# are related in 1:N.
    e.g. (data)
    MM# ITM# ..... <other attributes>
    M1 I1 ..... <data for other attributes>
    M1 I1 ..... <data for other attributes>
    M1 I2 ..... <data for other attributes>
    M2 I3 ..... <data for other attributes>
    M3 I4 ..... <data for other attributes>
    M3 I5 ..... <data for other attributes>
    Now by somehow writing a single select query can I get the only one-2-many data. So that a person who is not aware of this relationship, will be easily able to identify.
    e.g.
    M1 I1
    M1 I2
    M3 I4
    M3 I5
    I am able to write the following query (please ignore the qualify keyword. I have used it because I have written this in teradata).
    select subqry.itm_cd,subqry.mm_key
    from
    select mm_key,itm_cd,row_number() over (partition by mm_key,itm_cd order by mm_key) rn
    from <my_table>
    qualify rn = 1
    ) subqry
    qualify row_number() over (partition by subqry.itm_cd order by subqry.itm_cd) > 1
    order by subqry.itm_cd
    This gives the output like :
    M1 I2
    M3 I4
    But I want all the two occurrences of M1 and M3.
    Regards,
    Koushik Chandra

    Very simple... group by mm#,itm#
    SQL> create table test(mm# varchar2(3),itm# varchar2(2));
    Table created.
    SQL> insert into test values ('M1','I1');
    1 row created.
    SQL> insert into test values ('M1','I1');
    1 row created.
    SQL> insert into test values ('M1','I2');
    1 row created.
    SQL> insert into test values ('M2','I3');
    1 row created.
    SQL> insert into test values ('M3','I4');
    1 row created.
    SQL> insert into test values ('M3','I5');
    1 row created.
    SQL> select * from test group by mm#,itm#;
    MM# IT
    M2  I3
    M3  I5
    M3  I4
    M1  I1
    M1  I2
    SQL> select * from test group by mm#,itm# order by 1;
    MM# IT
    M1  I1
    M1  I2
    M2  I3
    M3  I4
    M3  I5
    SQL>HTH
    Girish Sharma

  • Index size greated then Table Size

    Hi all,
    We are running BI7.0 in our environment.
    One of the tables' index size is much greated than the table itself. The Details are listed below:
    Table Name: RSBERRORLOG
    Total Table Size: 141,795,392  KB
    Total Index Size: 299,300,576 KB
    Index:
    F5: Index Size / Allocated Size: 50%
    Is there any reason that the index should grow more than Table? If so, would Reorganizing index help and if this can be controlled?
    Please letme know on this as I am not very clear on DB much.
    Thanks and Regards,
    Raghavan

    Hi Hari
    Its basically degenerated index.  You can follow the below steps
    1. Delete some entries from RSBERRORLOG.
    BI database growing at 1 Gb per day while no data update on ECC
    2. Re-organize this table from BRSPACE . Now the size of the table would be very less.  I do not remember if this table has a LONG RAW field ( in that case export /import) of this table would be required.   ---Basis job
    3. Delete and recreate Index on this table
    You will gain lot of space.
    I assumed you are on Oracle.
    More information on reoganization  is LINK: [Reorg|TABLE SPACE REORGANIZATION !! QUICK EXPERT INPUTS;
    Anindya
    Regards
    Anindya

  • Specified a smaller partition size than the filesystem, using parted

    I felt so sorry to make such a stupid mistake:
    I shrinked the filesystem size with resize2fs, in the next step, I used parted to resize the corresponding partition. But unfortunately, because parted treated 1GB as 1000MB, which is quite different from the Linux system, that made me specified a smaller partition size than filesystem size. As you can predict, this ruined the filesystem. How can I restore my files?
    Last edited by victl (2014-12-07 17:06:55)

    victl wrote:
    ackt1c wrote:Boot Live CD and mount the partition, copy necessities.
    Thank you, I'll try. But is there any method to avoid data lose?
    Backups.
    Not a Sysadmin issue, moving to NC...

  • What index is suitable for a table with no unique columns and no primary key

    alpha
    beta 
    gamma
    col1
    col2
    col3
    100
    1
    -1
    a
    b
    c
    100
    1
    -2
    d
    e
    f
    101
    1
    -2
    t
    t
    y
    102
    2
    1
    j
    k
    l
    Sample data above  and below is the dataype for each one of them
    alpha datatype- string 
    beta datatype-integer
    gamma datatype-integer
    col1,col2,col3 are all string datatypes. 
    Note:columns are not unique and we would be using alpha,beta,gamma to uniquely identify a record .Now as you see my sample data this is in a table which doesnt have index .I would like to have a index created covering these columns (alpha,beta,gamma) .I
    beleive that creating clustered index having covering columns will be better.
    What would you recommend the index type should be here in this case.Say data volume is 1 milion records and we always use the alpha,beta,gamma columns when we filiter or query records 
    what index is suitable for a table with no unique columns and primary key?
    col1
    col2
    col3
    Mudassar

    Many thanks for your explanation .
    When I tried querying using the below query on my heap table the sql server suggested to create NON CLUSTERED INDEX INCLUDING columns    ,[beta],[gamma] ,[col1] 
     ,[col2]     ,[col3]
    SELECT [alpha]
          ,[beta]
          ,[gamma]
          ,[col1]
          ,[col2]
          ,[col3]
      FROM [TEST].[dbo].[Test]
    where   [alpha]='10100'
    My question is why it didn't suggest Clustered INDEX and chose NON clustered index ?
    Mudassar

Maybe you are looking for

  • Printing two lines of text in Print Module

    Is it possible to print two, or more lines of text, say on a contact sheet, such as filename and caption. If so, how?

  • Dead pixel on my mac book pro retina display

    Hi, i bought a mac book retina display and has a "dead pixel" I took it to apple's techical support (In Bogota-Colombia) and they told me tscrhat apple's warranty won't cover this issue..is that true? The sad thing is that I'm a designer and i bought

  • Setting a reverse counter of the # of characters as form is being filled.

    Hi, This question maybe a little strange. I was wondering, if it's possible to have a <counter> that counts the # of characters as it<s being typed into the field that I'll create in a form using Acrobat Pro. I've seen this function before, but in ot

  • Changing Password of a User

    Hi! I'm Xavi from Barcelona. My problem is: I do a transaction associated to a report for change the password of a user. The pasword change but when i do the first login , sap opens a prompt to change the password ,and i would like to change the pass

  • Only have LabVIEW 2012. Why am I asked to download LabVIEW 2011 SP1 f2 RTE Patch?

    Hello, I recently got a new machine (clean install of Windows 8), and installed LabVIEW 2012, with no other previous versions. However, when I ran the NI Update Service, it listed "LabVIEW 2011 SP1 f2 R(32-bit) Run-Time Engine Patch" as a critical up