Execution of SQL Query to slow

Hey all!!!
I'm using 10g express edition with apex 3.1, when I run this query:
select asig.idasig IDASIG, asig.idAsig "Código Asignatura", asig.idasig ID,substr(asig.codigoasig||' '||asig.nombre,0,40) "Asignatura", p.nombre||' '||p.apellidos "Responsable", t.usuario "Técnico", substr(ea.estado,0,22) "Estado Asignatura", ec.estado "Estado Certificado", cert.idestado
from certificado cert, asignatura asig, histasig ha, profesor p, tecnico t, estado ea, estado ec
where cert.idasig = asig.idasig and
p.idprof = asig.idprof and
t.idtecnico = asig.idtecnico and
*(cert.idasig, cert.fecha) in (select idasig, max(fecha) from certificado group by idasig) and*
ec.idestado = cert.idestado and
ha.idasig = asig.idasig and
*(ha.idasig, ha.fecha) in (select idasig, max(fecha) from histasig group by idasig) and*
ea.idestado = ha.idestado
It gets too slow, making the query gets results in approximately 149s.
Someone can give me an idea...
PD:The case is that we have another query that make almost the same but with this one I get the results in less than 1s.

These are the results:
TKPROF: Release 10.2.0.1.0 - Production on Mar Feb 10 10:35:58 2009
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
Trace file: C:\oraclexe\app\oracle\admin\XE\udump\xe_ora_4724.trc
Sort options: prsela  exeela  fchela 
count    = number of times OCI procedure was executed
cpu      = cpu time in seconds executing
elapsed  = elapsed time in seconds executing
disk     = number of physical reads of buffers from disk
query    = number of buffers gotten for consistent read
current  = number of buffers gotten in current mode (usually for update)
rows     = number of rows processed by the fetch or execute call
select asig.idasig ID1, asig.idAsig ID2, asig.idasig ID3,asig.codigoasig, asig.nombre, p.nombre,p.apellidos,t.usuario,ea.estado,ec.estado,cert.idestado
from certificado cert, asignatura asig, histasig ha,  profesor p, tecnico t, estado ea, estado ec
where cert.idasig = asig.idasig and
p.idprof = asig.idprof and
t.idtecnico = asig.idtecnico and
(cert.idasig, cert.fecha) in (select idasig, max(fecha) from certificado group by idasig) and
ec.idestado = cert.idestado and
ha.idasig = asig.idasig and
(ha.idasig, ha.fecha) in (select idasig, max(fecha) from histasig group by idasig) and
ea.idestado = ha.idestado
call     count       cpu    elapsed       disk      query    current        rows
Parse        1      0.15       0.14          0          0          0           0
Execute      1      0.00       0.00          0          0          0           0
Fetch       64    102.17     102.43          0     369673          0         937
total       66    102.32     102.57          0     369673          0         937
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 36 
Rows     Row Source Operation
    937  NESTED LOOPS  (cr=369673 pr=0 pw=0 time=102241172 us)
    937   NESTED LOOPS  (cr=368672 pr=0 pw=0 time=103609539 us)
    937    NESTED LOOPS  (cr=5030 pr=0 pw=0 time=97377 us)
    937     NESTED LOOPS  (cr=3082 pr=0 pw=0 time=72064 us)
    937      NESTED LOOPS  (cr=2081 pr=0 pw=0 time=55194 us)
    947       HASH JOIN RIGHT SEMI (cr=44 pr=0 pw=0 time=22573 us)
    947        VIEW  VW_NSO_1 (cr=17 pr=0 pw=0 time=4100 us)
    947         HASH GROUP BY (cr=17 pr=0 pw=0 time=3151 us)
   1659          INDEX FAST FULL SCAN PK_CERTIFICADO (cr=17 pr=0 pw=0 time=1728 us)(object id 15811)
   1659        MERGE JOIN  (cr=27 pr=0 pw=0 time=11173 us)
     39         TABLE ACCESS BY INDEX ROWID ESTADO (cr=10 pr=0 pw=0 time=286 us)
     39          INDEX FULL SCAN PK_ESTADO (cr=5 pr=0 pw=0 time=95 us)(object id 15790)
   1659         SORT JOIN (cr=17 pr=0 pw=0 time=7693 us)
   1659          INDEX FAST FULL SCAN PK_CERTIFICADO (cr=17 pr=0 pw=0 time=42 us)(object id 15811)
    937       TABLE ACCESS BY INDEX ROWID ASIGNATURA (cr=2037 pr=0 pw=0 time=31871 us)
    947        INDEX UNIQUE SCAN PK_ASIGNATURA (cr=1011 pr=0 pw=0 time=16230 us)(object id 15797)
    937      TABLE ACCESS BY INDEX ROWID TECNICO (cr=1001 pr=0 pw=0 time=14632 us)
    937       INDEX UNIQUE SCAN PK_TECNICO (cr=64 pr=0 pw=0 time=6532 us)(object id 15777)
    937     TABLE ACCESS BY INDEX ROWID PROFESOR (cr=1948 pr=0 pw=0 time=20712 us)
    937      INDEX UNIQUE SCAN PK_PROFESOR (cr=1001 pr=0 pw=0 time=11554 us)(object id 15795)
    937    INDEX RANGE SCAN PK_HISTASIG (cr=363642 pr=0 pw=0 time=102276685 us)(object id 15809)
    937     FILTER  (cr=361692 pr=0 pw=0 time=101967826 us)
64914543      HASH GROUP BY (cr=361692 pr=0 pw=0 time=139395915 us)
94619691       INDEX FAST FULL SCAN PK_HISTASIG (cr=361692 pr=0 pw=0 time=94752646 us)(object id 15809)
    937   TABLE ACCESS BY INDEX ROWID ESTADO (cr=1001 pr=0 pw=0 time=39308 us)
    937    INDEX UNIQUE SCAN PK_ESTADO (cr=64 pr=0 pw=0 time=15348 us)(object id 15790)
alter session set sql_trace true
call     count       cpu    elapsed       disk      query    current        rows
Parse        0      0.00       0.00          0          0          0           0
Execute      1      0.00       0.00          0          0          0           0
Fetch        0      0.00       0.00          0          0          0           0
total        1      0.00       0.00          0          0          0           0
Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: 36 
OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
call     count       cpu    elapsed       disk      query    current        rows
Parse        1      0.15       0.14          0          0          0           0
Execute      2      0.00       0.00          0          0          0           0
Fetch       64    102.17     102.43          0     369673          0         937
total       67    102.32     102.57          0     369673          0         937
Misses in library cache during parse: 1
OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
call     count       cpu    elapsed       disk      query    current        rows
Parse        0      0.00       0.00          0          0          0           0
Execute      0      0.00       0.00          0          0          0           0
Fetch        0      0.00       0.00          0          0          0           0
total        0      0.00       0.00          0          0          0           0
Misses in library cache during parse: 0
    2  user  SQL statements in session.
    0  internal SQL statements in session.
    2  SQL statements in session.
Trace file: C:\oraclexe\app\oracle\admin\XE\udump\xe_ora_4724.trc
Trace file compatibility: 10.01.00
Sort options: prsela  exeela  fchela 
       1  session in tracefile.
       2  user  SQL statements in trace file.
       0  internal SQL statements in trace file.
       2  SQL statements in trace file.
       2  unique SQL statements in trace file.
     147  lines in trace file.
     134  elapsed seconds in trace file.We had seen that the possible problems are here:
937               INDEX RANGE SCAN PK_HISTASIG (cr=363642 pr=0 pw=0 time=102276685 us)(object id 15809)
64914543       HASH GROUP BY (cr=361692 pr=0 pw=0 time=139395915 us)
94619691       INDEX FAST FULL SCAN PK_HISTASIG (cr=361692 pr=0 pw=0 time=94752646 us)(object id 15809)The time spent is too much, but we don't see how can we solve this problem, any idea?

Similar Messages

  • Sql query runing slow with lower cost

    Hello
    I am working on Oracle 11g and AIX.I have one sql query which is ruing slow as reported by user.
    When i am commenting few line of code it is runing fast.
    I noticed that the execution plan cost of first query is less and second ...as cost of sccond qurey is more.But users are say it is runing fast.
    How it can possiable ?
    Any idea why second query is runing fast after commenting few columns in select and group by clause.
    Query 1
    SELECT PH.CTRL_NBR, PD.SEQ_NBR,PH.CNTRY,PH.SHIP_DATE, PHI.WAVE_NBR, PD.ID, PD.QTY,
    IM.PACK_QTY,
    IM.UNIT_VOL,
    IM.PACK_QTY,
    MAX(CD.PACK_QTY) AS CASE_QTY,
    IM.UNIT_WT
    FROM HDR PH,
    HDR_INTRNL PHI,
    DTL PD,
    HDR CH,
    CASEDTL CD,
    IMASTER IM
    WHERE PH.CTRL_NBR = PHI.CTRL_NBR
    AND PD.CTRL_NBR = PH.CTRL_NBR
    AND PD.QTY > 0
    AND SUBSTR(CD.ID, 1, 9) = SUBSTR(PD.ID, 1, 9)
    AND CD.CASENBR = CH.CASENBR
    AND CH.STAT_CODE BETWEEN '10' AND '90'
    AND IM.ID = PD.ID
    AND PHI.WAVE_NBR='EL57893'
    GROUP BY PH.CTRL_NBR, PD.SEQ_NBR, PH.CNTRY, PH.SHIP_DATE, PHI.WAVE_NBR, PD.ID, PD.QTY,
    IM.PACK_QTY,
    IM.UNITVOL,
    IM.UNITWT,
    IM.PACK_QTY
    Query 2 .
    SELECT PH.CTRL_NBR,
    PD.SEQ_NBR,
    PH.CNTRY,
    PH.SHIP_DATE,
    PHI.WAVE_NBR,
    PD.ID,
    PD.QTY,
    -- IM.PACK_QTY,
    -- IM.UNIT_VOL,
    -- IM.PACK_QTY,
    MAX(CD.PACK_QTY) AS CASE_QTY,
    -- IM.UNIT_WT
    FROM HDR PH,
    HDR_INTRNL PHI,
    DTL PD,
    HDR CH,
    CASEDTL CD,
    IMASTER IM
    WHERE PH.CTRL_NBR = PHI.CTRL_NBR
    AND PD.CTRL_NBR = PH.CTRL_NBR
    AND PD.QTY > 0
    AND SUBSTR(CD.ID, 1, 9) = SUBSTR(PD.ID, 1, 9)
    AND CD.CASENBR = CH.CASENBR
    AND CH.STAT_CODE BETWEEN '10' AND '90'
    AND IM.ID = PD.ID
    AND PHI.WAVE_NBR='EL57893'
    GROUP BY PH.CTRL_NBR, PD.SEQ_NBR, PH.CNTRY, PH.SHIP_DATE, PHI.WAVE_NBR, PD.ID, PD.QTY,
    --IM.PACK_QTY,
    --IM.UNITVOL,
    --IM.UNITWT,
    --IM.PACK_QTY
    Edited by: oradba11 on Sep 6, 2012 2:11 PM
    Edited by: oradba11 on Sep 6, 2012 2:12 PM

    oradba11 wrote:
    Hello
    I am working on Oracle 11g and AIX.I have one sql query which is ruing slow as reported by user.
    When i am commenting few line of code it is runing fast.
    I noticed that the execution plan cost of first query is less and second ...as cost of sccond qurey is more.But users are say it is runing fast.
    How it can possiable ? <snip>
    This doesn't address your question, but let me suggest that for your own sanity you start brining some formatting to your sql. And for the sanity of those on this forum of whom you expect assistance, you preserve that formatting through the use of the code tags (see the FAQ for details).
    I've done the first one for you, as an example of what I mean
    SELECT
         PH.CTRL_NBR
    ,     PD.SEQ_NBR
    ,     PH.CNTRY
    ,     PH.SHIP_DATE
    ,     PHI.WAVE_NBR
    ,     PD.ID
    ,     PD.QTY
    ,     IM.PACK_QTY
    ,     IM.UNIT_VOL
    ,     IM.PACK_QTY
    ,     MAX(CD.PACK_QTY) AS CASE_QTY
    ,     IM.UNIT_WT
    FROM
         HDR PH
    ,     HDR_INTRNL PHI
    ,     DTL PD
    ,     HDR CH
    ,     CASEDTL CD
    ,     IMASTER IM
    WHERE
         PH.CTRL_NBR = PHI.CTRL_NBR
       AND  PD.CTRL_NBR = PH.CTRL_NBR
       AND  PD.QTY > 0
       AND  SUBSTR(CD.ID, 1, 9) = SUBSTR(PD.ID, 1, 9)
       AND  CD.CASENBR = CH.CASENBR
       AND  CH.STAT_CODE BETWEEN '10' AND '90'
       AND  IM.ID = PD.ID
       AND  PHI.WAVE_NBR='EL57893'
    GROUP BY
         PH.CTRL_NBR
    ,     PD.SEQ_NBR
    ,     PH.CNTRY
    ,     PH.SHIP_DATE
    ,      PHI.WAVE_NBR
    ,      PD.ID
    ,      PD.QTY
    ,      IM.PACK_QTY
    ,     IM.UNITVOL
    ,     IM.UNITWT
    ,     IM.PACK_QTY

  • Sql query extremely slow in the new linux environment , memory issues?

    We just migrated to a new dev environment in Linux REDHAT5, and now the query is very slow, and I used the TOAD to run the query, it took like 700 msecond to finish, however from any server connection, the sql query takes hours to finish.
    I checked toad monitor, it said need to increase db_buffer_cache and shared pool too small.
    Also three red alert from toad is:
    1. Library Cache get hit ratio: Dynamic or unsharable sql
    2. Chained fetch ratio: PCT free too low for a table
    3. parse to execute ratio: HIgh parse to execute ratio.
    App team said it ran real quick in the old AIX system, however I ran it in old system, and monitored in the toad, it gave me all same 5 red alerts in old system, and it did provide query results a lot quicker though.
    Here is the parameters in the old system (11gr1 on AIX):
    SQL> show parameter target
    NAME TYPE VALUE
    archive_lag_target integer 0
    db_flashback_retention_target integer 1440
    fast_start_io_target integer 0
    fast_start_mttr_target integer 0
    memory_max_target big integer 0
    memory_target big integer 0
    pga_aggregate_target big integer 278928K
    sga_target big integer 0
    SQL> show parameter shared
    NAME TYPE VALUE
    hi_shared_memory_address integer 0
    max_shared_servers integer
    shared_memory_address integer 0
    shared_pool_reserved_size big integer 31876710
    shared_pool_size big integer 608M
    shared_server_sessions integer
    shared_servers integer 0
    SQL> show parameter db_buffer
    SQL> show parameter buffer
    NAME TYPE VALUE
    buffer_pool_keep string
    buffer_pool_recycle string
    db_block_buffers integer 0
    log_buffer integer 2048000
    use_indirect_data_buffers boolean FALSE
    SQL>
    In new 11gr2 Linux REDHAT parameter:
    NAME TYPE VALUE
    archive_lag_target integer 0
    db_flashback_retention_target integer 1440
    fast_start_io_target integer 0
    fast_start_mttr_target integer 0
    memory_max_target big integer 2512M
    memory_target big integer 2512M
    parallel_servers_target integer 192
    pga_aggregate_target big integer 0
    sga_target big integer 1648M
    SQL> show parameter shared
    NAME TYPE VALUE
    hi_shared_memory_address integer 0
    max_shared_servers integer
    shared_memory_address integer 0
    shared_pool_reserved_size big integer 28M
    shared_pool_size big integer 0
    shared_server_sessions integer
    shared_servers integer 1
    SQL> show parameter buffer
    NAME TYPE VALUE
    buffer_pool_keep string
    buffer_pool_recycle string
    db_block_buffers integer 0
    log_buffer integer 18857984
    use_indirect_data_buffers boolean FALSE
    SQL>
    Please help. Thanks in advance.

    Duplicate question. Originally posted in sql query slow in new redhat enviornment
    Please post in just one forum.

  • First execution of sql statements is slow every morning

    Dears,
    we are running an oracle11g database (HP-UX Itanium) and have the following problem:
    Every morning the first execution of statements is very slow.
    After the first execution the statements are running fine.
    Does anyone have an idea where this can come from?
    Is it possible that the cache (shared pool, etc.) will be deleted every night (for example when new statistics are generated or something else)?
    Regards,
    Ilja

    I think you are close to answering your question.
    As you know, Oracle 11g has an automated job to run performance stats every night at approx. 10:00pm (until 2:00am).
    This is run by the dbms_scheduler.
    This could be causing the shared_pool to be flushed because it certainly uses it a lot. I have to manually flush the shared_pool every night in one of my databases before this job runs otherwise I get an ORA-01461.
    But, what I'm surprised is that you have this problem only in the morning.
    It seems you would want to pin your SQL in memory and perhaps set a profile for your execution.
    You don't bounce your database every night, do you?

  • Sql query runs slower from the application

    Hi,
    We are using oracle 9ias on AIX box.The jdk version used: 1.3.1 . From the j2ee application when we perfom a search, the sql query takes for ever to return the results. I know that we are waiting on the database because I can see the query working when I look at TOAD.But if i run the same query on the database server itself, it returns the results in less than a sec. Could you guys throw some light on how we could troubleshoot this problem. Thanks.

    When the results have to travel over the network, it is slow, and when they don't, it is fast.
    That is what you are saying, correct?
    So your approach should be to not bring so much data over the network. Don't select columns you don't need, and don't select rows you don't need.

  • SQL Query very slow.

    I have a table which has 40million data in it. Of-course partitioned!.
    begin
    pk_cm_entity_context.set_entity_in_context(1);
    end;
    SELECT COUNT(1) FROM XFACE_ADDL_DETAILS_TXNLOG;
    alter table XFACE_ADDL_DETAILS_TXNLOG rename to XFACE_ADDLDTS_TXNLOG_PTPART;
    SELECT COUNT(1) FROM XFACE_ADDLDTS_TXNLOG_PTPART;
    -- Create table
    create table XFACE_ADDL_DETAILS_TXNLOG
    REF_TXN_NO CHAR(40),
    REF_USR_NO CHAR(40),
    REF_KEY_NO VARCHAR2(50),
    REF_TXN_NO_ORG CHAR(40),
    REF_USR_NO_ORG CHAR(40),
    RECON_CODE VARCHAR2(25),
    COD_TASK_DERIVED VARCHAR2(5),
    COD_CHNL_ID VARCHAR2(6),
    COD_SERVICE_ID VARCHAR2(10),
    COD_USER_ID VARCHAR2(30),
    COD_AUTH_ID VARCHAR2(30),
    COD_ACCT_NO CHAR(22),
    TYP_ACCT_NO VARCHAR2(4),
    COD_SUB_ACCT_NO CHAR(16),
    COD_DEP_NO NUMBER(5),
    AMOUNT NUMBER(15,2),
    COD_CCY VARCHAR2(3),
    DAT_POST DATE,
    DAT_VALUE DATE,
    TXT_TXN_NARRATIVE VARCHAR2(60),
    DATE_CHEQUE_ISSUE DATE,
    TXN_BUSINESS_TYPE VARCHAR2(10),
    CARD_NO CHAR(20),
    INVENTORY_CODE CHAR(10),
    INVENTORY_NO CHAR(20),
    CARD_PASSBOOK_NO CHAR(30),
    COD_CASH_ANALYSIS CHAR(20),
    BANK_INFORMATION_NO CHAR(8),
    BATCH_NO CHAR(10),
    SUMMARY VARCHAR2(60),
    MAIN_IC_TYPE CHAR(1),
    MAIN_IC_NO CHAR(48),
    MAIN_IC_NAME CHAR(64),
    MAIN_IC_CHECK_RETURN_CODE CHAR(1),
    DEPUTY_IC_TYPE CHAR(1),
    DEPUTY_IC_NO CHAR(48),
    DEPUTY_NAME CHAR(64),
    DEPUTY_IC_CHECK_RETURN_CODE CHAR(1),
    ACCOUNT_PROPERTY CHAR(4),
    CHEQUE_NO CHAR(20),
    COD_EXT_TASK CHAR(10),
    COD_MODULE CHAR(4),
    ACC_PURPOSE_CODE VARCHAR2(15),
    NATIONALITY CHAR(3),
    CUSTOMER_NAME CHAR(192),
    COD_INCOME_EXPENSE CHAR(6),
    COD_EXT_BRANCH CHAR(6),
    COD_ACCT_TITLE CHAR(192),
    FLG_CA_TT CHAR(1),
    DAT_EXT_LOCAL DATE,
    ACCT_OWNER_VALID_RESULT CHAR(1),
    FLG_DR_CR CHAR(1),
    FLG_ONLINE_UPLOAD CHAR(1),
    FLG_STMT_DISPLAY CHAR(1),
    COD_TXN_TYPE NUMBER(1),
    DAT_TS_TXN TIMESTAMP(6),
    LC_BG_GUARANTEE_NO VARCHAR2(20),
    COD_OTHER_ACCT_NO CHAR(22),
    COD_MOD_OTHER_ACCT_NO CHAR(4),
    COD_CC_BRN_SUB_ACCT NUMBER(5),
    COD_CC_BRN_OTHR_ACCT NUMBER(5),
    COD_ENTITY_VPD NUMBER(5) default NVL(sys_context('CLIENTCONTEXT','entity_code'),11),
    COD_EXT_TASK_REV VARCHAR2(10)
    partition by hash (REF_TXN_NO)
    PARTITIONS 128
    store in (FCHDATA1,FCHDATA2,FCHDATA3,FCHDATA4, FCHDATA5, FCHDATA6, FCHDATA7, FCHDATA8);
    insert /*+APPEND NOLOGGING */ into XFACE_ADDL_DETAILS_TXNLOG
    select /*+PARALLEL */ * from XFACE_ADDLDTS_TXNLOG_PTPART;
    -- Add comments to the table
    comment on table XFACE_ADDL_DETAILS_TXNLOG
    is ' Additional Data log table ';
    -- Add comments to the columns
    comment on column XFACE_ADDL_DETAILS_TXNLOG.REF_TXN_NO
    is 'Transaction Reference Number';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.REF_USR_NO
    is 'User Reference Number';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.REF_KEY_NO
    is 'Unique key to identify a leg of the transaction';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.REF_TXN_NO_ORG
    is 'Original Transaction Reference Number';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.REF_USR_NO_ORG
    is 'Original Transaction User Reference Number';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.RECON_CODE
    is 'Reconciliation of transactions in future';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.COD_TASK_DERIVED
    is 'Transaction mnemonic for the request';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.COD_CHNL_ID
    is 'Channel ID';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.COD_SERVICE_ID
    is 'Service ID';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.COD_USER_ID
    is 'User ID';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.COD_AUTH_ID
    is 'Authorizer ID';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.COD_ACCT_NO
    is 'It can be Card number or MCA or GL or CASH GL';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.TYP_ACCT_NO
    is 'Type of input (Valid values CARD, MCA, GL, CASH, LN)';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.COD_SUB_ACCT_NO
    is 'MC Sub Account Number';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.COD_DEP_NO
    is 'Deposit Number';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.AMOUNT
    is 'Transaction Amount';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.COD_CCY
    is 'Currency Code';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.DAT_POST
    is 'Posting Date of the transaction';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.DAT_VALUE
    is 'Value Date of the transaction';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.TXT_TXN_NARRATIVE
    is 'Text Transaction Narrative';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.DATE_CHEQUE_ISSUE
    is 'Date of Issue of Cheque';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.TXN_BUSINESS_TYPE
    is 'Transaction Business Type';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.CARD_NO
    is 'Card Number';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.INVENTORY_CODE
    is 'Inventory Code';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.INVENTORY_NO
    is 'Inventory Number';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.CARD_PASSBOOK_NO
    is 'Card Passbook Number';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.COD_CASH_ANALYSIS
    is 'Cash Analysis Code';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.BANK_INFORMATION_NO
    is 'Bank Information Number';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.BATCH_NO
    is 'Batch Number';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.SUMMARY
    is 'Summary';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.MAIN_IC_TYPE
    is 'IC Type';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.MAIN_IC_NO
    is 'IC Number';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.MAIN_IC_NAME
    is 'IC Name';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.MAIN_IC_CHECK_RETURN_CODE
    is 'IC Check Return Code';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.DEPUTY_IC_TYPE
    is 'Deputy IC Type';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.DEPUTY_IC_NO
    is 'Deputy IC Number';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.DEPUTY_NAME
    is 'Deputy Name';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.DEPUTY_IC_CHECK_RETURN_CODE
    is 'Deputy IC Check Return Code';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.ACCOUNT_PROPERTY
    is 'Account Property';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.CHEQUE_NO
    is 'Cheque Number';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.COD_EXT_TASK
    is 'External Task Code';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.COD_MODULE
    is 'Module Code - CH, TD, RD , LN, CASH, GL';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.ACC_PURPOSE_CODE
    is 'Account Purpose Code';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.NATIONALITY
    is 'Nationality';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.CUSTOMER_NAME
    is 'Customer Name';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.COD_INCOME_EXPENSE
    is 'Income Expense Code';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.COD_EXT_BRANCH
    is 'External Branch Code';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.COD_ACCT_TITLE
    is 'Account Title Code';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.FLG_CA_TT
    is 'Cash or Funds Transfer flag';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.DAT_EXT_LOCAL
    is 'Local Date';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.ACCT_OWNER_VALID_RESULT
    is 'Account Owner Valid Result';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.FLG_DR_CR
    is 'Flag Debit Credit - D, C.';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.FLG_ONLINE_UPLOAD
    is 'Flag Online Upload - O, U.';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.FLG_STMT_DISPLAY
    is 'Statement Display Flag - Y/N, Y(Normal Reversal), N(Correction Reversal)';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.COD_TXN_TYPE
    is 'To denote the kind of transaction:
    1 ?Cash Credit Transaction
    2 ?Cash Debit Transaction
    3 ?Funds Transfer Credit Transaction
    4 ?Funds Transfer Debit Transaction
    comment on column XFACE_ADDL_DETAILS_TXNLOG.DAT_TS_TXN
    is 'Date and Timestamp of the record being inserted';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.LC_BG_GUARANTEE_NO
    is 'LC/BG Guarantee Number for which the request for the Liquidation has been initiated.';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.COD_OTHER_ACCT_NO
    is 'Other Account No';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.COD_MOD_OTHER_ACCT_NO
    is 'Module Code of Other Account No - CH, TD, RD , LN, CASH, GL';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.COD_CC_BRN_SUB_ACCT
    is 'Branch Code for Sub Account';
    comment on column XFACE_ADDL_DETAILS_TXNLOG.COD_CC_BRN_OTHR_ACCT
    is 'Branch Code for Other Account';
    -- Create/Recreate indexes
    drop index IN_XFACE_ADDL_DETAILS_TXNLOG_1;
    drop index IN_XFACE_ADDL_DETAILS_TXNLOG_2;
    drop index IN_XFACE_ADDL_DETAILS_TXNLOG_3;
    drop index IN_XFACE_ADDL_DETAILS_TXNLOG_4;
    drop index IN_XFACE_ADDL_DETAILS_TXNLOG_5;
    drop index IN_XFACE_ADDL_DETAILS_TXNLOG_6;
    drop index IN_XFACE_ADDL_DETAILS_TXNLOG_7;
    drop index IN_XFACE_ADDL_DETAILS_TXNLOG_8;
    create index IN_XFACE_ADDL_DETAILS_TXNLOG_1 on XFACE_ADDL_DETAILS_TXNLOG (REF_TXN_NO, REF_KEY_NO, COD_SUB_ACCT_NO, COD_ENTITY_VPD)
    GLOBAL PARTITION BY HASH (REF_TXN_NO, REF_KEY_NO, COD_SUB_ACCT_NO) PARTITIONS 128 STORE IN (FCHINDX1, FCHINDX2, FCHINDX3, FCHINDX4) PARALLEL (DEGREE 32) NOLOGGING;
    create index IN_XFACE_ADDL_DETAILS_TXNLOG_2 on XFACE_ADDL_DETAILS_TXNLOG (REF_USR_NO, REF_KEY_NO, COD_SUB_ACCT_NO, COD_ENTITY_VPD)
    GLOBAL PARTITION BY HASH(REF_USR_NO, REF_KEY_NO, COD_SUB_ACCT_NO) PARTITIONS 128 STORE IN (FCHINDX1, FCHINDX2, FCHINDX3, FCHINDX4) PARALLEL (DEGREE 32) NOLOGGING;
    create index IN_XFACE_ADDL_DETAILS_TXNLOG_3 on XFACE_ADDL_DETAILS_TXNLOG (COD_SUB_ACCT_NO, FLG_STMT_DISPLAY,DAT_POST COD_ENTITY_VPD)
    GLOBAL PARTITION BY HASH(COD_SUB_ACCT_NO, FLG_STMT_DISPLAY) PARTITIONS 128 STORE IN (FCHINDX1, FCHINDX2, FCHINDX3, FCHINDX4) PARALLEL (DEGREE 32) NOLOGGING;
    create index IN_XFACE_ADDL_DETAILS_TXNLOG_4 on
    XFACE_ADDL_DETAILS_TXNLOG (COD_ACCT_NO, REF_TXN_NO, COD_TXN_TYPE, COD_USER_ID, COD_EXT_BRANCH, COD_ENTITY_VPD)
    GLOBAL PARTITION BY HASH(COD_ACCT_NO, REF_TXN_NO, COD_TXN_TYPE, COD_USER_ID, COD_EXT_BRANCH)
    PARTITIONS 128 STORE IN (FCHINDX1, FCHINDX2, FCHINDX3, FCHINDX4) PARALLEL (DEGREE 32) NOLOGGING;
    create index IN_XFACE_ADDL_DETAILS_TXNLOG_5 on XFACE_ADDL_DETAILS_TXNLOG (COD_USER_ID, DAT_POST, COD_ENTITY_VPD)
    GLOBAL PARTITION BY HASH(COD_USER_ID) PARTITIONS 128 STORE IN (FCHINDX1, FCHINDX2, FCHINDX3, FCHINDX4) PARALLEL (DEGREE 32) NOLOGGING;
    create index IN_XFACE_ADDL_DETAILS_TXNLOG_6 on XFACE_ADDL_DETAILS_TXNLOG (REF_TXN_NO_ORG, COD_ENTITY_VPD)
    GLOBAL PARTITION BY HASH(REF_TXN_NO_ORG) PARTITIONS 128 STORE IN (FCHINDX1, FCHINDX2, FCHINDX3, FCHINDX4) PARALLEL (DEGREE 32) NOLOGGING;
    create index IN_XFACE_ADDL_DETAILS_TXNLOG_7 on XFACE_ADDL_DETAILS_TXNLOG (DAT_EXT_LOCAL, DAT_POST,TXN_BUSINESS_TYPE, FLG_ONLINE_UPLOAD, COD_CHNL_ID, REF_TXN_NO, COD_ENTITY_VPD)
    GLOBAL PARTITION BY HASH(DAT_EXT_LOCAL) PARTITIONS 128 STORE IN (FCHINDX1, FCHINDX2, FCHINDX3, FCHINDX4) PARALLEL (DEGREE 32) NOLOGGING;
    /* Previous Key order: (COD_EXT_BRANCH,DAT_POST,REF_TXN_NO_ORG,COD_SERVICE_ID,COD_ENTITY_VPD) */
    create index IN_XFACE_ADDL_DETAILS_TXNLOG_8 on XFACE_ADDL_DETAILS_TXNLOG (DAT_POST, COD_EXT_BRANCH, REF_TXN_NO_ORG, COD_SERVICE_ID, COD_ENTITY_VPD)
    GLOBAL PARTITION BY HASH(DAT_POST) PARTITIONS 128 STORE IN (FCHINDX1, FCHINDX2, FCHINDX3, FCHINDX4) PARALLEL (DEGREE 32) NOLOGGING;
    ALTER TABLE XFACE_ADDL_DETAILS_TXNLOG NOPARALLEL PCTFREE 50 INITRANS 128 LOGGING;
    ALTER index IN_XFACE_ADDL_DETAILS_TXNLOG_1 NOPARALLEL INITRANS 128;
    ALTER index IN_XFACE_ADDL_DETAILS_TXNLOG_2 NOPARALLEL INITRANS 128;
    ALTER index IN_XFACE_ADDL_DETAILS_TXNLOG_3 NOPARALLEL INITRANS 128;
    ALTER index IN_XFACE_ADDL_DETAILS_TXNLOG_4 NOPARALLEL INITRANS 128;
    ALTER index IN_XFACE_ADDL_DETAILS_TXNLOG_5 NOPARALLEL INITRANS 128;
    ALTER index IN_XFACE_ADDL_DETAILS_TXNLOG_6 NOPARALLEL INITRANS 128;
    ALTER index IN_XFACE_ADDL_DETAILS_TXNLOG_7 NOPARALLEL INITRANS 128;
    ALTER index IN_XFACE_ADDL_DETAILS_TXNLOG_8 NOPARALLEL INITRANS 128;
    BEGIN
    DBMS_RLS.ADD_POLICY(OBJECT_SCHEMA => UPPER('FCR44HOST'),
    OBJECT_NAME => UPPER('XFACE_ADDL_DETAILS_TXNLOG '),
    POLICY_NAME => 'FC_ENTITY_POLICY',
    FUNCTION_SCHEMA => UPPER('FCR44HOST'),
    POLICY_FUNCTION => 'pk_cm_vpd_policy.get_entity_predicate',
    STATEMENT_TYPES => 'select,insert,update,delete',
    UPDATE_CHECK => TRUE,
    ENABLE => TRUE,
    STATIC_POLICY => FALSE,
    POLICY_TYPE => DBMS_RLS.SHARED_STATIC,
    LONG_PREDICATE => FALSE,
    SEC_RELEVANT_COLS => NULL,
    SEC_RELEVANT_COLS_OPT => NULL);
    END;
    begin
    dbms_stats.gather_table_stats(ownname => 'FCR44HOST',tabname => 'XFACE_ADDL_DETAILS_TXNLOG', cascade=>true,method_opt=>'for all columns size 1',degree => 32, GRANULARITY => 'PARTITION');
    end;
    Query which takes time.
    INSERT INTO xface_addl_dtls_tlog_temp
    (ref_txn_no,
    ref_usr_no,
    ref_key_no,
    ref_txn_no_org,
    ref_usr_no_org,
    recon_code,
    cod_task_derived,
    cod_chnl_id,
    cod_service_id,
    cod_user_id,
    cod_auth_id,
    cod_acct_no,
    typ_acct_no,
    cod_sub_acct_no,
    cod_dep_no,
    amount,
    cod_ccy,
    dat_post,
    dat_value,
    txt_txn_narrative,
    date_cheque_issue,
    txn_business_type,
    card_no,
    inventory_code,
    inventory_no,
    card_passbook_no,
    cod_cash_analysis,
    bank_information_no,
    batch_no,
    summary,
    main_ic_type,
    main_ic_no,
    main_ic_name,
    main_ic_check_return_code,
    deputy_ic_type,
    deputy_ic_no,
    deputy_name,
    deputy_ic_check_return_code,
    account_property,
    cheque_no,
    cod_ext_task,
    cod_module,
    acc_purpose_code,
    nationality,
    customer_name,
    cod_income_expense,
    cod_ext_branch,
    cod_acct_title,
    flg_ca_tt,
    dat_ext_local,
    acct_owner_valid_result,
    flg_dr_cr,
    flg_online_upload,
    flg_stmt_display,
    cod_txn_type,
    dat_ts_txn,
    lc_bg_guarantee_no,
    cod_other_acct_no,
    cod_mod_other_acct_no,
    cod_cc_brn_sub_acct,
    cod_cc_brn_othr_acct,
    cod_ext_task_rev,
    sessionid)
    SELECT ref_txn_no,
    ref_usr_no,
    ref_key_no,
    ref_txn_no_org,
    ref_usr_no_org,
    recon_code,
    cod_task_derived,
    cod_chnl_id,
    cod_service_id,
    cod_user_id,
    cod_auth_id,
    cod_acct_no,
    typ_acct_no,
    cod_sub_acct_no,
    cod_dep_no,
    amount,
    cod_ccy,
    dat_post,
    dat_value,
    txt_txn_narrative,
    date_cheque_issue,
    txn_business_type,
    card_no,
    inventory_code,
    inventory_no,
    card_passbook_no,
    cod_cash_analysis,
    bank_information_no,
    batch_no,
    summary,
    main_ic_type,
    main_ic_no,
    main_ic_name,
    main_ic_check_return_code,
    deputy_ic_type,
    deputy_ic_no,
    deputy_name,
    deputy_ic_check_return_code,
    account_property,
    cheque_no,
    cod_ext_task,
    cod_module,
    acc_purpose_code,
    nationality,
    customer_name,
    cod_income_expense,
    cod_ext_branch,
    cod_acct_title,
    flg_ca_tt,
    dat_ext_local,
    acct_owner_valid_result,
    flg_dr_cr,
    flg_online_upload,
    flg_stmt_display,
    cod_txn_type,
    dat_ts_txn,
    lc_bg_guarantee_no,
    cod_other_acct_no,
    cod_mod_other_acct_no,
    cod_cc_brn_sub_acct,
    cod_cc_brn_othr_acct,
    cod_ext_task_rev,
    var_l_sessionid
    FROM xface_addl_details_txnlog
    WHERE cod_sub_acct_no = var_pi_cod_acct_no
    AND dat_post between var_pi_start_dat AND var_pi_end_dat;
    Index referred is in_xface_addl_details_txnlog_3.
    First time when i execute the query it takes huge time. but subsequent queries are faster. This is only if i pass same account and criteria again.
    Observed that first time it goes for physical reads which takes time. and subsequent runs physical reads are less.....
    Request suggestions.....this is account statement inquiry user may have 10000txns in a day as well
    Bymistake earlier i raised this in "Oracle -> Text"
    Slow inserts due to physical reads every time for fresh account i am passin
    They suggested to use bind variable. But as i know, we are already using bind variables to bind account number and start and end date.

    My Replies below.
    Whenever you post provide your 4 digit Oracle version (SELECT * FROM V$VERSION).
    Ans :
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    PL/SQL Release 11.2.0.3.0 - Production
    "CORE     11.2.0.3.0     Production"
    TNS for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production
    NLSRTL Version 11.2.0.3.0 - Production
    1. If your question is about the INSERT query into xface_addl_dtls_tlog_temp why didn't you post any information about the DDL for that table? Is it the same structure as the table you did post DDL for?
    Ans :
    -- Create table
    create global temporary table XFACE_ADDL_DTLS_TLOG_TEMP
    REF_TXN_NO CHAR(40) not null,
    REF_USR_NO CHAR(40) not null,
    REF_KEY_NO VARCHAR2(50),
    REF_TXN_NO_ORG CHAR(40),
    REF_USR_NO_ORG CHAR(40),
    RECON_CODE VARCHAR2(25),
    COD_TASK_DERIVED VARCHAR2(5),
    COD_CHNL_ID VARCHAR2(6),
    COD_SERVICE_ID VARCHAR2(10),
    COD_USER_ID VARCHAR2(30),
    COD_AUTH_ID VARCHAR2(30),
    COD_ACCT_NO CHAR(22),
    TYP_ACCT_NO VARCHAR2(4),
    COD_SUB_ACCT_NO CHAR(16),
    COD_DEP_NO NUMBER(5),
    AMOUNT NUMBER(15,2),
    COD_CCY VARCHAR2(3),
    DAT_POST DATE,
    DAT_VALUE DATE,
    TXT_TXN_NARRATIVE VARCHAR2(60),
    DATE_CHEQUE_ISSUE DATE,
    TXN_BUSINESS_TYPE VARCHAR2(10),
    CARD_NO CHAR(20),
    INVENTORY_CODE CHAR(10),
    INVENTORY_NO CHAR(20),
    CARD_PASSBOOK_NO CHAR(30),
    COD_CASH_ANALYSIS CHAR(20),
    BANK_INFORMATION_NO CHAR(8),
    BATCH_NO CHAR(10),
    SUMMARY VARCHAR2(60),
    MAIN_IC_TYPE CHAR(1),
    MAIN_IC_NO VARCHAR2(150),
    MAIN_IC_NAME VARCHAR2(192),
    MAIN_IC_CHECK_RETURN_CODE CHAR(1),
    DEPUTY_IC_TYPE CHAR(1),
    DEPUTY_IC_NO VARCHAR2(150),
    DEPUTY_NAME VARCHAR2(192),
    DEPUTY_IC_CHECK_RETURN_CODE CHAR(1),
    ACCOUNT_PROPERTY CHAR(4),
    CHEQUE_NO CHAR(20),
    COD_EXT_TASK CHAR(10),
    COD_MODULE CHAR(4),
    ACC_PURPOSE_CODE VARCHAR2(15),
    NATIONALITY CHAR(3),
    CUSTOMER_NAME CHAR(192),
    COD_INCOME_EXPENSE CHAR(6),
    COD_EXT_BRANCH CHAR(6),
    COD_ACCT_TITLE VARCHAR2(360),
    FLG_CA_TT CHAR(1),
    DAT_EXT_LOCAL DATE,
    ACCT_OWNER_VALID_RESULT CHAR(1),
    FLG_DR_CR CHAR(1),
    FLG_ONLINE_UPLOAD CHAR(1),
    FLG_STMT_DISPLAY CHAR(1),
    COD_TXN_TYPE NUMBER(1),
    DAT_TS_TXN TIMESTAMP(6),
    LC_BG_GUARANTEE_NO VARCHAR2(20),
    COD_OTHER_ACCT_NO CHAR(22),
    COD_MOD_OTHER_ACCT_NO CHAR(4),
    COD_CC_BRN_SUB_ACCT NUMBER(5),
    COD_CC_BRN_OTHR_ACCT NUMBER(5),
    COD_EXT_TASK_REV VARCHAR2(10),
    SESSIONID NUMBER default USERENV('SESSIONID') not null
    on commit delete rows;
    -- Create/Recreate indexes
    create index IN_XFACE_ADDL_DTLS_TLOG_TEMP on XFACE_ADDL_DTLS_TLOG_TEMP (COD_SUB_ACCT_NO, REF_TXN_NO, COD_SERVICE_ID, REF_KEY_NO, SESSIONID);
    2. Why doesn't your INSERT query use APPEND, NOLOGGING and PARALLEL like the first query you posted? If those help for the first query why didn't you try them for the query you are now having problems with?
    Ans :
    I will try to use append but i cannot use parallel since i have hardware limitations.
    3. What does this mean: 'Index referred is in_xface_addl_details_txnlog_3.'? You haven't posted any plan that refers to any index. Do you have an execution plan? Why didn't you post it?
    Ans :
    Plan hash value: 4081844790
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
    | 0 | INSERT STATEMENT | | | | 5 (100)| | | |
    | 1 | LOAD TABLE CONVENTIONAL | | | | | | | |
    | 2 | FILTER | | | | | | | |
    | 3 | PARTITION HASH ALL | | 1 | 494 | 5 (0)| 00:00:01 | 1 | 128 |
    | 4 | TABLE ACCESS BY GLOBAL INDEX ROWID| XFACE_ADDL_DETAILS_TXNLOG | 1 | 494 | 5 (0)| 00:00:01 | ROWID | ROWID |
    | 5 | INDEX RANGE SCAN | IN_XFACE_ADDL_DETAILS_TXNLOG_3 | 1 | | 3 (0)| 00:00:01 | 1 | 128 |
    4. Why are you defining 37 columns as CHAR datatypes? Are you aware that CHAR data REQUIRES the use of the designated number of BYTES/CHARACTERS?
    Ans :
    I understand and appreciate your points, but since it is huge application and is built over a period of time. I am afraid if i will be allowed to do change on datatypes. there are lot of queries over this table.
    5. Are you aware that #4 means those 37 columns columns, even if all of them are NULL, mean that your MINIMUM record length is 1012? Care to guess how many of those records Oracle can fit into an 8k block? And that is if you ignore the other 26 VARCHAR2, NUMBER and DATE columns.
    Two of your columns take 192 bytes MINIMUM even if they are null
    CUSTOMER_NAME CHAR(192),
    COD_ACCT_TITLE CHAR(192)
    Why are you wasting all of that space? If you are using a multi-byte character set and your data is multi-byte those 37 columns are using even more space because some characters will use more than one byte.
    If the name and title average 30 characters/bytes then those two columns alone use 300+ unused bytes. With 40 million records those unused bytes, just for those two columns take 12 GB of space.
    WIth a block size of 8k that would totally waste 1.5 million blocks that Oracle has to read just to ignore the empty space that isn't being used.
    I highly suspect that your use of CHAR is a large part of this performance problem and probably other performance problems in your system. Not only for this table but for any other table that uses similar CHAR datatypes and wastes space.
    Please reconsider your use of CHAR datatypes like this. I can't imagine what justification you have for using them.
    Ans :
    I understand your points, but since it is huge application is built over a period of time. I am afraid if i will be allowed to do change on datatypes.
    I have to manage in current situation. Not expecting query to respond in millisecs but not even 40secs which is happening currently.
    Edited by: Rohit Jadhav on Dec 30, 2012 6:44 PM

  • SQL query is slow after upgrading from SQL 2008 to SQL 2008 R2

    Hello
    We were using SQL 2008 Standard, but after upgrading to R2, following query is much slower (takes 5 seconds instead of less than 1 second), how is this possible?
    Regards, Hennie
    SELECT
     P.BSN,
     P.Persnr,
     P.Roepnaam,
     P.Tussenvoegsels,
     P.Achternaam,
     P.Geslacht,
     COALESCE (P.Achternaam + ', ' + P.Roepnaam + ' ' + P.Tussenvoegsels, P.Achternaam + ', ' + P.Roepnaam, P.Achternaam) AS naamvolledig,
     P.Telmobiel,
     P.Telvast,
     P.Postcode,
     G.groep,
     COALESCE (RM.nieuweDag, GR.Dag) AS dag,
     COALESCE (RM.nieuweDatum, GR.datum) AS datum,
     DATEPART(ww, COALESCE (RM.nieuweDatum, GR.datum)) AS weeknummer,
     DATEPART(yyyy, COALESCE (RM.nieuweDatum, GR.datum)) AS jaar,
     CONVERT(VARCHAR(8),
      CASE WHEN GR.ID_lokaties = 3 THEN COALESCE (RM.nieuweBegintijd,
       CASE WHEN GR.Tijdspan = 2 THEN R.begintijd2 ELSE R.begintijd END)
      ELSE COALESCE (RM.nieuweBegintijd, GR.begintijd) END, 108) AS begintijdberekend,
     CONVERT(VARCHAR(8),
      CASE WHEN GR.ID_lokaties = 3 THEN COALESCE (RM.nieuweEindtijd,
       CASE WHEN GR.Tijdspan = 2 THEN R.eindtijd2 ELSE R.eindtijd END)
      ELSE COALESCE (RM.nieuweEindtijd, GR.eindtijd) END, 108) AS eindtijdberekend,
     CASE WHEN GR.ID_lokaties = 3 THEN
       CONVERT(NCHAR(5), COALESCE (RM.nieuweBegintijd,CASE WHEN GR.Tijdspan = 2 THEN R.begintijd2 ELSE R.begintijd END), 108) + '-' +
       CONVERT(NCHAR(5), COALESCE (RM.nieuweEindtijd, CASE WHEN GR.Tijdspan = 2 THEN R.eindtijd2 ELSE R.eindtijd END), 108)
      ELSE CONVERT(NCHAR(5),COALESCE (RM.nieuweBegintijd, GR.begintijd), 108) + '-' + CONVERT(NCHAR(5), COALESCE (RM.nieuweEindtijd, GR.eindtijd), 108)
      END AS Tijdspanne,
     CASE
      WHEN GR.ID_lokaties = 3 AND R.id_relaties = 9 THEN 'Werk Intern'
      WHEN GR.ID_lokaties = 3 THEN R.relatienaam
      ELSE L.lokatie END AS Lokatieberekend,
     R.relatienaam AS relatie,
     L.IntExt,
     RA.Omschrijving AS roosteractiviteit,
     A.instroomdatum,
     A.uitstroomdatum,
     TT.trajecttype,
     W.Naamvolledig AS Werkcoach,
     A.ID_groepen,
     T.ID_personen,
     A.ID_werkcoaches,
     CASE
      WHEN GR.ID_lokaties = 3 AND R.id_relaties = 9 THEN 20
      WHEN GR.ID_lokaties = 3 THEN R.id_relaties
      ELSE L.ID_relaties END AS ID_lokatieberekend,
     A.ID_relaties AS ID_relatie,
     R.nummer2 AS capaciteit,
     GR.ID_groepsroosters,
     CAST(CASE WHEN foto IS NOT NULL THEN 'Ja' ELSE NULL END AS char(2)) AS Foto,
     W.Email,
     W.TelefoonMobiel,
     W.TelefoonVast
    FROM
     dbo.personen AS P INNER JOIN
     dbo.trajecten AS T ON T.ID_personen = P.ID_personen INNER JOIN
     dbo.trajecttype AS TT ON T.ID_trajecttype = TT.ID_trajecttype INNER JOIN
     dbo.trajectactiviteiten AS A ON A.ID_trajecten = T.ID_trajecten INNER JOIN
     dbo.groepsroosters AS GR ON GR.ID_groepen = A.ID_groepen LEFT OUTER JOIN
     dbo.roosteractiviteit AS RA ON GR.ID_roosteractiviteit = RA.ID_roosteractiviteit INNER JOIN
     dbo.lokaties AS L ON GR.ID_lokaties = L.ID_lokaties INNER JOIN
     dbo.werkcoaches AS W ON A.ID_werkcoaches = W.ID_werkcoaches INNER JOIN
     dbo.groepen AS G ON A.ID_groepen = G.ID_groepen LEFT OUTER JOIN
     dbo.relaties AS R ON A.ID_relaties = R.ID_relaties LEFT OUTER JOIN
     dbo.roostermutaties AS RM ON P.ID_personen = RM.ID_personen AND GR.ID_groepsroosters = RM.ID_groepsroosters AND RM.aanwezig IS NULL
    WHERE
     (COALESCE (RM.nieuweDatum, GR.datum) BETWEEN GETDATE() - 1 AND GETDATE() + 13)
     AND (COALESCE (DATEDIFF(day, COALESCE (RM.nieuweDatum, GR.datum), A.uitstroomdatum), 0) >= 0)
     AND (DATEDIFF(day, A.instroomdatum, COALESCE (RM.nieuweDatum, GR.datum)) >= 0)
     AND ((SELECT COUNT(*) AS Expr1
      FROM dbo.roostermutaties AS RM2
      WHERE (P.ID_personen = ID_personen)
      AND (GR.ID_groepsroosters = ID_groepsroosters)
      AND (CONVERT(VARCHAR(8), begintijdafwezig, 108) = CONVERT(VARCHAR(8),
      CASE WHEN GR.ID_lokaties = 3 THEN COALESCE (RM.nieuweBegintijd,
      CASE WHEN GR.Tijdspan = 2 THEN R.begintijd2 ELSE R.begintijd END)
      ELSE COALESCE (RM.nieuweBegintijd, GR.begintijd) END, 108)) AND
      (CONVERT(VARCHAR(8), eindtijdafwezig, 108) = CONVERT(VARCHAR(8), CASE WHEN GR.ID_lokaties = 3 THEN COALESCE (RM.nieuweEindtijd,
      CASE WHEN GR.Tijdspan = 2 THEN R.eindtijd2 ELSE R.eindtijd END) ELSE COALESCE (RM.nieuweEindtijd, GR.eindtijd) END, 108))) = 0)

    We were using SQL 2008 Standard, but after upgrading to R2, following query is much slower (takes 5 seconds instead of less than 1 second), how is this possible?
    It is not uncommon to experience performance problems following an upgrade when there are issues with original query.  Non-sargable expressions like Olaf called out are often the culprit, as well as lack of useful indexes and statistics. 
    The optimizer cannot glean accurate row count estimates or use indexes efficiently so the resultant plan may not be optimal for the task at hand.  It is only by happenstance that old plan performed better; it could just as well be the other way around,
    but again only by chance since the optimizer is guessing.
    You might also try using EXISTS instead of SELECT COUNT(*)...= 0:
    AND EXISTS(SELECT *
    FROM dbo.roostermutaties AS RM2
    WHERE P.ID_personen = ID_personen
    AND GR.ID_groepsroosters = ID_groepsroosters
    AND CONVERT(VARCHAR(8), begintijdafwezig, 108) = CONVERT(VARCHAR(8),
    CASE WHEN GR.ID_lokaties = 3 THEN COALESCE (RM.nieuweBegintijd,
    CASE WHEN GR.Tijdspan = 2 THEN R.begintijd2 ELSE R.begintijd END)
    ELSE COALESCE (RM.nieuweBegintijd, GR.begintijd) END, 108)
    AND CONVERT(VARCHAR(8), eindtijdafwezig, 108) = CONVERT(VARCHAR(8), CASE WHEN GR.ID_lokaties = 3 THEN COALESCE (RM.nieuweEindtijd,
    CASE WHEN GR.Tijdspan = 2 THEN R.eindtijd2 ELSE R.eindtijd END) ELSE COALESCE (RM.nieuweEindtijd, GR.eindtijd) END, 108))
    Dan Guzman, SQL Server MVP, http://www.dbdelta.com

  • Help on SQL Query Running slow -

    Explain plan -
    Explain plan for select is here:
    Execution Plan
    | Id | Operation | Name | Rows |
    Bytes | Cost (%CPU)|
    | 0 | SELECT STATEMENT | | 4589K|
    5497M| 352K (1)|
    | 1 | NESTED LOOPS OUTER | | 4589K|
    5497M| 352K (1)|
    | 2 | NESTED LOOPS OUTER | | 4589K|
    5409M| 214K (1)|
    | 3 | NESTED LOOPS | | 4589K|
    5322M| 168K (1)|
    | 4 | TABLE ACCESS FULL | SERVICE_REQUEST | 4634K|
    1423M| 75254 (2)|
    | 5 | TABLE ACCESS BY INDEX ROWID| S_SRV_REQ | 1 |
    894 | 1 (0)|
    |* 6 | INDEX UNIQUE SCAN | S_SRV_REQ_P1 | 1 |
    | 1 (0)|
    | 7 | TABLE ACCESS BY INDEX ROWID | S_SRV_REGN | 1 |
    20 | 1 (0)|
    |* 8 | INDEX UNIQUE SCAN | S_SRV_REGN_P1 | 1 |
    | 1 (0)|
    | 9 | TABLE ACCESS BY INDEX ROWID | S_SRV_REQ_X | 1 |
    20 | 1 (0)|
    |* 10 | INDEX RANGE SCAN | S_SRV_REQ_X_U1 | 1 |
    | 1 (0)|
    Predicate Information (identified by operation id):
    6 - access("S"."ROW_ID"="SR"."SERVICE_REQUEST_ROW_ID")
    8 - access("S"."SRV_REGN_ID"="R"."ROW_ID"(+))
    10 - access("SRX"."PAR_ROW_ID"(+)="S"."ROW_ID")
    SQL> set autotrace off
    SQL> select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    PL/SQL Release 10.2.0.4.0 - Production
    CORE 10.2.0.4.0 Production
    TNS for Solaris: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production
    SQL> show parameter opt
    NAME TYPE VALUE
    filesystemio_options string asynch
    object_cache_optimal_size integer 102400
    optimizer_dynamic_sampling integer 1
    optimizer_features_enable string 10.2.0.4
    optimizer_index_caching integer 0
    optimizer_index_cost_adj integer 1
    optimizer_mode string ALL_ROWS
    optimizer_secure_view_merging boolean TRUE
    plsql_optimize_level integer 2

    Thanks for the information. As the query is taking huge time to execute I am not able to get the trace of the query. Please suggest for any performance improvements based on the available explain plan details.
    Query -
         SELECT     /*+ FIRST_ROWS */
              s.row_id                    service_request_row_id,
              s.sr_num                    service_req_id,
              s.prdint_id                    product_id,
              s.x_comp_prd_id                    component_id,
              s.cst_ou_id                    account_id,
              s.cst_con_id                    contact_id,
              s.par_sr_id                    parent_service_request_row_id,
              s.agree_id                    entitlement_id,
              s.asset_id                    asset_id,
              s.x_locality                    locality,
              s.resolution_cd                    problem_classification,
              s.x_res_text                    resolution,
              s.post_mortem_rvw_by               front_line_owner_id,
              s.owner_emp_id                    resolution_owner_id,
              s.bu_id                         resolution_group_id,
              s.owner_ou_id                    front_line_workgroup_id,
              s.created_by                    created_by_id,
              sr.created_by_workgroup               created_by_workgroup,
              s.target_con_id                    secondary_contact_id,
              s.created                    time_opened,
              s.x_srvc_restored               time_service_restored,
              s.act_close_dt                    time_closed,
              s.last_upd                    last_updated,
              s.x_last_eservice_upd               last_eservice_update,
              s.x_sr_pref_comms_chnl               preferred_comms_channel,
              s.sr_area                    TYPE,
              s.sr_sub_area                    sub_type,
              s.sr_stat_id                    status,
              s.sr_sub_stat_id               sub_status,
              s.sr_title                    abstract,
              s.desc_text                    description,
              s.exp_close_dt                    response_time,
              s.x_likely_resolution_time          likely_resolution_time,
              s.x_proactive                    proactive_type,
              s.x_market_sector               market_sector,
              s.x_light_sr                    light_sr,
              s.x_esrvc_flg                    eservice,
              s.sr_sev_cd                    severity,
              s.x_urgency_copy               priority,
              s.x_impact                    impact,
              s.x_sr_category                    CATEGORY,
              s.x_generic_identifier               generic_id,
              sr.interface_name               interface_name,
              s.x_referral_target               referral_target,
              s.rtng_dlr_id                    referral_account_id,
              s.x_data_country               data_country,
              s.x_data_exchange               data_exchange,
              s.x_dc_loc                    data_centre_location,
              s.x_data_type                    data_type,
              s.x_data_source                    data_source,
              s.x_db_queried                    database_queried,
              s.x_data_item                    data_item,
              s.x_sr_class_type               classification_type,
              s.x_sr_class_sub_type               classification_sub_type,
              s.x_resolver_grp               ds_resolver_group,
              s.x_sys_subsys                    system_sub_system,
              s.x_assembly                    assembly_sub_assembly,
              s.x_prob_start_time               problem_start_time,
              s.x_prob_stop_time               problem_stop_time,
              s.x_del_infrastructure               delivery_infrastructure,
              s.x_network_srvc               network_service,
              s.x_telco_name                    telco_name,
              s.x_circuit_type               circuit_type,
              s.x_extra_telco_info               additional_circuit_telco_info,
              s.x_security_type               security_type,
              s.resolution_cd                    resolution_code,
              s.x_secondary_cntct               secondary_contact,
              s.sr_os                         operating_system,
              s.ou_addr_id                    service_address_id,
              s.x_external_srvc               external_service,
              s.x_system                    ops_ref_system,
              s.x_sub_system                    ops_ref_sub_system,
              s.x_symptom                    symptom,
              s.x_asset_subcomponent               asset_subcomponent,
              s.x_solution_flg               save_solution,
              s.x_trgt_rstrd_time               target_restoration_time,
              s.x_second_level               second_level,
              r.NAME                         service_region,
              s.x_spec_instrs                    special_instructions,
              s.x_ext_ticket_refno               external_ticket_ref_no,
              sr.original_priority               original_priority,
              sr.original_severity               original_severity,
              sr.originating_comm_type          originating_comm_type,
              sr.fline_owner_timezone_offset          fline_owner_timezone_offset,
              sr.res_owner_timezone_offset          res_owner_timezone_offset,
              sr.fixed_by_workgroup               fixed_by_workgroup          ,
              sr.fixed_by_owner_id               fixed_by_owner_id,
              sr.resolved_by_workgroup          resolved_by_workgroup,
              sr.channel                    channel,
              s.x_orig_commit                    time_of_1st_entitled_response,
              sr.time_of_1st_assignment          time_of_1st_assignment,
              sr.time_of_1st_call_back          time_of_1st_call_back,
              sr.time_of_resolution               time_of_resolution,
              sr.time_of_iface_assignment          time_of_iface_assignment,
              sr.time_to_1st_entitled_resp_24x7     time_to_1st_entitled_resp_24x7     ,
              sr.time_to_1st_assignment_24x7          time_to_1st_assignment_24x7          ,
              sr.time_to_1st_assign_24x7_excl          time_to_1st_assign_24x7_excl,
              sr.TIME_TO_1ST_INFOACT_CONTACT          TIME_TO_1ST_INFOACT_CONTACT,
              sr.TIME_TO_1ST_ENHAACT_CONTACT          TIME_TO_1ST_ENHAACT_CONTACT,
              sr.time_to_1st_call_back_24x7          time_to_1st_call_back_24x7          ,
              sr.time_to_1st_call_bck_24x7_excl     time_to_1st_call_bck_24x7_excl,
              sr.time_to_service_rest_24x7          time_to_service_rest_24x7          ,
              sr.time_to_service_rest_24x7_excl     time_to_service_rest_24x7_excl          ,
              sr.time_to_serv_rest_24x7_excl1          time_to_serv_rest_24x7_excl1,
              sr.time_to_serv_rest_24x7_excl2          time_to_serv_rest_24x7_excl2,
              sr.time_to_resolution_24x7          time_to_resolution_24x7          ,
              sr.time_to_closure_24x7               time_to_closure_24x7               ,
              sr.time_to_closure_24x7_excl          time_to_closure_24x7_excl,
              sr.time_to_iface_assignment_24x7     time_to_iface_assignment_24x7,
              sr.time_to_1st_entitled_resp_24x5     time_to_1st_entitled_resp_24x5     ,
              sr.time_to_1st_assignment_24x5          time_to_1st_assignment_24x5          ,
              sr.time_to_1st_call_back_24x5          time_to_1st_call_back_24x5          ,
              sr.time_to_service_rest_24x5          time_to_service_rest_24x5          ,
              sr.time_to_resolution_24x5          time_to_resolution_24x5          ,
              sr.time_to_closure_24x5               time_to_closure_24x5               ,
              sr.rsh_duration_type               rsh_duration_type               ,
              sr.time_to_1st_entitled_resp_rsh     time_to_1st_entitled_resp_rsh          ,
              sr.time_to_1st_assignment_rsh          time_to_1st_assignment_rsh          ,
              sr.time_to_1st_call_back_rsh          time_to_1st_call_back_rsh          ,
              sr.time_to_service_rest_rsh          time_to_service_rest_rsh          ,
              sr.time_to_resolution_rsh          time_to_resolution_rsh          ,
              sr.time_to_closure_rsh               time_to_closure_rsh               ,
              sr.resolved_within_same_day          resolved_within_same_day,
              sr.resolved_in_one_go               resolved_in_one_go,
              sr.resolved_within_crmc               resolved_within_crmc,
              sr.resolved_with_site_visit          resolved_with_site_visit,
              sr.involved_field_services          involved_field_services,
              sr.involved_data_centre               involved_data_centre,
              sr.involved_rdh                    involved_rdh,
              sr.involved_account_team          involved_account_team,
              sr.latest_parked_status               latest_parked_status,
              sr.num_front_line_owner_changes          num_front_line_owner_changes,
              sr.fs_time_of_1st_fs_activity,
              sr.fs_time_of_1st_dispatch,
              sr.fs_time_of_1st_fs_response,
              sr.fs_time_of_flo_reassign,
              sr.fs_time_to_1st_fs_activity_rsh,
              sr.fs_time_to_1st_dispatch_rsh,
              sr.fs_time_to_1st_fs_response_rsh,
              sr.fs_time_to_flo_reassign_rsh,
              sr.number_activities,
              sr.number_open_activities,
              s.x_prd_version                    product_version,
              s.x_prd_srvc_info               product_service_details,
              s.x_urgency                    notify_level,
              srx.attrib_47                concat_sr_attrib
              FROM     crmrep_rep.crm_s_srv_regn r, crmrep_rep.crm_s_srv_req s, crmrep_rep.SERVICE_REQUEST sr ,crmrep_rep.CRM_S_SRV_REQ_X srx
         WHERE     
         s.row_id = sr.service_request_row_id
         and s.srv_regn_id = r.row_id(+)
         AND srx.par_row_id(+) = s.row_id;
    Explain Plan
    The script for view creation is attached.
    Explain plan for select is here:
    Execution Plan
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
    | 0 | SELECT STATEMENT | | 4589K| 5497M| 352K (1)|
    | 1 | NESTED LOOPS OUTER | | 4589K| 5497M| 352K (1)|
    | 2 | NESTED LOOPS OUTER | | 4589K| 5409M| 214K (1)|
    | 3 | NESTED LOOPS | | 4589K| 5322M| 168K (1)|
    | 4 | TABLE ACCESS FULL | SERVICE_REQUEST | 4634K| 1423M| 75254 (2)|
    | 5 | TABLE ACCESS BY INDEX ROWID| S_SRV_REQ | 1 | 894 | 1 (0)|
    |* 6 | INDEX UNIQUE SCAN | S_SRV_REQ_P1 | 1 | | 1 (0)|
    | 7 | TABLE ACCESS BY INDEX ROWID | S_SRV_REGN | 1 | 20 | 1 (0)|
    |* 8 | INDEX UNIQUE SCAN | S_SRV_REGN_P1 | 1 | | 1 (0)|
    | 9 | TABLE ACCESS BY INDEX ROWID | S_SRV_REQ_X | 1 | 20 | 1 (0)|
    |* 10 | INDEX RANGE SCAN | S_SRV_REQ_X_U1 | 1 | | 1 (0)|
    Predicate Information (identified by operation id):
    6 - access("S"."ROW_ID"="SR"."SERVICE_REQUEST_ROW_ID")
    8 - access("S"."SRV_REGN_ID"="R"."ROW_ID"(+))
    10 - access("SRX"."PAR_ROW_ID"(+)="S"."ROW_ID")
    Note
    - 'PLAN_TABLE' is old version
    Version Information
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    PL/SQL Release 10.2.0.4.0 - Production
    CORE 10.2.0.4.0 Production
    TNS for Solaris: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production
    Optimizer parameters
    filesystemio_options string asynch
    object_cache_optimal_size integer 102400
    optimizer_dynamic_sampling integer 1
    optimizer_features_enable string 10.2.0.4
    optimizer_index_caching integer 0
    optimizer_index_cost_adj integer 1
    optimizer_mode string ALL_ROWS
    optimizer_secure_view_merging boolean TRUE
    plsql_optimize_level integer 2
    Cursor values
    NAME TYPE VALUE
    cursor_sharing string EXACT
    cursor_space_for_time boolean FALSE
    open_cursors integer 1500
    session_cached_cursors integer 200
    Block Details
    db_block_buffers integer 0
    db_block_checking string FALSE
    db_block_checksum string TRUE
    db_block_size integer 8192
    db_file_multiblock_read_count integer 8
    Thanks in advance.

  • SQL query very slow on Data warehouse

    Guys,
    Is there any soul who is an expert on SQL ? I do run this query agaist a 2 table and a view which has 30 million rows. Unfortunately the table is partitioned but not the Unique index.
    This query takes about 3 hours to run. Is there anyway of writing this in a better way ??
    select
    a.xcm_consumer_pk,
    b.p_vin_prtn_c,
    b.vin_type_c,
    b.vin_id_c,
    b.cveh_owner_cycle_r,
    b.veh_reg_no_c,
    b.veh_make_c,
    b.veh_model_c,
    b.veh_deriv_c,
    b.veh_reg_y,
    b.cveh_link_start_y,
    b.cveh_prd_rpl_y,
    b.cveh_sl_dlr_c,
    c.cu26_address_x
    from
    xcm_cu01_customer a, xcm_cv01_cons_veh b,
    xcm_view_cons_latest_e_mail c
    where
    a.country_iso3_c = 'GBR'
    and (a.cust_brand_c in ('F','Y'))
    and a.xcm_consumer_pk = b.xcm_consumer_pk(+)
    and b.cveh_owner_cycle_r(+) = 1
    and b.cveh_link_end_y(+) between SYSDATE and '31-Dec-9999'
    and a.xcm_consumer_pk = c.xcm_consumer_pk(+)
    The definition of the view xcm_view_cons_latest_e_mail is as below.
    SELECT
    A.xcm_consumer_pk,
    A.cu26_type_c,
    A.p_update_s,
    A.cu26_address_x
    FROM XCM_CU26_E_MAIL A
    WHERE TO_CHAR(NVL(A.p_update_s, '01-Jan-0001'), 'YYYYMMDD') || NVL(A.cu26_type_c, ' ') =
         (SELECT MAX(TO_CHAR(NVL(b.p_update_s, '01-Jan-0001'), 'YYYYMMDD') || NVL(b.cu26_type_c, ' '))
         FROM XCM_CU26_E_MAIL b
         WHERE A.xcm_consumer_pk = b.xcm_consumer_pk);
    Most of our query uses the same format and ver 9.2.0.2 has totally screwed up our job times.. Any idea please ??

    In addition to Maurice's questions:
    Are you sure you really need the outer joins?
    From your statement "... and ver 9.2.0.2 has totally screwed up our job times" I assume that you have recently upgraded. So:
    Are you sure that all relevant indexes exist on the new version?
    Have you analyzed all the tables involved since the upgrade?
    Are you sure that the init parameters are set appropriately? Note that depending on what version you upgraded from, you may need to make substantial changes to various parameters to get optimal performance.
    John

  • SQL query running slow

    Hi
    i have a query when i run it for the first time it returs result in 30 mins after few mins (say 2 m ins) if i run the same query it fetches result in 3 mins) can any one hel me to tune the issu
    when i saw AWR report i showed too many disk I/o and sql messege to client wait events
    DB: Oracle 10g
    O/S: Unix
    DB cahce size :1GB
    help Pleae

    PLAN_TABLE_OUTPUT
    Plan hash value: 3961783764
    | Id  | Operation                            | Name                       | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT                     |                            |     2 |   390 |   361   (2)| 00:00:05 |
    |   1 |  SORT GROUP BY                       |                            |     2 |   390 |   361   (2)| 00:00:05 |
    |   2 |   VIEW                               |                            |     2 |   390 |   360   (1)| 00:00:05 |
    |   3 |    UNION-ALL                         |                            |       |       |            |          |
    |   4 |     NESTED LOOPS                     |                            |     1 |   297 |   344   (1)| 00:00:05 |
    |*  5 |      HASH JOIN                       |                            |     1 |   231 |   343   (1)| 00:00:05 |
    |   6 |       TABLE ACCESS FULL              | TRAN_VH_INV_SS_PART        |  3634 | 72680 |   213   (0)| 00:00:03 |
    |*  7 |       HASH JOIN                      |                            |  1799 |   370K|   129   (2)| 00:00:02 |
    |   8 |        TABLE ACCESS FULL             | MAST_MF_NAME               |     4 |    84 |     5   (0)| 00:00:01 |
    |*  9 |        HASH JOIN                     |                            |  1799 |   333K|   123   (1)| 00:00:02 |
    |* 10 |         HASH JOIN                    |                            |  1552 |   209K|   120   (1)| 00:00:02 |
    |* 11 |          TABLE ACCESS FULL           | HIST_VH_INV_SS_PART        |  1188 | 62964 |   115   (0)| 00:00:02 |
    |  12 |          NESTED LOOPS                |                            | 24566 |  2039K|     4   (0)| 00:00:01 |
    |  13 |           TABLE ACCESS BY INDEX ROWID| MAST_YM_YARD               |     1 |    29 |     1   (0)| 00:00:01 |
    |* 14 |            INDEX UNIQUE SCAN         | MAST_YM_YARD_01            |     1 |       |     0   (0)| 00:00:01 |
    |  15 |           TABLE ACCESS BY INDEX ROWID| TRAN_VH_INV_SUB_SERVICE    | 24566 |  1343K|     3   (0)| 00:00:01 |
    |* 16 |            INDEX RANGE SCAN          | TRAN_VH_INV_SUB_SERVICE_02 |     1 |       |     2   (0)| 00:00:01 |
    |  17 |         TABLE ACCESS BY INDEX ROWID  | TRAN_VH_INV                |  3863 |   196K|     3   (0)| 00:00:01 |
    |* 18 |          INDEX RANGE SCAN            | TRAN_VH_INV_02             |     1 |       |     2   (0)| 00:00:01 |
    |* 19 |      TABLE ACCESS BY INDEX ROWID     | TRAN_VH_INV_WORKSHEET      |     1 |    66 |     1   (0)| 00:00:01 |
    |* 20 |       INDEX UNIQUE SCAN              | TRAN_VH_INV_WORKSHEET_01   |     1 |       |     0   (0)| 00:00:01 |
    |  21 |     NESTED LOOPS                     |                            |     1 |   297 |    16   (0)| 00:00:01 |
    |  22 |      NESTED LOOPS                    |                            |     1 |   277 |    14   (0)| 00:00:01 |
    |  23 |       NESTED LOOPS                   |                            |     1 |   224 |    10   (0)| 00:00:01 |
    |  24 |        NESTED LOOPS                  |                            |     1 |   203 |     9   (0)| 00:00:01 |
    |  25 |         NESTED LOOPS                 |                            |     1 |   151 |     7   (0)| 00:00:01 |
    |  26 |          NESTED LOOPS                |                            |     1 |    85 |     5   (0)| 00:00:01 |
    |  27 |           TABLE ACCESS BY INDEX ROWID| MAST_YM_YARD               |     1 |    29 |     1   (0)| 00:00:01 |
    |* 28 |            INDEX UNIQUE SCAN         | MAST_YM_YARD_01            |     1 |       |     0   (0)| 00:00:01 |
    |  29 |           TABLE ACCESS BY INDEX ROWID| TRAN_VH_SHP_SUB_SERVICE    |     1 |    56 |     4   (0)| 00:00:01 |
    |* 30 |            INDEX RANGE SCAN          | TRAN_VH_SHP_SUB_SERVICE_02 |     1 |       |     3   (0)| 00:00:01 |
    |* 31 |          TABLE ACCESS BY INDEX ROWID | TRAN_VH_SHP_WORKSHEET      |     1 |    66 |     2   (0)| 00:00:01 |
    |* 32 |           INDEX UNIQUE SCAN          | TRAN_VH_SHP_WORKSHEET_01   |     1 |       |     1   (0)| 00:00:01 |
    |* 33 |         TABLE ACCESS BY INDEX ROWID  | TRAN_VH_SHP                |     1 |    52 |     2   (0)| 00:00:01 |
    |* 34 |          INDEX UNIQUE SCAN           | TRAN_VH_SHP_01             |     1 |       |     1   (0)| 00:00:01 |
    |  35 |        TABLE ACCESS BY INDEX ROWID   | MAST_MF_NAME               |     1 |    21 |     1   (0)| 00:00:01 |
    |* 36 |         INDEX UNIQUE SCAN            | MAST_MF_NAME_01            |     1 |       |     0   (0)| 00:00:01 |
    |* 37 |       TABLE ACCESS BY INDEX ROWID    | HIST_VH_SHP_SS_PART        |     1 |    53 |     4   (0)| 00:00:01 |
    |* 38 |        INDEX RANGE SCAN              | HIST_VH_SHP_SS_PART_01     |     5 |       |     2   (0)| 00:00:01 |
    |* 39 |      TABLE ACCESS BY INDEX ROWID     | TRAN_VH_SHP_SS_PART        |     1 |    20 |     2   (0)| 00:00:01 |
    |* 40 |       INDEX UNIQUE SCAN              | TRAN_VH_SHP_SS_PART_01     |     1 |       |     1   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       5 - access("C"."SUB_SERVICE_SEQ_NUM"="H"."SUB_SERVICE_SEQ_NUM" AND
                  "C"."PDI_PART_ORDER_NUM"="H"."PDI_PART_ORDER_NUM" AND
                  "C"."SUB_SERVICE_PART_SEQ_NUM"="H"."SUB_SERVICE_PART_SEQ_NUM")
       7 - access("D"."MFG_CODE"="E"."MFG_CODE")
       9 - access("D"."YARD_CODE"="A"."YARD_CODE" AND "D"."VIN_NUM"="B"."VIN_NUM" AND
                  "B"."TERMINAL_SEQ_NO"="D"."TERMINAL_SEQ_NO" AND "B"."YARD_CODE"="D"."YARD_CODE")
      10 - access("B"."SUB_SERVICE_SEQ_NUM"="C"."SUB_SERVICE_SEQ_NUM")
      11 - filter("C"."PART_FRANCHISE">=U' ' AND TRUNC(INTERNAL_FUNCTION("C"."ACTUAL_ISSUE_DATE_TIME"))<>TO_DAT
                  E(' 0001-01-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
                  TRUNC(INTERNAL_FUNCTION("C"."ISSUE_DATE_TIME"))<=TO_DATE(' 2010-06-30 00:00:00', 'syyyy-mm-dd hh24:mi:ss')
                  AND "C"."PART_FRANCHISE"<=U'~')
      14 - access("A"."TERMINAL_SEQ_NO"=1 AND "A"."YARD_CODE"=U'1')
      16 - access("B"."TERMINAL_SEQ_NO"=1 AND "B"."YARD_CODE"=U'1')
      18 - access("D"."TERMINAL_SEQ_NO"=1 AND "D"."YARD_CODE"=U'1')
      19 - filter("G"."YARD_CODE"=U'1' AND TRUNC(INTERNAL_FUNCTION("G"."START_DATE_TIME"))<>TO_DATE('
                  0001-01-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "G"."TERMINAL_SEQ_NO"=1 AND
                  (TRUNC(INTERNAL_FUNCTION("G"."START_DATE_TIME"))>=TO_DATE(' 2010-06-01 00:00:00', 'syyyy-mm-dd
                  hh24:mi:ss') AND TRUNC(INTERNAL_FUNCTION("G"."START_DATE_TIME"))<=TO_DATE(' 2010-06-30 00:00:00',
                  'syyyy-mm-dd hh24:mi:ss') OR TRUNC(INTERNAL_FUNCTION("G"."START_DATE_TIME"))<TO_DATE(' 2010-06-01
                  00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND (TRUNC(INTERNAL_FUNCTION("G"."END_DATE_TIME"))>=TO_DATE('
                  2010-06-30 00:00:00', 'syyyy-mm-dd hh24:mi:ss') OR TRUNC(INTERNAL_FUNCTION("G"."END_DATE_TIME"))>=TO_DATE(
                   2010-06-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND TRUNC(INTERNAL_FUNCTION("G"."END_DATE_TIME"))<=TO_DAT
    E
                  (' 2010-06-30 00:00:00', 'syyyy-mm-dd hh24:mi:ss') OR
                  TRUNC(INTERNAL_FUNCTION("G"."END_DATE_TIME"))=TO_DATE(' 0001-01-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
                  OR TRUNC(INTERNAL_FUNCTION("C"."ISSUE_DATE_TIME"))>=TO_DATE(' 2010-06-01 00:00:00', 'syyyy-mm-dd
                  hh24:mi:ss') AND TRUNC(INTERNAL_FUNCTION("C"."ISSUE_DATE_TIME"))<=TO_DATE(' 2010-06-30 00:00:00',
                  'syyyy-mm-dd hh24:mi:ss')) AND "G"."VIN_NUM"="D"."VIN_NUM")
      20 - access("G"."WORKSHEET_NUM"="B"."WORKSHEET_NUM")
      28 - access("A"."TERMINAL_SEQ_NO"=1 AND "A"."YARD_CODE"=U'1')
      30 - access("B"."TERMINAL_SEQ_NO"=1 AND "B"."YARD_CODE"=U'1')
      31 - filter("G"."YARD_CODE"=U'1' AND TRUNC(INTERNAL_FUNCTION("G"."START_DATE_TIME"))<>TO_DATE('
                  0001-01-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "G"."TERMINAL_SEQ_NO"=1)
      32 - access("G"."WORKSHEET_NUM"="B"."WORKSHEET_NUM")
      33 - filter("D"."YARD_CODE"=U'1' AND "D"."TERMINAL_SEQ_NO"=1)
      34 - access("G"."VIN_NUM"="D"."VIN_NUM")
           filter("D"."VIN_NUM"="B"."VIN_NUM")
      36 - access("D"."MFG_CODE"="E"."MFG_CODE")
      37 - filter("C"."PART_FRANCHISE">=U' ' AND TRUNC(INTERNAL_FUNCTION("C"."ACTUAL_ISSUE_DATE_TIME"))<>TO_DAT
                  E(' 0001-01-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
                  TRUNC(INTERNAL_FUNCTION("C"."ISSUE_DATE_TIME"))<=TO_DATE(' 2010-06-30 00:00:00', 'syyyy-mm-dd hh24:mi:ss')
                  AND "C"."PART_FRANCHISE"<=U'~' AND (TRUNC(INTERNAL_FUNCTION("G"."START_DATE_TIME"))>=TO_DATE(' 2010-06-01
                  00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND TRUNC(INTERNAL_FUNCTION("G"."START_DATE_TIME"))<=TO_DATE('
                  2010-06-30 00:00:00', 'syyyy-mm-dd hh24:mi:ss') OR TRUNC(INTERNAL_FUNCTION("G"."START_DATE_TIME"))<TO_DATE
                  ' 2010-06-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
                  (TRUNC(INTERNAL_FUNCTION("G"."END_DATE_TIME"))>=TO_DATE(' 2010-06-30 00:00:00', 'syyyy-mm-dd hh24:mi:ss')
                  OR TRUNC(INTERNAL_FUNCTION("G"."END_DATE_TIME"))>=TO_DATE(' 2010-06-01 00:00:00', 'syyyy-mm-dd
                  hh24:mi:ss') AND TRUNC(INTERNAL_FUNCTION("G"."END_DATE_TIME"))<=TO_DATE(' 2010-06-30 00:00:00',
                  'syyyy-mm-dd hh24:mi:ss') OR TRUNC(INTERNAL_FUNCTION("G"."END_DATE_TIME"))=TO_DATE(' 0001-01-01 00:00:00',
                  'syyyy-mm-dd hh24:mi:ss')) OR TRUNC(INTERNAL_FUNCTION("C"."ISSUE_DATE_TIME"))>=TO_DATE(' 2010-06-01
                  00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND TRUNC(INTERNAL_FUNCTION("C"."ISSUE_DATE_TIME"))<=TO_DATE('
                  2010-06-30 00:00:00', 'syyyy-mm-dd hh24:mi:ss')))
      38 - access("B"."SUB_SERVICE_SEQ_NUM"="C"."SUB_SERVICE_SEQ_NUM")
      39 - filter("C"."PDI_PART_ORDER_NUM"="H"."PDI_PART_ORDER_NUM")
      40 - access("C"."SUB_SERVICE_SEQ_NUM"="H"."SUB_SERVICE_SEQ_NUM" AND
    PLAN_TABLE_OUTPUT
                  "C"."SUB_SERVICE_PART_SEQ_NUM"="H"."SUB_SERVICE_PART_SEQ_NUM")
    Note
       - SQL profile "SYS_SQLPROF_014aab7522964001" used for this statementEdited by: user629451 on Sep 22, 2010 12:23 AM
    Edited by: user629451 on Sep 22, 2010 12:25 AM

  • SSIS execution via sql query with dtexec utility by passing proxy account

    Hi, 
    i am executing ssis package with dtexec utility, with xp_cmdshell
    package is not a file based, but stored in sql/msdb
    while executing i am getting 'authentication failed'
    i haved tried with sa user and password, by passing it...but no luck
    so finally i want to authenticate it via proxy account, because same happen in sql agent job also but after creating proxy account it worked.
    please suggest me way to pass proxy account in query....i have used many combination like
    SET @SQLQuery = 'DTExec /SQL ^"\DataTransfer.dtx^" '
    SET @SQLQuery = @SQLQuery + ' /SET \Package.Variables[ServerName].Value;^"'+ @ServerName + '^" '
    EXEC master..xp_cmdshell @SQLQuery

    Have the EXEC master..xp_cmdshell run a batch instead that inside it it has a run as DOS command that runs the package with DTExec
    Arthur My Blog

  • Sql query slow in new redhat enviornment

    We just migrated to a new dev environment in Linux REDHAT5, and now the query is very slow, and I used the TOAD to run the query, it took like 700 msecond to finish, however from any server connection, the sql query takes hours to finish.
    I checked toad monitor, it said need to increase db_buffer_cache and shared pool too small.
    Also three red alert from toad is:
    1. Library Cache get hit ratio: Dynamic or unsharable sql
    2. Chained fetch ratio: PCT free too low for a table
    3. parse to execute ratio: HIgh parse to execute ratio.
    App team said it ran real quick in the old AIX system, however I ran it in old system, and monitored in the toad, it gave me all same 5 red alerts in old system, and it did provide query results a lot quicker though.
    Here is the parameters in the old system (11gr1 on AIX):
    SQL> show parameter target
    NAME TYPE VALUE
    -------------------------------- archive_lag_target integer 0
    db_flashback_retention_target integer 1440
    fast_start_io_target integer 0
    fast_start_mttr_target integer 0
    memory_max_target big integer 0
    memory_target big integer 0
    pga_aggregate_target big integer 278928K
    sga_target big integer 0
    SQL> show parameter shared
    NAME TYPE VALUE
    -------------------------------- hi_shared_memory_address integer 0
    max_shared_servers integer
    shared_memory_address integer 0
    shared_pool_reserved_size big integer 31876710
    shared_pool_size big integer 608M
    shared_server_sessions integer
    shared_servers integer 0
    SQL> show parameter db_buffer
    SQL> show parameter buffer
    NAME TYPE VALUE
    -------------------------------- buffer_pool_keep string
    buffer_pool_recycle string
    db_block_buffers integer 0
    log_buffer integer 2048000
    use_indirect_data_buffers boolean FALSE
    SQL>
    In new 11gr2 Linux REDHAT parameter:
    NAME TYPE VALUE
    ----------- archive_lag_target integer 0
    db_flashback_retention_target integer 1440
    fast_start_io_target integer 0
    fast_start_mttr_target integer 0
    memory_max_target big integer 2512M
    memory_target big integer 2512M
    parallel_servers_target integer 192
    pga_aggregate_target big integer 0
    sga_target big integer 1648M
    SQL> show parameter shared
    NAME TYPE VALUE
    ----------- hi_shared_memory_address integer 0
    max_shared_servers integer
    shared_memory_address integer 0
    shared_pool_reserved_size big integer 28M
    shared_pool_size big integer 0
    shared_server_sessions integer
    shared_servers integer 1
    SQL> show parameter buffer
    NAME TYPE VALUE
    ----------- buffer_pool_keep string
    buffer_pool_recycle string
    db_block_buffers integer 0
    log_buffer integer 18857984
    use_indirect_data_buffers boolean FALSE
    SQL>
    Please help. Thanks in advance.

    846422 wrote:
    why need ddl? we have a sql query slow.The DDL shows the physical structure of the table and physical storage characteristics. All relevant in performance tuning.
    As for the SQL query being slow. It is not.
    You have not provided any evidence that it is slow. And no, comparing performance with a totally different system is not a valid baseline for comparison. (most cars have 4 wheels, a gearbox and a steering wheel - but that does not mean you can compare different cars like a VW Beetle with a VW Porsche)
    What is slow? What are the biggest wait states for the SQL? What does the execution plan say?
    You have not defined a problem - you identified a symptom called "+query is slow+". You need to diagnose the condition by determining exactly what the SQL qeury is doing in the database. (and please, do not use TOAD and similar tools in an attempt to do this - do it properly instead)

  • Oracle 8i giving slow response when running sql query

    hi ,
    i am using oracle 8i server ;
    and sql query giving slow response before some days;
    so which parameter need to increase
    DB_BLOCK_BFFERS OR SHARE_POOL_SIZE
    CURRENT SETING IS
    DB_BLOCK_BUFFER=256000;
    SHARE POOLSIZE=300M;
    pls advice to me
    thanks

    No parameters need to be increased. Tuning is not done but making arbitrary changes to values and hoping that good things will happen by accident.
    The thing you really should be worrying about is your antique database and likely its impact on your skill set unless you are one year away from retirement.
    Where's the actual version number?
    Where's the DDL?
    Where's the DML?
    Where's the Explain Plan?

  • SQL query with Bind variable with slower execution plan

    I have a 'normal' sql select-insert statement (not using bind variable) and it yields the following execution plan:-
    Execution Plan
    0 INSERT STATEMENT Optimizer=CHOOSE (Cost=7 Card=1 Bytes=148)
    1 0 HASH JOIN (Cost=7 Card=1 Bytes=148)
    2 1 TABLE ACCESS (BY INDEX ROWID) OF 'TABLEA' (Cost=4 Card=1 Bytes=100)
    3 2 INDEX (RANGE SCAN) OF 'TABLEA_IDX_2' (NON-UNIQUE) (Cost=3 Card=1)
    4 1 INDEX (FAST FULL SCAN) OF 'TABLEB_IDX_003' (NON-UNIQUE)
    (Cost=2 Card=135 Bytes=6480)
    Statistics
    0 recursive calls
    18 db block gets
    15558 consistent gets
    47 physical reads
    9896 redo size
    423 bytes sent via SQL*Net to client
    1095 bytes received via SQL*Net from client
    3 SQL*Net roundtrips to/from client
    1 sorts (memory)
    0 sorts (disk)
    55 rows processed
    I have the same query but instead running using bind variable (I test it with both oracle form and SQL*plus), it takes considerably longer with a different execution plan:-
    Execution Plan
    0 INSERT STATEMENT Optimizer=CHOOSE (Cost=407 Card=1 Bytes=148)
    1 0 TABLE ACCESS (BY INDEX ROWID) OF 'TABLEA' (Cost=3 Card=1 Bytes=100)
    2 1 NESTED LOOPS (Cost=407 Card=1 Bytes=148)
    3 2 INDEX (FAST FULL SCAN) OF TABLEB_IDX_003' (NON-UNIQUE) (Cost=2 Card=135 Bytes=6480)
    4 2 INDEX (RANGE SCAN) OF 'TABLEA_IDX_2' (NON-UNIQUE) (Cost=2 Card=1)
    Statistics
    0 recursive calls
    12 db block gets
    3003199 consistent gets
    54 physical reads
    9448 redo size
    423 bytes sent via SQL*Net to client
    1258 bytes received via SQL*Net from client
    3 SQL*Net roundtrips to/from client
    1 sorts (memory)
    0 sorts (disk)
    55 rows processed
    TABLEA has around 3million record while TABLEB has 300 records. Is there anyway I can improve the speed of the sql query with bind variable? I have DBA Access to the database
    Regards
    Ivan

    Many thanks for your reply.
    I have run the statistic already for the both tableA and tableB as well all the indexes associated with both table (using dbms_stats, I am on 9i db ) but not the indexed columns.
    for table I use:-
    begin
    dbms_stats.gather_table_stats(ownname=> 'IVAN', tabname=> 'TABLEA', partname=> NULL);
    end;
    for index I use:-
    begin
    dbms_stats.gather_index_stats(ownname=> 'IVAN', indname=> 'TABLEB_IDX_003', partname=> NULL);
    end;
    Is it possible to show me a sample of how to collect statisc for INDEX columns stats?
    regards
    Ivan

  • Query is Slower in PL/SQL than in SQL*Plus ?

    I have a query that executes quiet fast in SQL*Plus (<1 second) but with EXECUTE IMMEDIATE withing an PL/SQL block its performance is really poor (=20 times slower)
    I am using the agregation function WMSYS.WM_CONCAT and I figured out that the poor PL/SQL performance must be related somehow to this function...
    I don't get why in SQL*Plus the query executes that much faster... Any ideas/solutions?
    Thanks!
    My PL/SQL query:
    EXECUTE IMMEDIATE 'INSERT INTO ' || temp_table_opt || '
    SELECT DISTINCT a.hs as HS, a.ht as HT, a.vehicle_id as VEHICLE_ID, c.option_id as OPTION_ID, WMSYS.WM_CONCAT(e.av_checked) as AV,
    d.vehicle_id || '';'' || d.option_code || '';'' || d.option_type || '';'' || d.manuf_name as COMPOUND_KEY
    FROM jumla.ax_vid a, jumla.version b, jumla.equipment c, jumla.option_list d, jaxlink_data.checked e
    WHERE a.hs = SUBSTR(''' || phsht || ''', 1, 2)
    AND a.ht = SUBSTR(''' || phsht || ''', -2, 2)
    AND b.vehicle_id = a.vehicle_id
    AND c.vehicle_id = a.vehicle_id
    AND d.vehicle_id = a.vehicle_id
    AND b.id_106 IN (''2'', ''4'', ''X'')
    AND d.option_type <> ''P''
    AND d.option_id = c.option_id
    AND e.hs = a.hs
    AND e.ht = a.ht
    AND e.schema_id = c.schema_id
    AND e.option_code = d.option_code
    AND e.description = d.manuf_name
    GROUP BY a.hs, a.ht, a.vehicle_id, c.option_id, d.vehicle_id || '';'' || d.option_code || '';'' || d.option_type || '';'' || d.manuf_name';

    > I am using the agregation function WMSYS.WM_CONCAT and I figured
    out that the poor PL/SQL performance must be related somehow to this
    function...
    Wrong.
    Who executes the SQL that is created?
    Answer - does not matter where the SQL comes from, from a PL procedure, Java program, SQL*Plus, TOAD or whatever, the SQL is parsed by the SQL engine, execution plan created by the CBO and stored in the SQL Shared Pool.
    An EXECUTE IMMEDIATE is a PL command that sends the string to the SQL engine to be processed. Just as SQL*Plus sends a string to the SQL engine to be processed.
    So how can the very same SQL be faster from SQL*Plus and slower from somewhere else?
    Nothing to do with where it comes from, but everything to do wrt the session that the SQL is being executed in. Issues such as settings for that session (which can be differ from session to session). Scope. Context. Etc.

Maybe you are looking for