SQL Optimization - Exit on First Match

Hi,
I have a requirement where a query, sometimes, takes more than 25 seconds. This should come out in less than 1 second.
About the Query :
SELECT 1 FROM DUAL
WHERE     exists
(SELECT TM.AD
FROM     TM,
     GM
WHERE     TM.AD = GM.AD
AND     TM.LOA = :b1
and     GM.soid='Y');
The way this query has been written, it fetches only 1 row. The plan of this query is (not from production but from my test instance as I could reproduce this but the number of rows differ) :
Rows Row Source Operation
1 FILTER (cr=26 pr=0 pw=0 time=433 us)
1 FAST DUAL (cr=0 pr=0 pw=0 time=12 us)
1 NESTED LOOPS (cr=26 pr=0 pw=0 time=398 us)
9 TABLE ACCESS BY INDEX ROWID TM (cr=6 pr=0 pw=0 time=150 us)
9 INDEX RANGE SCAN TM_LOA (cr=2 pr=0 pw=0 time=21 us)(object id 56302)
1 TABLE ACCESS BY INDEX ROWID GM (cr=20 pr=0 pw=0 time=258 us)
9 INDEX UNIQUE SCAN PK_GM (cr=11 pr=0 pw=0 time=123 us)(object id 56304)
The plan of Production is exactly the same. The issue here is :
1. LOA has an Index and for certain values of LOA, the number of records are around 1000. Issue is normally reported when the number of rows fetched are more than 800.
2. The clustering factor of LOA index is not good and from the plan, it is observed that for every row fetched from an Index, approx equal number of blocks are read from table.
3. AD column of GM is a Primary Key
Also, the problem is visible, when the disk reads of this query is very high i.e. if the CR is 800, PR is 700. For any subsequent executions, it gets the results in less than a second.
In my view, it is the table access of TM that is causing an increase in response time and therefore, if I can eliminate these (unwanted) table access. One way is reorganizing the table to improve the CF, but it can have a negative impact. Therefore, optimizing the query seems to be a better option. Based on the Query Plan, I assume, the optimizer gets 1000 rows from an Index and Table TM, then joins to GM. Fetching these 1000 rows seems to be an issue. The query can be optimized, if the search from TM exits immediately a matching row is found in GM table. Therefore, instead of fetching 1000 rows, it matches each and every row and exits immediately when the first match is found. AD in TM is not Unique, therefore, for each AD from TM, it checks for the existence in GM. So, in case there are 10 matching AD from TM and GM, the search should complete immediately on the first matching AD.
Would appreciate help on this.
Regards

Hi,
Will check for the performance with FIRST_ROWS and arrays, but, feel that these will not yield any benefit as 1) The code is directly run on the server, and 2) It is doing a proper index scan, but the code needs a modification to exit immediately as the first match is found.
A pl/sql representation of this code is pasted below :
create or replace function check_exists(la in varchar2)
return number
as
cursor tm_csr is
select ad from tm
where LOA = la;
l_number number:=0;
l_ad tm.ad%type;
begin
open tm_csr;
loop
fetch tm_csr into l_ad;
begin
select 1 into l_number from gm
where gm.ad = l_ad
AND     GM.soid='Y';
exception when others then
l_number:=0;
end;
exit when tm_csr%notfound or l_number=1;
end loop;
close tm_csr;
return l_number;
end;
The code, while not a feasible solution but is just a representation of the requirement, fetches AD from TM. Then it checks for the existence in GM and if a matching row is found, exits from the LOOP.
Edited by: Vivek Sharma on Jul 1, 2009 12:20 PM

Similar Messages

  • Does "first match" win on Content Filters?

    If I define multiple content filters for a given outbound mail policy, would system stop looking at filters once a match is found on one of the content filters or should I force that by using a "final" action in my content filters?
    I know "first match wins" apply to some other scenarios, but couldn't see a clear explanation to above question in section 6 of Config guide where content filters are defined (and testing with system did not clear that for me either).
    Thanks.
    Sent from Cisco Technical Support iPhone App

    Hello John,
    An emaill being processed by the content filters or messages filters will continue down the list of  content/message filters until it hits the last filter or a 'final' action filter command.   If the email being processed needs to exit (by administrative choice), the filter it hits, should have a final action.  This only applies to certain conditions, where the administrator does not want the filter's last action to be overwritten by another filter down the pipeline.
    cheers,
    -Alvaro

  • SQL command to select first record

    I would like to create an SQL command to link two tables on a field so that only the first matching record is selected. What would be the syntax for that? Thank you.

    Actually, that's not as simple as it sounds...  It also depends on your definition of "first", and what data you are looking for.
    For example, if you are looking for the earliest order date for each of your customers, you could do something like:
    select customer.code, customer.name, min(order.date) as First_Order_Date
    from customer, order
    where customer.code = order.cust_code
    group by customer.code, customer.name
    But if you also want the sales dollars for that first order, you'd have to do something like:
    select customer.*, firstOrder.first_order_date, sales.sales
    from customer
    join (
      select cust_code, min(date) as first_order_date
      from order
      group by cust_code
    ) firstOrder
    on customer.code = firstOrder.cust_code
    join (
      select cust_code, date, sum(sales) as sales
      from order_detail
      group by cust_code, date
    ) sales
    on firstOrder.cust_code = sales.cust_code and firstOrder.First_Order_Date = sales.date
    HTH,
    Carl

  • Query a table and exit when first record found

    I want to query a table and just want to know if any rows matching my query criteria exist in the table. I just want to find one row, irrespective of order and stop the query right there. How do I do that?

    The most efficient way would be either to use rownum = 1 as part of the condition in your second query, but, as written, both will return multiple rows. Your first will need to have an additional predicate and rownum = 1 in addition to the exists.
    Assuming that the predicate can use an index, then the most efficient approach would be either:
    SELECT 1 FROM table
    WHERE <conditions> and
          rownum = 1or possibly:
    SELECT 1 FROM dual
    WHERE EXISTS (SELECT 1 FROM table
                  WHERE <conditions>)Both will do a range scan on the applicable index, stopping when the find the first matching entry. To my mind, the first is clearer in intent.
    To illustrate the error in your first query, consider:
    SQL> SELECT * FROM t;
            ID DESCR
             1 One
             2 Two
             3 Three
             4 Four
             5 Five
             1 One
             2 Two
             3 Three
             4 Four
             5 Five
    SQL> SELECT * FROM t
      2  WHERE id = 1 and
      3        rownum = 1;
            ID DESCR
             1 One
    SQL> SELECT * FROM t
      2  WHERE EXISTS (SELECT 1 FROM t
      3                WHERE id = 1);
            ID DESCR
             1 One
             2 Two
             3 Three
             4 Four
             5 Five
             1 One
             2 Two
             3 Three
             4 Four
             5 FiveJohn
    Edited by: John Spencer on Oct 2, 2009 12:06 PM
    Added queries from t

  • The java and sql object type  was not matched

    My table(Oracle10.2) has a varying arrays column. For mapping to java classes, I use JDeveloper(10.1.3.1.0) to generate java classes. Then I try to insert a record into this varrying arrays column with java. While it always complaints java.sql.SQLException.the java and sql object type was not matched. I can not find the reason.
    My java code:
                   StructDescriptor structdesc = StructDescriptor.createDescriptor(
                             "VARRAY_SEQ", con);
                   int nid=20;
                   int pid=546;
                   BigDecimal mynid=new BigDecimal(nid);
                   mynid=mynid.setScale(0, BigDecimal.ROUND_HALF_UP);
                   BigDecimal mypid=new BigDecimal(pid);
                   mypid=mypid.setScale(0, BigDecimal.ROUND_HALF_UP);
                   Object[] attributes = { "ASDF", mynid, "Developer", mypid,
                             "rwretw" };
                   STRUCT Rel = new STRUCT(structdesc, con, attributes);
                   stmt.setObject(8, Rel);
                   stmt.execute();
                   stmt.close();
    And the STRUCT is
    public RelSeq(String nucl, java.math.BigDecimal neId, String nuor, java.math.BigDecimal pId, String phor) throws SQLException
    { _init_struct(true);
    setNucl(nucl);
    setNeId(neId);
    setNuor(nuor);
    setPId(pId);
    setPhor(phor);
    }

    My table(Oracle10.2) has a varying arrays column. For mapping to java classes, I use JDeveloper(10.1.3.1.0) to generate java classes. Then I try to insert a record into this varrying arrays column with java. While it always complaints java.sql.SQLException.the java and sql object type was not matched. I can not find the reason.
    My java code:
                   StructDescriptor structdesc = StructDescriptor.createDescriptor(
                             "VARRAY_SEQ", con);
                   int nid=20;
                   int pid=546;
                   BigDecimal mynid=new BigDecimal(nid);
                   mynid=mynid.setScale(0, BigDecimal.ROUND_HALF_UP);
                   BigDecimal mypid=new BigDecimal(pid);
                   mypid=mypid.setScale(0, BigDecimal.ROUND_HALF_UP);
                   Object[] attributes = { "ASDF", mynid, "Developer", mypid,
                             "rwretw" };
                   STRUCT Rel = new STRUCT(structdesc, con, attributes);
                   stmt.setObject(8, Rel);
                   stmt.execute();
                   stmt.close();
    And the STRUCT is
    public RelSeq(String nucl, java.math.BigDecimal neId, String nuor, java.math.BigDecimal pId, String phor) throws SQLException
    { _init_struct(true);
    setNucl(nucl);
    setNeId(neId);
    setNuor(nuor);
    setPId(pId);
    setPhor(phor);
    }

  • Regex and matcher only returns the first match

    Hi all.
    Im trying to rewrite some code and im using a regular expression to grab data out of a css formatted file, but im getting a bit confused. My matcher is only finding the first occurance of my pattern, how do i get it to find all occurances of my pattern?
    here is a sample css file
    .header
    font-family:arial, verdana;
    font-weight:bold;
    color:#ff00ff;
    background-image:url(background.jpg);
    .mainBody
    font-weight: bold;
    color: Red;
    padding 0px;
    }and here is my matcher code
    tstr = tstr.replaceAll("\\\\","/");
    tstr = tstr.replaceAll("\\n","");
    tstr = tstr.replaceAll("\\r","");
    Pattern styleFind=Pattern.compile("^\\.?[\\w\\s\\W]+?\\{.*?\\}",Pattern.DOTALL | Pattern.MULTILINE);
    Matcher styleMatch=styleFind.matcher(tstr);
    while(styleMatch.find())
    System.out.println("[A]"+styleMatch.group());
    }     i thought that if i did while(macther.find) then it would keep looping through finding all of the matches, but it is only finding the first match.
    any ideas what im doing wrong?

    tstr = tstr.replaceAll("\\\\","/");
    tstr = tstr.replaceAll("\\n","");
    tstr = tstr.replaceAll("\\r","");
    Pattern
    styleFind=Pattern.compile("^\\.?[\\w\\s\\W]+?\\{.*?\\}", Pattern.DOTALL | Pattern.MULTILINE);
    Matcher styleMatch=styleFind.matcher(tstr); You do MULTILINE despite the fact that you delete all end of line characters first. The '^' matches only at the very beginning of the input.
    Apart from that I would prefer "[^\\}]" anytime ofer ".*?\\}", because what you want is a shortest match which often turns out not to be the same as a non-greedy match.
    Harald.
    Java Text Crunching: http://www.ebi.ac.uk/Rebholz-srv/whatizit/software

  • HTMLDB 1.5  SQL Optimization

    Hi All
    I'm using HTMLDB 1.5, and SQL optimization hints vanish from all regions when my app is migrated from development to production. e.g. /*+ hint INDEX */
    Tested re-importing the app in the dev environ and have the same issue.
    Is this a htmldb bug or am I doing something wrong?
    Thanks
    Kezie

    Kezie - Actually that particular bug was fixed in 1.5.1. If you can apply the 1.5.1 patch, the application installation page will not strip out hints. For SQL*Plus import/install, you must connect as FLOWS_010500 (DBA can change password) or connect as any schema assigned to the workspace into which your application will be installed. The workspace ID and app ID must be identical to those from the source HTML DB instance for this to work.
    Scott

  • 많은 INLIST와 MULTIPLE OR 연산을 갖는 SQL의 OPTIMIZATION

    제품 : ORACLE SERVER
    작성날짜 : 2004-04-19
    많은 Inlist와 multiple OR 연산을 갖는 SQL의 Optimization
    =========================================================
    PURPOSE
    이 문서는 IN 연산 내의 많은 IN List와 많은 OR 연산자를 갖는
    경우에 CBO가 어떻게 처리하는가에 대한 자료이다.
    Explanation
    많은 개발자나 DBA들은 IN 연산자와 OR 연산자를 사용하는 SQL이
    과도한 Optimization time을 야기시키는 문제를 경험했을 것이다.
    이 문서에서는 CBO가 어떻게 IN list와 OR 연산자를 처리하는지
    설명하고자 한다.
    CBO가 IN list 연산을 만나면 다음과 같은 몇 가지 option을 가지고 판단한다.
    1. SQL 문장을 UNION ALL 이 들어간 문장의 연속으로 나눈다.
    SELECT empno FROM emp WHERE deptno IN (10,20,30);
    라는 문장을 살펴보자.
    이 문장은 다음과 같이 다시 쓰여질 수 있다.
    SELECT empno FROM emp WHERE deptno = 10
    UNION ALL
    SELECT empno FROM emp WHERE deptno = 20
    UNION ALL
    SELECT empno FROM emp WHERE deptno = 30
    만약 deptno column이 indexed된다면 index는 각 branch 단에서 loopup하기
    위해 사용될 수 있다.
    만약 split이 Cost Based Optimizer로 자동으로 발생하지 않는다면
    USE_CONCAT hint 를 사용함으로써 강제로 수행될 수 있다.
    이 내용에 대해서는 <Note:17214.1>을 참조하도록 한다.
    2. IN list를 list로 남겨 두고, filter로서 값을 사용한다.
    Oracle 7에서 이 옵션은 index를 사용할 수 없다.
    Oracle 8에서 이 옵션은 index를 사용할 수 있는 'inlist iterator' 라는
    것을 사용하여 제공된다.
    NO_EXPAND hint를 사용함으로써 expand가 일어나지 않도록 CBO 에게 지정할 수 있다.
    아주 긴 inlist는 CBO 환경에서 문제를 야기시킬 수 있다. 특히 inlist가 많은 수의
    UNION ALL 문장으로 expand될 때 그러하다. 왜냐하면 CBO가 expand된 문장들에
    대해서 Cost를 결정해야 하기 때문이다. 이러한 expand된 문장들은 많은 수의
    branch 때문에 time을 소모하는 문장들이다.
    RBO(Rule Based Optimizer) 환경에서는 이것은 cost 산정을 하지 않으므로 문제가
    되지 않는다.
    Workaround
    만약 아주 긴 inlist 때문에 parsing 문제가 있다면 workaround는 다음과 같다.
    1) NO_EXPAND hint를 사용하도록 한다. 이 힌트를 쓰면 Oracle 7에서는 index를
    사용하지 않고, Oracle 8에서는 index를 사용할 수 있다.
    2) RBO 를 사용하도록 한다.
    3) Query를 재작성한다. Inlist가 lookup table에 저장이 되도록 해서
    inlist를 사용하는 대신에 그 table에 join을 한다.
    주의) hint를 사용하게 되면 CBO로 동작하게 됨을 기억해야 한다.
    Example
    none
    Reference Documents
    <Note:62153.1>

  • Oracle 8i SQL - Dealing with no records matching a value

    Warning: before you read this, please understand I'm no expert on SQL, so it's quite likely I screwed something obvious up...
    I'm trying to do a query kind of like the following:
    SELECT
    BOM.COMPONENT, BOM.QTY_PER, BOM.PARENT, BOM2.PARENT_QTY_PER
    FROM
    BOM BOM, BOM BOM2
    WHERE
    BOM2.COMPONENT=BOM.PARENT AND
    BOM.TOP_ASSY='ABC-123'
    (Don't worry about my punctuation, my company only allows me to do [read-only] queries through Excel, so I don't need the semi-colons)
    What I'm doing is pulling information from the bill of materials (BOM) for a particular assembly (BOM.TOP_ASSY). Each assembly has components (BOM.COMPONENT), and each component has a parent part (BOM.PARENT), which it goes into. Each parent part will also have its own parent part, unless the parent part is the assembly for which I'm querying (BOM.TOP_ASSY) - in the example above, the assembly I'm looking for is 'ABC-123'.
    This leads me to my problem. Since I'm looking for the QTY_PER for both the component and the parent, I have to refer to two separate copies of the BOM table. And, since BOM.PARENT could equal BOM.TOP_ASSY, and BOM.TOP_ASSY has no parent, so it can't be a component, so it would never be in the column BOM.COMPONENT. Thus, when I run this query, all components that go directly into the top assembly ('ABC-123') are left off the query.
    Is there any way to retrieve the records for the components that go directly into the top assembly, and just make BOM2.PARENT_QTY_PER equal to 0? Basically, I only want BOM2.PARENT_QTY_PER to equal something if the parent is also a component, but 0 if it's the top assembly.
    Using NVL doesn't help, and since I'm stuck with an Oracle 8i database to query, I can't use CASE...WHEN either (though, I don't even know if this is possible with a case statement or not)...
    I don't even know if this is possible, but could someone let me know one way or the other?
    Thanks so much!

    Hi,
    user11033437 wrote:
    The whole example with the BOM and BOM2 tables were just an example of what I'm actually doing. What I'm actually doing is much more complex, and since it's all in VBA code, it was much easier for me to make up a simple example then to actually get my SQL out of VBA That's an excellent approach! I suggest you continue with it. Make sure the tiny test situation works as posted, and then, when it does work perfectly, make it a little more like your real case (say, add just one more condition in the WHERE clause), and test again.
    (which looks like this:
    strSQL = "SELECT "
    strSQL = strSQL & "C_BOM.BILL_LEVEL, "
    strSQL = strSQL & "C_BOM.COMP_PART_NBR, "
    strSQL = strSQL & "C_PART.PART_DESC, " )
    But, in the interest of getting my query to work, and hopefully learning a few things in the process, I've extracted my actual SQL, and pasted it below:
    SELECT
         C_BOM.BILL_LEVEL,
         C_BOM.COMP_PART_NBR,
         C_PART.PART_DESC,
         C_PART.PART_TYPE,
         C_BOM.QTY_PER,
         C_BOM.BOM_UM,
         C_BOM.BOM_DOC_NBR,
         C_BOM.OPER_NBR,
         C_BILL.COMP_OFF_ADJ,
         C_PART.QTY_ON_HAND,
         P_PART.QTY_ON_HAND,
         NVL(P_BOM.QTY_PER,0)
    FROM
         PART C_PART,
         PART P_PART,
         BILL C_BILL,
         V087_BOM C_BOM,
         V087_BOM P_BOM
    WHERE
         C_PART.PART_NBR=C_BOM.COMP_PART_NBR AND
         P_PART.PART_NBR=C_BOM.BOM_DOC_NBR AND  --fixed a typo here from extracting from vba
         P_BOM.COMP_PART_NBR (+) = C_BOM.BOM_DOC_NBR AND
         C_BILL.COMP_PART_NBR=C_BOM.COMP_PART_NBR AND 
         C_BILL.BOM_DOC_NBR = C_BOM.BOM_DOC_NBR AND
         ((C_BOM.STATUS = 'RL') AND
         (C_BOM.PART_NBR= 'ABC-123') AND
         (C_BOM.END_EFF_DT>sysdate) AND
         (C_BOM.BEGN_EFF_DT<=sysdate) AND
         (C_BOM.VIEW_CODE<>'E') AND
         (P_BOM.STATUS = 'RL') AND
         (P_BOM.PART_NBR= 'ABC-123') AND
         (P_BOM.END_EFF_DT>sysdate) AND
         (P_BOM.BEGN_EFF_DT<=sysdate) AND
         (P_BOM.VIEW_CODE <> 'E') AND
         (C_BILL.VIEW_CODE <> 'E') AND     <--for some reason my <> is being parsed out here
         (C_BILL.QTY_PER_TYPE <> 0) AND  <--for some reason my <> is being parsed out here
         (C_BILL.END_EFF_DT>sysdate) AND
         (C_BILL.BEGN_EFF_DT<=sysdate))
    ORDER BY
         C_BOM.BILL_LEVEL, C_BOM.BOM_DOC_NBRPART is the table with the information associated with each part in the system
    BILL is the table with the bill of materials for each assembly in the system
    V087_BOM is a view that I didn't create, but seems to compile the full bill of materials (from the BILL table) for a top-level assembly (so, the BOM for that part, and for all of it's sub-assemblies, and all of their sub-assemblies, etc.)
    Does that give a clearer picture of what I'm trying to accomplish?
    Edited by: user11033437 on Apr 15, 2009 10:07 AM
    Fixed a typo where indicated (P_PART_NBR changed to P_PART.PART_NBR)I see where you made the join condition between p_bom and c_bom an outer join:
    P_BOM.COMP_PART_NBR (+) = C_BOM.BOM_DOC_NBRThat says: "join the tables like this if possible, but if there's no match, then pretend there was a match in the table marked with the + sign". The resuolting joined row will have bom_doc_nbr (and all the other columns from c_bom), but comp_part_nbr (and all the other columns from p_bom) will be NULL.
    One of those columns is status. Your WHERE clause includes the condition:
    (P_BOM.STATUS = 'RL')Since all columns from p_bom are NULL in this case, the condition above will fail, even though the first condition succeeded.
    You have to add a + to all the conditions in this query that refer to p_bom, including
    ...     (P_BOM.STATUS (+)      = 'RL')      AND
         (P_BOM.PART_NBR (+)    = 'ABC-123') AND
         (P_BOM.END_EFF_DT (+)  > sysdate)   AND If you want to include rows that have no match in the p_part table, you'll have to make all of its conditions outer-joins, too:
         P_PART.PART_NBR (+) = C_BOM.BOM_DOC_NBRIsn't that annoying about the &lt;&gt; operator? This site treats it as some kind of markup, even inside &#123;code&#125; tags. I'm surprised any of them showed up. Thanks for flagging them with comments.
    There's no problem with the other inequality operator, !=. You can use that when you post to this site.

  • SQL Optimization with join and in subselect

    Hello,
    I am having problems finding a way to optimize a query that has a join from a fact table to several dimension tables (star schema) and a constraint defined as an in (select ....). I am hoping that this constraint will filter the fact table then perform the joins but I am seeing just the opposite with the optimizer joining first and then filtering at the very end. I am using the cost optimizer and saw that it does in subselects last in the predicate order. I tried the push_subq hint with no success.
    Does anyone have any other suggestions?
    Thanks in advance,
    David
    example sql:
    select ....
    from fact, dim1, dim2, .... dim &lt;n&gt;
    where
    fact.dim1_fk in ( select pf from dim1 where code = '10' )
    and fact.dim1_fk = dim1.pk
    and fact.dim2_fk = dim2.pk
    and fact.dim&lt;n&gt;_fk = dim&lt;n&gt;.pk

    The original query probably shouldn't use the IN clause because in this example it is not necessary. There is no limit on the values returned if a sub-select is used, the limit is only an issue with hard coded literals like
    .. in (1, 2, 3, 4 ...)Something like this is okay even in 8.1.7
    SQL> select count(*) from all_objects
      2  where object_id in
      3    (select object_id from all_objects);
      COUNT(*)
         32378The IN clause has its uses and performs better than EXISTS in some conditions. Blanket statements to avoid IN and use EXISTS instead are just nonsense.
    Martin

  • Oracle 10.2.0.4 vs 10.2.0.5 SQL optimizer

    Hello,
    Recently we upgraded from Oracle 10.2.0.4 to 10.2.0.5 deployed on AIX 5. Immediately we could see slowness for a particular SQL which used partition as well as indexed column in predicate clause.
    e.g.
    SELECT COL1, COL2
    FROM TAB1 PARTITION (P1)
    WHERE TAB1.COL3 = 123;
    There is an index created on COL3. However explain plan for this SQL showed that this index was not getting used. Surprisingly, when we removed partition from SQL, itused the index
    SELECT COL1, COL2
    FROM TAB1
    WHERE TAB1.COL3 = 123;
    There is one more observation - When we reverted back to 10.2.0.4 optimization strategy on Oracle 10.2.0.5. The original SQL that had partition clause used the index as it should have been and explain plan matched to what was before the Oracle upgrade.
    I have few questions based on these observations. Any help will be appreciated.
    1. Are there any changes in the 10.2.0.5 optimizer that is making SQL becoming slow?
    2. Is there any problem in SQL that is making it slow?
    3. I believe moving to 10.2.0.4 optmizer on Oracle 10.2.0.5 is a short-term solution. Is there any permanent fix to this problem?
    4. Does Oracle 11g support 10.2.0.4 optimizer?
    Please let me know if more details are needed.
    Thank you!

    Onkar Talekar wrote:
    1. Are there any changes in the 10.2.0.5 optimizer that is making SQL becoming slow?There are always changes with the CBO happening, it's a complicated bit of software. Some bugs will be fixed, others introduced. You may have been unfortunate enough to hit a bug, search MOS or raise a SR with Oracle support if you feel that is the case.
    Onkar Talekar wrote:
    2. Is there any problem in SQL that is making it slow?Entirely possible you have a poorly written SQL statement, yes.
    Onkar Talekar wrote:
    3. I believe moving to 10.2.0.4 optmizer on Oracle 10.2.0.5 is a short-term solution. Is there any permanent fix to this problem?Yes, raise a SR with Oracle.
    Onkar Talekar wrote:
    4. Does Oracle 11g support 10.2.0.4 optimizer?Yes, but i wouldn't recommend running an 11 instance with optimizer compatibility set to less than the current version without a very compelling reason (the one you've posted doesn't seem to be compelling to me at the moment).
    What happens if you specify the partition column in the WHERE clause instead of the actual partition in the FROM clause ... Oracle should use partition elimination to visit only that partition and utilize the local index on COL3 (i am assuming there is a local index in play here).
    I would guess, a very speculative guess, that you hit a bug pertaining to specifying the partition name, and that if you can get Oracle to do a partition elimination on it's own (instead of 'hard coding' the partition name) that it will smarten up and you'll get the execution plan you want / expect ... just a guess.

  • 10.2.0.4 vs 10.2.0.5 SQL optimizer

    Hello,
    Recently we upgraded from Oracle 10.2.0.4 to 10.2.0.5 deployed on AIX 5. Immediately we could see slowness for a particular SQL which used partition as well as indexed column in predicate clause.
    e.g.
    SELECT COL1, COL2
    FROM TAB1 PARTITION (P1)
    WHERE TAB1.COL3 = 123;
    There is an index created on COL3. However explain plan for this SQL showed that this index was not getting used. Surprisingly, when we removed partition from SQL, itused the index
    SELECT COL1, COL2
    FROM TAB1
    WHERE TAB1.COL3 = 123;
    There is one more observation - When we reverted back to 10.2.0.4 optimization strategy on Oracle 10.2.0.5. The original SQL that had partition clause used the index as it should have been and explain plan matched to what was before the Oracle upgrade.
    I have few questions based on these observations. Any help will be appreciated.
    1. Are there any changes in the 10.2.0.5 optimizer that is making SQL becoming slow?
    2. Is there any problem in SQL that is making it slow?
    3. I believe moving to 10.2.0.4 optmizer on Oracle 10.2.0.5 is a short-term solution. Is there any permanent fix to this problem?
    4. Does Oracle 11g support 10.2.0.4 optimizer?
    Please let me know if more details are needed.
    Thank you!

    Have statistics been gathered after the upgrade ? Has the OPTIMIZER_FEATURES_ENABLE init.ora parameter been set to 10.2.0.5 after the upgrade ?
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14237/initparams142.htm#CHDFABEF
    Pl post the explain plans for the statement in both 10.2.0.4 and 10.2.0.5 following the instructions in this thread - HOW TO: Post a SQL statement tuning request - template posting
    Every upgrade/patch can introduce changes in the optimizer. You can use 10.2.0.4 features in 11g using the parameter mentioned above - but why would you want to do that ?
    HTH
    Srini

  • Select one record for the first matching condition only in four where condi

    I need your suggestion to write one tricky SQL query to select only one record from database on the following condition.I explained simple table structure below.I have a table temp with four columns a,b,c,d in it.
    I have to select column d from this temp table based on the following four conditions.If it matches any condition, It should skip other conditions, that's the tricky thing.
    Conditions order is like shown below.
    1) a='argument1' and b='argument2' and c='argument3'(If it matches this condition, it should stop selecting below 3 conditions)
    2) a='argument1' and b='argument2' and c='none'(If it matches this condition, it should stop selecting below 2 conditions)
    3) a='argument1' and b='none' and c='argument3'(If it matches this condition, it should stop selecting below condition)
    4) a='argument1' and b='none' and c='none'(this is last condition)
    If I use OR operator , it matches all of those other conditions too.I never wrote query like this before.
    I greatly appreciate if somebody sheds light on me to start writing this query with a simple suggestion.
    Thanks,
    GD

    This forum might help you out, as they are experienced SQL developers, however, this forum is primarily for queries about the tool, SQL Developer. I recommend you post this on the SQL & PL/SQL forum where they focus on these queries:
    PL/SQL
    Sue

  • SQL Developer Screens Don't Match Tutorial Screens

    Hi, I am new to SQL Developer and am starting to go through the tutorial that is at this URL http://st-curriculum.oracle.com/tutorial/SQLDeveloper/index.htm. The version of SQLDeveloper that I just downloaded and am running is version 1.1.0.23.
    My problem is that the screens with my version of SQL Developer do not match the tutorial. For example when editing a Table my version of SQL Developer has a windowed area on the left with the options "Column, Primary Key, Unique Constraints, Foreign Keys, Check Constraints, Indexes, Storage Options, Lob Paramaters, Comment and DDL" listed top to bottom as a list. The Tutorial, on the other hand has these options as "Tabs" across the top. Also, when I select "Primary Key" with SQL Developer I don't get the option anywhere for "Populate Primary Key Column:" with radiobuttons for From: Existing Sequence or New Sequence.
    I am running Windows XP Professional. Any help would be appreciated as I can't use the tutorial since it doesn't match my version of SQL Developer. I seem to be missing options as well. I have screen captures showing the differences between SQL Developer and the Tutorial if someone wants me to email them so they can better understand what I am seeing.
    Thank You,
    Chris

    Yes, we are in the process of updating all the doc and collateral for 1.1.
    If you have not yet created your table, then in the Advanced Create table dialog, select Sequences. The dialog will display an area to create the new sequence name and trigger code. The functionality is the same, the dialog a little different in layout.
    If the table already exists:To create a sequence for your primary key, or any other column for that matter, right click the table created and select Trigger -> Create (PK from Sequence)
    This dialog will give you the option of creating a sequence and new trigger for any column in your table.
    Regards
    Sue

  • PL SQL Array comparisons (Looking for matches)

    I have two tables and I am trying to derive a XML structure out of it, based on certain criteria.
    The oracle version I am using is
         Oracle9i Enterprise Edition Release 9.2.0.7.0 - 64bit Production
         PL/SQL Release 9.2.0.7.0 - Production
         CORE     9.2.0.7.0     Production
         TNS for Solaris: Version 9.2.0.7.0 - Production
         NLSRTL Version 9.2.0.7.0 - ProductionStructure and Data
    QUOTE_LINES
    QUOTE_NO LINE_SEQ CLASS TYPE PERIOD RENT
    100 001 MERC LEASE 12 680.00
    100 002 MERC LEASE 10 775.00
    100 003 JAG LEASE 10 785.00
    QUOTE_ADTL
    QUOTE_NO LINE_SEQ ADTL_SEQ ADDON CHARGE
    100 001 001 GPS 199.99
    100 002 001 XM 24.99
    100 003 001 GPS 199.99
    100 003 002 CHILDSEAT 25.99
    There are two cursors to get information.
    The first cursor is on the QUOTE_LINES table and the second one is on the QUOTE_ADTL table.
    What the program is currently doing is opening the cursor on QUOTE_LINES, getting information, then moving to QUOTE_ADTL and appending this information.
    So my XML String is being formed like this.
    <QUOTE_LINE>
                <LINE_SEQ>001</ LINE_SEQ >
                <CLASS>MERC</CLASS>
                <PERIOD>12</PERIOD>
                <RENT>680.00</RENT>
                <QUOTE_ADTL>
                            <LINE_SEQ>001</LINE_SEQ>
                            < ADTL_SEQ>001</ADTL_SEQ>
                            <ADDON>GPS</ADDON>
                            <CHARGE>199.99</CHARGE>
    </QUOTE_ADTL>
    </QUOTE_LINE>
    <QUOTE_LINE>
                <LINE_SEQ>002</ LINE_SEQ >
                <CLASS>MERC</CLASS>
                <PERIOD>10</PERIOD>
                <RENT>775.00</RENT>
                <QUOTE_ADTL>
                            <LINE_SEQ>002</LINE_SEQ>
                            < ADTL_SEQ>001</ADTL_SEQ>
                            <ADDON>XM</ADDON>
                            <CHARGE>24.99</CHARGE>
    </QUOTE_ADTL>
    </QUOTE_LINE>
    <QUOTE_LINE>
                <LINE_SEQ>003</ LINE_SEQ >
                <CLASS>JAG</CLASS>
                <PERIOD>10</PERIOD>
                <RENT>785.00</RENT>
                <QUOTE_ADTL>
                            <LINE_SEQ>003</LINE_SEQ>
                            < ADTL_SEQ>001</ADTL_SEQ>
                            <ADDON>GPS</ADDON>
                            <CHARGE>199.99</CHARGE>
                            <LINE_SEQ>003</LINE_SEQ>
                            < ADTL_SEQ>002</ADTL_SEQ>
                            <ADDON>CHILDSEAT</ADDON>
                            <CHARGE>25.99</CHARGE>
    </QUOTE_ADTL>
    </QUOTE_LINE> The change that is required is to combine the unit lines if LINE_SEQ /CLASS /TYPE have the same values.
    So the new XML will have to be something like this.
    <QUOTE_LINE>
                <CAR>
                <LINE_SEQ>001</ LINE_SEQ >
                <CLASS>MERC</CLASS>
                <PERIOD>12</PERIOD>
                <RENT>680.00</RENT>
                </CAR>
                <CAR>
                <LINE_SEQ>002</ LINE_SEQ >
                <CLASS>MERC</CLASS>
                <PERIOD>10</PERIOD>
                <RENT>775.00</RENT>
                </CAR>
                <QUOTE_ADTL>
                            <LINE_SEQ>001</LINE_SEQ>
                            < ADTL_SEQ>001</ADTL_SEQ>
                            <ADDON>GPS</ADDON>
                            <CHARGE>199.99</CHARGE>
                            <LINE_SEQ>002</LINE_SEQ>
                            < ADTL_SEQ>001</ADTL_SEQ>
                            <ADDON>XM</ADDON>
                            <CHARGE>24.99</CHARGE>
    </QUOTE_ADTL>
    </QUOTE_LINE>
    <QUOTE_LINE>
                <LINE_SEQ>003</ LINE_SEQ >
                <CLASS>JAG</CLASS>
                <PERIOD>10</PERIOD>
                <RENT>785.00</RENT>
                <QUOTE_ADTL>
                            <LINE_SEQ>003</LINE_SEQ>
                            < ADTL_SEQ>001</ADTL_SEQ>
                            <ADDON>GPS</ADDON>
                            <CHARGE>199.99</CHARGE>
                            <LINE_SEQ>003</LINE_SEQ>
                            < ADTL_SEQ>002</ADTL_SEQ>
                            <ADDON>CHILDSEAT</ADDON>
                            <CHARGE>25.99</CHARGE>
    </QUOTE_ADTL>
    </QUOTE_LINE>Edited by: abhijit74 on Dec 18, 2008 6:46 AM (Added code tags).

    btw you can use ** tags when posting code to improve readability. See the FAQ.                                                                                                                                                                           

Maybe you are looking for

  • Safari doesn't open properly at startup

    Hi everybody, I've been browsing the forum a bit, but didn't find an answer to my question. Here it goes: I have Safari added in my dock, and I marked it as 'open after login'. The same for Mail. When my mac has started up my Mail indeed opens, but S

  • Macbook pro retina haswell 13 lag using (Photoshop)

    Hi ALL, MY macbook pro retina display haswell (13 in) lags while using Adobe Photoshop CC (V 14.1.2 x64). I have no other applications open except photoshop. Is this normal for this model? i was told by apple that photoshop would not lag when editing

  • Sandisk Mobile Mate SD will not read

    I have tried rebooting with the device plugged in. It just won't show up in Finder or desktop. The light on the device is lit and it shows up in system profiler but I don't know what else can do. Hopefully someone here can help me. I know this has to

  • Apache error messages

    Hi : I have started to see some strange messages in my apache logs. What does this mean? When I see this messages the system is kind of hungup state? How do I identify the root cause of this issue that I am seeing. [Sun Jun  1 10:56:30 2008] [error]

  • Update "no permission"??

    I just did a "software update," of which there were five. But two of them could not be installed, and had exclamation points next to them, with a message saying that they could not be installed because I did not have proper permissions. I've done cou