Order of hints in a SQL query

Will the execution plan of the query vary based on the position of the hints in the below select segments. The only change in the below segments is that the postion of the NO_MERGE varies.
SELECT /*+ NO_MERGE ORDERED USE_HASH(RCTLGD RCT) FULL(RCTLGD) FULL(RCT) PARALLEL(RCTLGD,2) PARALLEL(RCT,2)*/
SELECT /*+ ORDERED NO_MERGE USE_HASH(RCTLGD RCT) FULL(RCTLGD) FULL(RCT) PARALLEL(RCTLGD,2) PARALLEL(RCT,2)*/

I would not expect it to make a difference, no.
If you are asking the question, however, I would tend to suspect that you are seeing a difference in the plan. Is that the case?
Justin

Similar Messages

  • Check the hints used in SQL Query (Parallel, First_Rows)

    Hi,
    I have used above hints in my sql query and found no difference in execution time.
    I just want to know whether the hints are used in my sql are not.
    Could you please let me know where to check for it.
    Thanks in advance

    Can you post the SQL which uses these hints and the execution plan with and without those hints here? Then only community can help you find out if the hints are really used or not.
    Please use code tags to preserve the format of execution plan.
    Edited by: Satish Kandi on Jun 23, 2009 5:37 PM

  • SEQUENCE Select within an SQL Query with an ORDER BY statement

    Does anyone know why you cannot use an ORDER BY statement within an SQL query when also selecting from a SEQUENCE? My query was selecting production data as a result of a filtered search. I want to take the results of the filtered search and create a transaction. I have a sequence for generating transaction numbers where I select NEXTVAL. Since I could possibly obtain multiple, yet distinct, rows based upon my search criteria, I wanted to use an ORDER BY statement to simplify and order the resulting row(s).
    I was able to get the SQL select with SEQUENCE.NEXTVAL to work without the ORDER BY, so I know that my SQL is correct. Thanks in-advance.

    Okay,
    I understand. You want the sequence assigned first and the you want to ORDER BY. You
    can do this using pipelined functions. See here:
    CREATE OR REPLACE TYPE emp_rec_seq AS OBJECT (
       seq     NUMBER,
       ename   VARCHAR2 (20),
       job     VARCHAR2 (20),
       sal     NUMBER
    CREATE OR REPLACE TYPE emp_tab_seq AS TABLE OF emp_rec_seq;
    CREATE OR REPLACE FUNCTION get_emp_with_sequence
       RETURN emp_tab_seq PIPELINED
    IS
       my_record   emp_rec_seq := emp_rec_seq (NULL, NULL, NULL, NULL);
    BEGIN
       FOR c IN (SELECT dummy.NEXTVAL seq, ename, job, sal
                   FROM emp)
       LOOP
          my_record.seq := c.seq;
          my_record.ename := c.ename;
          my_record.job := c.job;
          my_record.sal := c.sal;
          PIPE ROW (my_record);
       END LOOP;
       RETURN;
    END get_emp_with_sequence;after that, you can do a select like this:
    SELECT seq, ename, job, sal
      FROM TABLE (get_emp_with_sequence)
      order by enamewhich will get you this:
           SEQ ENAME                JOB                         SAL
          1053 BLAKE                MANAGER                    2850
          1054 CLARK                MANAGER                    2450
          1057 FORD                 ANALYST                    3000
          1062 JAMES                CLERK                       950
          1055 JONES                MANAGER                    2975
          1052 KING                 MANAGER                   20000
          1060 MARTIN               SALESMAN                   1250
          1063 MILLER               CLERK                      1300
          1064 DKUBICEK             MANAGER                   12000
          1056 SCOTT                ANALYST                    3000
          1058 SMITH                CLERK                       800
          1061 TURNER               SALESMAN                   1500
          1059 WARD                 SALESMAN                   1250Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://htmldb.oracle.com/pls/otn/f?p=31517:1
    -------------------------------------------------------------------

  • Problem in sql query because of order by clause

    Hi All,
    I am facing a one problem in my one sql query.I am using Oracle 10gR2.
    Query is given below:
    SELECT t1.ename
            FROM T1, T2
           WHERE T1.EMPNO = 1234
             AND T1.ACCOUNTNO = T2.ACCOUNTNO
             AND T1.SEQ = T2.SEQ
           ORDER BY T2.SEQThe Plan of the query is :
    | Id  | Operation                     | Name                 | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT              |                      |     2 |   218 | 11716   (1)| 00:00:41 |
    |*  1 |  TABLE ACCESS BY INDEX ROWID  | T1                   |     1 |    89 |     1   (0)| 00:00:01 |
    |   2 |   NESTED LOOPS                |                      |     2 |   218 | 11716   (1)| 00:00:41 |
    |*  3 |    TABLE ACCESS BY INDEX ROWID| T2                   |     2 |    40 | 11715   (1)| 00:00:41 |
    |   4 |     INDEX FULL SCAN           | PK_T2_SEQ            | 58752 |       |   122   (5)| 00:00:01 |
    |*  5 |    INDEX RANGE SCAN           | FK_ACCOUNTNO         |     3 |       |     0   (0)| 00:00:01 |
    ----------------------------------------------------------------------------------------------------Now i want to reduce the time of this query.
    If i am removing Order by clause from query than performance of the query is totally perfect but with order by clause its taking a time.
    I have already set SORT_AREA_SIZE but still nothing is improving.
    Welcome and thanks for your suggestions.
    Thanks,
    Edited by: BluShadow on 23-Jun-2011 07:55
    added {noformat}{noformat} tags and formatted explain plan to make it readable.  Please see {message:id=9360002} for details on how to post code and data                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Hi,
    There are a couple of things I do not understand.
    1. Why don't you put {noformat}{noformat} around your code, it makes it so much easier to read, especially your explain plan
    2. You claim that the ORDER BY is problematic compared to no order by. Then why do you choose to post only one plan?
    3. It is hard to understand how your tables relate, and which indexes you have and which you don't.
    - PK_T2_SEQ, does this mean that SEQ alone is primary key of T2?
    - If SEQ is primary key of T2, why do you join on accountno, seq and not just seq?
    - If SEQ is primary key of T2 one of the tables is denormalized.
    4. FK_ACCOUNTNO, is this an index on accountno, alone?
    - Or is this AccountNo, Seq?
    5. Is there no index on T1.EMPNO?
    Above could of course just be a case of my not understanding the names of your indexes.
    So, here are my guesses:
    Above plan is for the ORDER BY query. That means the optimizer, has chosen to full scan PK_T2_SEQ, since data is then read according to the ORDER BY.
    (This could be a bad choice)I
    You could try and order by t1.seq, instead. Result should be the same.
    Regards
    Peter                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • SQL query performance difference with Index Hint in Oracle 10g

    Hi,
    I was having a problem in SQL select query which was taking around 20 seconds to get the results. So, by hit and trail method I added Index Oracle Hint into the same query with the list of indexes of the tables and the results are retrieved with in 10 milli seconds. I am not sure to get How this is working with Indexes Hint.
    The query with out Index Hint:
    select /*+rule*/ FdnTab2.fdn, paramTab3.attr_name from fdnmappingtable FdnTab, fdnmappingtable FdnTab2, parametertable paramTab1 ,parametertable paramTab3  where FdnTab.id=52787 and paramTab1.id= FdnTab.id  and paramTab3.id = FdnTab.id  and paramTab3.attr_value = FdnTab2.fdn  and paramTab1.attr_name='harqUsersMax' and paramTab1.attr_value <> 'DEFAULT' and exists ( select ParamTab2.attr_name from parametertable ParamTab2, templaterelationtable TemplateTab2  where TemplateTab2.id=FdnTab.id  and ParamTab2.id=TemplateTab2.template_id  and ParamTab2.id=FdnTab2.id  and ParamTab2.attr_name=paramTab1.attr_name)  ==> EXECUTION TIME: 20 secs
    The same query with Index Hint:
    select /*+INDEX(fdnmappingtable[PRIMARY_KY_FDNMAPPINGTABLE],parametertable[PRIMARY_KY_PARAMETERTABLE])*/ FdnTab2.fdn, paramTab3.attr_name from fdnmappingtable FdnTab, fdnmappingtable FdnTab2, parametertable paramTab1 ,parametertable paramTab3 where FdnTab.id=52787 and paramTab1.id= FdnTab.id and paramTab3.id = FdnTab.id and paramTab3.attr_value = FdnTab2.fdn and paramTab1.attr_name='harqUsersMax' and paramTab1.attr_value <> 'DEFAULT' and exists ( select ParamTab2.attr_name from parametertable ParamTab2, templaterelationtable TemplateTab2 where TemplateTab2.id=FdnTab.id and ParamTab2.id=TemplateTab2.template_id and ParamTab2.id=FdnTab2.id and ParamTab2.attr_name=paramTab1.attr_name) ==> EXECUTION TIME: 10 milli secs
    Can any one suggest what could be the real problem?
    Regards,
    Purushotham

    Sorry,
    The right query and the explain plan:
    select /*+rule*/ FdnTab2.fdn, paramTab3.attr_name from fdnmappingtable FdnTab, fdnmappingtable FdnTab2, parametertable paramTab1 ,parametertable paramTab3  where FdnTab.id=52787 and paramTab1.id= FdnTab.id  and paramTab3.id = FdnTab.id  and paramTab3.attr_value = FdnTab2.fdn  and paramTab1.attr_name='harqUsersMax' and paramTab1.attr_value <> 'DEFAULT' and exists ( select ParamTab2.attr_name from parametertable ParamTab2, templaterelationtable TemplateTab2  where TemplateTab2.id=FdnTab.id  and ParamTab2.id=TemplateTab2.template_id  and ParamTab2.id=FdnTab2.id  and ParamTab2.attr_name=paramTab1.attr_name) 
    SQL> @$ORACLE_HOME/rdbms/admin/utlxpls.sql
    PLAN_TABLE_OUTPUT
    Plan hash value: 651267974
    | Id | Operation | Name |
    | 0 | SELECT STATEMENT | |
    |* 1 | FILTER | |
    | 2 | NESTED LOOPS | |
    | 3 | NESTED LOOPS | |
    | 4 | NESTED LOOPS | |
    |* 5 | INDEX UNIQUE SCAN | PRIMARY_KY_FDNMAPPINGTABLE |
    PLAN_TABLE_OUTPUT
    |* 6 | TABLE ACCESS BY INDEX ROWID| PARAMETERTABLE |
    |* 7 | INDEX UNIQUE SCAN | PRIMARY_KY_PARAMETERTABLE |
    | 8 | TABLE ACCESS BY INDEX ROWID | PARAMETERTABLE |
    |* 9 | INDEX RANGE SCAN | PRIMARY_KY_PARAMETERTABLE |
    | 10 | TABLE ACCESS BY INDEX ROWID | FDNMAPPINGTABLE |
    |* 11 | INDEX UNIQUE SCAN | SYS_C005695 |
    | 12 | NESTED LOOPS | |
    |* 13 | INDEX UNIQUE SCAN | PRIMARY_KY_PARAMETERTABLE |
    |* 14 | INDEX UNIQUE SCAN | PRIMARY_KEY_TRTABLE |
    PLAN_TABLE_OUTPUT
    Predicate Information (identified by operation id):
    1 - filter( EXISTS (SELECT 0 FROM "TEMPLATERELATIONTABLE"
    "TEMPLATETAB2","PARAMETERTABLE" "PARAMTAB2" WHERE
    "PARAMTAB2"."ATTR_NAME"=:B1 AND "PARAMTAB2"."ID"=:B2 AND
    "PARAMTAB2"."ID"="TEMPLATETAB2"."TEMPLATE_ID" AND
    "TEMPLATETAB2"."ID"=:B3))
    5 - access("FDNTAB"."ID"=52787)
    6 - filter("PARAMTAB1"."ATTR_VALUE"<>'DEFAULT')
    7 - access("PARAMTAB1"."ID"="FDNTAB"."ID" AND
    PLAN_TABLE_OUTPUT
    "PARAMTAB1"."ATTR_NAME"='harqUsersMax')
    9 - access("PARAMTAB3"."ID"="FDNTAB"."ID")
    11 - access("PARAMTAB3"."ATTR_VALUE"="FDNTAB2"."FDN")
    13 - access("PARAMTAB2"."ID"=:B1 AND "PARAMTAB2"."ATTR_NAME"=:B2)
    14 - access("TEMPLATETAB2"."ID"=:B1 AND
    "PARAMTAB2"."ID"="TEMPLATETAB2"."TEMPLATE_ID")
    Note
    - rule based optimizer used (consider using cbo)
    43 rows selected.
    WITH INDEX HINT:
    select /*+INDEX(fdnmappingtable[PRIMARY_KY_FDNMAPPINGTABLE],parametertable[PRIMARY_KY_PARAMETERTABLE])*/ FdnTab2.fdn, paramTab3.attr_name from fdnmappingtable FdnTab, fdnmappingtable FdnTab2, parametertable paramTab1 ,parametertable paramTab3 where FdnTab.id=52787 and paramTab1.id= FdnTab.id and paramTab3.id = FdnTab.id and paramTab3.attr_value = FdnTab2.fdn and paramTab1.attr_name='harqUsersMax' and paramTab1.attr_value <> 'DEFAULT' and exists ( select ParamTab2.attr_name from parametertable ParamTab2, templaterelationtable TemplateTab2 where TemplateTab2.id=FdnTab.id and ParamTab2.id=TemplateTab2.template_id and ParamTab2.id=FdnTab2.id and ParamTab2.attr_name=paramTab1.attr_name);
    SQL> @$ORACLE_HOME/rdbms/admin/utlxpls.sql
    PLAN_TABLE_OUTPUT
    Plan hash value: 2924316070
    | Id | Operation | Name | Rows | B
    ytes | Cost (%CPU)| Time |
    PLAN_TABLE_OUTPUT
    | 0 | SELECT STATEMENT | | 1 |
    916 | 6 (0)| 00:00:01 |
    |* 1 | FILTER | | |
    | | |
    | 2 | NESTED LOOPS | | 1 |
    916 | 4 (0)| 00:00:01 |
    | 3 | NESTED LOOPS | | 1 |
    401 | 3 (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    | 4 | NESTED LOOPS | | 1 |
    207 | 2 (0)| 00:00:01 |
    |* 5 | TABLE ACCESS BY INDEX ROWID| PARAMETERTABLE | 1 |
    194 | 1 (0)| 00:00:01 |
    |* 6 | INDEX UNIQUE SCAN | PRIMARY_KY_PARAMETERTABLE | 1 |
    | 1 (0)| 00:00:01 |
    |* 7 | INDEX UNIQUE SCAN | PRIMARY_KY_FDNMAPPINGTABLE | 1 |
    PLAN_TABLE_OUTPUT
    13 | 1 (0)| 00:00:01 |
    | 8 | TABLE ACCESS BY INDEX ROWID | PARAMETERTABLE | 1 |
    194 | 1 (0)| 00:00:01 |
    |* 9 | INDEX RANGE SCAN | PRIMARY_KY_PARAMETERTABLE | 1 |
    | 1 (0)| 00:00:01 |
    | 10 | TABLE ACCESS BY INDEX ROWID | FDNMAPPINGTABLE | 1 |
    515 | 1 (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    |* 11 | INDEX UNIQUE SCAN | SYS_C005695 | 1 |
    | 1 (0)| 00:00:01 |
    | 12 | NESTED LOOPS | | 1 |
    91 | 2 (0)| 00:00:01 |
    |* 13 | INDEX UNIQUE SCAN | PRIMARY_KEY_TRTABLE | 1 |
    26 | 1 (0)| 00:00:01 |
    |* 14 | INDEX UNIQUE SCAN | PRIMARY_KY_PARAMETERTABLE | 1 |
    65 | 1 (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    Predicate Information (identified by operation id):
    1 - filter( EXISTS (SELECT /*+ */ 0 FROM "TEMPLATERELATIONTABLE" "TEMPLATETAB
    2","PARAMETERTABLE"
    PLAN_TABLE_OUTPUT
    "PARAMTAB2" WHERE "PARAMTAB2"."ATTR_NAME"=:B1 AND "PARAMTAB2"."ID"
    =:B2 AND
    "TEMPLATETAB2"."TEMPLATE_ID"=:B3 AND "TEMPLATETAB2"."ID"=:B4))
    5 - filter("PARAMTAB1"."ATTR_VALUE"<>'DEFAULT')
    6 - access("PARAMTAB1"."ID"=52787 AND "PARAMTAB1"."ATTR_NAME"='harqUsersMax')
    7 - access("FDNTAB"."ID"=52787)
    9 - access("PARAMTAB3"."ID"=52787)
    11 - access("PARAMTAB3"."ATTR_VALUE"="FDNTAB2"."FDN")
    13 - access("TEMPLATETAB2"."ID"=:B1 AND "TEMPLATETAB2"."TEMPLATE_ID"=:B2)
    14 - access("PARAMTAB2"."ID"=:B1 AND "PARAMTAB2"."ATTR_NAME"=:B2)
    PLAN_TABLE_OUTPUT
    Note
    - dynamic sampling used for this statement
    39 rows selected.

  • Order by  in sql query

    I am executing one sql query with order by clause.
    how to check sort is happing in memory or disk ?
    what are all the init parameter affect in order by clause

    There are a couple of ways.
    1. Query the V$MYSTAT view before and after your query and take the delta of the statistics. A query to retrieve sort information could be the following:
    SELECT name,value FROM V$mystat m JOIN v$statname USING (statistic#) where name like 'sorts%';2. In SQL*Plus Set AUTOTRACE TO STATISTICS and run your query. The sort information will be at the bottom.
    Sample:
    SQL > set autotrace off;
    SQL > SELECT name,value FROM V$mystat m JOIN v$statname USING (statistic#) where name like 'sorts%';
    NAME                                                                  VALUE
    sorts (memory)                                                           12
    sorts (disk)                                                              0
    sorts (rows)                                                             42
    SQL > SET AUTOTRACE TRACEONLY STATISTICS
    SQL > SELECT * FROM (SELECT OBJECT_NAME FROM ALL_OBJECTS WHERE ROWNUM <= 100) ORDER BY OBJECT_NAME;
    100 rows selected.
    Statistics
            674  recursive calls
              0  db block gets
            245  consistent gets
              0  physical reads
              0  redo size
           2257  bytes sent via SQL*Net to client
            462  bytes received via SQL*Net from client
              8  SQL*Net roundtrips to/from client
             31  sorts (memory)
              0  sorts (disk)
            100  rows processed
    SQL > SET AUTOTRACE OFF;
    SQL > SELECT name,value FROM V$mystat m JOIN v$statname USING (statistic#) where name like 'sorts%';
    NAME                                                                  VALUE
    sorts (memory)                                                           43
    sorts (disk)                                                              0
    sorts (rows)                                                            173HTH!

  • Change column order updateable sql query report APEX 4

    Hi all,
    I have a master detail page. Detail is SQL Query (updateable report)
    I want to change the column order but seems not possiible anymore in A4.
    In A3... on the right side of the report attributes it was possible to move columns up or down.
    path is Home>>Application Builder>>Application nnn >>Page xx >>Report Attributes
    It seems that A4 the move up or down functionality is hidden or the region is to small with no horizontal scrollbar.
    Is there a work_aorund?
    This is also the case when the pages are displayed in icon view when showing all pages using.
    Home >> Application Builder >>Application
    Most right icons are hidden after the about and task regions.
    The work-around here is to display the pages in report or detail view
    Maybe a fix needed for APEX4?
    have nice weekend!
    Hugo Perfors
    Enthousiastic APEX developer

    Hi,
    It could be your browser settings. Try zooiming out in the browser View - Zoom - Zoom Out.
    Regards

  • SQL query with parallel hint  running very slow

    I have a SQL query which joins three huge tables. (given below)
         insert /*+ append */ into final_table (oid, rmeth, id, expdt, crddt, coupon, bitfields, processed_count)
         select /*+ full(t2) parallel(t2,31) full(t3) parallel(t3,31)*/
         seq_final_table.nextval, '200', t2.id, t3.end_date, '1/jul/2009',123,t2.bitfield, 0
         from table1 t1, table2 t2, table3 t3 where
         t1.id=t2.id and
         t2.pid=t3.pid and
         t2.vid=t3.vid and
         t3.end_date is not null and
         (trunc(t1.expiry_date) != trunc(t3.end_date) or trim(t1.expiry_date) is null);
         Below are some statistics of the three tables.
         Table_Name          RowCount    Size(MB)
         table1 36469938 532
         table2 242172205     39184
         table3 231756758     29814
         The above query ran for 30+ hours, and returned with no rows inserted into final_table. I didn't get any error message also.
         But when I ran the query with table1 containing just 10000 records, the query completed succesfully within 20 minutes.
         Can any one please optimize the above query?
    Edited by: jaysara on Aug 18, 2009 11:51 PM

    As a side note: You probably don't want to insert a string into a date field, won't you?
    Under the assumption that crddt is of datatype date:
    crddt='1/jul/2009' needs to be changed into
    crddt= to_date('01/07/2009','dd/mm/yyyy') This is data type correct and nls independent.

  • Help with sql query the status of  A/P Reserve Invoice

    Hi,
    I am trying to write a query which lists all A/P Reserve Invoice info with OPEN status.
    I check the OPCH table and cannot find the rule to tell the status.
    The "DocStatus" field has two values only: 'O' for open and 'C' for closed.
    However, the status of A/P Reserve Invoice are OPEN, CLOSED, DELIVERED, PAID, etc.
    I try to use DocStatus field to filter, but the result does not match what I see in SAP.
    Could you please give me some hints about how to get the data I need? Thank you.
    Best regards,
    Sylvia
    Edited by: csylvia on Jun 23, 2011 5:54 AM

    Hi Darius,
    Thanks for your reply.
    However, I don't know what is the relationship between Purchase order and A/P Reserve Invoice.
    Do you mean using "SELECT T0.DocEntry FROM OPCH T0, OPOR T1 WHERE T0.DocNum = T1.DocNum AND T1.DocStatus = 'O';" to query the A/P Reserve Invoice data with OPEN status?
    But the result is not what I want.
    The result of "*SELECT * FROM OPOR WHERE DocStatus = 'O';*" is also not.
    I'd like to query A/P Reserve Invoice list with OPEN status, and I try the following sql query:
    SELECT DocEntry FROM OPCH WHERE DocStatus = 'O' AND InvntSttus = 'O';
    The result is close to what I need, but it's not exactly correct.
    Moreover, I don't think the sql query conditions is accurate.
    Please give me some advice. Thank you.
    Best regards,
    Sylvia

  • SQL Query produces different results when inserting into a table

    I have an SQL query which produces different results when run as a simple query to when it is run as an INSERT INTO table SELECT ...
    The query is:
    SELECT   mhldr.account_number
    ,        NVL(MAX(DECODE(ap.party_sysid, mhldr.party_sysid,ap.empcat_code,NULL)),'UNKNWN') main_borrower_status
    ,        COUNT(1) num_apps
    FROM     app_parties ap
    SELECT   accsta.account_number
    ,        actply.party_sysid
    ,        RANK() OVER (PARTITION BY actply.table_sysid, actply.loanac_latype_code ORDER BY start_date, SYSID) ranking
    FROM     activity_players actply
    ,        account_status accsta
    WHERE    1 = 1
    AND      actply.table_id (+) = 'ACCGRP'
    AND      actply.acttyp_code (+) = 'MHLDRM'
    AND      NVL(actply.loanac_latype_code (+),TO_NUMBER(SUBSTR(accsta.account_number,9,2))) = TO_NUMBER(SUBSTR(accsta.account_number,9,2))
    AND      actply.table_sysid (+) = TO_NUMBER(SUBSTR(accsta.account_number,1,8))
    ) mhldr
    WHERE    1 = 1
    AND      ap.lenapp_account_number (+) = TO_NUMBER(SUBSTR(mhldr.account_number,1,8))
    GROUP BY mhldr.account_number;      The INSERT INTO code:
    TRUNCATE TABLE applicant_summary;
    INSERT /*+ APPEND */
    INTO     applicant_summary
    (  account_number
    ,  main_borrower_status
    ,  num_apps
    SELECT   mhldr.account_number
    ,        NVL(MAX(DECODE(ap.party_sysid, mhldr.party_sysid,ap.empcat_code,NULL)),'UNKNWN') main_borrower_status
    ,        COUNT(1) num_apps
    FROM     app_parties ap
    SELECT   accsta.account_number
    ,        actply.party_sysid
    ,        RANK() OVER (PARTITION BY actply.table_sysid, actply.loanac_latype_code ORDER BY start_date, SYSID) ranking
    FROM     activity_players actply
    ,        account_status accsta
    WHERE    1 = 1
    AND      actply.table_id (+) = 'ACCGRP'
    AND      actply.acttyp_code (+) = 'MHLDRM'
    AND      NVL(actply.loanac_latype_code (+),TO_NUMBER(SUBSTR(accsta.account_number,9,2))) = TO_NUMBER(SUBSTR(accsta.account_number,9,2))
    AND      actply.table_sysid (+) = TO_NUMBER(SUBSTR(accsta.account_number,1,8))
    ) mhldr
    WHERE    1 = 1
    AND      ap.lenapp_account_number (+) = TO_NUMBER(SUBSTR(mhldr.account_number,1,8))
    GROUP BY mhldr.account_number;      When run as a query, this code consistently returns 2 for the num_apps field (for a certain group of accounts), but when run as an INSERT INTO command, the num_apps field is logged as 1. I have secured the tables used within the query to ensure that nothing is changing the data in the underlying tables.
    If I run the query as a cursor for loop with an insert into the applicant_summary table within the loop, I get the same results in the table as I get when I run as a stand alone query.
    I would appreciate any suggestions for what could be causing this odd behaviour.
    Cheers,
    Steve
    Oracle database details:
    Oracle Database 10g Release 10.2.0.2.0 - Production
    PL/SQL Release 10.2.0.2.0 - Production
    CORE 10.2.0.2.0 Production
    TNS for 32-bit Windows: Version 10.2.0.2.0 - Production
    NLSRTL Version 10.2.0.2.0 - Production
    Edited by: stevensutcliffe on Oct 10, 2008 5:26 AM
    Edited by: stevensutcliffe on Oct 10, 2008 5:27 AM

    stevensutcliffe wrote:
    Yes, using COUNT(*) gives the same result as COUNT(1).
    I have found another example of this kind of behaviour:
    Running the following INSERT statements produce different values for the total_amount_invested and num_records fields. It appears that adding the additional aggregation (MAX(amount_invested)) is causing problems with the other aggregated values.
    Again, I have ensured that the source data and destination tables are not being accessed / changed by any other processes or users. Is this potentially a bug in Oracle?Just as a side note, these are not INSERT statements but CTAS statements.
    The only non-bug explanation for this behaviour would be a potential query rewrite happening only under particular circumstances (but not always) in the lower integrity modes "trusted" or "stale_tolerated". So if you're not aware of any corresponding materialized views, your QUERY_REWRITE_INTEGRITY parameter is set to the default of "enforced" and your explain plan doesn't show any "MAT_VIEW REWRITE ACCESS" lines, I would consider this as a bug.
    Since you're running on 10.2.0.2 it's not unlikely that you hit one of the various "wrong result" bugs that exist(ed) in Oracle. I'm aware of a particular one I've hit in 10.2.0.2 when performing a parallel NESTED LOOP ANTI operation which returned wrong results, but only in parallel execution. Serial execution was showing the correct results.
    If you're performing parallel ddl/dml/query operations, try to do the same in serial execution to check if it is related to the parallel feature.
    You could also test if omitting the "APPEND" hint changes anything but still these are just workarounds for a buggy behaviour.
    I suggest to consider installing the latest patch set 10.2.0.4 but this requires thorough testing because there were (more or less) subtle changes/bugs introduced with [10.2.0.3|http://oracle-randolf.blogspot.com/2008/02/nasty-bug-introduced-with-patch-set.html] and [10.2.0.4|http://oracle-randolf.blogspot.com/2008/04/overview-of-new-and-changed-features-in.html].
    You could also open a SR with Oracle and clarify if there is already a one-off patch available for your 10.2.0.2 platform release. If not it's quite unlikely that you are going to get a backport for 10.2.0.2.
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • SQL Query (challenge)

    Hello,
    I have 2 tables of events E1 and E2
    E1: (Time, Event), E2: (Time, Event)
    Where the columns Time in both tables are ordered.
    Ex.
       E1: ((1, a) (2, b) (4, d) (6, c))
       E2: ((2, x) (3, y) (6, z))
    To find the events of both tables at the same time it is obvious to do & join between E1 and E2
    Q1 -> select e1.Time, e1.Event, e2.Event from E1 e1, E2 e2 where e1.Time=e2.Time;
    The result of the query is:
    ((2, b, x) (6, c, z))
    Given that there is no indexes for this tables, an efficient execution plan can be a hash join (under conditions mentioned in Oracle Database Performance Tuning Guide Ch 14).
    Now, the hash join suffers from locality problem if the hash table is large and does not fit in memory; it may happen that one block of data is read in memory and swaped out frequently.
    Given that the Time columns are sorted is ascending order, I find the following algorithm, known idea in the literature, apropriate to this problem; The algorithm is in pseudocode close to pl/sql, for simplicity (I home the still is clear):
    -- start algorithm
    open cursors for e1 and e2
    loop
      if e1.Time = e2.Time then
         pipe row (e1.Time, e1.Event, e2.Event);
         fetch next e1 record
         exit when notfound
         fetch next e2 record
          exit when notfound
      else
         if e1.Time < e2.Time then
            fetch next e1 record
            exit when notfound
         else
            fetch next e2 record
            exit when notfound
         end if;
      end if;
    end loop
    -- end algorithm
    As you can see the algorithm does not suffer from locality issue since it iterates sequentially over the arrays.
    Now the problem: The algorithm shown below hints the use of pipelined function to implement it in pl/sql, but it is slow compared to hash join in the implicit cursor of the query shown above (Q1).
    Is there an implicit SQL query to implement this algorithm? The objective is to beat the hash join of the query (Q1), so queries that use sorting are not accepted.
    A difficulty I foound is that the explicit cursor are much slower that implict ones (SQL queries)
    Example: for a large table (2.5 million records)
    create table mytable (x number);
    declare
    begin
    open c for 'select 1 from mytable';
    fetch c bulk collect into l_data;
    close c;
    dbms_output.put_line('couont = '||l_data.count);
    end;
    is 5 times slower then
    select count(*) from mytable;
    I do not understand why it should be the case, I read that this may be explained because pl/sql is interpreted, but I think this does not explain the whole issue. May be because the fetch copies data from one space to your space and this takes a long time.

    Hi
    A correction in the algorithm:
    -- start algorithm
    open cursors for e1 and e2
    fetch next e1 record
    fetch next e2 record
    loop
      exit when e1%notfound
      exit when e2%notfound
      if e1.Time = e2.Time then
         pipe row (e1.Time, e1.Event, e2.Event);
         fetch next e1 record
         fetch next e2 record
      else
         if e1.Time < e2.Time then
            fetch next e1 record
         else
            fetch next e2 record
         end if;
      end if;
    end loop
    -- end algorithm
    Best regards
    Taoufik

  • Need help in improving the performance for the sql query

    Thanks in advance for helping me.
    I was trying to improve the performance of the below query. I tried the following methods used merge instead of update, used bulk collect / Forall update, used ordered hint, created a temp table and upadated the target table using the same. The methods which I used did not improve any performance. The data count which is updated in the target table is 2 million records and the target table has 15 million records.
    Any suggestions or solutions for improving performance are appreciated
    SQL query:
    update targettable tt
    set mnop = 'G',
    where ( x,y,z ) in
    select a.x, a.y,a.z
    from table1 a
    where (a.x, a.y,a.z) not in (
    select b.x,b.y,b.z
    from table2 b
    where 'O' = b.defg
    and mnop = 'P'
    and hijkl = 'UVW';

    987981 wrote:
    I was trying to improve the performance of the below query. I tried the following methods used merge instead of update, used bulk collect / Forall update, used ordered hint, created a temp table and upadated the target table using the same. The methods which I used did not improve any performance. And that meant what? Surely if you spend all that time and effort to try various approaches, it should mean something? Failures are as important teachers as successes. You need to learn from failures too. :-)
    The data count which is updated in the target table is 2 million records and the target table has 15 million records.Tables have rows btw, not records. Database people tend to get upset when rows are called records, as records exist in files and a database is not a mere collection of records and files.
    The failure to find a single faster method with the approaches you tried, points to that you do not know what the actual performance problem is. And without knowing the problem, you still went ahead, guns blazing.
    The very first step in dealing with any software engineering problem, is to identify the problem. Seeing the symptoms (slow performance) is still a long way from problem identification.
    Part of identifying the performance problem, is understanding the workload. Just what does the code task the database to do?
    From your comments, it needs to find 2 million rows from 15 million rows. Change these rows. And then write 2 million rows back to disk.
    That is not a small workload. Simple example. Let's say that the 2 million row find is 1ms/row and the 2 million row write is also 1ms/row. This means a 66 minute workload. Due to the number of rows, an increase in time/row either way, will potentially have 2 million fold impact.
    So where is the performance problem? Time spend finding the 2 million rows (where other tables need to be read, indexes used, etc)? Time spend writing the 2 million rows (where triggers and indexes need to be fired and maintained)? Both?

  • How to get sql query data and write into csv file?

    I am writing to seek help, in how can I create bat. script which can execute the following logic:
    connection to the database
    run sql query
    create CSV file
    output query data, into CSV file
    save the CSV file
    osql
    -S 84.18.111.111
    -U adw
    -P rem
    -i "c:\query.sql"
    send ""
    sed -e 's/,\s\+/,/g' MCI_04Dec2014.csv > localNoSpaces.csv
    -o "c:\MCI_04Dec2014.csv"
    This what i have so far, and I am little struggling with the logic after creating CSV file. I am unable to get the above script to work, please advice further, where I may be going wrong. 
    Can you create if statement logic within window's script, to check for null parameters or data feeds?
    Any hints would be most appreciated. 

    Thank you for your reply. 
    Apology for posting the code irrelevant to the forum, as I am still novice scripting user.  
    My goal is to create window's script which can compute the above logic and send the final output file (csv), to FTP folder. 
    Can this logic be implemented via bat. script, if so, is there a example or tutorial i could follow, in order to achieve my task. 
    Any help would be much appreciated. 

  • SQL query doesn't work in VB program

    Hi:
    The following SQL query doesn't work into a VB program, I'm using Oracle OLEDB to established connection to the DB, ... the query returns 0 rows ...
    When I run this same query from any SQL Plus, works well (returning me something like 119 rows) ...
    Any clue or hint ??
    Thanks in advanced
    Angel Castro
    SELECT OPERADOR, ID_ALIMENTADOR, RB_FSC, NUM_CTROL, COND_OPERA, TRANSITORIO, PENDIENTES, ANORMAL, EDO_REAL, IDENTIFICADOR, CAUSA
    FROM HISTORICO_OPERACION
    WHERE (FECHA BETWEEN '20-AUG-2004' AND '5-NOV-2004')
    AND (HORA BETWEEN '10:00:00' AND '16:00:00')
    ORDER BY ID_ALIMENTADOR ASC;

    Is the column FECHA of datatype DATE?
    Are you running the query with the constant date looking like strings ('20-AUG-2004' in your post, for example) as-is from the VB program?
    If not, are you binding the parameters correctly?
    What is the setting of your NLS_DATE_FORMAT parameter?
    What happens if you do a
    ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YYYY'from your VB program before running the query?

  • Zimbra login is very slow - SQL query takes 35+ seconds

    Hi,
    my Zimbra login process remains very slow, 35-40 seconds with only a single user using it. I have Beehive set up as directory synchronized, with about 6500 users in it. However, I and a couple of colleagues the only ones making any use of it for testing. With just one person logging in, the following SQL query takes about 35 seconds to execute:
    SELECT /*+ LEADING(rf rf_pp) USE_NL(rf_pp) INDEX_ASC(@rf_connect_by rf@rf_connect_by (ws_real_folders.parent_eid ws_real_folders.eid)) */ RF.ENTERPRISE_ID AS
    ENTERPRISE_ID, RF.SITE_ID AS SITE_ID, RF.ENTITY_TYPE AS ENTITY_TYPE, RF.EID AS EID, RF.LOCK_ID AS LOCK_ID, RF.CACHE_ID AS CACHE_ID, RF.CACHE_TS AS
    CACHE_TS, RF.CACHE_SQ AS CACHE_SQ, FLOOR(RF.SECURE_CHECK/10) AS ACCESS_TYPES, RF.PARENT_ENTITY_TYPE AS PARENT_ENTITY_TYPE, RF.PARENT_EID AS
    PARENT_EID, RF.NAME AS NAME, RF.OWNER_ENTITY_TYPE AS OWNER_ENTITY_TYPE, RF.OWNER_EID AS OWNER_EID, RF.CREATED_ON AS CREATED_ON,
    RF.CREATOR_ENTITY_TYPE AS CREATOR_ENTITY_TYPE, RF.CREATOR_EID AS CREATOR_EID, RF.MODIFIEDON AS MODIFIED_ON, RF.MODIFIED_BY_ENTITY_TYPE AS
    MODIFIED_BY_ENTITY_TYPE, RF.MODIFIED_BY_EID AS MODIFIED_BY_EID, RF.VISIBILITY AS VISIBILITY, CASE WHEN (BITAND(:B13 , :B12 ) = :B12 ) THEN CAST(MULTISET(
    SELECT METADATA_CEN
    FROM OCS_ENTITY_METADATA_CENS_2_V META
    WHERE META.ENTITY_EID = RF.EID ) AS OCS_COLLAB_ID_TBL_T) ELSE CAST(NULL AS OCS_COLLAB_ID_TBL_T) END AS METADATA_CENS, CASE WHEN
    RF_PP.LAST_ACCESSED IS NULL THEN 'N' WHEN RF.MODIFIEDON > RF_PP.LAST_ACCESSED THEN 'U' ELSE NVL(RF_PP.RELATIVE_STATUS, 'N') END AS CHANGE_STATUS,
    RF.PROPERTIES AS PROPERTIES_CLOB, RF_PP.PROPERTIES AS VIEWERPROPERTIES_CLOB, RF.DESCRIPTION AS DESCRIPTION
    FROM (
    SELECT /*+ QB_NAME(rf_connect_by) no_connect_by_cost_based */ RF.ENTERPRISE_ID ENTERPRISE_ID, :B4 SITE_ID, :B3 ENTITY_TYPE, RF.EID EID, RF.LOCK_ID LOCK_ID,
    RF.ORA_ROWSCN CACHE_ID, RF.CACHE_TS CACHE_TS, RF.CACHE_SQ CACHE_SQ, RF.PARENT_TYPE PARENT_ENTITY_TYPE, RF.PARENT_EID PARENT_EID, RF.NAME
    NAME, RF.OWNER_TYPE OWNER_ENTITY_TYPE, RF.OWNER_EID OWNER_EID, RF.CREATED_ON CREATED_ON, RF.CREATOR_TYPE CREATOR_ENTITY_TYPE,
    RF.CREATOR_EID CREATOR_EID, RF.MODIFIED_ON MODIFIEDON, RF.MODIFIED_BY_TYPE MODIFIED_BY_ENTITY_TYPE, RF.MODIFIED_BY_EID MODIFIED_BY_EID,
    RF.VISIBILITY VISIBILITY, RF.PROPERTIES PROPERTIES, RF.DESCRIPTION DESCRIPTION, RF.IS_HIDDEN IS_HIDDEN, LEVEL LEVEL_NUM, COALESCE (
    (SELECT :B10 * 10 + 1
    FROM AC_ENTITIES AEI
    WHERE RF.EID = AEI.EID AND ( 1 = DECODE(AEI.SENSITIVITY_EID, :B9 , 1, 0) AND 1 = DECODE(AEI.OWNER_EID, :B8 , 1, 0) AND 1 = DECODE(AEI.AT_READ, :B7 , 1, 0) AND 1 =
    DECODE(AEI.AT_DISCOVER, :B6 , 1, 0) AND 1 = DECODE(AEI.LOCAL_ACL_ID, :B5 , 1, 0) ) ) ,
    (SELECT ACV.ACCESS_TYPES * 10 + ACV.IS_ALLOWED
    FROM AC_CHECK_ONE_OF_V ACV
    WHERE ACV.EID = RF.EID ) ) SECURE_CHECK
    FROM WS_REAL_FOLDERS RF
    WHERE RF.IS_HIDDEN = :B2 START WITH RF.PARENT_EID = :B1 CONNECT BY PRIOR RF.EID = RF.PARENT_EID ) RF, WS_RF_PRVT_PROPERTIES RF_PP
    WHERE RF.EID = RF_PP.EID (+) AND :B11 = RF_PP.VIEWER_EID (+) AND 1 = BITAND(RF.SECURE_CHECK, 1) ORDER BY RF.LEVEL_NUMIt has ID atrvjdrmz2v6d in Enterprise Manager, and I've tried tuning it with the SQL tuning advisor in EM. I did the statistics gathering mentioned in another thread yesterday, to see if that helped - doesn't seem liked it. I'm running Database 11.1.0.6 and Beehive 1.5.1 in the build from the day it released.
    Any hints? I'll post this to MetaLink as well, unless someone has some immediate idea what's wrong :-)

    No speedup, the 35-40 seconds is for normal logins - and it's very consistent, at least if the database is otherwise idle. Immediately logging out and back in gives me the same wait, and the same query shows up in the Enterprise Manager interface.
    It seems it might be related to Workspaces - from EM:
    "PL/SQL Source (Line Number)          BEE_CODE.WS_REAL_FOLDER_PKG (2998)"

Maybe you are looking for