Optimization of all indexes?

Hello,
I know that an "alter index X coalesce" optimizes the index X. But I want to optimize all indexes of a database but I don't want to write a script with some hundred alter index statements? Is there a smart way to do this like:
for i in indexes loop
alter index i coalesce;
commit;
end loop;
(Pseudocode)
Edited by: user9206958 on 01.04.2010 01:30

Actually, no. If the following conditions are all true:
1.) Sequence generated key.
2.) Newest key values are inserted.
3.) Keys are updated over time.
4.) Oldest keys are deleted.
5.) Deletion doesn't skip any key values, leaving behind older key values forever.
If all the above is true, you should never need to coalesce or rebuild your indexes.
All the new key values go into the "Right hand" leaf block. On the left side, when the last key in a particular block is deleted, the empty block is left in the index structure and added back to the pool of free blocks. As a new block is needed on the right side, Oracle will grab the emptied block from the left side, unlink it from the structure, and move it to the right side.
So, in this way, blocks move from the left over to the right to be recycled. The only time this cannot happen is if some old values are left behind in the blocks on the left. (i.e. if item #5 above is not true.) If that's the case, there may be some benefit in periodic coalesces.
For more than you ever needed to know about indexes, how they work, and when index rebuilds are necessary, see Richard Foote's blog, and check out his white papers, especially "Rebuilding the Truth".
http://richardfoote.wordpress.com/
Hope that helps,
-Mark

Similar Messages

  • Gather_table_stats with a method opt of "for all indexed columns size 0"

    I have 9 databases I support that contain the same structure, and very similar data concentrations. We are seeing inconsistent performance in the different databases due to bind variable peeking.. I have tracked it down to the Min and Max values that are gathered during the analyze. I analyze from one cluster, and export/import those statistics into the other clusters.. I then go about locking down the stats gathered. Some of the statistics are on tables that contain transient data (the older data is purged, and new data gets a new PK sequence number).
    Since I am gathering statistics with a 'FOR ALL INDEXED COLUMNS SIZE 1', a min and max value are grabbed. This value is only appropriate for a short period of time, and only for a specific database. I do want oracle to know the density to help calculate, but I don't want cardinality based on whether the current bind values fall in this range..
    Example
    COLUMN PK
    When I analyze the min is 1 and max is 5. I then let the database run, and the new min is 100 and max is 105.. same number of rows, but different min/max. At first a select * from table where pk>=1 and pk <=5 would return a cardinality of 5.. Later, a seelct * from tables where pk>=100 and pk<=105 would return a cardinaility 1.
    Any ideas how to avoid this other than trying set min and max to something myself (like min =1 max = 99999999). ??

    MarkDPowell wrote:
    The Oracle documentation on bind variable peeking said it did not peek without histograms and I cannot remember ever seeing on 9.2 where the trace showed otherwise. Mark,
    see this simple test case run on 9.2.0.8. No histograms, but bind variable peeking, as you can see that the EXPLAIN PLAN output generated by AUTOTRACE differs from the estimated cardinality of the actual plan used at runtime.
    Which documentation do you refer to?
    SQL>
    SQL> alter session set nls_language = 'AMERICAN';
    Session altered.
    SQL>
    SQL> drop table bind_peek_test;
    Table dropped.
    SQL>
    SQL> create table bind_peek_test
      2  as
      3  select
      4             100 as n1
      5           , cast(dbms_random.string('a', 20) as varchar2(20)) as filler
      6  from
      7             dual
      8  connect by
      9             level <= 1000;
    Table created.
    SQL>
    SQL> exec dbms_stats.gather_table_stats(null, 'bind_peek_test', method_opt=>'FOR ALL COLUMNS SIZE 1')
    PL/SQL procedure successfully completed.
    SQL>
    SQL> variable n number
    SQL>
    SQL> variable n2 number
    SQL>
    SQL> alter system flush shared_pool;
    System altered.
    SQL>
    SQL> exec :n := 1; :n2 := 50;
    PL/SQL procedure successfully completed.
    SQL>
    SQL> set autotrace traceonly
    SQL>
    SQL> select * from bind_peek_test where n1 >= :n and n1 <= :n2;
    no rows selected
    Execution Plan
       0      SELECT STATEMENT Optimizer=CHOOSE (Cost=2 Card=1000 Bytes=24
              000)
       1    0   FILTER
       2    1     TABLE ACCESS (FULL) OF 'BIND_PEEK_TEST' (Cost=2 Card=100
              0 Bytes=24000)
    Statistics
            236  recursive calls
              0  db block gets
             35  consistent gets
              0  physical reads
              0  redo size
            299  bytes sent via SQL*Net to client
            372  bytes received via SQL*Net from client
              1  SQL*Net roundtrips to/from client
              4  sorts (memory)
              0  sorts (disk)
              0  rows processed
    SQL>
    SQL> set autotrace off
    SQL>
    SQL> select
      2             cardinality
      3  from
      4             v$sql_plan
      5  where
      6             cardinality is not null
      7  and      hash_value in (
      8    select
      9            hash_value
    10    from
    11            v$sql
    12    where
    13            sql_text like 'select * from bind_peek_test%'
    14    );
    CARDINALITY
              1
    SQL>
    SQL> alter system flush shared_pool;
    System altered.
    SQL>
    SQL> exec :n := 100; :n2 := 100;
    PL/SQL procedure successfully completed.
    SQL>
    SQL> set autotrace traceonly
    SQL>
    SQL> select * from bind_peek_test where n1 >= :n and n1 <= :n2;
    1000 rows selected.
    Execution Plan
       0      SELECT STATEMENT Optimizer=CHOOSE (Cost=2 Card=1000 Bytes=24
              000)
       1    0   FILTER
       2    1     TABLE ACCESS (FULL) OF 'BIND_PEEK_TEST' (Cost=2 Card=100
              0 Bytes=24000)
    Statistics
            236  recursive calls
              0  db block gets
            102  consistent gets
              0  physical reads
              0  redo size
          34435  bytes sent via SQL*Net to client
           1109  bytes received via SQL*Net from client
             68  SQL*Net roundtrips to/from client
              4  sorts (memory)
              0  sorts (disk)
           1000  rows processed
    SQL>
    SQL> set autotrace off
    SQL>
    SQL> select
      2             cardinality
      3  from
      4             v$sql_plan
      5  where
      6             cardinality is not null
      7  and      hash_value = (
      8    select
      9            hash_value
    10    from
    11            v$sql
    12    where
    13            sql_text like 'select * from bind_peek_test%'
    14    );
    CARDINALITY
           1000
    SQL>
    SQL> spool offRegards,
    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/

  • Synchronizing ALL Indexes

    Hi,
    I'd like to synchronize my indexes periodically. I know I need to use ctx_ddl.sync_index(). I'd like to use it to synchronize ALL my indexes, not just one. So if I understand correctly, to do that I need to execute it as CTXSYS, right? And if I don't pass it any parameters, it will update ALL my indexes?
    I have Oracle 9i on a Linux server and I'm accessing it from a Windows client.
    I made an sql script in my oracle_home/bin directory called "syncjob.sql" that I'd run. I'm just not sure where I'd run the script from and what I would do to call it.
    define interval = "&1"
    set serveroutput on
    declare job number;
    begin
    dbms_job.submit(job, 'ctx_ddl.sync_index();', interval=>'SYSDATE+&interval/1440');
    commit;
    end;
    Some help on synchronizing all my indexes would be great. Thanks!

    Well I figured out how to make all the indexes synchronize, but now I don't know how to make them all optimize. Does anyone know a way to make ctx_ddl.optimize_index() work on ALL indexes?

  • How to get all INDEXes from a database

    How to get all INDEXes in a database? I need to store them in script file (.SQL). My database version is 10.2.0.3.0.
    Edited by: Iniyavan on Sep 18, 2009 1:39 PM

    --Thanks, Koppelaars. The second query works. But I'm unable to store in spool file. May be it's due to CLOBs in the output. I did the following:
    set head off
    set feedback off
    set linesize 32727
    set pagesize 50000
    spool c:\indexes.sql
    select dbms_metadata.get_ddl('INDEX',INDEX_NAME,'MYSCHEMA')
    from user_indexes;
    spool off
    --In the spool file, I find only this
    CREATE UNIQUE INDEX "MYSCHEMA"."A" ON "MYSCHEMA"."BNK_DEALID" ("DEAL_ID")
    PCTF
    CREATE INDEX "MYSCHEMA"."ACCENT_RAC_REPORT" ON "MYSCHEMA"."ACCENT" ("SCHEME", "VAL
    CREATE INDEX "MYSCHEMA"."ACCENT_REPORT" ON "MYSCHEMA"."ACCENT" ("SCHEME", "APP_REF
    CREATE UNIQUE INDEX "MYSCHEMA"."ACCENT_X" ON "MYSCHEMA"."ACCENT" ("DEAL_ID")
    P
    CREATE UNIQUE INDEX "MYSCHEMA"."ACCNAV_X" ON "MYSCHEMA"."ACCNAV" ("SCHEME", "ACCNA
    --How to get all the DMLs in one SQL file?
    --Nagappan, I'm using WIN.

  • How to generate all index creation scripts without it's storage clause?

    How to generate all index creation scripts without it's storage clause?

    Execute this before running the actual dbms_metadata.get_ddl
    exec dbms_metadata.set_transform_param(dbms_metadata.session_transform, 'STORAGE', FALSE);
    SELECT DBMS_METADATA.GET_DDL('INDEX',a.index_name) FROM USER_INDEXES A;-Anantha
    Edited by: Anantha R on Sep 30, 2009 11:40 AM

  • Set logging to NO for all index in primary DB

    Hi,
    can i set the logging option to NO for all index in primary DB (versus standby DB).
    Because the execute plan of queries changes with this option and the time it's very long for geats tables if the option logging it's YES.
    Regards.

    Hi,
    personally I have never seen that execution plan changes if objects in nologging mode. Could you show sql statements that have changed execution plans due to nologging clause.
    Thanks,
    Andrey

  • Syntax for building all indexes on a table

    I know the syntax for re-building of index on a table like :
    ALTER INDEX index_name REBUILD;
    But, what is the syntax to re-build all the indexes on a table with one statement.
    I hope, my question is clear. Please help in solving the doubt.
    regards.

    This is a Syntax for building all indexes on a table

  • Find Whether Array Element have same element in all index

    Hi ,
    I need to check if an array have the same element in all its indexes.(Example: An Array of Size 4, should have index 0 ..index 3 as 1 and during next iteration let it be number 2 in all indexes......how do I check if all index have same number)
    Attached the VI I did.
    Anyone can suggest better than this.
    Solved!
    Go to Solution.
    Attachments:
    Check array_For Same Element.vi ‏12 KB

    get the first element , compare it with the hole array , AND all elements
    Greetings from Germany
    Henrik
    LV since v3.1
    “ground” is a convenient fantasy
    '˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'

  • What value for DBMS_STATS method_opt= 'for all indexed columns ???'

    What value, one should use for method_opt , while collecting stats for database/schema/table.
    It is obseverd AUTO never give good result, in some case "for all indexed columns 1" work fine and some case "for all indexed columns 254".
    Please advise , what is right way to collect stats.
    OS : Linux AS 4
    DB : 9.2.0.8 , 10.2.0.3
    Thanks

    Gather AUTO. Gathers all necessary statistics automatically. Oracle implicitly determines which objects need new statistics, and determines how to gather those statistics. When GATHER AUTO is specified, the only additional valid parameters are stattab, statid, objlist and statown; all other parameter settings are ignored. Returns a list of processed objects.
    If you specify the for all indexed columns, or specify the column, it will gather histograms. Those are useful if you have an uneven data distribution, and are specially useful for DSS databases, where Oracle will determine if a column is suitable, on a given data rage, to perform full table scan or index scan. If uncertain about it I suggest you not to gather column statistics, as they are costly.
    ~ Madrid.

  • Estimate time to enable all constraints and create all indexes

    Hi,
    To prepare a project to export/import for a whole database,
    How can I estimate time required to enable all constraints and create all indexes
    * Assume one full table scan per one FK constraint
    * Assume one full table scan plus one sort/merge operation per one index
    * Check it out whether we can use parallel DDL feature to speed up enabling of FK constraints
    how can I use core schema (which will be exp/imp) in the production db to get needed metric for the calcualtion?
    thanks
    Jerry

    There is no definative way to find the time it takes to enable a constraint / create a Index
    It toatally depends on the Size of the table / execution plan / resources available (In terms of CPU and Physical Memory ) /
    Amount of Temporary tablespace

  • Script: Lists All Indexes that Benefit from a Rebuild

    Hi,
    I have some problems in MyOracleSupport to get the "Script: Lists All Indexes that Benefit from a Rebuild". 122008.1 says me, that it is out of date and I should use "NOTE:989186.1". But when I click on the Link I only get failure that he can't find the site.
    I using Firefox 3, maybe this is a problem?! Maybe someone can post the script?
    greetings from Germany

    When I go to the original document in metalink and then click on the NOTE:989093.1 link, I get to that note.
    Using
    Mozilla/5.0 (Windows; U; Windows NT 5.1; de-DE; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10
    Seems like a local problem at your site.
    By the way, if you search a little after index rebuild here, you may get an idea that you probably just don't need that script :-) I recommend especially postings from Jonathan Lewis & Richard Foote about that topic.
    Kind regards
    Uwe
    http://uhesse.wordpress.com

  • Rebuild all indexes

    Hi,
    Anyone know how to rebuild all indexes of all tables from a database ?
    Thanks

    We maintain 1 application that has 2 version of database, Oracle (if Unix) and MS-SQL (if Windows).
    One day, in the site that is using MS-SQL there was a database problem, suddenly the application stop and the application support said about "index corruption". They gave us code how to rebuild all the indexes. We did it, and it solved the problem.
    So, I just wondering, how to do this in Oracle (8.1.7), just in case we got the same problem. We do have a site that is not using MS-SQL, it uses Oracle because it runs in Unix.
    PS: Of course ! call that application support ! But well, calling them need sometimes. So, I tought that I can simply do it my self. Unfortunately, my Oracle knowledge does not help me in this task.

  • Remove All InDex Markers in empty cells

    I have a doc with lots of tables & empty cells. Each empty cells have an index markers in it and I need to remove all of them.
    The find/change replacing  '^I' by '' (nothing) don’t remove them.
    Is their a way to remove all Index Markers via a script?
    Jean-Claude

    Can you send an example idml or inx?
    Otherwise perhaps you can try something like this:
    var aDoc = app.documents[0]; 
    var allTables = aDoc.stories.everyItem().tables.everyItem().getElements();
    app.findTextPreferences = app.changeTextPreferences = null;
    app.findTextPreferences.findWhat = "<FEFF>";
    app.changeTextPreferences.changeTo = "";
    aDoc.stories.everyItem().tables.everyItem().changeText();
    app.findTextPreferences = app.changeTextPreferences = null;
    alert("done");
    This is a part of a script written by Uwe Laubender. I think this could help you.

  • Analyzing tables and all index

    hi
    What is the command to analyze the tables and all indexes and columns for a particular table
    rgds
    rajesh

    9i and 10g:
    exec dbms_stats.gather_table_stats('<schema>' , '<table_name>', cascade=>true);

  • How to select all  indexes in a schema , for gathering the statistics

    In OEM 10g , How can we select all the indexes in a particular schema for gathering the statistics.
    For example , consider the schema got 1500 indexes. When i clicked on select all , it is selecting 10 indexes in one stretch ( all which are present in that page).
    For 1500 indexes , i have to make 150 such selection.
    How can we avoid it.
    In 9i OEM, its quite simple. With just 1 mouse clicke , we can select all the indexes .
    Thanks
    Naveen
    314 439 9554

    On the Administration Tab of the instance, choose Statistics Management - Manage Optimizer Statistics, then Gather Optimizer Statistics and click Continue. You then get a choice of Database, Schema, Tables or Indexes.
    Stupid that you have to supply an OS username and password to do this but anyway.

Maybe you are looking for