[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Optimizing Oracle Optimizer Statistics - Excution Plan is not being generated as expected

Posted on 2007-08-03
4
Medium Priority
?
702 Views
Last Modified: 2013-12-19
Hi experts!!!

Some weeks ago, a built a new oracle server box and imported data from another server on it. Last week, I put the server on production. Since I put this new box on production, some users reported me performance issues on acessing data on some tables, while other tables are running really fast...

So, I decided to see the executions plans of queries that was reporting performance issues and discovered that these queries wasn't being the executions plans generated as expected... By example:

There is a table that have about 10.000.000 of rows and have the folowing DDL:

CREATE TABLE winthor2.pcmov
    (dtmov                          DATE NOT NULL,
    codprod                        NUMBER(6,0) NOT NULL,
    numnota                        NUMBER(10,0) NOT NULL,
    codoper                        VARCHAR2(2) NOT NULL,
    qt                             NUMBER(20,6),
    punit                          NUMBER(18,6),
    codfilial                      VARCHAR2(2) NOT NULL,
    status                         VARCHAR2(2) NOT NULL,
    codcli                         NUMBER(6,0) NOT NULL,
    codusur                        NUMBER(4,0) NOT NULL,
    custofin                       NUMBER(18,6),
    numcar                         NUMBER(6,0),
    numped                         NUMBER(10,0),
    ptabela                        NUMBER(18,6),
    numregiao                      NUMBER(4,0),
    percomsup                      NUMBER(8,4))
  PCTFREE     10
  INITRANS    1
  MAXTRANS    255
  TABLESPACE  ts_dados
  STORAGE   (
    INITIAL     65536
    MINEXTENTS  1
    MAXEXTENTS  2147483645
  )

The table have some Indexes, including the index below:

CREATE INDEX winthor2.pcmov_index1 ON winthor2.pcmov
  (
    dtmov                           ASC
  )
  PCTFREE     10
  INITRANS    2
  MAXTRANS    255
  TABLESPACE  ts_indice
  STORAGE   (
    INITIAL     220864512
    MINEXTENTS  1
    MAXEXTENTS  2147483645
  )


But, when I issue the query "select * from pcmov where dtmov between sysdate - 90 and sysdate - 60" the execution plan show me that oracle prefered perform a FULL TABLE SCAN instead of using the Index to find the data. If i runs the same query on the OLD server, the execution plan prefers to use the INDEX, as expected.

Searching on internet, I found that this issue could be caused by incorrect statistics on my schema objects, that causes oracle optimizer to not generate a optimal execution plan.

Does anybody knows how could I solve this problem?
I'm running Oracle 10G R2 x64 on a SuSE Linux Enterprise Server 10 box.

Thanks a lot!
0
Comment
Question by:regisdaniel
  • 2
4 Comments
 
LVL 8

Expert Comment

by:YANN0S
ID: 19630250
Certain database environment changes may affect the performance characteristics of applications. Such changes include changes in optimizer statistics, changes to the optimizer mode settings, and changes to parameters affecting the sizes of memory structures, such as SORT_AREA_SIZE and BITMAP_MERGE_AREA_SIZE.

Since you created a new instance some of the initialization parameters may differ from the old one.

What you can do is
1) gather fresh statistics for your tables indexes etc.
http://download.oracle.com/docs/cd/B10501_01/server.920/a96533/stats.htm#26713
2) Use optimizer hints in certain statements (but this requires modifying the code of your application)
select /*+ INDEX(pcmov_index1) */ * from pcmov where dtmov between sysdate - 90 and sysdate - 60
3) If the execution plans remain unstable you can use stored outlines to preserve plan stability:
http://download.oracle.com/docs/cd/B10501_01/server.920/a96533/outlines.htm#13547
0
 
LVL 11

Assisted Solution

by:mohammadzahid
mohammadzahid earned 800 total points
ID: 19630260
I think you need to analyze the index winthor2.pcmov_index1  

Goto this site for possible solution.
http://www.psoug.org/reference/indexes.html#ixbt

Also you might want to try using greater then >=   :date1  and column_name <= :date2

Hope this helps!!

0
 

Author Comment

by:regisdaniel
ID: 19638279
Hi YANN0S and mohammadzahid,
Thanks a lot for your help!

This weekend I submitted a job on my Oracle Server that caught fresh estatistics for all objects on my schema.

That query that I first issued on this question is running really fast now, but, the query below

SELECT   a.codusur, NVL (SUM (qt * (a.punit - a.ptabela)), 0) AS valor_dccalculado
          FROM pcmov a, pcnfsaid b
         WHERE a.numtransvenda = b.numtransvenda AND a.codoper = 'S' AND b.dtsaida BETWEEN sysdate - 30 AND sysdate
      GROUP BY a.codusur

are giving me the folowing execution plan:
  SQL Statement from editor:
   
   
        SELECT   a.codusur, NVL (SUM (qt * (a.punit - a.ptabela)), 0) AS valor_dccalculado
            FROM pcmov a, pcnfsaid b
           WHERE a.numtransvenda = b.numtransvenda AND a.codoper = 'S' AND b.dtsaida BETWEEN sysdate - 30 AND sysdate
        GROUP BY a.codusur
    SQL Statement from editor:
   
   
        SELECT   a.codusur, NVL (SUM (qt * (a.punit - a.ptabela)), 0) AS valor_dccalculado
            FROM pcmov a, pcnfsaid b
           WHERE a.numtransvenda = b.numtransvenda AND a.codoper = 'S' AND b.dtsaida BETWEEN sysdate - 30 AND sysdate
        GROUP BY a.codusur
  ------------------------------------------------------------
   
  Statement Id=3   Type=HASH JOIN
  Cost=82112  TimeStamp=06-08-07::10::51:05
 
       (1)  SELECT STATEMENT  ALL_ROWS
     Est. Rows: 450  Cost: 82.129
       (7)  HASH GROUP BY
     Est. Rows: 450  Cost: 82.129
           (6)  FILTER
               (5)  HASH JOIN
                    Est. Rows: 309.071  Cost: 82.112
                   (3)  TABLE TABLE ACCESS BY INDEX ROWID WINTHOR2.PCNFSAID  [Analyzed]
                   (3)   Blocks: 17.254 Est. Rows: 21.853 of 518.296  Cost: 762
                        Tablespace: TS_DADOS
                       (2)  INDEX INDEX SKIP SCAN WINTHOR2.PCNFSAID_IDX10  [Analyzed]
                            Est. Rows: 921  Cost: 466
                   (4)  TABLE TABLE ACCESS FULL WINTHOR2.PCMOV  [Analyzed]
                   (4)   Blocks: 368.812 Est. Rows: 7.326.948 of 9.597.089  Cost: 81.301
                        Tablespace: TS_DADOS

The table PCMOV has a INDEX on column NUMTRANSVENDA:

CREATE INDEX winthor2.pcmov_idx8 ON winthor2.pcmov
  (
    numtransvenda                   ASC
  )
  PCTFREE     10
  INITRANS    2
  MAXTRANS    255
  TABLESPACE  ts_indice
  STORAGE   (
    INITIAL     124018688
    MINEXTENTS  1
    MAXEXTENTS  2147483645
  )


Why the oracle is prefering do a FULL TABLE SCAN instead of using this index?
Thanks a lot!!!
0
 
LVL 8

Accepted Solution

by:
YANN0S earned 1200 total points
ID: 19638773
Well oracle optimization is really complex.

You can check the documentation for some information:
http://download.oracle.com/docs/cd/B10501_01/server.920/a96533/optimops.htm#37379
http://download.oracle.com/docs/cd/B10501_01/server.920/a96533/optimops.htm#39473

The only thing I can say in your case is that the optimizer expects 21.853 rows from WINTHOR2.PCNFSAID, so if the index scan of the index is 4 the total cost would be more than 82.129.

If you want to try some hints, try /*+ FIRST_ROWS */ or /*+ INDEX(a, pcmov_idx8) */ or USE_NL
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Suggested Courses
Course of the Month18 days, 13 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question