Analyze Table Or Schema

when we want to query the dba_tables or user_tables to find the no of rows in a particular table or no of rows of all the tables then why do we need to analyze that particual table or schema to get the num_rows columns values??

"RTFM" is the best teacher always"
When you analyze the table:
Oracle collects the following statistics for a table. Statistics marked with an
asterisk are always computed exactly. Table statistics, including the status of
domain indexes, appear in the data dictionary views USER_TABLES,
ALL_TABLES, and DBA_TABLES in the columns shown in parentheses.
->"Number of rows (NUM_ROWS) "
-> * Number of data blocks below the high water mark (that is, the number of data
blocks that have been formatted to receive data, regardless whether they currently
contain data or are empty) (BLOCKS)
-> * Number of data blocks allocated to the table that have never been used (EMPTY_BLOCKS)
-> Average available free space in each data block in bytes (AVG_SPACE)
-> Number of chained rows (CHAIN_COUNT)
-> Average row length, including the row's overhead, in bytes (AVG_ROW_LEN) Jameel

Similar Messages

  • Analyzing all tables in schema

    Hello everyone,
    I am used below command to analyze all tables in schema
    EXEC DBMS_STATS.gather_schema_stats (ownname => 'CONTRACT', cascade =>true,estimate_percent => dbms_stats.auto_sample_size);when look at tables in dba_tables, for none of the tables LAST_ANALYZED date is changed to today. But when I did below
    EXECUTE DBMS_STATS.GATHER_TABLE_STATS(ownname => 'CONTRACT', tabname => 'CONT_NAME', method_opt => 'FOR ALL COLUMNS', granularity => 'ALL', cascade => TRUE, degree => DBMS_STATS.DEFAULT_DEGREE);I am see LAST_ANALYZED changed to today in dba_tables.
    If I need to change LAST_ANALYZED to all tables do I need to produce the above command for all tables? There are more then 700 tables for this application.
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    CORE    11.2.0.2.0      Production
    TNS for IBM/AIX RISC System/6000: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production

    user3636719 wrote:
    EXEC DBMS_STATS.gather_schema_stats (ownname => 'CONTRACT', cascade =>true,estimate_percent => dbms_stats.auto_sample_size);
    and
    EXECUTE DBMS_STATS.GATHER_TABLE_STATS(ownname => 'CONTRACT', tabname => 'CONT_NAME', method_opt => 'FOR ALL COLUMNS', granularity => 'ALL', cascade => TRUE, degree => DBMS_STATS.DEFAULT_DEGREE);are fundamentally different, you cannot compare them. In gather_schema_stats, oracle used most defaults, decided none needed new stats collected, so it didn't do anything. In the second, you changed method_opt, granularity and degree etc from default values (as set in your db perhaps), so db went ahead and collected stats.
    You need to look up manual and try to understand the default and non-default behavior for parameters and then make an educated decision. Changing stats randomly is not generally a great idea.

  • SCHEMA STATS OR ANALYZE TABLE

    Hi,
    Can any one tell me what are the advantages of schema stats or table stats over analyzing the table.
    Regards,
    Umair

    Hi,
    Following are the advantages of using the DBMS_STATS to gather either table or schema or d/b stats
    A. ANALYZE always runs serially. DBMS_STATS can run in serial or parallel.
    Whenever possible, DBMS_STATS calls a parallel query to gather statistics with
    the specified degree of parallelism; otherwise, it calls a serial query or the
    ANALYZE statement. Index statistics are not gathered in parallel.
    B. ANALYZE calculates global statistics for partitioned tables and indexes
    instead of gathering them directly. This can lead to inaccuracies for some
    statistics, such as the number of distinct values.
    C. For partitioned tables and indexes, ANALYZE gathers statistics for the
    individual partitions and then calculates the global statistics from the
    partition statistics. DBMS_STATS can gather separate statistics for each
    partition as well as global statistics for the entire table or index. Depending
    on the SQL statement being optimized, the optimizer may choose to use either
    the partition (or subpartition) statistics or the global statistics.
    D. For composite partitioning, ANALYZE gathers statistics for the subpartitions
    and then calculates the partition statistics and global statistics from the
    subpartition statistics. DBMS_STATS can gather separate statistics for
    subpartitions, partitions, and the entire table or index. Depending on the SQL
    statement being optimized, the optimizer may choose to use either the partition
    (or subpartition) statistics or the global statistics.
    E. ANALYZE cannot overwrite or delete some of the values of statistics that were
    gathered by DBMS_STATS.
    F. ANALYZE can gather additional information that is not used by the optimizer,
    such as information about chained rows and the structural integrity of indexes,
    tables, and clusters. DBMS_STATS does not gather this information. DBMS_STATS
    gathers statistics only for cost-based optimization; it does not gather other
    statistics. For example, the table statistics gathered by DBMS_STATS include
    the number of rows, number of blocks currently containing data, and average row
    length but not the number of chained rows, average free space, or number of
    unused data blocks.
    G. DBMS_STATS does not call statistics collection methods associated with
    individual columns. Use the ANALYZE statement to gather such information.

  • Analyze table

    Dear all,
    What are the advantages if we do
    analyze table <table name> compute statisticsWhen ever i run this it is computing huge CPU utilization and taking long time........
    if we do this as far as i know
    1)it will analyze the table and count number of rows in a table properly.......
    Is there any advantage for INDEX if we do this operation.
    Regards,
    Vamsi

    Hey,
    Actually this command is old. I think it is 9i and below; It is still there for backwards compatibility.
    Since you are computing the statitics, oracle is going over all the records to get the stats. You can do estimate statics instead.
    OR, even better, you can use the new DBMS_Stats Package:
    EXEC DBMS_STATS.GATHER_TABLE_STATS (ownname=>'SCHEMA_NAME', tabname => 'TABLE_NAME', estimate_percent=>dbms_stats.auto_sample_size, degree=>2);
    This uses DBMS stats package, to estimate the statistics via a sample size automatically set through oracle.
    You can also use a similar command to estimate the stats of the whole schema
    EXEC DBMS_STATS.GATHER_SCHEMA_STATS (ownname=> 'SCHEMA_NAME', estimate_percent=>dbms_stats.auto_sample_size, degree=>2);
    From previous experience, creating an index is not enough, you have to gather the stats on the related table, so that the execution plan gets optimized.
    This command get table stats, histogram, uniqueness.. etc

  • ORA-20000: Unable to analyze TABLE "ECI"."COUNTRY"

    Oracle9i 9.2.0.7 on Windows Server 2003 32bit
    Using the "ANALYZE" in the Enterrpise Manager Console
    begin
    dbms_stats.gather_table_stats(ownname=>'ECI',tabname=>'COUNTRY',partname=>NULL);
    end;
    ORA-20000: Unable to analyze TABLE "ECI"."COUNTRY", insufficient priviledges or does not exist
    ORA-06512: at "SYS.DBMS_STATS", line 10292
    ORA-06512: at "SYS.DBMS_STATS", line 10315
    ORA-06512: at line 2
    Using SQLPLUS
    SQL>begin
    2>dbms_stats.gather_table_stats(ownname=>'ECI',tabname=>'country',partname=>NULL);
    3>end;
    4>/
    ORA-20000: Unable to analyze TABLE "ECI"."COUNTRY", insufficient priviledges or does not exist
    ORA-06512: at "SYS.DBMS_STATS", line 10292
    ORA-06512: at "SYS.DBMS_STATS", line 10315
    ORA-06512: at line 2
    COMMENT:I noticed here that eventhough I specifically used (tabname=>'country') it still used "ECI"."COUNTRY"(ALL CAPS) in executing my statement
    I also tested on other procedure.
    Using SQLPLUS
    SQL>begin
    2>dbms_redefinition.can_redef_table('ECI','country',dbms_redefinition.cons_use_pk);
    3>end;
    4>/
    BEGIN
    ERROR at line 1:
    ORA-00942: table or view does not exist
    ORA-06512: at "SYS.DBMS_REDEFINITION", line 8
    ORA-06512: at "SYS.DBMS_REDEFINITION", line 247
    ORA-06512: at line 2
    I don't understand why this error happens because
    a) the schema and table exist (I double checked)
    b) the error only happens on a single schema for only the old tables, when I create new tables I could "ANALYZE" it. I also can "ANALYZE" the indexes.
    c)I have used both the sys and system user logging in as SYSDBA
    In the ff exercise, I noticed that "ECI"."productrange" will work but "ECI"."PRODUCTRANGE" won't:
    SQL>select count(*) from "ECI"."productrange";
    COUNT(*)
    8
    SQL>select count(*) from "ECI"."PRODUCTRANGE";
    select count(*) from "ECI"."PRODUCTRANGE"
    ERROR at line 1:
    ora-00942: TABLE OR VIEW DOES NOT EXIST
    Can anyone kindly help me?

    You should not be creating tables in Oracle with names enclosed in double quotes. In that case Oracle preserves the case, making it difficult for others to identify the table.
    Create the table without using double quotes (may be CTAS) and everything should work fine.

  • OWB ORA-2000 unable to analyze table

    During execution I received the error above. In the mapping, I have two targets in two different schema's. I receive the error on the target that is in a different schema than the mapping.
    Is there a workaround? We do not have rights to grant analyze any table to the schema owner of the mapping.

    In OWB select Mapping, context menu Properties -> Code generation options -> Change Analyze table statements to false.
    Bye
    Detlef

  • Sql slow afterweekly STATS-JOB,then run analyze table it is fast again

    Oracle R11.2.0.2 :
    I hade some slow sql / reports and found the effect,
    that the sql is slow obvious after the weekend ,
    when STATS - JOB BSLN_MAINTAIN_STATS_JOB and other Jobs were running weekly on SYS.
    I did run dbms_stats.GATHER_TABLE_STATS on schema
    it doesn't help.
    But when
    run ANALYZE TABLE afterwards on only one or two tables of the schema
    the sql / reports performance is well and fast.
    in the dba_tables I can see the last_analyze - date
    and in GLOBAL_STATS = NO ( when Table runs with ANALYZE ),
    GLOBAL_STATS = YES( when Table runs with STATS )
    what does the ANALYZE TABLE command doing good and let my sql run well and fast,
    while dbms_stats.GATHER_TABLE_STATS
    seems not work well in this situation ?
    regards

    astramare wrote:
    Oracle R11.2.0.2 :
    I hade some slow sql / reports and found the effect,
    that the sql is slow obvious after the weekend ,
    when STATS - JOB BSLN_MAINTAIN_STATS_JOB and other Jobs were running weekly on SYS.
    I did run dbms_stats.GATHER_TABLE_STATS on schema
    it doesn't help.
    What options do you use for the gather_stats command ?
    Do you also have collected system stats?
    But when
    run ANALYZE TABLE afterwards on only one or two tables of the schema
    the sql / reports performance is well and fast.Analyze table is deprecated, but still does its work for some part. It is not as complete as dbms_stats
    >
    in the dba_tables I can see the last_analyze - date
    and in GLOBAL_STATS = NO ( when Table runs with ANALYZE ),
    GLOBAL_STATS = YES( when Table runs with STATS )
    It must have to do something with the way you use it..
    HTH
    FJFranken

  • Analyze table 10g steps

    Hi,
    DB: 10.2.0.4 RAC ASM
    OS: AIX 5.3L 64-bit
    I want to do analyze tables for all users.Please give me the steps for table and schema level.
    Thanks & Regards,
    Sunand

    CJ,
    dbms_utility.analyze_schema has been deprecated since 9i- you should be using dbms_stats.
    Sunand, by default there will be a gather stats job running on your database picking up any 'stale' statistics, have you disabled it?
    If you want/need to run it manually, dbms_stats.gather_database_stats is what you need. Documentation is here http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/stats.htm#i41448
    Carl

  • Analyze table taking lot of time

    HI,
    I am analyzing fact table. its taking almost 1 hour to. is there any solution for the same?
    i am using compute statistics.
    regards,
    sandeep

    Hi,
    Why not DBMS_STATS which collects stats in parallel so much faster then analyze command.I strongly recommand use DBMS_STATS in case of partition tables.Much faster, collects local and global stats both.
    Analyze cmd for partitioned table:--
    analyze table <schema>.<table> partition (<partition_name>) estimate statistics sample 5 percent;
    Use GATHER_SCHEMA_STATS for whole schema analysis .

  • Analyze tables using procedure .

    Hello Friends,
    I my schema , I had to analyze all the tables ( gather statistics ) before I start the loading process to target tables.
    I have created a procedure -
    create or replace procedure proc_analyze_tables as
    table_count number :=0;
    sqlstatement varchar2(4000);
    begin
    for i in ( select TNAME from TAB where TABTYPE='TABLE' AND TNAME ='ABC') loop
    sqlstatement := 'ANALYZE TABLE ' || i.TNAME || 'ESTIMATE STATISTICS ';
    EXECUTE IMMEDIATE sqlstatement ;
    dbms_output.put_line ( 'table name is ' || i.TNAME );
    end loop;
    end proc_analyze_tables;
    is it appropiate to use the folllowing statment.
    exec dbms_stats.gather_schema_stats(ownname=>'myschema_name', options=>'GATHER AUTO');
    When I execute the procedure , I am getting invalid analyze command .
    How I can use the procedure or is their any command that can be executed by execute immediate statement !!
    thanks/kumar

    kumar73 wrote:
    Hello Friends,
    I my schema , I had to analyze all the tables ( gather statistics ) before I start the loading process to target tables.
    I have created a procedure -
    create or replace procedure proc_analyze_tables as
    table_count number :=0;
    sqlstatement varchar2(4000);
    begin
    for i in ( select TNAME from TAB where TABTYPE='TABLE' AND TNAME ='ABC') loop
    sqlstatement := 'ANALYZE TABLE ' || i.TNAME || 'ESTIMATE STATISTICS ';
    EXECUTE IMMEDIATE sqlstatement ;
    dbms_output.put_line ( 'table name is ' || i.TNAME );
    end loop;
    end proc_analyze_tables;
    When I execute the procedure , I am getting invalid analyze command .
    How I can use the procedure or is their any command that can be executed by execute immediate statement !!
    thanks/kumarANALYZE TABLE is obsoleted & deprecated.
    use DBMS_STATS instead
    The standard advice when (ab)using EXECUTE IMMEDIATE is to compose the SQL statement in a single VARCHAR2 variable
    Then print the variable before passing it to EXECUTE IMMEDIATE.
    COPY the statement & PASTE into sqlplus to validate its correctness.

  • ANALYZE Tables

    I am trying to find out what is the best approach for Optimizer_Mode and ANALYZE Tables. In v11.0.3 NAC, is it still RULE Mode and NO ANALYZE?
    What is the scenario in 11i?
    RDBMS is currently 8.1.5.1 but will be 8.1.6.x this weekend.
    Also does anyone have a shareable list of parameters for the init<SID>.ora? I have a machine with 18 CPU and a huge chunk of RAM.
    Regards

    Remember :
    - RULE Mode is for transactionnal Oracle Applications. Therefore, Forms screens and so on are coded with RULE optimization in mind.
    - Benefits of ANALYZE can be proven with some selected reports that uses HINTS in the SELECT statement.
    => I suggest u to monitor reports submitted and their execution time, collect their names, verify their codes. U'll have a deep vision of ur system.
    Instead of that, analyze all schemas without questions (careful it can be long !!!) but u will never know whether it is needed or not.

  • Analyze Table required on a Global Temp. Table

    Hi,
    This is the background. We have a Windows reporting Oracle Server where we write stored procedures to access data mainly based off a warehouse residing on a unix box. DBLinks have been setup and synonym's created .
    We create Global Temp. Tables to store temp. data used by our report stored procedures. I have one query that accesses 5 remote tables and one local table
    The query was taking hours to run...after some research i found out that when I did an "Analyze Table" on my Global temp. table, the query came back in a few minutes.
    My confusion is that this table being a GTT.. it will always be empty when we run "Analyze Table" on it. What information is oracle? Do we need to run "analyze table" on all our GTT's created for different reports?
    Second question on show query plan
    Also if I do a query plan on this query ORacle dooes not provide a plan on the remote tables. If i change the query by removing the reference to the local table and hardcoing some vlaues, oralce returns a query plan for the query which now only uses the remote tables. Is this correct?

    Hi,
    you can fake the statistics of the temporary table.
    First create a real table (with indexes) that looks like the temporary table. Load the table with representative data.
    Then
    dbms_stats.gather_table_stats(ownname=>'schemauser',tabname=>'TEMPCOPY');
    dbms_stats.create_stat_table(ownname=>'schemauser',stattab=>'TEMPSTATS');
    dbms_stats.export_table_stats(ownname=>'schemauser',tabname=>'TEMPCOPY',stattab=>'TEMPSTATS'); --do that for every index
    dbms_stats.export_index_stats(ownname=>'schemauser',indname=>'INDEXNAME',stattab=>'TEMPSTATS');Now we import the generated statistics:
    dbms_stats.import_table_stats(ownname=>'schemauser',tabname=>'TEMPTABLE',stattab=>'TEMPSTATS');
    dbms_stats.import_index_stats(ownname=>'schemauser',tabname=>'TEMPTABLE',stattab=>'TEMPSTATS'); --for every indexOf course you can create a set of statistics and load them as needed.
    Dim
    dbms_stats.

  • Training an SVM on table with schema flexibility fails

    Dear colleagues,
    I'm trying to train a Support Vector Machine on a table with schema flexibility.
    On a small test table with only a couple of columns both the training and the prediction using the PAL libraries work fine. However, on my large sparse table with more than 1000 columns and "schema flexibility" set at creation time, I constantly run into the following error:
    Could not execute 'CALL SYSTEM.AFL_WRAPPER_GENERATOR ('PAL_SV', 'AFLPAL', 'SVMTRAIN', PAL_SV_SIGNATURE)' in 30 ms 529 µs .
    SAP DBTech JDBC: [423]: AFL error:  [423] "SYSTEM"."AFL_WRAPPER_GENERATOR": line 32 col 1 (at pos 1346): [423] (range 3) AFL error exception: AFL error: registration finished with errors, see indexserver trace
    The indexserver trace gives me something strange like:
    AFLPM_SQLDriverObj.cpp(02439) : aflpm_creator : direction must be in or out
    As far as I see it, all parameters are fine, though.
    Is there a limitation that does not allow PAL functions to be executed on tables with schema flexibility? I suspect so, because I'm running into similar problems with the SUBSTITUTE_MISSING_VALUES function.
    Thanks for any help,
    Daniel

    Hey there,
    isn't there anyone who came across this issue? I'd love to know if this is a known technical limitation with tables that use the "schema flexibility" or rather a bug. In the former case, can anyone suggest a workaround?
    I'd be grateful for any help or any pointer to further documentation.
    Best,
    Daniel

  • Analyze table in oracle 8.1.6

    Hi,
    I am working in oracle 8.1.6 on unix.the optimizer used here is RBO. I need to analyze a table using the command "analyze table <tablename> compute statistics; but my team mate said that the using anlyze table will degrade the performance.
    how can i analyze a table without affecting the performance?...
    give me an example..
    rgds..

    user537350 wrote:
    hi,
    i did defrag table using the command alter table move tablespace then rebuild the indexes and then analyze the table.
    while doing the analyze of table my teammate said it will degrade the performance?..how can i proceed ..First, I wouldn't just blindly assume I have a problem to be fixed just because "my teammate" said that what I did would degrade performance. Did he have a valid theory to back up his assertion? Why not actually measure performance and see if it degraded?
    BTW, I assume you realize that your vesion of oracle is totally unsupported in this millenium .... which means your organization doesn't value the data in the database.
    Edited by: EdStevens on Aug 12, 2009 10:46 AM

  • Where is the output of analyze table name validate structure cascade

    Hi,
    database version:8.1.7.0.0
    os :solaris 5.9
    since i used to get ORA-00600: INTERNAL ERROR CODE, ARGUMENTS: [25012], [7], [39] and i need to validate the table and this table is very huge(200 gb) where will be the output generated if any error is there in table including indexes.
    sql>analyze table event_t validate structure cascade;
    Regards
    Prakash

    Hello Helios
    sorry ,
    I am using 10.2 and reviewing
    http://docs.oracle.com/cd/B14117_01/server.101/b10759/statements_4005.htm#sthref4205
    my quote is from this document. My question of an ideal case, when there is no block corruption
    regards ,
    Pavel
    Edited by: Pavel on Oct 17, 2012 3:55 AM

Maybe you are looking for