많은 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>

Similar Messages

  • 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

  • Multiple pl/sql expressions for a conditonal process

    Can I put multiple pl/sql expressions in the expression one box? I want run a process on conditions that posts an update when the user has checked a box that was not previously checked.
    looks something like this:
    when
    (p1_checkbox1 = 'Y' or p1_checkbox2 = 'Y')
    and ((p1_checkbox1 =! p1_checkbox1_sav)
    or (p1_checkbox2 =! p1_checkbox2_sav))
    Is this possible or will I need to create multiple processes that do the same thing with different run conditions?

    Please tell us your first name and update your forum profile with it to help us. Thanks.
    The answer is no, you can only have one expression, for example:
    (:p1_checkbox1 = 'Y' or :p1_checkbox2 = 'Y')
      and ((:p1_checkbox1 =! :p1_checkbox1_sav)
      or (:p1_checkbox2 =! :p1_checkbox2_sav))Scott

  • Iterating through the result of a multiple row sql statement

    Hi all,
    I would like to access the results of a multiple row sql-statement. However I can't find out how to do this, can you help me here?
    I have tried using the "node-set" functions in xpath, but I can't seem to get it right.
    How should I approach this scenario?
    Sincerely
    Kim

    The jdbc service has the option of returning xml back to you ...if you do it this way then you can interogate the xml

  • Chart with multiple series (SQL?)

    Hello everyone,
    I have an sql question relating to flash charts in APEX 3.
    I have a table "TREND" that has data like this :-
    WEEK LOCN COST
    ===== ==== =====
    45........A......10
    46........A......12
    47........A......15
    45........B......18
    46........B......16
    47........B......11
    45........C......13
    46........C......14
    47........C......10
    How do I create an sql statement that can compile multiple values for a chart at runtime. In other words I want a chart that can show three LOCN lines (A,B and C) over the WEEKs (x axis) in the table.
    Using the standard chart source only gives one value on the chart ..........
    SELECT NULL link, LOCN label, COST value FROM TREND
    I need something like this ..........
    SELECT link, label, value1, value2, value3 FROM TREND
    But I don't know how to transpose my data into that format, can anyone help ?
    I need my data to look like this I think :-
    WEEK A B C
    ===== == == ==
    45....10.18.13
    46....12.16.14
    47....15.11.10
    Thanks,
    Jack.

    Hi Jack,
    you have 2 possibilities.
    1) You can create 3 distinct series sql statements (with the "Add Series" button) where you restrict the query to LOCN. Disadvantage: The table is scanned 3 times.
    2) You can create just one series where the distinct series values are mapped to columns. eg:
    SELECT NULL AS LINK
         , WEEK AS LABEL
         , SUM(DECODE(LOCN, 'A', COST, 0)) AS A
         , SUM(DECODE(LOCN, 'B', COST, 0)) AS B
         , SUM(DECODE(LOCN, 'C', COST, 0)) AS C    
      FROM TREND
    GROUP BY WEEKAdvantage: Table is just scanned once.
    Patrick
    My APEX Blog: http://inside-apex.blogspot.com
    The ApexLib Framework: http://apexlib.sourceforge.net
    The APEX Builder Plugin: http://sourceforge.net/projects/apexplugin/

  • Is there any simple way to run same sql script on multiple remote sql server databases at once?

    i am using sql server 2005. our company has many branches. each branch is located in different country. so when i update database in any country over the VPN connection then i need to update db in another country one by one over the vpn connection. it
    is very tire some job....so i was think that there could be any easy trick to update multiple db in different country easily. so am developing a store procedure which will connect each DB in different database one after one over the vpn and read script from
    sql file and execute the script in remote db over vpn. so please have look at my script and tell me how to do it. please do not advise me to use any 3rd party.
    here is a table structure where i will put all my remote db details.
    CREATE TABLE [dbo].[DBDetails]
    [ServerName] [varchar](max)     NULL,
    [DBName] [varchar](max)         NULL,
    [UserID] [varchar](max)         NULL,
    [Password] [varchar](max)       NULL,
    [CountryCode] [varchar](2)      NULL
    SET NOCOUNT ON
    DECLARE DB CURSOR FOR SELECT ServerName,DBName,UserID,Password,CountryCode FROM    DBDetails
    OPEN DB
    DECLARE @ServerName     varchar(MAX)
    DECLARE @DBName         varchar(MAX)
    DECLARE @UserID         varchar(MAX)
    DECLARE @Password       varchar(MAX)
    DECLARE @CountryCode    varchar(2)
    FETCH NEXT FROM DB INTO @ServerName,@DBName,@UserID,@Password,@CountryCode
    WHILE @@FETCH_STATUS = 0
    BEGIN
    -- here i need some help for opening db connection and read sql file and execute  the statement
    -- Please help here
    FETCH NEXT FROM DB INTO @ServerName,@DBName,@UserID,@Password,@CountryCode
     END
     CLOSE DB
     DEALLOCATE DB
    thanks

    One way: set them as jobs and assign the same schedule or start them from a stored procedure:
    http://www.sqlusa.com/bestpractices2005/startjobfromstoredproc/
    Note: when you start a job from a stored procedure, control proceeds to the next statement, there is no wait for the job to finish.
    Kalman Toth SQL SERVER 2012 & BI TRAINING
    New Book: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2012

  • How to deal with multiple language SQL script?

    Hi All,
    We now want to create a SQL script that contains multiple languages(English, Chinese, Japanese), this script need to be run at there different database installed on different OS, for example, Oracle9i on Windows 2000 English Edition/Chinese Edition/Japanese Edition.
    If I save the file as ANSI format, this file will only be recognized at local OS(e.g. the Chinese and Japanese character will not be normally displayed on other OS, if I run the script, the CH/JP characters will not be stored normally in DB).
    If I save the file as Unicode format, this file can be recognized by all three OS, but Oracle SQL Plus will not recognize it, thus we can't run the script.
    Who can tell me how to deal with this issue? Is it possible to save only one script that can run on different language OS?
    Thanks,
    Spark

    Hi,
    The ISQLplus supports multiple languages, but there will be following problems for my case:
    1.ISQLplus don't support Unicode format script too, so I must save the file as ANSI format.
    2.To display the characters normally depends on the database server's platform. I create a script contain three languages with ANSI format in Chinese OS, but if I want to load this script to database server installed on English OS via ISQLplus, the Chinese characters will not be displayed normally too.
    PS:
    So, I think this is not only related with Oracle but also the Windows OS, it is hard to create one file with ANSI format that can be displayed normally in different platforms.
    Thank you all the same,
    Spark

  • 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.

  • Multiple Physical SQL for one report

    Hi,
    Can someone please explain me why i am seeing multiple physical Queries generated for a single report.
    Please find below the physical sql.
    select sum(T314772.MONTHLY_BUDGET_AMT) as c1,
    T157680.NAME as c2
    from
    W_PARTY_D T157680,
    XXKC_CUSTSITE_SHIPTO_BUDGET_F T314772 / Fact_XXKC_CUSTSITE_SHIPTO_BUDGET_F */*
    where  ( T157680.ROW_WID = T314772.CUSTOMER_WID )
    group by T157680.NAME
    and
    select sum(case  when T97600.W_XACT_TYPE_CODE = 'Chargeback' then T93664.NET_AMT T93664.GLOBAL1_EXCHANGE_RATE end ) as c1,*
    sum(case  when T97600.W_XACT_TYPE_CODE = 'Credit Memo' then T93664.NET_AMT T93664.GLOBAL1_EXCHANGE_RATE end ) as c2,*
    sum(case  when T97600.W_XACT_TYPE_CODE = 'Debit Memo' then T93664.NET_AMT T93664.GLOBAL1_EXCHANGE_RATE end ) as c3,*
    sum(case  when T97600.W_XACT_TYPE_CODE = 'Standard Invoice' then T93664.NET_AMT T93664.GLOBAL1_EXCHANGE_RATE when T97600.W_XACT_TYPE_CODE = 'Invoice Cancellation' then T93664.NET_AMT * -1 * T93664.GLOBAL1_EXCHANGE_RATE end ) as c4,*
    T157680.NAME as c5
    from
    W_PARTY_D T157680,
    W_SALES_INVOICE_LINE_F T93664 / Fact_W_SALES_INVOICE_LINE_F */ ,*
    W_XACT_TYPE_D T97600 / Dim_W_XACT_TYPE_D_Sales_Ivclns */*
    where  ( T93664.CUSTOMER_WID = T157680.ROW_WID and T93664.XACT_TYPE_WID = T97600.ROW_WID and T93664.DELETE_FLG = 'N' )
    group by T157680.NAME
    please let me know the reason and how to control this kind off behavior

    Combined request is like, within a report you can create multiple requests. You can either use it in case of combining different subject area or within the same subject area and in same report when different filters apply.
    For example
    Fire Marine Motor
    State No. Amt. No. Amt. No. Amt.
    Andra Pradesh 10 |20000 11 |100000 20 |200000
    TamilNadu 11 |40000 10 |120000 20 |200000
    The first request is for Andra, so we will apply the filter as 'state is equal to in 'andra pradesh''. We specify filter(No using Product_code in 'Fire') in the column formula. Then there is an option as 'combine' by which u create another request and now the filter is 'state is equal to in 'Tamil Nadu''. So when you execute the report, it will generate you two different queries.
    Regards,
    Anitha.B

  • 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

  • SQL Optimization Help

    Hi,
    I'm relatively new to SQL and I'm trying to figure out a good way to run a select statement multiple times (with different parameters) and only have one results table.
    SELECT *
    FROM table
    WHERE date=&1
    This is what I'm doing now, but I'm sure it's not optimal:
    SELECT *
    FROM table
    WHERE date=date1
    UNION ALL
    SELECT *
    FROM table
    WHERE date=date2
    UNION ALL
    SELECT *
    FROM table
    WHERE date=date1
    ect....
    Help please.

    Hi,
    Can you insert the parameters into a global temporary table? If so, you could join to the global temporary table like this:
    /* Set up demo table */
    create table source_table (
    id number,
    date_field date
    create index idx_date_field on source_table (date_field);
    /* Insert 10000 dates */
    insert into source_table
    select rownum, trunc(sysdate) + rownum from dual connect by rownum < 10000;
    commit;
    /* Set up the global temporary table */
    create global temporary table gtt_dates (date_val date) on commit preserve rows;
    /* Insert 10 random dates */
    insert into gtt_dates
    select * from (select date_field from source_table order by dbms_random.random) where rownum <= 10;
    /* Demo query */
    select a.*
    from source_table a,
    gtt_dates g
    where a.date_field = g.date_val;
    Regards,
    Melvin

  • 1 form, 1 table, multiple PHP/SQL UPDATES

    Hi guys,
    I'm hoping you can help me on this one
    I would like to submit multiple entries from a form after hitting one submit button, but am having no luck.
    MySQL Table name: nwbps_class
    Fields: nwbpsclass_id, class, nwbpsclass_welcome, nwbpsclass_order.
    I’m using a PHP/SQL repeat region which will add more fields to the form, for every submission of the above.
    Id like to be able to edit the ‘nwbpsclass_order’ and ‘class’ fields (of each entry) manually in 1 big form submission. I hope I’m making sense.
    David

    Multiple queries are not a problem, you can set conditions to them as well, meaning
    $query1="...";
    if (some condition exist){
    $query3="...";
    etc.
    You can also use a switch statement for queries.
    But your not really giving enough information for someone to give you any more specific help.
    Gary

  • Splitting multiple (pl/sql)/sql statements

    Hi,
    I am trying to build a pl/sql editor on my website. Everything works fine for single commands, but the way it is going to be used the user can enter multiple commands/blocks on the text editor to execute and in which case the OracleCommand throws an error. I know I can wrap the multiple commands in a block but when I do an ExecuteNonQuery it returns -1 instead of how many rows are changed. For example, the following commands could be entered:
    INSERT INTO someTable(col1, col2, col3) VALUES (val1, val2, val3);
    INSERT INTO someTable(col1, col2, col3) VALUES (val4, val5, val6);
    BEGIN
    do something;
    END;
    And when the user clicks run I have two choices that I know of. I could wrap all the text in BEGIN and END; but as stated above it then does not return the correct row count, or I could try and split up the commands/blocks, which looks like thats what I'm going to have to do. So my question is is there an easy way, or hard anyway, to split multiple statements into individual statements? What is really giving me the problems are the annonymous blocks, so if there is an easy what to tell when an annonymous block is complete that would be very helpful.
    Thanks in advance

    >
    I am trying to build a pl/sql editor on my website. Everything works fine for single commands, but the way it is going to be used the user can enter multiple commands/blocks on the text editor to execute and in which case the OracleCommand throws an error. I know I can wrap the multiple commands in a block but when I do an ExecuteNonQuery it returns -1 instead of how many rows are changed.
    >
    So far everything you have said is correct. Sounds like things are working exactly as they are documented to work.
    Per the Oracle Data Provider for .NET Developer's Guide
    http://docs.oracle.com/cd/B19306_01/win.102/b14307/OracleCommandClass.htm
    >
    OracleCommand Class
    An OracleCommand object represents a SQL command, a stored procedure, or a table name. The OracleCommand object is responsible for formulating the request and passing it to the database. If results are returned, OracleCommand is responsible for returning results as an OracleDataReader, a .NET XmlReader, a .NET Stream, a scalar value, or as output parameters.
    >
    Note the 'a SQL command, a stored procedure, or a table name'. Multiple commands/blocks don't fall into any of those categories so, of course, you get an error.
    And in the same document page
    >
    ExecuteNonQuery returns the number of rows affected, for the following:
    •If the command is UPDATE, INSERT, or DELETE and the XmlCommandType property is set to OracleXmlCommandType.None.
    •If the XmlCommandType property is set to OracleXmlCommandType.Insert, OracleXmlCommandType.Update, OracleXmlCommandType.Delete.
    For all other types of statements, the return value is -1.
    >
    Your 'block' is not an UPDATE, INSERT or DELETE, etc so, as the doc says, 'For all other types of statements, the return value is -1.
    It is YOUR responsibility to submit the individual statements and capture the results of each one.

  • 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

Maybe you are looking for

  • I'm getting an error everytime I open iTunes

    Recently, I had a problems with my DVD drives. A solution I came across was to delete some registry keys that related to them. After fixing that issue, I got an iTunes message that said this: Warning! The registry settings used by the iTunes drivers

  • Google Calendar doesn't show

    Please Help! I have inserted a Google Calendar(iframe html code) into one of my iweb pages but it doesn't show in Safari. I get an error in the Activity window that says "too many http redirects" if I refresh Safari a few times it works although it w

  • Create new client in Solution Manager?

    I finished installing Solution Manager 4.0 sp1 for the first time and have the default clients of 000, 001, and 066. I can log on with the SAP* user.  I'm a little confused about the next step. Do I create an addtional client (For example, 100) just

  • How to trace JC00 instance reboot error?

    hi all, currently my JC00 instance was reboot by itself, is there anyway i can trace the error log? where is the location for the error log? thanks.

  • b / ? space after the b?

    Why is dreamweaver putting a space after the "b" in <b />?