"analyze index"  vs  "rebuild index"

Hi,
I don't undestand the difference between "analyze index" and "rebuild index".
I have a table where I do a lot of "insert" and "update" and "query", What is the best thing to do ??
thanks
Giordano

When you use dbms_stats.gather_schema_stats package with cascade=>true option, you are also collecting stats for the indexes, no need to collects stats separately using dbms_stats.gather_index_stats.Of course, but I refered to the rebuild index question. Therefore I only mentioned the GATHER_INDEX_STATS.
Auto_sample_size has many problems/bugs in 9iOk didn't know that - I'm using 10gR2.
But this discussion made me curious. So I tried something (10gR2):
CREATE TABLE BIG NOLOGGING AS
WITH GEN AS (
SELECT ROWNUM ID FROM ALL_OBJECTS WHERE ROWNUM <=10000)
SELECT V1.ID,RPAD('A',10) C FROM GEN V1,GEN V2
WHERE ROWNUM <=10000000;
SELECT COUNT(*) FROM BIG;
COUNT(*)
10000000
So I had a Table containing 10 Million rows. Now I indexed ID:
CREATE INDEX BIG_IDX ON BIG(ID)
I tested two different methods:
1.) GATHER_TABLE_STATS with estimate 10%
EXEC DBMS_STATS.GATHER_TABLE_STATS(TABNAME=>'BIG',OWNNAME=>'DIMITRI',CASCADE=>TRUE,ESTIMATE_PERCENT=>10);
It took about 6 seconds (I only set timing on in sqlplus, no 10046 trace) Now I checked the estimated values:
SELECT NUM_ROWS,SAMPLE_SIZE,ABS(10000000-NUM_ROWS)/100000 VARIANCE,'TABLE' OBJECT FROM USER_TABLES WHERE TABLE_NAME='BIG'
UNION ALL
SELECT NUM_ROWS,SAMPLE_SIZE,ABS(10000000-NUM_ROWS)/100000 VARIANCE,'INDEX' OBJECT FROM USER_INDEXES WHERE INDEX_NAME='BIG_IDX';
NUM_ROWS SAMPLE_SIZE VARIANCE OBJEC
9985220 998522 ,1478 TABLE
9996210 999621 ,0379 INDEX
2.) GATHER_TABLE_STATS with DBMS_STATS.AUTO_SAMPLE_SIZE
EXEC DBMS_STATS.DELETE_TABLE_STATS(OWNNAME=>'DIMITRI',TABNAME=>'BIG');
EXEC DBMS_STATS.GATHER_TABLE_STATS(TABNAME=>'BIG',OWNNAME=>'DIMITRI',CASCADE=>TRUE,ESTIMATE_PERCENT=>DBMS_STATS.AUTO_SAMPLE_SIZE);
It took about 1,5 seconds. Now the results:
NUM_ROWS SAMPLE_SIZE VARIANCE OBJEC
9826851 4715 1,73149 TABLE
10262432 561326 2,62432 INDEX
The estimate 10% was more exact - also a 1,7 and 2,6 percent variance is still ok. It's also very interesting, that using AUTO_SAMPLE_SIZE
causes oracle to execute a estimate 5% for the index and a estimate 0.5 for the table.
I tried again with a table containing only 1 Million records and oracle did an estimate with 100% for the index.
So for me I will continue using AUTO_SAMPLE_SIZE. Its very flexible, fast and accurate.
Dim
PS: Is there a way to format code like one can do in HTML using <code> or <pre>?

Similar Messages

  • What is the difference between the drop and create the index and rebuild index ?

    Hi All,
    what is the difference between drop and create index & rebuild index ? i think both are same...Please clarify if both are same or any difference...
    Thanks in Advance,
    rup

    Both are same. Rebuilding an index drops and re-creates the index. 
    Ref:
    SSMS - https://technet.microsoft.com/en-us/library/ms187874(v=sql.105).aspx
    TSQL - https://msdn.microsoft.com/en-us/library/ms188388.aspx
    I would suggest you to also refer one of the best index maintenance script as below:
    https://ola.hallengren.com/sql-server-index-and-statistics-maintenance.html

  • Rebuild index vs Analyze index

    Hi All,
    I am realy confused about rebuilding index versus Analyzing index.
    Could anyone plz help me out what is the diffrence between them.
    How to Perform analyze of indexes and Rebuld of Indexes for both Oracle 9i and 10g databases.
    Thanks a lot

    CKPT wrote:
    You can see the posts of experts by jonathan
    I am realy confused about rebuilding index versus Analyzing index. tell us you are getting confused why we need to ananlyze before reubild index? if so
    if index analyzed the whole statistics of index will be gathered.... then you can check what is the hieght of the index.. according to the height of the index you need to take step is index need to be really rebuild or not...
    lets see furhter posts from experts if not clear..Thanks OK, so you determine the height of an index is (say) 4. What then ? If you decide to rebuild the index and the index remains at a height of 4, what now ? Was it really worth doing and do you rebuild it again as the index height is still 4 and still within your index rebuild criteria ? At what point do you decide that rebuilding the index just because it has a height of 4 is a total waste of time in this case ?
    OK, so you determine the index only has a height of (say) 3, does that mean you don't rebuild the index ? But what if by rebuilding the index, the index now reduces to a height of just 1 ? Perhaps not rebuilding the index even though it has just a height of 3 and doesn't currently meet your index rebuild criteria is totally the wrong thing to do and a rebuild would result in a significantly leaner and more efficient index structure ?
    So what if it's pointless rebuilding an index with a height of 4 but another index with a height of 3 is a perfect candidate to be rebuilt ?
    Perhaps knowing just the height of an index leaves one totally clueless after all as to whether the index might benefit from an index rebuild ...
    Cheers
    Richard Foote
    http://richardfoote.wordpress.com/

  • Rebuilding indexes with monotonically increasing sequences

    Hi
    I have been reading this paper
    http://richardfoote.files.wordpress.com/2007/12/index-internals-rebuilding-the-truth.pdf
    *On page 91 we  have*
    CREATE TABLE test_empty_block (id NUMBER, name VARCHAR2(30));
    Table created.
    INSERT INTO test_empty_block SELECT rownum, 'BOWIE' FROM dual
    CONNECT BY level <= 10000;
    10000 rows created.
    COMMIT;
    CREATE INDEX test_empty_block_idx ON test_empty_block(id);
    Index created.
    On page 92 we have
    SQL> DELETE test_empty_block WHERE id between 1 and 9990;
    9990 rows deleted.
    SQL> COMMIT;
    Commit complete.
    SQL> ANALYZE INDEX test_empty_block_idx VALIDATE STRUCTURE;
    Index analyzed.
    SQL> SELECT lf_blks, del_lf_rows FROM index_stats;
    LF_BLKS DEL_LF_ROWS
    21 9990
    On page 93
    SQL> INSERT INTO test_empty_block SELECT rownum+20000, 'ZIGGY' FROM dual CONNECT BY level <= 10000;
    10000 rows created.
    SQL> COMMIT;Commit complete.
    SQL> ANALYZE INDEX test_empty_block_idx VALIDATE STRUCTURE;
    Index analyzed.
    SQL> SELECT lf_blks, del_lf_rows FROM index_stats;
    LF_BLKS DEL_LF_ROWS
    21 0
    when the DEL_LF_ROWS is 0
    How come Richard goes on to state that on page 96.
    Although deleted index space is generally reusable, there can be wasted space
    Monotonically increasing index values and deletions
    Edited by: 899881 on Jan 3, 2012 9:05 PM
    Edited by: 899881 on Jan 3, 2012 9:06 PM

    899881 wrote:
    How come Richard goes on to state that on page 96.
    Although deleted index space is generally reusable, there can be wasted space
    Monotonically increasing index values and deletions
    I believe this is addressed in page 103 of the same document you posted a link to.

  • Rebuilding indexes after importing...

    My coworker and I are discussing whether it is necessary, or advised, to rebuild indexes after an import of the schema.
    My thinking is that the index data is put into fresh blocks thereby creating a very flat index tree without any fragmentation.
    But my coworker suspects that perhaps the blocks are built exactly as they existed in the source database.
    I could understand, perhaps, if the refresh were done by using RMAN which copies block by block, but even then I'm not sure.
    Can you help us understand this please?
    Thanks.
    Ed

    Hi,
    Normally, the indexes are build and statistics upfated after the import automatically. You do not ned to generate the statistics after the import until unless you are running very old version of database.
    Regards
    [sfa-dev1:oracle:10.2.0] $ imp help=Y
    Import: Release 10.2.0.4.0 - Production on Fri Nov 13 11:49:56 2009
    Copyright (c) 1982, 2007, Oracle. All rights reserved.
    You can let Import prompt you for parameters by entering the IMP
    command followed by your username/password:
    Example: IMP SCOTT/TIGER
    Or, you can control how Import runs by entering the IMP command followed
    by various arguments. To specify parameters, you use keywords:
    Format: IMP KEYWORD=value or KEYWORD=(value1,value2,...,valueN)
    Example: IMP SCOTT/TIGER IGNORE=Y TABLES=(EMP,DEPT) FULL=N
    or TABLES=(T1:P1,T1:P2), if T1 is partitioned table
    USERID must be the first parameter on the command line.
    Keyword Description (Default) Keyword Description (Default)
    USERID username/password FULL import entire file (N)
    BUFFER size of data buffer FROMUSER list of owner usernames
    FILE input files (EXPDAT.DMP) TOUSER list of usernames
    SHOW just list file contents (N) TABLES list of table names
    IGNORE ignore create errors (N) RECORDLENGTH length of IO record
    GRANTS import grants (Y) INCTYPE incremental import type
    INDEXES import indexes (Y) COMMIT commit array insert (N)
    ROWS import data rows (Y) PARFILE parameter filename
    LOG log file of screen output CONSTRAINTS import constraints (Y)
    DESTROY overwrite tablespace data file (N)
    INDEXFILE write table/index info to specified file
    SKIP_UNUSABLE_INDEXES skip maintenance of unusable indexes (N)
    FEEDBACK display progress every x rows(0)
    TOID_NOVALIDATE skip validation of specified type ids
    FILESIZE maximum size of each dump file
    STATISTICS             import precomputed statistics (always) On 10gR2
    Edited by: skvaish1 on Nov 13, 2009 11:50 AM

  • REBUILD INDEX vs DROP/CREATE INDEX

    Hi there,
    Does anyone has already got some performance degradation after REBUILD INDEXes ? Would it be better to perform DROP/CREATE INDEX instead ?
    Thank you very much for anu reply.
    Best regards,
    Helena

    Hi,
    >>so is it then better to DROP/CREATE them ?
    Well, In fact I learned that when you rebuild an index, Oracle creates a new index from the old index and does not perform sorting while building the new index, which results in performance enhancement. In this case, depending of the size of your data it's necessary sufficient space on a tablespace for storing the old as well as the new index (while creating the new index). Other advantage, is that Oracle can use the old index for answering queries while it builds the new index too using [alter index <index_name> rebuild online].
    Cheers

  • Rebuild Index VS Drop and Rebuild?

    Hey all,
    I am currently redesigning a weekly process (weekly coz we pre determined the rate of index fragmentation) for specific indexes that get massive updates. The old process has proved to be able to fix and maintain reports performance.
    In this process we rebuild specific indexes using the below command:
    Alter index index_name rebuild online;
    This command takes around 10 min for selected indexes.
    Testing the below took 2 min for 6 or 7 indexes.
    Drop Index Index_Name;
    Create Index Index_Name on Table_name (Col1, col, ..);
    I know that indexes might not be used, and the application performance would be degraded with stale or non-existent stats. But our production and all our test DBs have procedures that daily gather stats on them.
    I tested the below script to make sure that execution plan does not change:
    SELECT ProductID, ProductName, MfrID FROM PRODUCT WHERE MFRID = 'Mfr1';
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
    | 0 | SELECT STATEMENT | | 37 | 3737 | 13 (0)|
    | 1 | TABLE ACCESS BY INDEX ROWID| PRODUCT | 37 | 3737 | 13 (0)|
    | 2 | INDEX RANGE SCAN | PRODUCT_X1 | 37 | | 3 (0)|
    dropping PRODUCT_X1 and recreating it only changed the cost to 12.
    Gathering the stats again took the cost to 14.
    No performance issues were faced and index was still used.
    My question is: Is there any oracle recommendation that requires rebuilding the index instead of dropping and recreating it?
    Is there any side effect to my approach that I did not consider?
    Thank you

    Charlov wrote:
    I am currently redesigning a weekly process (weekly coz we pre determined the rate of index fragmentation)Nice. Not only have you defined and located index fragmentation but have also measured the rate at which it occurs.
    Could you please share your definition of index fragmentation, how you detect it, and how you measure the rate of change of this fragmentation.
    I am curious about all this since it can be repeatedly shown that Oracle btree indexes are never fragmented.
    http://richardfoote.files.wordpress.com/2007/12/index-internals-rebuilding-the-truth-ii.pdf
    The old process has proved to be able to fix and maintain reports performance.Great so you have traces and run time statistics from before and after the rebuild that highlight this mysterious fragmentation and show how the fragmentation caused the report to be slow, details what effects the rebuild had that caused the reports to perform better.
    Please share them as these would be an interesting discussion point since no one has been able to show previously how an index rebuild caused a report to run faster or even show the fragmentation that caused it to be slow in the first place.
    I mean it would be a pity if the report was just slow because of an inefficient plan and compressing an index or two that probably shouldn't be used in teh first place appears to temporarily speed it up. Could you imagine rebuilding indexes every week, because some developer put the wrong hint in a query? That would be pretty funny.

  • Q/s on rebuilding index

    Hi All
    in one of our applications we want to rebuild index which his craete as below, this is on 11G 11.2.0.3.0 Solaris 64bit
    CREATE INDEX idx_id ON scott.branch(bank_id)
    INDEXTYPE IS CTXSYS.CONTEXT PARAMETERS
    ('FILTER CTXSYS.NULL_FILTER SECTION GROUP CTXSYS.HTML_SECTION_GROUP');
    Is rebuilding the index a reasonable option or will that be much slower than a sync ?
    secondly is ctx_ddl package installed by default
    thanks

    hi,
    you should ask this question to: Text for get answers faster.
    by the way, if you installed Oracle Text (which is default on installation) ctx_ddl package is also comming too.

  • Multiple objects with same name when rebuilding index online

    I am looking for advice on how to handle a race-condition in sql server, related to reading metadata while an online index rebuild is being performed.
    The problem is as follows:
    At some point we execute the following statement:
    SELECT 
    obj.object_id AS id, 
    scm.name AS scm, 
    obj.name AS name, 
    obj.type AS type, 
    ds.name AS dataspace_name, 
    prop.value AS description, 
    part.data_compression_desc as compression_desc
    FROM sys.objects AS obj
    INNER JOIN sys.schemas AS scm ON obj.schema_id = scm.schema_id
    INNER JOIN sys.indexes AS idx ON obj.object_id = idx.object_id AND idx.type IN (0,1)
    INNER JOIN sys.data_spaces AS ds ON idx.data_space_id = ds.data_space_id
    INNER JOIN (SELECT object_id, data_compression_desc FROM sys.partitions WHERE index_id IN (0,1) /*Heap, Clustered*/) AS part ON part.object_id = obj.object_id
    LEFT OUTER JOIN sys.extended_properties AS prop ON obj.object_id = prop.major_id AND prop.minor_id = 0 AND prop.class = 1 AND prop.name = 'Description'
    WHERE obj.type = 'U' OR obj.type = 'S'";
    The statement returns some metadata for indexes (indices?), the purpose of wich is not the subject.
    When executed while an online index rebuild is running, a race condition occurs: When the rebuilding enters the final phase, the new index, which have the same name, becomes visible and thus results in two rows with the same name (from sys.object). I am unaware
    if this only occurs for clustered index (which is what we have observed).
    We became aware of this behaviour, as we added the metadata to a .Net Dictionary using name as key, and received a duplicate key exception. We have, hoewever, not been able to reproduce the situation, due to the nature of the race condition, and we found very
    little documentation on the subject.
    What we would like to do now, is to differentiate between the two. We see two options:
    1) We could just use the first of the rows and ignore the second. This solution would require that the metadata for both rows are identical.
    2) We could discern the "real" index from the "rebuilding" index. This requires some kind of extension of the Where-part.
    We have not been able to determine if the requirements for either option is present, as we havent found any documentation, nor have we been able to test for differences, as we cannot reproduce the situation.
    We would also like some way of reproducing the situation, so ideas as to how to do that is welcome.
    Can anyone direct me to relevant documentation, or alternate solutions.
    HRP

    1. Use the index with the lower fragmentation to identify the newly rebuilt index (as it almost always will have lower fragmentation)
    2. To reproduce, block the online index rebuild process by trying to alter the table's definition in a transaction (and don't commit, which will place schema lock on the table)
    Satish Kartan http://www.sqlfood.com/

  • How to rebuild index in E-Business

    Hi
    As on core DB side we can check index status for rebuild with command
    select owner,index_name,blevel,last_analyzed from dba_indexes where blevel>3 order by last_analyzed
    and after that
    alter index <index_name> rebuild compute statistics;
    my question is can we do the same with my e-business R12.1.2 and 10.2.0.4 database or there is some other recommendation. I want to do this for performance increase.
    Thanks
    Krishna

    Hi krishna,
    Also please see
    note 163208.1 bde_last_analyzed.sql - Verifies CBO Statistics
    note 174605.1 bde_chk_cbo.sql - Reports Database Initialization Parameters related to an Apps 12 or 11i instance
    note 396009.1 Database Initialization Parameters for Oracle Applications Release 12
    note 216205.1 Database Initialization Parameters for Oracle Applications 11i
    note 744143.1 Tuning performance on eBusiness suite
    note 169935.1 Troubleshooting Oracle Applications Performance Issues
    note 244040.1 Oracle E-Business Suite Recommended Performance Patches

  • How to rebuild index on a table in a faster way

    Hi All,
    We have using Oracle 9.2.0.3
    On weekly basis we are loading around 20-30 million of data into a table using sqlloader.
    Before loading the data into the table, we are dropping all the indexes adn rebuilding the same once done.
    There are 6 index on the table and rebuilding them takes around 10-11 hours.
    Is there any ways to reduce the time of index rebuilding.
    Rgds,
    Amol

    Doing it that way a
    alter session set skip_unusable_indexes=truemight also be necessary.

  • How to rebuild index from different schema

    Hi All,
    I want to rebuild an Index of schema A from Schema B.
    Is there any grant needs to be give to Schema B in order to rebuild index of Schema A?
    Thanks,
    Tarak

    It is true what P. Forstmann said. However if you don't want to give the second user the ANY priviledge, then you can do a little workaround. Create a small procedure in Schema A that does the rebuild (maybe dynamically). Then grant execute rights on the procedure to Schema B.

  • Rebuild indexes in sap

    Dear Experts
    When i chk the update optimizer  statistics, there are 26 missing indexes, please help me how to rebuild the missing indexes.
    regards
    varun

    Completely missunderstood the question, indexes can be rebuilt by using instructions above.
    You can also use Brtools to rebuild indexes...
    Read,
    http://help.sap.com/saphelp_nw70/helpdata/en/75/95536a63b44b4a9e7f278c7d9c2b67/frameset.htm
    Regards
    Juan

  • SCCM database Modified date doesn't change / rebuild indexes

    Hi all,
    I have 2 questions
    1)
    We have a month ago upgraded our SCCM environment from SCCM 2012 RTM -> SCCM 2012 SP1 (no CU), and we have upgraded SQL 2008 R2 (CU6) to SQL 2008 R2 SP2.
    We have a SCCM 2012 primary site and an SCCM 2012 CAS site from both these sites its database file has not changed its modified date since the data of upgrade (SQL is installed on the same server so the database is local). However the WSUS database and the
    reporting DB that exist on the same server updates its modified date.
     SCCM is running and all status messages are OK. All component status's are updating and have correct dates based on when e.g. the last backup ran (that is at 6 pm every night) with no errors. To make a long story short, everything works
    as it should. Deployments and advertisements and OSD arrive, collections get updated, no errors appear in the log files or in the component or site status, but the database on these servers (CAS and Primary) does not modify its date. SCCM backup of these servers
    is running and the database file in that backup also contains the same modified date.
    Anyone knows why this happens , or do we have an issue ?
     2)
    Maintenance task rebuild indexes
    Is there a best practice according to the maintenance task rebuild indexes?
    In our environment we have not enabled this maintenance task, both sites run for over one year.
    Can we enable this task without disturbing or is it a better idea to enable this task in the weekend when there is less workload , and afterwards schedule this task once a week
    regards and thx in advance
    Johan

    As stated “The time stamp will also change if the database files size are expanded as well when the database grow”
    does that mean that after our upgrade a month ago the database has not grown with new data??
    It depends. Data might have been added to the database (which it was fur sure with ConfigMgr), but the timestamp will only change if the file size was increased too. That has something to do with the initial and max file size settings in SQL and the autogrowth
    settings.
    Torsten Meringer | http://www.mssccmfaq.de

  • Rebuild indexes on partitioned table

    Hi
    We have a very large table hh_advance which hold 1.5billion records and is partitioned by range
    we a index (non parititioned) index on this table.
    after adding partitions to hh_advance table the index has become unusable
    the size of index is too huge and we need to rebuild the index in least possible time
    what is the best used practice in this case
    thanx
    kb

    KB.. wrote:
    Hi
    We have a very large table hh_advance which hold 1.5billion records and is partitioned by range
    we a index (non parititioned) index on this table.
    after adding partitions to hh_advance table the index has become unusable
    the size of index is too huge and we need to rebuild the index in least possible time
    what is the best used practice in this casekb,
    you haven't mentioned your database version, but the best practice would be in many cases to use the "UPDATE \[GLOBAL\] INDEXES" clause of the ALTER TABLE command if you're at least on 9i or later to prevent any (global) indexes from becoming unusable.
    By the way, adding a partition to a range partitioned table shouldn't invalidate neither a global nor a local index.
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

Maybe you are looking for

  • I have an ipad and want to buy an ipad mini. Can I transfer everything over?

    I have 3 ipads under one apple ID and soon to have a fourth. I want to rearrage who has what device. Here is how they are now: iPad 3 16m wifi:User 1 iPad 2 16m wifi:User 2 iPad 2 16m wifi:User 3 User 4 currently has no ipad. User 1 is getting a new

  • Acrobat Toolbar in Lotus Notes 8.5

    Does anyone know how i can get the acrobat toolbar to show up in Lotus Notes 8.5. I know this has been an issue in the past and I have already tried the steps of manually adding the add-ons into the configuration files for Notes but that doesn't seem

  • How do I get rid of apps that I have deleted completely??

    I've deleted some apps off my iphone as well as in my apps folder on itunes but each time itunes opens it tries to download and update the apps that I have deleted. The download then comes up with an error 8008. I have also cleared the apps from my r

  • PSE 7 has stopped working

    I've never had any issue w/ pse, but tonight nothing works.  I started w/ a text box - tried to change font, but the list of fonts opens, flashes, disappears, so I'm left w/ an empty box.  I literally can't get the program to respond to anything.  I'

  • Best aproach to zoom in on a clip

    What would be the best apporach to zoom on a certain area on a clip? Is there a plugin to do this automaticaly?