Table Statistics Gathering Query

Hey there,
I'm currently getting trained in Oracle and one of the questions posed to me were create a table, insert a million rows into it and try to find the number of rows in it. I've tried the following steps to solve this,
First table creation
SQL> create table t1(id number);
Table created.Data insertion
SQL> insert into t1 select level from dual connect by level < 50000000;
49999999 rows created.Gathering statistics
SQL> exec dbms_stats.gather_table_stats('HR','T1');
PL/SQL procedure successfully completed.Finally counting the number of rows
SQL> select num_rows from user_tables where table_name='T1';
  NUM_ROWS
  49960410
SQL> select count(*) from t1;
  COUNT(*)
  49999999My database version is,
SQL> select * from v$version;
BANNER
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product
PL/SQL Release 10.2.0.1.0 - Production
CORE    10.2.0.1.0      Production
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - ProductionI would like to know why there are two different results for the same table when using "num_rows" from the view "user_tables" and the aggregate function "count()" over the same table. Please do keep in mind that i'm studying oracle and this is from a conceptual point of view only. I would like to know how gathering the table statistics works using dbms_stats package works.
Thank You,
Vishal

vishm8 wrote:
Gathering statistics
SQL> exec dbms_stats.gather_table_stats('HR','T1');
PL/SQL procedure successfully completed.I would like to know why there are two different results for the same table when using "num_rows" from the view "user_tables" and the aggregate function "count()" over the same table. Please do keep in mind that i'm studying oracle and this is from a conceptual point of view only. I would like to know how gathering the table statistics works using dbms_stats package works.
Thank You,
VishalBecause you aren't specifying a value for estimate_percent in the procedure call (to gather_table_stats) Oracle will pick an estimate value for you. If you want to sample the entire table you would need to explicitly specify that in your procedure call.
http://download.oracle.com/docs/cd/E11882_01/appdev.112/e16760/d_stats.htm#ARPLS68582

Similar Messages

  • How to check the progress of statistics gathering on a table?

    Hi,
    I have started the statistics gathering on a few big tables in my database.
    How to check the progress of statistics gathering on a table? Is there any data dictionary views or tables to monitor the progress of stats gathering.
    Regds,
    Kunwar

    Hi all
    you can check with this small script.
    it lists the sid details for long running session like
    when it started
    when last update
    how much time still left
    session status "ACTIVE/INACTIVE". etc.
    -- Author               : Syed Kaleemuddin_
    -- Script_name          : sid_long_ops.sql
    -- Description          : list the sid details for long running session like when it started when last update how much time still left.
    set lines 200
    col OPNAME for a25
    Select
    a.sid,
    a.serial#,
    b.status,
    a.opname,
    to_char(a.START_TIME,' dd-Mon-YYYY HH24:mi:ss') START_TIME,
    to_char(a.LAST_UPDATE_TIME,' dd-Mon-YYYY HH24:mi:ss') LAST_UPDATE_TIME,
    a.time_remaining as "Time Remaining Sec" ,
    a.time_remaining/60 as "Time Remaining Min",
    a.time_remaining/60/60 as "Time Remaining HR"
    From v$session_longops a, v$session b
    where a.sid = b.sid
    and a.sid =&sid
    And time_remaining > 0;
    Sample output:
    SQL> @sid_long_ops
    Enter value for sid: 474
    old 13: and a.sid =&sid
    new 13: and a.sid =474
    SID SERIAL# STATUS OPNAME START_TIME LAST_UPDATE_TIME Time Remaining Sec Time Remaining Min Time Remaining HR
    474 2033 ACTIVE Gather Schema Statistics 06-Jun-2012 20:10:49 07-Jun-2012 01:35:24 572 9.53333333 .158888889
    Thanks & Regards
    Syed Kaleemuddin.
    Oracle Apps DBA
    Mobile: +91 9966270072
    Email: [email protected]

  • Setting of Optimizer Statistics Gathering

    I'm checking in my db setting and database is analysing each day. But as I notice there are a lot of tables that information shows last analysis in about month ago... Do I have to change some parameters?

    lesak wrote:
    I don't have any data that show you that my idea is good. I'd like to confirm on this forum that my idea is good or not. I've planned to make some changes to have better performance of query that read from top use tables. If this is bad solutions it's also important information for me.One point of view is that your idea is bad. That point of view would be to figure out what the best access for your query is and set that as a baseline, or figure out what statistics get you the correct plans on a single query that has multiple plans that are best with different values sent in through bind variables, and lock the statistics.
    Another point of view would be to gather current plans for currently used queries, then do nothing at all unless the optimizer suddenly decides to switch away from one, then figure out why.
    Also note the default statistics gathering is done in a window, if you have a lot of tables changing it could happen that you can't get stats in a timely fashion within the window.
    Whether the statistics gathering is appropriate may depend on how far off histograms are from describing the actual data distribution you see. What my be appropriate worry for one app may be obsessive tuning disorder for another. 200K rows out of millions may make no difference at all, or may make a huge difference if the newly added data is way off from what the statistics make the opitmizer think it is.
    One thing you are probably doing right is to recognize that tuning particular queries may be much more useful than obsessing over statistics.
    Note how much I've used the word "may" here.

  • Table statistics delete

    Hi
    Is there any command to delete gathered statistics of a table
    suppose : I have gather table statistics as under
    exec dbms_stats.gather_table_stats('TEST1','EMP');
    now I want to delete the statistics from the above table EMP
    Regards
    Jewel

    The package dbms_stats is fully documented in the Oracle supplied package and type reference manual for your unknown version of Oracle.
    It has a call to delete statistics.
    As per forums etiquette, please do the obvious first and consult documentation.
    Sybrand Bakker
    Senior Oracle DBA

  • Rows in all tables in one query

    Hi All,
    How can i find the numbers of rows (records) in all the tables except system tables with single query.
    In one tran table i have around 10,00,000 (TEN LACS) rows. while processing it take time. Plz suggest some solution for this.
    Regards,
    Mummy

    Hi,
    You could use the NUM_ROWS column in the ALL_TABLES table. This column only gets populated if you collect statistics on the relevant tables though.
    See: http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14237/statviews_2105.htm#REFRN20286
    You can analyze the relevant tables first and then use a SUM. For instance this query gets the total number of rows in the tables in the schema MAST:
    select sum(num_rows) from all_tables where owner = 'MAST';
    Regards,
    Marco
    =
    www.marcostuijvenberg.nl

  • Statistics gathering

    Hello ,
    Every one I'm little confuse about "Statistics gathering" in ebs so I have some question in my mind which are following.
    kindly any one clear my concept about it.I really appreciate you.
    1.What is Statistics gathering ?
    2. What is the benefit of it?
    3.Can after this our ERP performance is better?
    one question is out this subject is that can If any one wanna APPS DBA then who must be DBA(oracle 10g,9i etc) or who only have a concept of oracle dba like backup,recovery,cloning etc.
    Regards,
    Shahbaz khan

    1.What is Statistics gathering ?
    Statistics gathering is a process by which Oracle scans some or all of your database objects (such as tables, indexes etc.) and stores the information in objects such as dbal_tables, dba_histograms. Oracle uses this information to determine the best execution path for statements it has to execute (such as select, update etc.)
    2. What is the benefit of it?
    It does help the queries become more efficient.
    3.Can after this our ERP performance is better?
    Typically, if you are experiencing performance issues, this is one of the first remedies.
    one question is out this subject is that can If any one wanna APPS DBA then who must be DBA(oracle 10g,9i etc) or who only have a concept of oracle dba like backup,recovery,cloning etc.I will let Hussein or Helios answer that question. They can offer a lot of helpful advice. You can also refer to Hussein's recent thread on a similar topic.
    See Re: Time Management and planned prep
    Hope this helps,
    Sandeep Gandhi

  • Statistics gathering error

    Hi all,
    I am running on AIX  version 5.3 with oracle 10.2.0.1 database.
    Since yesterday I am encountering errors when gathering statistics from table partitions that already have data in it. I was able to gather without errors for years but then suddenly I got the following errors:
    exec dbms_stats.gather_table_stats('BLP', 'ADJUSTMENT_TRANSACTION', 'ADJUSTMENT_TRANSACTION_P201311', GRANULARITY=>'PARTITION')
    BEGIN dbms_stats.gather_table_stats('BLP', 'ADJUSTMENT_TRANSACTION', 'ADJUSTMENT_TRANSACTION_P201311', GRANULARITY=>'PARTITION'); END;
    ERROR at line 1:
    ORA-06502: PL/SQL: numeric or value error: character string buffer too small
    ORA-06512: at "SYS.DBMS_STATS", line 13044
    ORA-00942: table or view does not exist
    ORA-06512: at "SYS.DBMS_STATS", line 13076
    ORA-06512: at line 1
    I also got the following errors in the alert_logs:
    ORA-00600: internal error code, arguments: [KSFD_DECAIOPC], [0x7000004FF189780], [], [], [], [], [], []
    The other day the alert_log generated this error when generating statistics also for another table:
    ORA-01114: IO error writing block to file 1001 (block # 4026567)
    ORA-27063: number of bytes read/written is incorrect
    IBM AIX RISC System/6000 Error: 28: No space left on device
    As I checked, the server has sufficient space.
    Do you guys have any idea what could be the problem? I can't generate table statistics as of the moment due to this problem.
    Regards,
    Tim

    Hi Suntrupth,
    BLP@OLSG3DB  > show parameter filesystemio_options
    NAME                                 TYPE        VALUE
    filesystemio_options                 string      asynch
    BLP@OLSG3DB  > show parameter disk_asynch_io
    NAME                                 TYPE        VALUE
    disk_asynch_io                       boolean     TRUE
    No invalid objects where returned also:
    BLP@OLSG3DB  > select object_name from dba_objects where status='INVALID' and owner='SYS';
    no rows selected
    Regards,
    Tim

  • How to set the table input in Query template?

    Hi all.
    I need to call a Bapi_objcl_change, with import parameter and a table as an input. I have done this, in BLS. I have set the table input in the
    form of xml. In BLS, I get the output(the value gets change in SAP R3, what i have given in BLS).  But if i set the same xml structure  in
    query template, I didn't get the output. Table input parameter does not take that xml source.  How to set the table input in Query template?
    can anyone help me?
    Regards,
    Hemalatha

    Hema,
    You probably need to XML encode the data so that it will pass properly and then xmldecode() it to set the BAPI input value.
    Sam

  • Error while executing the table statistics using Brtools

    Dear Team,
    We are getting ORA-01031: insufficient privileges error whenever we have tried to execute the update or table statistics using brtools on our SAP development server. I have checked the permissions of sapcheck directory and changed it to 775 still error remains the same. I have observed, it is failing to create the sta or chk files in sapcheck directory after executing update statistics using Brtools.
    BR0291I BRCONNECT will be started with options '-p initDEV.sap -l E -f stats -t  "USTUD" -p 1'
    BR0280I BRTOOLS time stamp: 2010-07-20 12.02.33
    BR0670I Enter 'c[ont]' to continue, 'b[ack]' to go back, 's[top]' to abort:
    c
    BR0280I BRTOOLS time stamp: 2010-07-20 12.02.34
    BR0257I Your reply: 'c'
    BR0259I Program execution will be continued...
    BR0801I BRCONNECT 6.40 (50)
    BR0280I BRCONNECT time stamp: 2010-07-20 12.02.42
    BR0301E SQL error -1031 at location BrLicCheck-12
    ORA-01031: insufficient privileges
    BR0806I End of BRCONNECT processing: cedsegpe.log 2010-07-20 12.02.42
    BR0280I BRCONNECT time stamp: 2010-07-20 12.02.42
    BR0804I BRCONNECT terminated with errors
    I have checked the owner for SAPUSER table and it is showing as OPS$DEVADM
    Please, advise me on the same.
    Thanks and Regards,
    Kedar

    Dear All,
    Thanks for your responses.
    Permissions are set as below for br* files.
    sap-dev:devadm 23> ls -ltr br*
    -rwxrwxr-x   1 oradev     sapsys     3437688 Oct 31  2008 brarchive
    -rwxrwxr-x   1 oradev     sapsys     3547760 Oct 31  2008 brbackup
    -rwxrwxr-x   1 oradev     sapsys     4632408 Oct 31  2008 brconnect
    -rwxrwxr-x   1 devadm     sapsys     3850224 Oct 31  2008 brrecover
    -rwxrwxr-x   1 devadm     sapsys     1480656 Oct 31  2008 brrestore
    -rwxrwxr-x   1 devadm     sapsys     4837672 Oct 31  2008 brspace
    -rwxrwxr-x   1 oradev     sapsys     2175208 Oct 31  2008 brtools
    I guess it is fine because with these set of permissions, it is working absolutely fine in my quality system.
    QAS Permissions are as belows for your information
    sap-qas:qa1adm 22> ls -ltr br*
    -rwsrwxr-x   1 oraqa1     sapsys     3437688 Oct 31  2008 brarchive
    -rwsrwxr-x   1 oraqa1     sapsys     3547760 Oct 31  2008 brbackup
    -rwsrwxr-x   1 oraqa1     sapsys     4632408 Oct 31  2008 brconnect
    -rwxrwxr-x   1 qa1adm     sapsys     3850224 Oct 31  2008 brrecover
    -rwxrwxr-x   1 qa1adm     sapsys     1480656 Oct 31  2008 brrestore
    -rwxrwxr-x   1 qa1adm     sapsys     4837672 Oct 31  2008 brspace
    -rwsrwxr-x   1 oraqa1     sapsys     2175208 Oct 31  2008 brtools
    So do you feel still it has something to do with permissions?
    Thanks and Regards,
    Kedar

  • Internal table in ABAP Query

    Hi all,
    Can we use internal table in ABAP/SAP Query (Infoset - SQ02)? If yes, Pls guide me on the same.
    Thanks in advance
    Regards
    Madhumathi A

    to my knowledge u can't use internal tables in ABAP query...it is a mix of tables...

  • Import Table Statistics to another table

    Hi,
    Just like to know if I can use dbms_stats.import_table_stats to import table statistics to another table?
    Scenario:
    I exported the table statistics of the table (T1) using the command below.
    exec dbms_stats.export_table_stats('<user>','T1',NULL,'<stat table>');
    PL/SQL procedure successfully completed.
    And then, I have another table named T2, T1 and T2 are identical tables. T2 does not have statistics (I intentionally did not run gather statistics). I am wondering
    if I can import table statistics from T1 to T2 using dbms_stats package?.
    For what I understand, statistics can be imported back at the same table which is T1 but not for another table using dbms_stat package. If I am wrong, anyone can correct me.
    Thanks

    hi
    just try ;-) you lose nothing probably,
    check afterwards last_analyzed value for that table in user_tables
    if something is wrong, run regular stats

  • How can I find number of columns in a table using a query

    Hi
    I want to find the number of columns in a table using a query.
    Any help in this regard is much appreciated.
    Cheers

    Hi,
    This is the output i get when i executed ur query
    OWNER     OBJECT_NAME     OBJECT_TYPE
    SMLDBO     T2311_SURVEY_QUESTIONS     TABLE
    select OWNER,OBJECT_NAME,OBJECT_TYPE
    from all_objects
    where OBJECT_NAME = 'T2311_SURVEY_QUESTIONS';
    works Fine.
    But if i use the below query it returns : 0
    SELECT count(*) FROM user_tab_columns
    WHERE table_name =upper( 'T2311_SURVEY_QUESTIONS');
    What could be problem.
    The table exists + name of the table is correct + it resides in my schema itself.
    Any guess !!!

  • Maximum number of tables that can be outer joined with one table in a query

    Hi All,
    Iam new to sql, so can you please let me know What is the maximum number of tables that can be outer joined with one table in a query?
    Thanks,
    Srini

    srinu2 wrote:
    Iam new to sql, so can you please let me know What is the maximum number of tables that can be outer joined with one table in a query?
    There is no limit to the number of tables you can outer join as long as you join them correctly.
    SQL> with a as
      2      (
      3      select 1 id, 2 b_key, 3 c_key from dual union all
      4      select 2 id, 1 b_key, 4 c_key from dual union all
      5      select 3 id, 3 b_key, 1 c_key from dual union all
      6      select 4 id, 4 b_key, 2 c_key from dual
      7      ),
      8      b as
      9      (
    10      select 1 id, 1 c_key2 from dual union all
    11      select 2 id, 5 c_key2 from dual union all
    12      select 3 id, 3 c_key2 from dual union all
    13      select 4 id, 2 c_key2 from dual
    14      ),
    15      c as
    16      (
    17      select 1 key1, 1 key2, '1-1' dta from dual union all
    18      select 1 key1, 2 key2, '1-2' dta from dual union all
    19      select 1 key1, 3 key2, '1-3' dta from dual union all
    20      select 1 key1, 4 key2, '1-4' dta from dual union all
    21      select 2 key1, 1 key2, '2-1' dta from dual union all
    22      select 2 key1, 2 key2, '2-2' dta from dual union all
    23      select 2 key1, 3 key2, '2-3' dta from dual union all
    24      select 2 key1, 4 key2, '2-4' dta from dual union all
    25      select 3 key1, 1 key2, '3-1' dta from dual union all
    26      select 3 key1, 2 key2, '3-2' dta from dual union all
    27      select 3 key1, 3 key2, '3-3' dta from dual union all
    28      select 3 key1, 4 key2, '3-4' dta from dual union all
    29      select 4 key1, 1 key2, '4-1' dta from dual union all
    30      select 4 key1, 2 key2, '4-2' dta from dual union all
    31      select 4 key1, 3 key2, '4-3' dta from dual union all
    32      select 4 key1, 4 key2, '4-4' dta from dual
    33      )
    34  select d.a_id, d.b_id, c.key1 as c_key1, c.key2 as c_key3, c.dta
    35  from
    36      c,
    37      (
    38      select
    39          a.id as a_id, b.id as b_id, a.c_key, b.c_key2
    40      from a, b
    41      where a.b_key = b.id
    42      ) d
    43  where d.c_key = c.key1 (+)
    44  and   d.c_key2 = c.key2 (+);
          A_ID       B_ID     C_KEY1     C_KEY3 DTA
             3          3          1          3 1-3
             4          4          2          2 2-2
             2          1          4          1 4-1
             1          2
    SQL>

  • Having more LTSs in logical dimension table hit the query performance?

    Hi,
    We have a logical table having around 19 LTSs. Having more LTSs in logical dimension table hit the query performance?
    Thanks,
    Anilesh

    Hi Anilesh,
    Its kind of both YES and NO. Here is why...
    NO:
    LTS are supposed to give BI Server an optimistic and logical way to retrieve the data. So, having more Optimistic LTS might help the BI Server with some good options tailored to a variety of analysis requests.
    YES:
    Many times, we have to bring in multiple physical tables as a part of single LTS (Mostly when the physical model is a snowflake) which might cause performance issues. Say there is a LTS with two tables "A" and "B", but for a ad-hoc analysis just on columns in "A", the query would still include the join with table "B" if this LTS is being used. We might want to avoid this kind of situations with multiple LTS each for a table and one for both of them.
    Hope this helps.
    Thank you,
    Dhar

  • Cgi statistics gathering under 6.1 and Solaris 9

    Hello all,
    is it possible to log for cgi requests the value for handling each of the time spent on the request?
    I see a lot of editable parameters in the 'Performance, Tuning and Scaling Guide' but can't figure out how to do that.
    Once in a thread I read "...enable statistics gathering, then add %duration% to your access log format line".
    I can't find the terminus %duration% in the guide, which parameter is taken?
    Regards Nick

    Hello elvin,
    thanks for your reply. Now I think I managed to let the webserver log the duration of a cgi request, but I'm unsure how to interpret the value eg. in the access log I get
    ..."GET /cgi/beenden.cgi ... Gecko/20040113 MultiZilla/1.6.3.1d" 431710"
    ..."GET /pic.gif ... Gecko/20040113 MultiZilla/1.6.3.1d" 670"
    so the last value corresponds to my %duration% in the magnus.conf.
    431710 ... in msec? - makes no sense
    670 ... in msec?
    The complete string in magnus.conf reads as follows:
    Init fn="flex-init" access="$accesslog" format.access="%Ses->client.ip% - %Req->vars.auth-user% [%SYSDATE%] \"%Req->reqpb.clf
    -request%\" %Req->srvhdrs.clf-status% %Req->srvhdrs.content-length% \"%Req->headers.user-agent%\" \%duration%\""Regards Nick

Maybe you are looking for

  • Install OS X on replacement macbook air HD from Lion

    Hi, My Macbook air hard drive recently gave up after 4 years (therefore out of warranty) so I bought a replacement hard drive for it. At the time I was running snow leopard on my imac and understood I could use it's optical drive to install snow leop

  • RFC call from Lotus Notes

    Hi, I have create an RFC function,and have a successful test in R/3. And when I call this RFC function from Lotus Notes.The return message is AA 291 'No correction'. Anybody know the reason? Best regards, leric

  • Sd billing with wbs element

    dear all, please understand the scenario example: item - "cable" . total order quantity - 5 kilometers of installation installation charges: 100000 per kilometer. (total order value- 500000) billing can be done partially.  (multiple invoices against

  • How can i add new contacts to the adress book? iOS5

    i've just upgrade to iOS 5 and i notice that i can't add new contacts to my adress book beacuse there is no + button

  • Contextual Menu messed up

    When I right click on my contextual menus, all the categories/options appear as numbers rather than names (ie: N151, N165 etc). I am not sure how to correct this problem. Anything I can do about it? Any help is appreciated!! Thanks.