Question on query SQL Tuning

We have made from a 9i database to an 11 g database.  The defined query works perfectly under 9i (about 1 second) but takes 60 to 70 seconds back to 11g.  The strange thing is that it has an outer query and a subquery.  If I remove the where clause of the outer query, it runs in less than a second.  Here's the query...

SELECT the period, biweek_start, biweek_end, pay_period_complete, worker_count

FROM (SELECT to_char (en.start_date, ' dd/mm/yyyy') |) « à » ||

TO_CHAR (en.start_date + 13, ' dd/mm/yyyy') period.

en.start_date biweek_start,

en.start_date + biweek_end 13,

Decode (sign (sysdate - en.start_date - 13),

-1,

'Ongoing',

Pay_period_complete 'Done'),

ta_mssauth_pkg.actual_endorser (en.start_date, '33811') worker_count

FROM (select worker_id,

default_endorser resolved_endorser,

effective_date,

correspondents

of endorse_delegate_history_v

where default_endorser = '33811'

Union

Select worker_id,

temporary_delegate resolved_endorser,

effective_date,

correspondents

of endorse_delegate_history_v

where temporary_delegate = '33811'

and temporary_delegate is not null),

endorse_activity_v en

WHERE en.worker_id = de.worker_id

AND en.endorse_status = n

AND en.start_date < = de.expiration_date

AND en.start_date + 13 > = de.effective_date

GROUP BY en.start_date)

WHERE worker_count > 0;

The function that is used in the inner query to generate the worker_counts is quite complex.  But it works subsecond if you run manually.  And it works very well when you run the query without the "where worker_count > 0" part.

So the where clause of the outer query seems to be the cause of the problem - it is based on a function which should have calculated a value FIRST, and then the outer query must run depending on the result of the inner query.  Here are the plans to explain to the two different versions:

BAD REQUEST - 60 to 70 seconds

Object owner name cardinality bytes cost object description
SELECT STATEMENT, GOAL = 41 1 617 ALL_ROWS
HASH GROUP BY 41 1 617
NESTED LOOPS
616 1 41 NESTED LOOPS
VIEW CA17062 58 186 4464
58 186 5392 SINGLE FATE
UNION-ALL
TABLE ACCESS BY INDEX ROWID TAS_AUTH ENDORSE_DELEGATE_HISTORY_TBL 42 139 4170
INDEX RANGE SCAN TAS_AUTH ENDORSE_DELEGATE_HIST_DEF_IDX 3 139
TABLE ACCESS BY INDEX ROWID TAS_AUTH 14 47 1222 ENDORSE_DELEGATE_HISTORY_TBL
INDEX RANGE SCAN 3 47 ENDORSE_DELEGATE_HIST_TEMP_IDX TAS_AUTH
INDEX RANGE SCAN TAS_AUTH 2 1 TA_SCLENDORSE_PK

TABLE ACCESS BY INDEX ROWID 3 1 17 ENDORSE_ACTIVITY_TBL TAS_AUTH

GOOD QUESTION < 1 second

Object owner name cardinality bytes cost object description
SELECT STATEMENT, GOAL = 1025 25 617 ALL_ROWS
HASH GROUP BY 1025 25 617
NESTED LOOPS
616 25 1025 NESTED LOOPS
VIEW CA17062 58 186 4464
58 186 5392 SINGLE FATE
UNION-ALL
TABLE ACCESS BY INDEX ROWID TAS_AUTH ENDORSE_DELEGATE_HISTORY_TBL 42 139 4170
INDEX RANGE SCAN TAS_AUTH ENDORSE_DELEGATE_HIST_DEF_IDX 3 139
TABLE ACCESS BY INDEX ROWID TAS_AUTH 14 47 1222 ENDORSE_DELEGATE_HISTORY_TBL
INDEX RANGE SCAN 3 47 ENDORSE_DELEGATE_HIST_TEMP_IDX TAS_AUTH
INDEX RANGE SCAN TAS_AUTH 2 1 TA_SCLENDORSE_PK
TABLE ACCESS BY INDEX ROWID 3 1 17 ENDORSE_ACTIVITY_TBL TAS_AUTH

If these expleain plans look almost identical to me - can someone tell me why having where clause of the outer query is originally so wrong and how I can solve this problem?  I tried using the NO_MERGE and PUSH_SUBQ - tips but nothing of what I did so wrong not better requested.

Thanks in advance!

Cory

You can also try taking advantage of the scalar subquery caching by changing

ta_mssauth_pkg.actual_endorser (en.start_date, '33811') worker_count

TO

worker_count (select ta_mssauth_pkg.actual_endorser (en.start_date, '33811') of double)

Which could cache the results for recent start dates, massively reducing the number of calls.

I think the NO_PUSH_PRED is a better approach, because the cache is less reliable to eliminate duplicate calls - it can cache the value, it could have thrown the corresponding value in the cache already, there is no guarantee of behavior and values the more en.start_date the request to meet the less reliable the caching will be.

Tags: Database

Similar Questions

  • SQL Tuning Advisor on a select Question

    Hi all.
    10.2.0.4 RAC
    I have a select sequential reading of file db high. I used sql tuning advisor on OEM, and the Adviser show me these recommendations:
    RECOMMENDATIONS
    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    GENERAL INFORMATION SECTION
    -------------------------------------------------------------------------------
    Tuning Task Name                  : SQL_TUNING_1266335308111
    Tuning Task Owner                 : SYSTEM
    Scope                             : COMPREHENSIVE
    Time Limit(seconds)               : 1800
    Completion Status                 : COMPLETED
    Started at                        : 02/16/2010 16:48:44
    Completed at                      : 02/16/2010 16:50:06
    Number of SQL Profile Findings    : 1
    
    -------------------------------------------------------------------------------
    Schema Name: CRM
    SQL ID     : b7cd8jntqpcgu
    SQL Text   : select * from ( select this_.ENVIO_ID as ENVIO1_33_0_,
                 this_.NOMCLIENTE as NOMCLIENTE33_0_, this_.NOMCONTACTO as
                 NOMCONTA3_33_0_, this_.APLICACION_ID as APLICACION4_33_0_,
                 this_.PRIORIDAD as PRIORIDAD33_0_, this_.MEDIO as MEDIO33_0_,
                 this_.MEDIO_VALOR as MEDIO7_33_0_, this_.ESTADO as ESTADO33_0_,
                 this_.ESTADO_DESC as ESTADO9_33_0_, this_.FEC_PREVISTA as
                 FEC10_33_0_, this_.FECHA_ENVIO as FECHA11_33_0_,
                 this_.REC_CLIENTE as REC12_33_0_, this_.FECHACREA as
                 FECHACREA33_0_, this_.FECHAMODIF as FECHAMODIF33_0_,
                 this_.FLAGBLOQUEO as FLAGBLO15_33_0_, this_.FLAGBORRADO as
                 FLAGBOR16_33_0_, this_.COMENTARIOS as COMENTA17_33_0_,
                 this_.HORAENVIO as HORAENVIO33_0_, this_.EMISOR as EMISOR33_0_,
                 this_.IDENTIFICADOR as IDENTIF20_33_0_, this_.MEDIO_VALOR_DESC
                 as MEDIO21_33_0_, this_.DEBUG_TRACE as DEBUG22_33_0_,
                 this_.FORMULARIO_ID as FORMULARIO23_33_0_, this_.CAMPANYA_ID as
                 CAMPANYA24_33_0_, this_.CONTACTO_ID as CONTACTO25_33_0_,
                 this_.USUARIOCREA as USUARIO26_33_0_, this_.USUARIOMODIF as
                 USUARIO27_33_0_, this_.CLIENTE_ID as CLIENTE28_33_0_,
                 this_.CAMPPOS_ID as CAMPPOS29_33_0_, this_.ACTIVIDAD_ID as
                 ACTIVIDAD30_33_0_, this_.TAGCLICONEXT_ID as TAGCLIC31_33_0_ from
                 CRM.CRM_ENVIOS this_ where this_.MEDIO=:1 and this_.ESTADO=:2
                 and this_.FECHA_ENVIO<=:3 order by this_.ENVIO_ID asc ) where
                 rownum <= :4
    
    -------------------------------------------------------------------------------
    FINDINGS SECTION (1 finding)
    -------------------------------------------------------------------------------
    
    1- SQL Profile Finding (see explain plans section below)
    --------------------------------------------------------
      A potentially better execution plan was found for this statement.
    
      Recommendation (estimated benefit: 99.43%)
      ------------------------------------------
      - Consider accepting the recommended SQL profile.
        execute dbms_sqltune.accept_sql_profile(task_name =>
                'SQL_TUNING_1266335308111', replace => TRUE);
    
    -------------------------------------------------------------------------------
    ADDITIONAL INFORMATION SECTION
    -------------------------------------------------------------------------------
    - The optimizer could not merge the view at line ID 2 of the execution plan.
      The optimizer cannot merge a view that contains an "ORDER BY" clause unless
      the statement is a "DELETE" or an "UPDATE" and the parent query is the top
      most query in the statement.
    
    -------------------------------------------------------------------------------
    EXPLAIN PLANS SECTION
    -------------------------------------------------------------------------------
    
    1- Original With Adjusted Cost
    ------------------------------
    Plan hash value: 3505713201
    
    ----------------------------------------------------------------------------------------------
    | Id  | Operation                     | Name         | Rows  | Bytes | Cost (%CPU)| Time     |
    ----------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT              |              |     1 |  4416 |   604K  (1)| 02:00:53 |
    |*  1 |  COUNT STOPKEY                |              |       |       |            |          |
    |   2 |   VIEW                        |              |     1 |  4416 |   604K  (1)| 02:00:53 |
    |*  3 |    TABLE ACCESS BY INDEX ROWID| CRM_ENVIOS   |     1 |   352 |   604K  (1)| 02:00:53 |
    |   4 |     INDEX FULL SCAN           | SYS_C0020438 |  2718K|       |  8153   (1)| 00:01:38 |
    ----------------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       1 - filter(ROWNUM<=:4)
       3 - filter("THIS_"."MEDIO"=:1 AND "THIS_"."ESTADO"=:2 AND
                  "THIS_"."FECHA_ENVIO"<=:3)
    
    2- Using SQL Profile
    --------------------
    Plan hash value: 3391889105
    
    ------------------------------------------------------------------------------------------------------
    | Id  | Operation                      | Name                | Rows  | Bytes | Cost (%CPU)| Time     |
    ------------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT               |                     |     1 |  4416 |  3431   (1)| 00:00:42 |
    |*  1 |  COUNT STOPKEY                 |                     |       |       |            |          |
    |   2 |   VIEW                         |                     |     1 |  4416 |  3431   (1)| 00:00:42 |
    |*  3 |    SORT ORDER BY STOPKEY       |                     |     1 |   352 |  3431   (1)| 00:00:42 |
    |*  4 |     TABLE ACCESS BY INDEX ROWID| CRM_ENVIOS          |     1 |   352 |  3430   (1)| 00:00:42 |
    |*  5 |      INDEX SKIP SCAN           | APLICACIONENVIO_IDX |     1 |       |  3429   (1)| 00:00:42 |
    ------------------------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       1 - filter(ROWNUM<=:4)
       3 - filter(ROWNUM<=:4)
       4 - filter("THIS_"."MEDIO"=:1 AND "THIS_"."FECHA_ENVIO"<=:3)
       5 - access("THIS_"."ESTADO"=:2)
           filter("THIS_"."ESTADO"=:2)
    
    -------------------------------------------------------------------------------
    I think the main problem is the order, but when I run autotrace traceonly without order by the plan of the explain command is diferent to advise:
    SELECT *
      2    FROM (SELECT this_.envio_id AS envio1_33_0_,
      3                 this_.nomcliente AS nomcliente33_0_,
      4                 this_.nomcontacto AS nomconta3_33_0_,
      5                 this_.aplicacion_id AS aplicacion4_33_0_,
      6                 this_.prioridad AS prioridad33_0_, this_.medio AS medio33_0_,
      7                 this_.medio_valor AS medio7_33_0_, this_.estado AS estado33_0_,
      8                 this_.estado_desc AS estado9_33_0_,
      9                 this_.fec_prevista AS fec10_33_0_,
     10                 this_.fecha_envio AS fecha11_33_0_,
     11                 this_.rec_cliente AS rec12_33_0_,
     12                 this_.fechacrea AS fechacrea33_0_,
     13                 this_.fechamodif AS fechamodif33_0_,
     14                 this_.flagbloqueo AS flagblo15_33_0_,
     15                 this_.flagborrado AS flagbor16_33_0_,
     16                 this_.comentarios AS comenta17_33_0_,
     17                 this_.horaenvio AS horaenvio33_0_, this_.emisor AS emisor33_0_,
     18                 this_.identificador AS identif20_33_0_,
     19                 this_.medio_valor_desc AS medio21_33_0_,
     20                 this_.debug_trace AS debug22_33_0_,
     21                 this_.formulario_id AS formulario23_33_0_,
     22                 this_.campanya_id AS campanya24_33_0_,
     23                 this_.contacto_id AS contacto25_33_0_,
     24                 this_.usuariocrea AS usuario26_33_0_,
     25                 this_.usuariomodif AS usuario27_33_0_,
     26                 this_.cliente_id AS cliente28_33_0_,
     27                 this_.camppos_id AS camppos29_33_0_,
     28                 this_.actividad_id AS actividad30_33_0_,
     29                 this_.tagcliconext_id AS tagclic31_33_0_
     30            FROM crm.crm_envios this_
     31               where this_.estado = 'Enviado'
     32           and this_.medio = 3482 AND this_.fecha_envio <= '02/04/10 00:00:00')
     33   WHERE ROWNUM <= 500;
    
    no rows selected
    
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 1577868436
    
    ------------------------------------------------------------------------------------------------
    | Id  | Operation                    | Name            | Rows  | Bytes | Cost (%CPU)| Time     |
    ------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT             |                 |   500 |   171K|  2425   (1)| 00:00:30 |
    |*  1 |  COUNT STOPKEY               |                 |       |       |            |          |
    |*  2 |   TABLE ACCESS BY INDEX ROWID| CRM_ENVIOS      |   500 |   171K|  2425   (1)| 00:00:30 |
    |*  3 |    INDEX RANGE SCAN          | ESTADOENVIO_IDX |       |       |   104   (0)| 00:00:02 |
    ------------------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       1 - filter(ROWNUM<=500)
       2 - filter(TO_NUMBER("THIS_"."MEDIO")=3482 AND "THIS_"."FECHA_ENVIO"<='02/04/10
                  00:00:00')
       3 - access("THIS_"."ESTADO"='Enviado')
    
    
    Statistics
    ----------------------------------------------------------
              1  recursive calls
              0  db block gets
         138277  consistent gets
          45240  physical reads
              0  redo size
           2629  bytes sent via SQL*Net to client
            488  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              0  rows processed
    I was looking for a way to see who wear's Advisor using his plan, but didn't see a way of knowing on docs, or at least I have not found it.
    Can someone show me that some light on what changes made Advisor to select to reach that way, or how can I watch this that select uses?
    Any help will be appreciate
    Thank you

    The Adviser does not create a new SQL statement - what it has done is create a SQL profile - to accept SQL profile for the task of tuning above:

        execute dbms_sqltune.accept_sql_profile(task_name =>
                'SQL_TUNING_1266335308111', replace => TRUE);
    

    as mentioned in the above report...

    A sql profile applys tips for change (correct) the cost of certain operations - and, to change the execution path chosen by the optiimizer.

  • Need to learn the code of PL/SQL tuning

    Hi all

    I already asked this question earlier, but the link provided was too difficult to understand, I really grateful if someone suggest me the good and simple link or presentation for mentioned topic question.

    In addition, I just want to learn some basic for this. Appreciate your response. Thank you

    Concerning

    Muzz

    I already asked this question earlier, but the link provided was too difficult to understand, I really grateful if someone suggest me the good and simple link or presentation for mentioned topic question.

    Why PL/SQL tuning?

    The best advice re PL/SQL is to AVOID at all costs. Whenever possible, use SQL.

    It is usually the SQL to be tuned so that sql is autonomous or in code.

    As the major part of PL/SQL uses SQL to get the job done, you will be not successful tuning PL/SQL, unless you set the SQL contained in it.

    Start with the Oracle documentation:

    http://docs.Oracle.com/CD/B28359_01/server.111/b28274/sql_overview.htm

    This chapter deals with the objectives for the development, explains how to identify the high resource SQL statements, which must be collected, offers suggestions of setting and explains how to create SQL test scenarios to solve problems in SQL.

    This chapter contains the following sections:

    Then, learn how to use and interpret what the Wizard Setup of Sql from Oracle can make and provide:

    Update Auto SQL - 11 g Release 2 (11.2)

    17 automatic SQL Tuning

    This chapter examines the SQL Auto setting of the Oracle database features. Automatic tuning of SQL automates the manual process, which is complex, time consuming and repetitive.

    This chapter contains the following sections:

    A lot of questions of PL/SQL, you encounter will be due to one of these things:

    1 poorly written SQL (see SQL tuning above)

    2. use of slow-by-slow (line by line) treatment in a loop

    3. poor use of collections and in bulk of treatment

    4. use of the dynamic sql

    All those who will take you to the SQL itself. The SQL is not set correctly if it is not possible for the PL/SQL to be tuned.

  • There will be a review of certification SQL Tuning 12 c?

    Hello

    I hope soon the SQL Tuning oracle 11g certification exam.

    Certification exam SQL Tuning oracle 12 c comes?

    Thank you


    Sorry - end of the day - my right jumped brain beyond the portion "SQL" to your question.  I seriously doubt that there will be an update to the review of SQL Tuning (1Z0-117) 11 g just for Oracle 12 c.  There is not a lot of change in the way that SQL should be given between 11 billion and 12 c, so a separate trial would be pretty useless.

  • That means 1z0-117 oracle 11g sql tuning now say it includes v12 addition v11

    Hello

    I did the 1z0-117 sql tuning review once.

    Not too far away.

    I studied under and turned off for a while.

    I anticipate taking in 1 month.

    However, I just noticed that the oracle site says 1z0-117 also said that v12 is also included for consideration:

    Oracle 11g sql tuning.

    It makes no sense at all.

    Roger

    However, I just noticed that the oracle site says 1z0-117 also said that v12 is also included for consideration:

    Oracle 11g sql tuning.

    Unless you are looking for something I'm not, what actually is the 1Z0-117 page says: "validated against: review has been validated against Oracle Database 11g Release 2 version 11.2.0.1.0 and database Oracle 12 c 12.1.0.1.0"

    What they actually mean by it is that someone went through all the issues and and asked the question "is still a relevant issue for the release of 12 c to Oracle?'." "  If they find issues that are not valid because of an update/change, then the question will be removed from review (or changed) so that someone who has used 12 c but not 11 g will not at a disadvantage.

    This is * No * means that Oracle has added questions to the review of the capabilities that were introduced in version 12 c.

  • Need your help for sql tuning


    Hi gurus

    I really want to learn a few basics against SQL tuning, can you please guide me how will I achieve my goal? Thanks in advance.

    Concerning

    Shu

    I am professional tuner and this for 20 years. Firstly, I think that the best way is always a course with instructor. In other words, you can't ask for books. You have no need to read tuning guide in this case, the instructor he will tell you. If the time and the budget does not allow you a course, you can go online or material and DVD tutorial. As a next steop I would recommend Cary Milsap's "Optimizing Oracle Perforamance". I'll be your right mind game. Jonathan and Chris books you must have if you do practical work. You don't need to read all the chapters in detail from the beginning, but you should check out them if you have any questions when you work on a tuning tasks. If you want to go more advanced subjects discover Wolfgang Breitlings presentation on http://www.centrexcc.com/. Very valuable are also Throw away method of Martin Berg and the SQL Diagraming of Daniel Tow technique.

  • Exception ORA when accepting SQL Tuning Set

    Hello

    RDBMS version: 11.2.0.1.0 & 11.2.0.4.0

    OS: OEL 5 (64-bit)

    I am creating a SQL tuning set and get both to do exception below. Tried to search on the forums also with the exception of the ORA, but unable to get any resolution for this exception ORA.

    The following awards were made: -.

    GRANT CREATE ANY SQL PROFILE TO SCOTT;
    GRANT DROP ANY SQL PROFILE TO SCOTT;
    GRANT ALTER ANY SQL PROFILE TO SCOTT;
    GRANT ADVISOR TO SCOTT;
    GRANT ADMINISTER SQL MANAGEMENT OBJECT TO SCOTT;
    grant execute on dbms_spm to SCOTT;
    grant administer sql management object to SCOTT;
    
    

    DECLARE
      my_task_name VARCHAR2(30);
      my_sqltext CLOB;
      my_sqlprofile_name VARCHAR2(4000);
    BEGIN
      my_sqltext   := 'SELECT * FROM emp';
      my_task_name := DBMS_SQLTUNE.CREATE_TUNING_TASK(sql_text => my_sqltext, user_name => 'SCOTT', scope => 'COMPREHENSIVE', time_limit => 60, task_name => 'my_sql_tuning_task3', description => 'Demo Task to tune a query');
      DBMS_SQLTUNE.EXECUTE_TUNING_TASK( task_name => 'my_sql_tuning_task3');
      my_sqlprofile_name := DBMS_SQLTUNE.ACCEPT_SQL_PROFILE (task_name =>'my_sql_tuning_task3', name => 'my_sql_profile');   -- Culprit for the exception
      --dbms_output.put_line(my_sqlprofile_name);
    END;
    /
    
    Error report -
    ORA-13786: missing SQL text of statement object "1" for tuning task "my_sql_tuning_task3"
    ORA-06512: at "SYS.DBMS_SYS_ERROR", line 95
    ORA-06512: at "SYS.DBMS_SQLTUNE_INTERNAL", line 16255
    ORA-06512: at "SYS.PRVT_SQLPROF_INFRA", line 31
    ORA-06512: at "SYS.DBMS_SQLTUNE", line 7133
    ORA-06512: at line 4
    13786. 00000 -  "missing SQL text of statement object \"%s\" for tuning task \"%s\""
    *Cause:    The user attempted to accept SQL profile for an object
               that has not a SQL text associated to it.
    *Action:   Check the identifier of the object and retry the operation.
    
    
    

    Would be really grateful if someone could point me in the right direction here.

    TIA...

    Personally, I wouldn't bother with a task of setting.

    If you are lucky who will recommend a sql profile based on adjustments of cardinality which may or may not be effective.

    I would just use either the COE_XFR_SQL_PROFILE. SQL script SQLT ( doc-id 1487302.1Support) or use SQL Plan baseline to apply the previous execution plan. The latter has the advantage of being able to make an evolution controlled all plans potentially better which would otherwise be generated.

    You can choose the older, better plan AWR in the same database or a different database, and then transport it.

  • Create a simple query (SQL)

    Hi experts,

    I have a table with data as follows:

    Database version: 10.2.0.4
    Table name: TRANSACTION_HIST_TAB
    TRANS_ID      LOT_NO    PART_NO    QTY    TRANSACTION         LOCATION_NO    ROWVERSION
    ---------     -------   --------   ----   -----------------   ------------   ----------------------
    T00000X1      L001     ABC         10     CHANGE LOCATION     WRH_1          01/01/13 08:00:00 AM
    T00000X2      L001     ABC        10     CHANGE LOCATION     WRH_2          01/02/13 10:00:00 AM
    T00000X3      L002     XYZ        20     CHANGE LOCATION     WRH_3          01/03/13 11:00:00 AM
    and I want to create a single query (SQL) which can get data grouped by LOT_NO and only the first transaction by LOT_NO

    Expected results:
    TRANS_ID      LOT_NO    PART_NO    QTY    TRANSACTION         LOCATION_NO    ROWVERSION
    ---------     -------   --------   ----   -----------------   ------------   ----------------------
    T00000X1      L001     ABC         10     CHANGE LOCATION     WRH_1          01/01/13 08:00:00 AM
    T00000X3      L002     XYZ        20     CHANGE LOCATION     WRH_3          01/03/13 11:00:00 AM
    Someone has an idea?

    Kind regards

    Rob

    Hi, Rob.

    Here's one way:

    WITH     got_r_num     AS
    (
         SELECT     t.*     -- or list columns you want
         ,     ROW_NUMBER () OVER ( PARTITION BY  lot_no
                                   ORDER BY          rowversion
                           )  AS r_num
         FROM    transaction_hist_tab  t
    )
    SELECT       *     -- or list all columns except r_num
    FROM       got_r_num
    WHERE       r_num     = 1
    ;
    

    Depending on your data and your needs, match Sub like Manik suggested, might work. I think that you want to GROUP BY lot_no only, no transid.

    I hope that answers your question.
    If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements), and the results you want from this data.
    Explain, using specific examples, how you get these results from these data.
    Always say what version of Oracle you are using (for example, 11.2.0.2.0).
    See the FAQ forum {message identifier: = 9360002}

  • 1Z0-117: Oracle Certified Expert, Oracle Database 11 g Release 2 SQL Tuning

    Hello

    I failed the exam 1Z0-047 Oracle database SQL Expert"x 3 and will pass the exam in January 2012. I'm sure I'll spend this time :-) to 95%

    Now my question: what's next 1Z0-047? I only know how to leave 1Z0-047. I am SQL scripts to my work, but no DBA work and not of PL/SQL. So I guess that the "Oracle Certified Expert, Oracle Database 11 g Release 2 SQL Tuning" would be the next logical step?

    Is 'Oracle Certified Expert, Oracle Database 11g Release 2 SQL Tuning' too complicated for me (only have knowledge of the exam 1Z0-047). Because I don't have experience with the topics listed in the objectives, for the most part never heard talk about.

    What study guide?

    So I guess that the "Oracle Certified Expert, Oracle Database 11 g Release 2 SQL Tuning" would be the next logical step?

    I agree with you.

    The Oracle 11 g Release 2 database: review SQL Tuning is still in beta at least until November 24, 2012. Beta versions have been known to be extended. Even if this isn't the case, the examination of the production is not available before mid-January 2013 about. I had one experience with a beta. I hated and will never be another. There is little reason to do so, and most importantly (reduced cost) is not important to me because my company reimburses the cost of my essay, so I don't really care about the savings. They take several times longer to complete and I was a mess at the time that I finished that I did with a headache roaring through a large part of the review.

    That said - answering your question:

    1Z0-047 is a really complicated test. The questions and answers are designed to mislead. There is a reason for that. SQL, by its very nature, is a fairly simple language. Part of its appeal, is that it is easy to understand and write. If the people who wrote the essay was not gone to their best to make the deliberately convoluted SQL code, then it would not have required skills 'experts' to pass. It is much more difficult to read and diagnose poorly written SQL as well written SQL.

    I also took the test Application Express Expert: 1Z0-450. The questions that it were not written in a deliberately confusing manner. However, they had need intimate knowledge of the interface of the Apex. Because it was possible to write questions 'hard' without having to make them deliberately more obscure, the questions were simpler. I did not review SQL Tuning (as I said... no more betas for me), but I suspect that it will be similar to 1Z0-450 has enough information "at the level of experts" to write questions on that test will not attempt to write "hard" questions

    Is 'Oracle Certified Expert, Oracle Database 11g Release 2 SQL Tuning' too complicated for me.
    Because I don't have experience with the topics listed in the objectives, for the most part never heard talk about.

    Not sure what is in the test. This is excellent news. Student for the test will teach you a lot of new things about writing and tuning SQL. In my posts, a concept is repeated again and again. The value of certification is not make a piece of paper to stick in a workbook. The value comes to what new skills you gain in is about to pass the test. If you do not know the information and that you are not studying for the test, Yes, you will not pass. If you prepare for the test until you do understand the objectives, then you should be able to pass the test.

    What study guide?

    None does not yet exist. There is no doubt that I will write a review study guide. It won't be until some time after the test is in production. I do not publish guides for which I hold the certification. Do not wait for good. You can use the same exact source, I will use in his creation - the Oracle documentation. I guarantee you that all topics on the unique OE page and every single question that is under review are answered somewhere in the documentation.

  • Noob in SQL Tuning seeking help

    I am learning SQL Tuning and operation of it. I know that the first step is probably explain the sql statement execution plan? My problem is that I do not understand what am I suppose to collect from the execution plan.
    SQL> set autotrace traceonly explain
    SQL> select * from employees A
         where A.last_employed =
         ( SELECT TO_CHAR(MAX(TO_DATE(PAY_DATE,'MMRR')),'MMYY')
           FROM PAYROLL_VW1 B
           WHERE B.SSN = A.SSN AND B.PAY_TYPE_CODE IN ('02','12','22','32')
          AND STATUS = 'ACTIVE' AND A.BRANCH=B.BRANCH
         );
    Execution Plan
    ----------------------------------------------------------
       0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=47427 Card=1 Bytes
              =180)
    
       1    0   FILTER
       2    1     TABLE ACCESS (FULL) OF 'EMPLOYEES' (TABLE) (Cost=1618 Card
              =297964 Bytes=53633520)
    
       3    1     SORT (AGGREGATE)
       4    3       VIEW OF 'PAYROLL_VW1' (VIEW) (Cost=2290 Card=2 Bytes=
              46)
    
       5    4         SORT (UNIQUE) (Cost=2290 Card=2 Bytes=217)
       6    5           UNION-ALL
       7    6             FILTER
       8    7               TABLE ACCESS (FULL) OF 'PAYROLL2012' (TABLE) (C
              ost=2284 Card=1 Bytes=105)
    
       9    6             FILTER
      10    9               TABLE ACCESS (BY INDEX ROWID) OF 'PAYROLL2011'
              (TABLE) (Cost=4 Card=1 Bytes=112)
    
      11   10                 INDEX (RANGE SCAN) OF 'PAYROLL2011_IDX1' (IND
              EX) (Cost=3 Card=29)
    Then what should I do with the execution plan? What else should I check on it? How to grant the request?

    Edited by: apex_disco may 1, 2012 05:57

    I don't know how the licenses work. There is a difference between EM and Grid Control. I think that if you have just one instance, Enterprise Manager is installed, and if nothing is free I think it would be. Now, how much diagnosis is free? Who knows.

    But it may not be important. If you simply play "learning SQL Tuning" say, at home on a Linux machine, you can install anything you want and play with him.

    If adding an accelerated things index (in your re-written query logic now) then you must have had a considerable amount of documents in one of these tables not indexed. If you look at the plan to explain it now, it will probably show the indexes used, fewer files searched, less costly, etc as the other plan.

    But maybe I missed your point of departure. You want to learn how to set up queries in general or you try to resolve this particular application? I took the first for my previous answers.

    As for your results, your statistics say at least high level info. Becomes coherent and physical readings went down WAY.

    Initial statistics
    ----------------------------------------------------------
    0 recursive calls
    0 db block Gets
    1172490142 compatible Gets
    4914 physical reads
    Redo 191496 size

    2340 bytes sent via SQL * Net to client
    329 bytes received via SQL * Net from client
    1 SQL * Net back and forth to and from the client
    115881 sorts (memory)
    0 sorts (disk)
    0 rows processed

    on these tables and below are my stats. I think this is a major improvement. Elapsed time was reduced significantly to 00:00:00.65

    To listen statistics
    ----------------------------------------------------------
    352 recursive calls
    0 db block Gets
    31498 compatible Gets
    1101 physical reads
    0 redo size

    2340 bytes sent via SQL * Net to client
    329 bytes received via SQL * Net from client
    1 SQL * Net back and forth to and from the client
    13 sorts (memory)
    0 sorts (disk)
    0 rows processed

    Published by: gaffe on May 1, 2012 13:18

  • Query SQL Report with condition (multiple settings) at the point of the apex?

    Hi all

    I have a small problem and cannot find a solution.

    I need to create reports based on a query, SQL or I.R. Nothing hard here.
    I need to add the WHERE clause dynamically with javascript to an element of the Apex.
    Even once is not very difficult. I set the agenda of the Summit, put my query like this "SELECT * FROM MYTAB WHERE COL1 =: P1_SEARCH" then I call the page by setting the P1_SEARCH value. For example, COL1 is rowid. It works very well.

    But here's my problem. Consider that P1_SEARCH contains several ROWID, and I don't know the number of these values,
    (no I don't create a large number of items and create a query with so much GOLD!), I would sotheming like "SELECT * FROM MYTAB WHERE ROWID IN (: P1_SEARCH) with something like: ROWID1, ROWID2 in P1_SEARCH."

    I also tried: 'ROWID1, ROWID2' and 'ROWID1', 'ROWID2 '.
    but I can't get anything else than the mistake of filter. It works with a value, but as soon as there are two values or more, it seems that the Apex is unable to read the string.


    How can I do it please?

    Thanks for your help.

    Max

    mnoscars wrote:

    But here's my problem. Consider that P1_SEARCH contains several ROWID, and I don't know the number of these values,
    (no I don't create a large number of items and create a query with so much GOLD!), I would sotheming like "SELECT * FROM MYTAB WHERE ROWID IN (: P1_SEARCH) with something like: ROWID1, ROWID2 in P1_SEARCH."

    I also tried: 'ROWID1, ROWID2' and 'ROWID1', 'ROWID2 '.
    but I can't get anything else than the mistake of filter. It works with a value, but as soon as there are two values or more, it seems that the Apex is unable to read the string.

    For a standard report, see + {message identifier: = 9609120} +.

    For an IR - and improve safety by avoiding the risk of SQL Injection, use a collection containing the values in a column instead of a CSV list:
    {code}
    SELECT * FROM MYTAB WHERE ROWID IN (SELECT c001 FROM apex_collections WHERE collection_name = "P1_SEARCH")
    {code}
    (Please close duplicate threads spawned by your original question.)

  • SQL tuning advisor recommnds to create the function SYS_OP_C2C function index

    I have a large table and an index on it. I use a tool to fill data, this simple tool submits the sql for Oracle DB and it does NOT index to use for requests. When I run the sql tuning advisor, he recommends to create additional indexes and use the SYS_OP_C2C function, which I don't want.

    When I run the query through sql plus picks it up in the index.
    Someone of you came, why its recommend that additional nonsense?

    create index abc.xxxx on this_table (SYS_OP_C2C ("this_column"));

    Thank you

    The internal Oracle SYS_OP_C2C function perform the conversion of a set of characters to another set of characters - C (haracterSet) 2 c (haracterSet). There are situations where you will see this conversion without explicit, as in this case command that should be a sign that the data types are not the same and the implicit conversion takes place and this could also be a problem from the point of view performance because it can disable the use of the index.

    Make sure you the characterset and nls set of all of the database and the tool are the same.
    Make sure that the data type of the column in the index is the same as the database.
    Confirm the ETL vendor for your database support and fixes, etc..

    Optimizer will only advise to use this function when the data type or the character set does not match.

    Thank you
    Kerry

  • SQL tuning with siebel 8.0

    Hi all

    I am currently working with siebel 8.0 with oracle database (10g), can someone give me with sql tuning docs

    as I have never worked with siebel and especially the work of setting needs to be done on the dynamic sql


    Thanks in advance

    If you can fix the way statistics are collected, it resolves most of the query performance problems.

    If you have access to metalink, go through the following document, which contains information about the instance parameters, guidelines for the collection of statistics and the etc..

    Oracle CBO and Siebel Business Applications - 478028.1

    HTH
    -André

  • Validation of a region defined as a QUERY SQL type (updated report)

    Hello

    I am trying to perform validation on a region defined as type of QUERY SQL (editable report). The report has two columns.
    One of the columns is a Select list and I want to make sure that the user can select the same value twice
    in the report. For example, if the selection list has 5 values A, B, C, D, E, I don't want a user to be able to select
    B twice in the report. Will it use javascript to perform validation? If Yes, could someone provide some guidance on
    where to embed the javascript? Are there other alternatives than javascript? I create an element that came from a sql query
    counts the number of lines where the value of the column is the same. I then used the item in my validation logic. The problem with this logic
    is that a user can enter the same value and it is not until the 3rd attempt to select the same value that the validation works using the number of lines which is why I think that I need to somehow capture the value of the selection list when a user selects and then compare it to what is already in the database column Select.

    I hope that my question and explanations are clear.

    Thanks in advance for your help,

    Michael

    Hello

    This can be managed using javascript or a validation of the page. Here is an example of use of javascript: [http://htmldb.oracle.com/pls/otn/f?p=267:7]

    To do this, I have:

    1 - a model of button which does not send the page but just runs javascript. The model will depend on your theme, but should include:

    <a href="#BUTTON_ATTRIBUTES#">#LABEL#</a>
    

    If #BUTTON_ATTRIBUTES # appears on the template, delete it as we need it only once. You must create a new button model based on a copy of your existing across models, shared components. Normally, he would show href = "" #LINK # "-we do not want that this would become doSubmit('buttonname')." If your model does not use tags for buttons, you might need to create one from scratch.

    2 - I have updated the button on my page to use this template and then assign the setting button attributes:

    javascript:check();
    

    3. in the header of the HTML page, I added:

    <script type="text/javascript">
    function check()
    {
     var e = 0;
     var f = document.getElementsByName("f02");
     var k1;
     var k2;
     var v1;
     var v2;
     if (f)
     {
      for (k1 = 0; k1 < (f.length - 1); k1++)
      {
       v1 = f[k1].value;
       for (k2 = (k1 + 1); k2 < f.length; k2++)
       {
        v2 = f[k2].value;
        if (v1 == v2)
        {
         e = 1;
        }
       }
      }
     }
     if (e > 0)
     {
      alert("Duplicates found!");
     }
     else
     {
      doSubmit("SUBMIT");
     }
    }
    </script>
    

    In this example, SUBMIT is the name of the button and "f02" is the name attribute of the select list items that we want to check - change these needs by your page.

    Now, when the Submit button is clicked, instead of directly submit the page, the javascript function is called. This function loops through each selection list and gets its value. Then, he compared it to the remaining items. If there is a match, the e flag is set to 1. After all the items have been verified, if e is not 0, then a message appears. Otherwise, the page is sent.

    Andy

  • SQL Tuning sets and SQL Tuning Advisor.

    Hello

    We run oracle11g r2 where under win server 2008 R2.

    How can I find out when Tuning SQL and SQL Tuning games advisors are enabled in my database.

    Is Oracle11g has default setting YES for this tuning packs

    Thank you

    It seems you found somone activated of sets and the setting of advisers.  as others have said, theyre part of the D & T and theyre always there but only, you become eligible for a permit after that you use.   This will tell you the first time they have been used if at all, the key here for you field be FIRST_USAGE_DATE that must be completed only if detected_usages > 0

    fixed lines 180

    Col name format a30

    SELECT name, version, detected_usages, FIRST_USAGE_DATE, last_usage_date

    of DBA_FEATURE_USAGE_STATISTICS

    where upper (NAME) like '% % TUNING '.

Maybe you are looking for

  • updates to the pages?

    How can I get the latest updates of the pages? I get a notification update is available, but Apple Store does not show me a download of update.

  • Automatic files in Excel import of PDM

    I was looking at the NI TDMS for Excel import plugin and it seems that the latest version of the plugin uses the COM API that could allow to import feature be used automatcially. There is a page of brief info on this here http://zone.ni.com/devzone/c

  • What is function of the fn key

    Searched and searched a defiition and nothng found, even on the HP site.  I have a new HP Pavilion dm41060us laptop and don't have a clue about key.usage fn pourrait-someone ' a Please direct me to a site that provides usage? Thank you, Miles

  • Office from vista to windows 7 upgrade does not

    After that upgrade to Windows 7, Vista, the Office has no icons, no reuse the locker, nothing and I cannot put anything on it except by using the Control Panel, I can add gadgets. I can find the old desktop as a folder, but cannot move anything from

  • Unity UCSE exam - how to upgrade is it?

    Hey people. The UCSE 644-101 and UCSE 642-103 tests identical? The only one who can be booked is the 642-103. I have some QS of Boson to 644-101, but they seem to be updated. Some Qs refer to platform for example overlays that are not current support