Oracle 8.0.5
AIX 4.3.3
I Have following statement, which takes forever and does lots of physical
reads

******************************************************************************************
insert into test_table
   SELECT   v1.engagement, v1.YEAR, v1.period, MAX (v2.net_fee_earned_ptd)
,
            MAX (v2.exp_wip_val_ptd)
       FROM (SELECT   MAX (wstat.eng_numb) engagement,
                      MAX (wstat.fnancl_year) YEAR, MAX (wstat.prd_numb)
period,
                        SUM (NVL (wstat.time_wip_val_ptd, 0))
                      + SUM (NVL (wstat.gnrl_w_on_ptd, 0))
                      - SUM (NVL (wstat.gnrl_w_off_ptd, 0))
                      - SUM (NVL (wstat.time_wip_val_w_off_ptd, 0))
                      - SUM (NVL (wstat.wip_prvsn_ptd, 0))
                      - SUM (NVL (wstat.exp_wip_val_w_off_ptd, 0))
                      - SUM (NVL (dstat.dbtrs_w_off_ptd, 0))
                      - SUM (NVL (dstat.dbtrs_prvsn_ptd, 0))
                            net_fee_earned_ptd,
                      SUM (NVL (wstat.exp_wip_val_ptd, 0)) exp_wip_val_ptd
                 FROM eng_wip_stats wstat, eng_dbtrs_stats dstat
                WHERE wstat.eng_numb(+) = dstat.eng_numb
                  AND wstat.fnancl_year = dstat.fnancl_year
                  AND wstat.prd_numb = dstat.prd_numb
                  AND wstat.eng_numb = '1000001'
             GROUP BY wstat.eng_numb, wstat.fnancl_year, wstat.prd_numb)
v1,
            (SELECT   MAX (wstat.eng_numb) engagement,
                      MAX (wstat.fnancl_year) YEAR, MAX (wstat.prd_numb)
period,
                        SUM (NVL (wstat.time_wip_val_ptd, 0))
                      + SUM (NVL (wstat.gnrl_w_on_ptd, 0))
                      - SUM (NVL (wstat.gnrl_w_off_ptd, 0))
                      - SUM (NVL (wstat.time_wip_val_w_off_ptd, 0))
                      - SUM (NVL (wstat.wip_prvsn_ptd, 0))
                      - SUM (NVL (wstat.exp_wip_val_w_off_ptd, 0))
                      - SUM (NVL (dstat.dbtrs_w_off_ptd, 0))
                      - SUM (NVL (dstat.dbtrs_prvsn_ptd, 0))
                            net_fee_earned_ptd,
                      SUM (NVL (wstat.exp_wip_val_ptd, 0)) exp_wip_val_ptd
                 FROM eng_wip_stats wstat, eng_dbtrs_stats dstat
                WHERE wstat.eng_numb(+) = dstat.eng_numb
                  AND wstat.fnancl_year = dstat.fnancl_year
                  AND wstat.prd_numb = dstat.prd_numb
                  AND wstat.eng_numb = '1000001'
             GROUP BY wstat.eng_numb, wstat.fnancl_year, wstat.prd_numb) v2
      WHERE v1.engagement = v2.engagement(+)
        AND TO_DATE (   v2.YEAR(+)
                     || v2.period(+), 'YYYYMM') >=
                   ADD_MONTHS (TO_DATE (   v1.YEAR
                                        || v1.period, 'YYYYMM'), -12)
        AND TO_DATE (   v2.YEAR(+)
                     || v2.period(+), 'YYYYMM') <=
                                    TO_DATE (   v1.YEAR
                                             || v1.period, 'YYYYMM')
   GROUP BY v1.engagement, v1.YEAR, v1.period
/
******************************************************************************************

Here is the explain plan:

******************************************************************************************
   ID   PID QUERY_PLAN
----- -----
----------------------------------------------------------------------------------------
    0       INSERT STATEMENT   Cost = 106
    1     0   SORT GROUP BY  Card=1
    2     1     NESTED LOOPS OUTER  Card=1
    3     2       VIEW   Card=1
    4     3         SORT GROUP BY  Card=1
    5     4           HASH JOIN   Card=1
    6     5             TABLE ACCESS BY INDEX ROWID ENG_DBTRS_STATS Card=19
    7     6               INDEX RANGE SCAN IDX_EG10_ENGNUMB_CRNTFLAG
Card=19
    8     5             TABLE ACCESS BY INDEX ROWID ENG_WIP_STATS Card=21
    9     8               INDEX RANGE SCAN IDX_EG09_ENGNUMB_CRNTFLAG
Card=21
   10     2       VIEW   Card=1
   11    10         SORT GROUP BY  Card=1
   12    11           HASH JOIN   Card=1
   13    12             TABLE ACCESS BY INDEX ROWID ENG_DBTRS_STATS Card=19
   14    13               INDEX RANGE SCAN IDX_EG10_ENGNUMB_CRNTFLAG
Card=19
   15    12             TABLE ACCESS BY INDEX ROWID ENG_WIP_STATS Card=21
   16    15               INDEX RANGE SCAN IDX_EG09_ENGNUMB_CRNTFLAG
Card=21

17 rows selected.
******************************************************************************************

If I just run the select part (not insert into) it's really quick

With the following explain plan:
******************************************************************************************
   ID   PID QUERY_PLAN
----- -----
----------------------------------------------------------------------------------------
    0       SELECT STATEMENT   Cost = 106
    1     0   SORT GROUP BY  Card=1
    2     1     NESTED LOOPS OUTER  Card=1
    3     2       VIEW   Card=1
    4     3         SORT GROUP BY  Card=1
    5     4           HASH JOIN   Card=1
    6     5             TABLE ACCESS BY INDEX ROWID ENG_DBTRS_STATS Card=19
    7     6               INDEX RANGE SCAN IDX_EG10_ENGNUMB_CRNTFLAG
Card=19
    8     5             TABLE ACCESS BY INDEX ROWID ENG_WIP_STATS Card=21
    9     8               INDEX RANGE SCAN IDX_EG09_ENGNUMB_CRNTFLAG
Card=21
   10     2       VIEW   Card=1
   11    10         SORT GROUP BY  Card=1
   12    11           HASH JOIN   Card=1
   13    12             TABLE ACCESS BY INDEX ROWID ENG_DBTRS_STATS Card=19
   14    13               INDEX RANGE SCAN IDX_EG10_ENGNUMB_CRNTFLAG
Card=19
   15    12             TABLE ACCESS BY INDEX ROWID ENG_WIP_STATS Card=21
   16    15               INDEX RANGE SCAN IDX_EG09_ENGNUMB_CRNTFLAG
Card=21

17 rows selected.
******************************************************************************************

Apart from the word INSERT being replaced by SELECT I don't see why it
would take so long. (no difference)


I turned tracing on and looked at the trace files for both statements and
the difference seems to be only in "WAIT #1: nam='db file sequential read'
ela= 0 p1=37 p2=127244 p3=1" which the insert into has many many many in th
etrace file and the normal select only has few.( different numbers)


Anybody seen this before?? Know a solution??


Oh ja: If I do "create table as"  it works really quick also

TIA


Jack

===================================================================
De informatie verzonden in dit e-mailbericht is vertrouwelijk en is
uitsluitend bestemd voor de geadresseerde. Openbaarmaking,
vermenigvuldiging, verspreiding en/of verstrekking van deze informatie aan
derden is, behoudens voorafgaande schriftelijke toestemming van Ernst &
Young, niet toegestaan. Ernst & Young staat niet in voor de juiste en
volledige overbrenging van de inhoud van een verzonden e-mailbericht, noch
voor tijdige ontvangst daarvan. Ernst & Young kan niet garanderen dat een
verzonden e-mailbericht vrij is van virussen, noch dat e-mailberichten
worden overgebracht zonder inbreuk of tussenkomst van onbevoegde derden.

Indien bovenstaand e-mailbericht niet aan u is gericht, verzoeken wij u
vriendelijk doch dringend het e-mailbericht te retourneren aan de verzender
en het origineel en eventuele kopieën te verwijderen en te vernietigen.

Ernst & Young hanteert bij de uitoefening van haar werkzaamheden algemene
voorwaarden, waarin een beperking van aansprakelijkheid is opgenomen. De
algemene voorwaarden worden u op verzoek kosteloos toegezonden.
=====================================================================
The information contained in this communication is confidential and is
intended solely for the use of the individual or entity to whom it is
addressed. You should not copy, disclose or distribute this communication
without the authority of Ernst & Young. Ernst & Young is neither liable for
the proper and complete transmission of the information contained in this
communication nor for any delay in its receipt. Ernst & Young does not
guarantee that the integrity of this communication has been maintained nor
that the communication is free of viruses, interceptions or interference.

If you are not the intended recipient of this communication please return
the communication to the sender and delete and destroy all copies.

In carrying out its engagements, Ernst & Young applies general terms and
conditions, which contain a clause that limits its liability. A copy of
these terms and conditions is available on request free of charge.
===================================================================





--
Please see the official ORACLE-L FAQ: http://www.orafaq.com
--
Author: Jack van Zanen
  INET: [EMAIL PROTECTED]

Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).

Reply via email to