Nested Loop Help

Hello,
I have generated a simple VI, to make multiplication and division operations. I have the following operation performed with the following inputs.
A1 has a value range from 1 -10 fixed
A2 has an input range of 1 - 5
A3,A4 are constants.
so Result  = (A1*A3 ) / (A4*A2)*100 ,
I want to  plot "Result Vs. A1" with a current value of A2, increment A2 and repeat the procedure. So I generate 5 graphs and display it in only one. I need to write a nested loop to perform this operation.however I am able to do it only once.
I am trying to use for loop structure in one another but havent gone ahead in this.Any help will be appreciable..Thanks in advance.

altenbach wrote:
Dravi99 wrote:
The Problem is that I want to plot the division result vs. the # of array out elements and i am unsuccessful at it. May be i am missing on the waveform graph properties.
You should make the current values default before saving so we have some typical data to play with.
Currently, your code makes very little sense, because the inner loop has no purpose.
If you plot the division result versus array index (I assume that's what you want, I don't understand what you mean by "the # of array out elements "), you only have one plot. What should be on the other plots???
Please explain or even attach an image of the desired output. Thanks!
Thanks Altenbach for the inputs.
I have made the values default. Srry for the previous one.
Now the inner loop was placed so that i can create a 2D array.
I need to plot the division result vs. the value of the element in the arry out. i.e. currently my array out has 0.0...,0.3 I want that to be the X axis.
 The graph plotted   is for 1st value of "in", this value will change like from 4.5 to 4.7 to 4.9, not necesarily in steps.
Thus my one graph should have multiple plots of "in" which has the above mentioned axis.
Hope this time i was clear in my msg. I have attached the modified VI.
Attachments:
For_loop_prob.vi ‏17 KB

Similar Messages

  • Help with my nested loop...

    this application allows a user to enter two int values, rows(height) and columns(length), that are used to create a box of asterisks.
    my createBox() does not work correctly, only prints first line, loops infinitely, or doesnt loop. can someone help me out please?
    import java.io.*;
    public final class AsteriskBox
    /****InstanceVariables****/
    public static int row;
    public static int col;
    /****Constructor()****/
    public AsteriskBox()
    /****Access()'s****/
    public void createBox(int x, int y)
    if((x > 0) && (y > 0))
    for(int i = x; i > 0; i--)
    for(i = y; i > 0; i--)
    System.out.print("*");
    System.out.println();
    } // createBox()
    public void getInput() throws IOException
    BufferedReader input = new BufferedReader
    (new InputStreamReader(System.in));
    System.out.print("Enter a number of rows: ");
    String inputString = input.readLine();
    row = convertStringToInteger(inputString);
    System.out.print("Enter a number of columns: ");
    inputString = input.readLine();
    col = convertStringToInteger(inputString);
    } // getInput()
    /****Helper()****/
    private int convertStringToInteger(String s)
    Integer intObject = Integer.valueOf(s);
    return intObject.intValue();
    } // convertStringToInt()
    } // AsteriskBox class
    import java.io.*;
    public class AsteriskBoxUser
    public static void main(String args[]) throws IOException
    AsteriskBox box = new AsteriskBox();
    System.out.println("This program creates a box made of asterisks with values given by you!");
    System.out.println();
    box.getInput();
    box.createBox(AsteriskBox.row, AsteriskBox.col);
    }

    You will never break out of the first loop because you are using the same index variable i for both of your nested loops. Use a different variable, say j for your inner loop.
    Incidentally, your row and col variables are mislabeled. If you use the static modifier, they are class variables, not instance variables. This could cost you points on your assignment since it would imply that you don't know the difference.

  • Help tuning NESTED LOOPS OUTER joins

    Hello,
    I have inherited this nasty query (below) that is taking an awful time to complete (more than 2 hrs a day)
    The worst bit is that I need to outer join my fact table so many times as I need bit’s and pieces from other tables/mviews.
    When I look at the explain plan I see that this situation means that the cbo is doing several NESTED LOOPS OUTER join operations. I understand that these nested loops mean going through every row in my primary table to see if there is a match in the secondary table (much smaller) which makes it extremely inefficient, is this right?
    The stats on the tables are all refreshed daily.
    Any ideas on how I can improve the performance here?
    Thanks in advance!
    The query:
    explain plan for
    SELECT x.user_id AS user_id,
    x.login_name AS login_name,
    c.date_of_birth AS date_of_birth,
    x.registration_site AS registration_site,
    x.organisation AS organisation,
    c.user_title AS user_title,
    c.first_name AS first_name,
    c.last_name AS last_name,
    x.email_address AS email_address,
    x.user_status AS user_status,
    x.user_privilege AS user_access_privilege,
    x.date_registration AS date_registration,
    x.affiliate_id AS affiliate_id,
    x.mobile_number AS mobile_number,
    x.optional_parameter AS vt_number,
    gud.display_name AS chat_name,
    REPLACE (s4.address_line_1, ',', '') AS address_line_1,
    REPLACE (s4.address_line_2, ',', '') AS address_line_2,
    REPLACE (s4.town, ',', '') AS town,
    REPLACE (s4.county, ',', '') AS county,
    REPLACE (s4.postcode, ',', '') AS postcode,
    s4.country AS country,
    s3.last_login AS last_login_date,
    x.email_send_newsletter AS email_send_newsletter,
    x.email_give_details_thirdparty AS email_give_details_thirdparty,
    NVL (ia.cash_balance, 0) AS current_cash_balance,
    NVL (ia.bonus_balance, 0) AS current_bonus_balance,
    x.external_affiliate_id AS external_affiliate_id,
    r.currency_code AS currency,
    NVL (ia.points_balance, 0) AS current_loyalty_points_balance,
    p.status AS buyer_status,
    NVL (ia.bi_bonus_balance, 0) AS current_bi_bonus_balance,
    NVL (ia.pending_balance, 0) AS current_pending_balance,
    l.level_name AS current_loyalty_level,
    l.date_level_achieved AS date_level_achieved,
    NVL (l.current_period_loyalty_points, 0) AS current_period_loyalty_points,
    r.region AS user_region,
    x.registration_platform AS registration_platform,
    x.external_user_name AS external_user_name,
    c.home_number AS home_number,
    pr.code AS reg_promo_code,
    g.date_first_buy AS date_first_buy
    FROM gl_user_registrations x,
    gl_region r,
    MVW_USER_BALANCES ia,
    gl_customers c,
    gl_user_display_names gud,
    gl_user_last_login s3,
    (SELECT z.user_id AS user_id,
    z.address_line_1 AS address_line_1,
    z.address_line_2 AS address_line_2,
    z.town AS town,
    z.county AS county,
    z.postcode AS postcode,
    z.country AS country
    FROM gl_user_addresses z
    WHERE z.is_current = 1) s4,
    gl_user_buyer_mapping upm,
    gl_buyer p,
    mvw_user_loyalty_points l,
    MVW_USER_PROMO_CODE_REG pr,
    MVW_USER_FIRST_BUY_DATE g
    WHERE x.base_region = r.region
    AND x.user_id = ia.user_id (+)
    AND x.customer_id = c.customer_id(+)
    AND x.user_id = gud.user_id (+)
    AND x.user_id = s4.user_id (+)
    AND x.user_id = s3.user_id (+)
    AND x.user_id = upm.user_id (+)
    AND upm.buyer_id = p.buyer_id
    AND x.user_id = l.user_id (+)
    AND x.user_id = pr.user_id (+)
    AND x.user_id = g.user_id (+);
    select * from table(dbms_xplan.display);
    Plan hash value: 2158171613
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 100 | 63100 | 135 (1)| 00:00:01 |
    | 1 | NESTED LOOPS OUTER | | 100 | 63100 | 135 (1)| 00:00:01 |
    | 2 | NESTED LOOPS OUTER | | 100 | 60600 | 120 (1)| 00:00:01 |
    | 3 | NESTED LOOPS OUTER | | 100 | 57100 | 105 (1)| 00:00:01 |
    | 4 | NESTED LOOPS OUTER | | 100 | 55400 | 90 (2)| 00:00:01 |
    | 5 | NESTED LOOPS OUTER | | 100 | 53600 | 70 (2)| 00:00:01 |
    |* 6 | HASH JOIN | | 100 | 47000 | 55 (2)| 00:00:01 |
    | 7 | TABLE ACCESS FULL | GL_REGION | 18 | 252 | 2 (0)| 00:00:01 |
    | 8 | NESTED LOOPS OUTER | | 100 | 22800 | 52 (0)| 00:00:01 |
    | 9 | NESTED LOOPS OUTER | | 100 | 19700 | 47 (0)| 00:00:01 |
    | 10 | NESTED LOOPS OUTER | | 100 | 17600 | 37 (0)| 00:00:01 |
    | 11 | NESTED LOOPS | | 100 | 15800 | 27 (0)| 00:00:01 |
    | 12 | NESTED LOOPS | | 102 | 2754 | 17 (0)| 00:00:01 |
    | 13 | TABLE ACCESS FULL | GL_BUYER | 6143K| 64M| 2 (0)| 00:00:01 |
    | 14 | TABLE ACCESS BY INDEX ROWID| GL_USER_BUYER_MAPPING | 1 | 16 | 1 (0)| 00:00:01 |
    |* 15 | INDEX RANGE SCAN | GL_USER_BUYER_MAPPPING_IX | 1 | | 1 (0)| 00:00:01 |
    | 16 | TABLE ACCESS BY INDEX ROWID | GL_USER_REGISTRATIONS | 1 | 131 | 1 (0)| 00:00:01 |
    |* 17 | INDEX UNIQUE SCAN | PK_GL_USER_REGISTRATIONS | 1 | | 1 (0)| 00:00:01 |
    | 18 | TABLE ACCESS BY INDEX ROWID | GL_USER_LAST_LOGIN | 1 | 18 | 1 (0)| 00:00:01 |
    |* 19 | INDEX UNIQUE SCAN | GL_USER_LAST_LOGIN_PK | 1 | | 1 (0)| 00:00:01 |
    | 20 | TABLE ACCESS BY INDEX ROWID | GL_USER_DISPLAY_NAMES | 1 | 21 | 1 (0)| 00:00:01 |
    |* 21 | INDEX UNIQUE SCAN | PK_GL_USER_DISPLAY_NAMES | 1 | | 1 (0)| 00:00:01 |
    | 22 | TABLE ACCESS BY INDEX ROWID | GL_CUSTOMERS | 1 | 31 | 1 (0)| 00:00:01 |
    |* 23 | INDEX UNIQUE SCAN | PK_GL_CUSTOMERS | 1 | | 1 (0)| 00:00:01 |
    |* 24 | TABLE ACCESS BY INDEX ROWID | GL_USER_ADDRESSES | 1 | 66 | 1 (0)| 00:00:01 |
    |* 25 | INDEX RANGE SCAN | IX_GL_USER_ADDRESSES1 | 1 | | 1 (0)| 00:00:01 |
    | 26 | MAT_VIEW ACCESS BY INDEX ROWID | MVW_USER_FIRST_BUY_DATE | 1 | 18 | 1 (0)| 00:00:01 |
    |* 27 | INDEX RANGE SCAN | MVW_USER_FS_DATE_IDX | 1 | | 1 (0)| 00:00:01 |
    | 28 | MAT_VIEW ACCESS BY INDEX ROWID | MVW_USER_PROMO_CODE_REG | 1 | 17 | 1 (0)| 00:00:01 |
    |* 29 | INDEX RANGE SCAN | MVW_USER_PROMO_CODE_IDX | 1 | | 1 (0)| 00:00:01 |
    | 30 | MAT_VIEW ACCESS BY INDEX ROWID | MVW_USER_LOYALTY_POINTS | 1 | 35 | 1 (0)| 00:00:01 |
    |* 31 | INDEX RANGE SCAN | MVW_USER_LYP_IDX | 1 | | 1 (0)| 00:00:01 |
    | 32 | MAT_VIEW ACCESS BY INDEX ROWID | MVW_USER_BALANCES | 1 | 25 | 1 (0)| 00:00:01 |
    |* 33 | INDEX RANGE SCAN | MVW_USER_BALANCES_IDX | 1 | | 1 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    6 - access("X"."BASE_REGION"="R"."REGION")
    15 - access("UPM"."BUYER_ID"="P"."BUYER_ID")
    17 - access("X"."USER_ID"="UPM"."USER_ID")
    19 - access("X"."USER_ID"="S3"."USER_ID"(+))
    21 - access("X"."USER_ID"="GUD"."USER_ID"(+))
    23 - access("X"."CUSTOMER_ID"="C"."CUSTOMER_ID"(+))
    24 - filter("Z"."IS_CURRENT"(+)=1)
    25 - access("X"."USER_ID"="Z"."USER_ID"(+))
    27 - access("X"."USER_ID"="G"."USER_ID"(+))
    29 - access("X"."USER_ID"="PR"."USER_ID"(+))
    31 - access("X"."USER_ID"="L"."USER_ID"(+))
    33 - access("X"."USER_ID"="IA"."USER_ID"(+))

    Hi,
    1) What you are saying about nested loops is true about any join (except, of course, cartesian joins): you are taking rows from rowsource A and find matching rows from rowsource B. This doesn't make a join method efficient or inefficient.
    2) The plan you posted does not indicate any performance problem whatsoever. I know you have one, but it's not possible to address it without having any information about it. Trace it, get dbms_xplan.display_cursor dump with rowsource stats, or real-time SQL monitoring report (if your version and license allow it) and post the results here, then we'd be able to help
    3) One efficient way to perform queries of your type (big fact table joined to a bunch of small dimension tables) is star transformation, but there are certain pre-requisites for that (like bitmap indexes on FK constraints) -- please read the documentation on star queries/transformations and see if that is an option for you
    Best regards,
    Nikolay

  • Need help with nested loop (c:forEach) tags. Can I break from inner loop?

    Hi all, I have this annoying problem and I am looking for any suggestions.
    I have 2 select boxes. One is for all available users, and second - for selected users (designated as admins). The list of all users is available in a collection (2 properties userId and userName displayed in the code below). The list of admins contains only userId (as strings).
    I have no problem with populating selected users (admins) list, reusing pretty much the same logic below, but I cannot find a way to break out from the nested loop once the match is found, to avoid repetitions leading to incorrect display of results.
    <select name=available>
    <c:forEach items="${users}" var="user" varStatus="outer">
        <c:forEach items="${adminIds}" var="adminId" varStatus="inner">
            <c:if test="${user.userId!=adminId">
                 <option value="<c:out value="${user.userId}" />"><c:out value="${user.userFullName}"/></option>
            </c:if>
        </c:forEach>
    </c:forEach>
    </select>
    <select name=selected>
    <c:forEach items="${users}" var="user" varStatus="outer">
        <c:forEach items="${adminIds}" var="adminId" varStatus="inner">
            <c:if test="${user.userId==adminId">
                 <option value="<c:out value="${user.userId}" />"><c:out value="${user.userFullName}"/></option>
            </c:if>
        </c:forEach>
    </c:forEach>
    </select>Can anyone help, please? I am also restricted to JSP 1.2

    Double post: http://forum.java.sun.com/thread.jspa?threadID=707950&tstart=0

  • Problem with Nested loop in Fox-Formula

    Dear Experts,
    Let s share the scenario :
    MaterialGroups with following Keys for Example AAAA, BBBB, CCCC..., Materialgroups are selected in the 1st input ready query, which is assigned to DataProvider DP_1 in a  webtemplate.
    every Materialgroup has several Materials, for instance:
    Materialgroup AAAA has following Materials: AAAA10, AAAA11, AAAA12, AAAA13...
    Materials are  selected in a second  input ready Query, which is assigned to a second DataProvider DP_2 in the Same Webtemplate as the query 1.
    Both Materialgroup and Material are based on the same Aggreagtion level and same real time cube.
    I want to copy the input values for every  MaterialGroup ( 1st query, DP_1) only to it s own Materials (2cond Query, DP_2).
    To resolve this Issue i wrote the following Fox Formula code with a nested loop, however it does not work properly. when I m debugging the code, i could release that the second Loop was ignored.but wehn i replace the second loop (nested loop) with a fixed value it s seems to work properly
    DATA MG1 TYPE MATG.<------ MaterialGroup
    DATA MT1 TYPE MAT.<----
    Material
    DATA S1 TYPE STRING.
    DATA S2 TYPE STRING.
    DATA S3 TYPE STRING
    DATA K TYPE F.
    DATA Z TYPE F.
    FOREACH MG1.
    To check Materialgroup in debugger
    S1= MG1.
    BREAK-POINT.
    K = {KEYfIG, #, MG1}.
    BREAK-POINT.
    FOREACH  MT1.   <----- if i set MT1 to a fixed value like AAAA11 then S3 get the wished value namely AAAA
    S2 = MT1.
    BREAK-POINT.
    S3 =  SUBSTR (MT1, 0, 4).  
    BREAK-POINT.
    IF S1 = S3.
    {KEYFIG, MT1, #} = K.
    following Statement is only used To check in debugger if Material has become the same Materialgroup value
    Z = {KEYFIG, MT1, #}.
    BREAK-POINT.
    ENDIF.
    ENDFOR.
    ENDFOR.
    Thakns for any help
    Frank
    Edited by: FRYYYBM on Mar 17, 2011 10:54 PM
    Edited by: FRYYYBM on Mar 17, 2011 11:06 PM

    Hi,
    Please try this way.
    DATA MG1 TYPE MATG.<------ MaterialGroup
    DATA MT1 TYPE MAT.<----
    Material
    DATA S1 TYPE STRING.
    DATA S2 TYPE STRING.
    DATA S3 TYPE STRING
    DATA K TYPE F.
    DATA Z TYPE F.
    FOREACH MT1.
    FOREACH MG1.
    To check Materialgroup in debugger
    S1= MG1.
    BREAK-POINT.
    K = {KEYfIG, #, MG1}.
    BREAK-POINT.
    FOREACH MT1. <----- if i set MT1 to a fixed value like AAAA11 then S3 get the wished value namely AAAA
    S2 = MT1.
    BREAK-POINT.
    S3 = SUBSTR (MT1, 0, 4).
    BREAK-POINT.
    IF S1 = S3.
    {KEYFIG, MT1, #} = K.
    following Statement is only used To check in debugger if Material has become the same Materialgroup value
    Z = {KEYFIG, MT1, #}.
    BREAK-POINT.
    ENDIF.
    ENDFOR.
    ENDFOR.
    ENDFOR.
    Thanks.
    With regards,
    Anand Kumar

  • Hash join vs nested loop

    DECLARE @tableA table (Productid varchar(20),Product varchar(20),RateID int)
    insert into @tableA values('1','Mobile',2);
    insert into @tableA values('2','Chargers',4);
    insert into @tableA values('3','Stand',6);
    insert into @tableA values('4','Adapter',8);
    insert into @tableA values('5','Cover',10);
    insert into @tableA values('6','Protector',12);
    --SELECT * FROM @tableA
    DECLARE @tableB table (id varchar(20),RateID int,Rate int)
    insert into @tableB values('1',2,200);
    insert into @tableB values('2',4,40);
    insert into @tableB values('3',6,60);
    insert into @tableB values('4',8,80);
    insert into @tableB values('5',10,10);
    insert into @tableB values('6',12,15);
    --SELECT * FROM @tableB
    SELECT Product,Rate
    FROM @tableA a
    JOIN @tableB b ON a.RateID = b.RateID
    Above is the sample query, where in execution plan it shows the Hash Match (inner Join). Now how do I change it to Nested Loop with out changing the query? help plz

    Is Hash Match(inner join) or Nested loop is better to have in the query?
    That depends on the size of the tables, available indexes etc. The optimizer will (hopefully) make the best choice.
    Above is the sample query, where in execution plan it shows the Hash Match (inner Join). Now how do I change it to Nested Loop with out changing the query?
    The answer that you should leave that to the optimizer in most cases.
    I see that the logical read for nested loop is higher than Hash Match.
    But Hash Match tends to need more CPU. The best way to two compare two queries or plans is wallclock time.
    On a big tables, how do we reduce the logical read? 
    Make sure that there are usable indexes.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Oracle 11g - Nested loops on outer joins

    Hello,
    I have a select query that was working with no problems. The results are used to insert data into a temp table.
    Recently, it would not complete executing. The explain plan shows a cartesian. But, there could be problems with using nested loops on the outer join. Interestingly, when I copy production code and rename the temp table and rename the view, it works.
    Can someone take a look at the code and help. Maybe offer a suggestion on tuning too? Thanks.
    CREATE TABLE "CT"
    ( "TN" VARCHAR2(30) NOT NULL ENABLE,
    "COL_NAME" VARCHAR2(30) NOT NULL ENABLE,
    "CDE" VARCHAR2(5) NOT NULL ENABLE,
    "CDE_DESC" VARCHAR2(80) NOT NULL ENABLE,
    "CDE_STAT" CHAR(1));
    insert into CT (TN, COL_NAME, CDE, CDE_DESC, CDE_STAT)
    values ('INDSD', 'STCD', 'U', 'RF', 'A');
    insert into CT (TN, COL_NAME, CDE, CDE_DESC, CDE_STAT)
    values ('AT', 'TCD', '001', 'RL', 'A');
    insert into CT (TN, COL_NAME, CDE, CDE_DESC, CDE_STAT)
    values ('AT', 'TCD', '033', 'PFR', 'A');
    CREATE TABLE "IPP"
    ( "IND_ID" NUMBER(9,0) NOT NULL ENABLE,
    "PLCD" VARCHAR2(5) NOT NULL ENABLE,
    "CBCD" VARCHAR2(5));
    insert into IPP (IND_ID, PLCD, CBCD)
    values (2007, 'AS', '04');
    insert into IPP (IND_ID, PLCD, CBCD)
    values (797098, 'AS', '34');
    insert into IPP (IND_ID, PLCD, CBCD)
    values (797191, 'AS','04');
    CREATE TABLE "INDS"
    ( "OPCD" VARCHAR2(5) NOT NULL ENABLE,
    "IND_ID" NUMBER(9,0) NOT NULL ENABLE,
    "IND_CID" NUMBER(*,0),
    "GFLG" VARCHAR2(1),
    "HHID" NUMBER(9,0),
    "DOB" DATE,
    "DOB_FLAG" VARCHAR2(1),
    "VCD" VARCHAR2(5),
    "VTDTE" DATE,
    "VPPCD" VARCHAR2(4),
    "VRCDTE" DATE NOT NULL ENABLE,
    "VDSID" NUMBER(9,0),
    "VTRANSID" NUMBER(12,0),
    "VOWNCD" VARCHAR2(5),
    "RCDTE" DATE,
    "LRDTE" DATE
    insert into INDS (OPCD, IND_ID, IND_CID, GFLG, HHID, DOB, DOB_FLAG, VCD, VTDTE, VPPCD, VRCDTE, VDSID, VTRANSID, VOWNCD, RCDTE, LRDTE)
    values ('USST', 2007, 114522319, '', 304087673, to_date('01-01-1980', 'dd-mm-yyyy'), 'F', '2', to_date('06-04-2011 09:21:37', 'dd-mm-yyyy hh24:mi:ss'), '', to_date('06-04-2011 09:21:37', 'dd-mm-yyyy hh24:mi:ss'), 1500016, null, 'USST', to_date('06-04-2011 09:21:37', 'dd-mm-yyyy hh24:mi:ss'), to_date('18-07-2012 21:52:53', 'dd-mm-yyyy hh24:mi:ss'));
    insert into INDS (OPCD, IND_ID, IND_CID, GFLG, HHID, DOB, DOB_FLAG, VCD, VTDTE, VPPCD, VRCDTE, VDSID, VTRANSID, VOWNCD, RCDTE, LRDTE)
    values ('USST', 304087678, 115242519, '', 304087678, to_date('01-01-1984', 'dd-mm-yyyy'), 'F', '2', to_date('06-04-2011 09:21:39', 'dd-mm-yyyy hh24:mi:ss'), '', to_date('06-04-2011 09:21:39', 'dd-mm-yyyy hh24:mi:ss'), 1500016, null, 'USST', to_date('06-04-2011 09:21:39', 'dd-mm-yyyy hh24:mi:ss'), to_date('18-07-2012 21:52:53', 'dd-mm-yyyy hh24:mi:ss'));
    CREATE TABLE "INDS_TYPE"
    ( "IND_ID" NUMBER(9,0) NOT NULL ENABLE,
    "STCD" VARCHAR2(5) NOT NULL ENABLE);
    insert into INDS_type (IND_ID, STCD)
    values (2007, 'U');
    insert into INDS_type (IND_ID, STCD)
    values (313250322, 'U');
    insert into INDS_type (IND_ID, STCD)
    values (480058122, 'U');
    CREATE TABLE "PLOP"
    ( "OPCD" VARCHAR2(5) NOT NULL ENABLE,
    "PLCD" VARCHAR2(5) NOT NULL ENABLE,
    "PPLF" VARCHAR2(1));
    insert into PLOP (OPCD, PLCD, PPLF)
    values ('USST', 'SP', 'Y');
    insert into PLOP (OPCD, PLCD, PPLF)
    values ('PMUSA', 'ST', '');
    insert into PLOP (OPCD, PLCD, PPLF)
    values ('USST', 'RC', '');
    CREATE TABLE "IND_T"
    ( "OPCD" VARCHAR2(5) NOT NULL ENABLE,
    "CID" NUMBER(9,0) NOT NULL ENABLE,
    "CBCD" VARCHAR2(5),
    "PF" VARCHAR2(1) NOT NULL ENABLE,
    "DOB" DATE,
    "VCD" VARCHAR2(5),
    "VOCD" VARCHAR2(5),
    "IND_CID" NUMBER,
    "RCDTE" DATE NOT NULL ENABLE
    insert into IND_T (OPCD, CID, CBCD,PF, DOB, VCD, VOCD, IND_CID, RCDTE)
    values ('JMC', 2007, '04', 'F',to_date('11-10-1933', 'dd-mm-yyyy'), '2', 'PMUSA', 363004880, to_date('30-09-2009 04:31:34', 'dd-mm-yyyy hh24:mi:ss'));
    insert into IND_T (OPCD, CID, CBCD,PF, DOB, VCD, VOCD, IND_CID, RCDTE)
    values ('JMC', 2008, '04', 'N',to_date('01-01-1980', 'dd-mm-yyyy'), '2', 'PMUSA', 712606335, to_date('05-04-2013 19:36:05', 'dd-mm-yyyy hh24:mi:ss'));
    CREATE TABLE "IC"
    ( "CID" NUMBER(9,0) NOT NULL ENABLE,
    "CF" CHAR(1));
    insert into IC (CID, CF)
    values (2007, 'N');
    insert into IC (CID, CF)
    values (100, 'N');
    insert into IC (CID, CF)
    values (200, 'N');
    CREATE OR REPLACE FORCE VIEW "INDSS_V" ("OPCD", "IND_ID", "IND_CID", "GFLG", "HHID", "DOB", "DOB_FLAG", "VCD", "VTDTE", "VPPCD", "VRCDTE", "VDSID", "VTRANSID", "VOWNCD", "RCDTE", "LRDTE") AS
    SELECT DISTINCT a.OPCD, a.IND_ID, a.IND_CID, a.GFLG, a.HHID,
    a.DOB, a.DOB_flag, a.VCD, a.VTDTE,
    a.VPPCD, a.VRCDTE, a.VDSID, a.VTRANSID,
    a.VOWNCD, a.RCDTE, a.LRDTE
    FROM INDS a, INDS_type b
    WHERE a.IND_ID = b.IND_ID
    AND b.STCD in (select CDE
    from CT --database link
    where TN = 'INDSD'
    and COL_NAME = 'STCD'
    and CDE_STAT = 'A') ;
    --insert /*+ parallel(IND_T,2) */ into IND_T
    select /*+ parallel(a,4) */
    a.OPCD as OPCD
    , a.IND_ID as CID
    , b.CBCD as CBCD
    , NULL as BFCD
    , 'N' as PF
    , a.DOB as DOB
    , a.VCD as VCD
    , a.VOWNCD as VOCD
    , a.IND_CID as IND_CID
    , a.RCDTE as RCDTE
    from INDSS_V a
    , (select /*+ parallel(IPP,4) */ * from IPP IPP , PLOP PLO
    where plo.PLCD = ipp.PLCD
    and PPLF='Y') b
    , IC c
    where a.IND_ID = b.IND_ID (+)
    and a.OPCD = b.OPCD (+)
    and a.IND_ID = c.CID
    and c.CF = 'N';

    Please consult
    HOW TO: Post a SQL statement tuning request - template posting
    Also format your code and post it using the [ code ] and [ /code ] tags. (Leave out the extra space after [ and before ])
    Sybrand Bakker
    Senior Oracle DBA
    Edited by: sybrand_b on 10-apr-2013 17:57

  • Partition pruning, Nested loops

    Hi,
    I am having a problem with getting partition pruning in a query. I've managed to dumb down the problem to two tables and a minimal query (see below).
    Basically, I have a partitioned table "Yearly Facts", and a helper table "Current Year" that always contain 1 row. The sole purpose of this one row is to tell what the curent year is, what the previous year was and what the next year will be. (In the real problem, there are non-standard timeperiods, so one cannot just calculate previous and next by adding/subtracting 1 as would be possible in this example).
    The following query is executed the way I want.
    It performs a scan on current_year, and then nested loop into the facts. And partition pruning was happening.
    select sum(decode(a.year_key, b.curr_year, some_measure)) as curr_year_measure
      from yearly_fact_t a
          ,current_year  b
    where a.year_key = b.curr_year;
    | Id  | Operation                  | Name          | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
    |   0 | SELECT STATEMENT           |               |     1 |    39 |     4   (0)| 00:00:01 |       |    |
    |   1 |  SORT AGGREGATE            |               |     1 |    39 |            |          |       |    |
    |   2 |   NESTED LOOPS             |               |     1 |    39 |     4   (0)| 00:00:01 |       |    |
    |   3 |    INDEX FAST FULL SCAN    | SYS_C00247890 |     1 |    13 |     2   (0)| 00:00:01 |       |    |
    |   4 |    PARTITION RANGE ITERATOR|               |     1 |    26 |     2   (0)| 00:00:01 |   KEY |   KEY |
    |*  5 |     TABLE ACCESS FULL      | YEARLY_FACT_T |     1 |    26 |     2   (0)| 00:00:01 |   KEY |   KEY |
    Predicate Information (identified by operation id):
       5 - filter("A"."YEAR_KEY"="B"."CURR_YEAR")The following query is where I have my problem.
    The basic xplan is the same, but for some reason the cbo gave up and decide to scan all partitions, which was not very scalable on production data :)
    I would have thought that the plan would be the same.
    select sum(decode(a.year_key, b.curr_year, some_measure)) as curr_year_measure
          ,sum(decode(a.year_key, b.prev_year, some_measure)) as prev_year_measure
      from yearly_fact_t a
          ,current_year  b
    where a.year_key = b.curr_year
        or a.year_key = b.prev_year;
    | Id  | Operation             | Name          | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
    |   0 | SELECT STATEMENT      |               |     1 |    52 |    13   (0)| 00:00:01 |       |       |
    |   1 |  SORT AGGREGATE       |               |     1 |    52 |            |          |       |       |
    |   2 |   NESTED LOOPS        |               |     4 |   208 |    13   (0)| 00:00:01 |       |       |
    |   3 |    TABLE ACCESS FULL  | CURRENT_YEAR  |     1 |    26 |     4   (0)| 00:00:01 |       |       |
    |   4 |    PARTITION RANGE ALL|               |     4 |   104 |     9   (0)| 00:00:01 |     1 |     6 |
    |*  5 |     TABLE ACCESS FULL | YEARLY_FACT_T |     4 |   104 |     9   (0)| 00:00:01 |     1 |     6 |
    Predicate Information (identified by operation id):
       5 - filter("A"."YEAR_KEY"="B"."CURR_YEAR" OR "A"."YEAR_KEY"="B"."PREV_YEAR")
    -- drop table yearly_fact_t purge;
    -- drop table current_year  purge;
    create table current_year(
       curr_year number(4) not null
      ,prev_year number(4) not null
      ,next_year number(4) not null
      ,primary key(curr_year)
      ,unique(prev_year)
      ,unique(next_year)
    insert into current_year(curr_year, prev_year, next_year) values(2010, 2009, 2011);
    commit;
    create table yearly_fact_t(
       year_key     number(4) not null
      ,some_dim_key number    not null
      ,some_measure number    not null
    partition by range(year_key)(
       partition p2007 values less than(2008)
      ,partition p2008 values less than(2009)
      ,partition p2009 values less than(2010)
      ,partition p2010 values less than(2011)
      ,partition p2011 values less than(2012) 
      ,partition pmax  values less than(maxvalue)
    insert into yearly_fact_t(year_key, some_dim_key, some_measure) values(2007,1, 10);
    insert into yearly_fact_t(year_key, some_dim_key, some_measure) values(2008,1, 20);
    insert into yearly_fact_t(year_key, some_dim_key, some_measure) values(2009,1, 30);
    insert into yearly_fact_t(year_key, some_dim_key, some_measure) values(2010,1, 40);
    commit; What can I do to get partition pruning to happen in the second query?
    Or even better, what is it in my query that prevents it from happening?
    We're running Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit.
    Best regards
    Ronnie

    Hi Ronnie,
    Check whether your statistics are up to date.
    SQL> set autotrace traceonly exp
    SQL> select sum(decode(a.year_key, b.curr_year, some_measure)) as curr_year_measure
      2        ,sum(decode(a.year_key, b.prev_year, some_measure)) as prev_year_measure
      3    from yearly_fact_t a
      4        ,current_year  b
      5   where a.year_key = b.curr_year
      6      or a.year_key = b.prev_year;
    Execution Plan
    Plan hash value: 229094315
    | Id  | Operation             | Name          | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
    |   0 | SELECT STATEMENT      |               |     1 |    52 |    10   (0)| 00:00:01 |       |       |
    |   1 |  SORT AGGREGATE       |               |     1 |    52 |            |          |       |       |
    |   2 |   NESTED LOOPS        |               |     4 |   208 |    10   (0)| 00:00:01 |       |       |
    |   3 |    TABLE ACCESS FULL  | CURRENT_YEAR  |     1 |    26 |     3   (0)| 00:00:01 |       |       |
    |   4 |    PARTITION RANGE ALL|               |     4 |   104 |     7   (0)| 00:00:01 |     1 |     6 |
    |*  5 |     TABLE ACCESS FULL | YEARLY_FACT_T |     4 |   104 |     7   (0)| 00:00:01 |     1 |     6 |
    Predicate Information (identified by operation id):
       5 - filter("A"."YEAR_KEY"="B"."CURR_YEAR" OR "A"."YEAR_KEY"="B"."PREV_YEAR")
    Note
       - dynamic sampling used for this statement
    SQL> set autotrace off
    SQL> exec dbms_stats.gather_table_stats(user, 'current_year', estimate_percent=>100, cascade=>true, method_opt
    =>'for all columns size 1');
    PL/SQL procedure successfully completed.
    SQL>
    SQL> exec dbms_stats.gather_table_stats(user, 'yearly_fact_t', estimate_percent=>100, cascade=>true, method_op
    t=>'for all columns size 1');
    PL/SQL procedure successfully completed.
    SQL> set autotrace traceonly exp
    SQL> select sum(decode(a.year_key, b.curr_year, some_measure)) as curr_year_measure
      2        ,sum(decode(a.year_key, b.prev_year, some_measure)) as prev_year_measure
      3    from yearly_fact_t a
      4        ,current_year  b
      5   where a.year_key = b.curr_year
      6      or a.year_key = b.prev_year;
    Execution Plan
    Plan hash value: 2253546831
    | Id  | Operation                   | Name          | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
    |   0 | SELECT STATEMENT            |               |     1 |    15 |     8   (0)| 00:00:01 |       |       |
    |   1 |  SORT AGGREGATE             |               |     1 |    15 |            |          |       |       |
    |   2 |   CONCATENATION             |               |       |       |            |          |       |       |
    |   3 |    NESTED LOOPS             |               |     1 |    15 |     4   (0)| 00:00:01 |       |       |
    |   4 |     TABLE ACCESS FULL       | CURRENT_YEAR  |     1 |     8 |     3   (0)| 00:00:01 |       |       |
    |   5 |     PARTITION RANGE ITERATOR|               |     1 |     7 |     1   (0)| 00:00:01 |   KEY |   KEY |
    |*  6 |      TABLE ACCESS FULL      | YEARLY_FACT_T |     1 |     7 |     1   (0)| 00:00:01 |   KEY |   KEY |
    |   7 |    NESTED LOOPS             |               |     1 |    15 |     4   (0)| 00:00:01 |       |       |
    |   8 |     TABLE ACCESS FULL       | CURRENT_YEAR  |     1 |     8 |     3   (0)| 00:00:01 |       |       |
    |   9 |     PARTITION RANGE ITERATOR|               |     1 |     7 |     1   (0)| 00:00:01 |   KEY |   KEY |
    |* 10 |      TABLE ACCESS FULL      | YEARLY_FACT_T |     1 |     7 |     1   (0)| 00:00:01 |   KEY |   KEY |
    Predicate Information (identified by operation id):
       6 - filter("A"."YEAR_KEY"="B"."PREV_YEAR")
      10 - filter("A"."YEAR_KEY"="B"."CURR_YEAR" AND LNNVL("A"."YEAR_KEY"="B"."PREV_YEAR"))
    SQL> set autotrace off
    SQL>Asif Momen
    http://momendba.blogspot.com

  • Nested Loop and Driving Table.

    In the documentation I read these (/B19306_01/server.102/b14211/optimops.htm#i82080).
    The optimizer uses nested loop joins when joining small number of rows, with a good driving condition between the two tables. You drive from the outer loop to the inner loop, so the order of tables in the execution plan is important.
    The outer loop is the driving row source. It produces a set of rows for driving the join condition. The row source can be a table accessed using an index scan or a full table scan. Also, the rows can be produced from any other operation. For example, the output from a nested loop join can be used as a row source for another nested loop join.>
    I need some help to understand the bold line, i.e. so the order of tables in the execution plan is important.
    There are various conflicting opinion about the driving table (some says smaller and some says larger table is good option) and unfortunately I did not understand any of those logic.
    I read these threads/blogs also.
    CBO (optimizer) nest-loop join question
    http://hoopercharles.wordpress.com/2011/03/21/nested-loops-join-the-smaller-table-is-the-driving-table-the-larger-table-is-the-driving-table/
    In practice, I have seen explain plan for select e.ename,d.dname
      2  from emp e, dept d
      3  where e.deptno=d.deptno; usages emp as driving table (I only understood part of Aman's logic that dept table access would be faster when there would be an index available over it and hence it is in the inner loop)
    Whereas, SQL> explain plan for
      2  select e.ename,d.dname
      3  from emp e, dept d
      4  where e.deptno=d.deptno
      5  and e.deptno=20; usages dept as driving table.
    I have use USE_NL_WITH_INDEX with LEADING hint to change it, but it is giving some adverse effect (sometimes with optimizer_mode ALL_ROWS it is ignoring the hint completely).
    so the order of tables in the execution plan is important. How can I determine it ? I have read Tom's effective oracle by design but there is also no solution.

    Not sure I quite understand the question.
    Both threads contain lots of useful information about the broad considerations in play and debunking any myths.
    I need some help to understand the bold line, i.e.
    "so the order of tables in the execution plan is important"I read this as meaning just what it says, i.e. read the execution plan carefully and that
    NESTED LOOP
      A
      Bis not the same as
    NESTED LOOP
      B
      AA 10053 trace would normally be quite verbose about it's considerations as to join order.

  • Need nested loop's solution....

    hi..
    i have done following coding for my one senario..i've used nested loop.but can anyone pls give me other solution than nested loop statement?
    i dont wnat to use nested loop...
    SELECT WI_ID WI_STAT WI_CD WI_AAGENT FROM SWWWIHEAD           "FETCHING WORK ITEM DATA FROM THE SWWWIHEAD
        INTO TABLE IT_SWWWIHEAD
        WHERE WI_CD IN SO_WI_CD.
      SORT IT_SWWWIHEAD.
      IF SY-SUBRC = 0.
      <b>  LOOP AT IT_SWWWIHEAD INTO WA_SWWWIHEAD.</b>
          CALL FUNCTION 'SWI_GET_DEPENDENT_WORKITEMS'      "FUNCTION MODULE TO GET DEPENDENT WORK ITEM ID, IF ANY.
            EXPORTING
              WI_ID         = WA_SWWWIHEAD-WI_ID
            TABLES
              DEPENDENT_WIS = IT_SWWWIHEAD_D.
          IF IT_SWWWIHEAD_D IS NOT INITIAL.
            DELETE IT_SWWWIHEAD_D WHERE WI_TYPE <> 'W'.
            SORT IT_SWWWIHEAD_D.
          <b>  LOOP AT IT_SWWWIHEAD_D INTO WA_SWWWIHEAD_D.</b>
              CALL FUNCTION 'SAP_WAPI_READ_CONTAINER'          "FUNCTION MODULE TO GET DATA FROM EVERY DEPENDENT ID.
                EXPORTING
                  WORKITEM_ID                    = WA_SWWWIHEAD_D-WI_ID
                LANGUAGE                       = SY-LANGU
                USER                           = SY-UNAME
              IMPORTING
                RETURN_CODE                    =
                IFS_XML_CONTAINER              =
                IFS_XML_CONTAINER_SCHEMA       =
               TABLES
                 SIMPLE_CONTAINER               = IT_SIM_CONT
               MESSAGE_LINES                  =
               MESSAGE_STRUCT                 =
               SUBCONTAINER_BOR_OBJECTS       =
                SUBCONTAINER_ALL_OBJECTS       = IT_SUBCONTAINER
              READ TABLE IT_SIM_CONT
                  INTO WA_SIM_CONT WITH KEY ELEMENT = '_WI_RESULT'.        "getting the result(approved or rejected).
              IF SY-SUBRC = 0.
                IF wa_sim_cont-value = '0001'.
                  WA_FINAL-WI_STAT = 'APPROVED'.
                ELSEIF WA_SIM_CONT-VALUE = '0002'.
                  WA_FINAL-WI_STAT = 'REJECTED'.
                ENDIF.
              ENDIF.
              READ TABLE IT_SUBCONTAINER
                  INTO WA_SUBCONTAINER WITH KEY ELEMENT = 'SODATA'.  "getting SO DOCUMENT for this workitem.
              IF SY-SUBRC = 0.
                WA_FINAL-WI_AAGENT    = WA_SWWWIHEAD_D-WI_AAGENT.
              ENDIF.
                WA_FINAL-WI_ID        = WA_SWWWIHEAD-WI_ID.
                WA_FINAL-WI_ID_D      = WA_SWWWIHEAD_D-WI_ID.
                WA_FINAL-WI_CD        = WA_SWWWIHEAD-WI_CD.
                WA_FINAL-WI_SO        = wa_subcontainer-value+0(10).
                WA_FINAL-WI_RESULT    = WA_SIM_CONT-VALUE.
                SELECT SINGLE VKORG MAHDT FROM VBAK
                  INTO (VKORG, MAHDT)
                  WHERE VBELN = WA_FINAL-WI_SO.
                IF SY-SUBRC = 0.
                  WA_FINAL-WI_VKORG = VKORG.
                  IF MAHDT <> '00000000'.
                    WA_FINAL-WI_FINAL_RESULT = 'OK'.
                  ELSE.
                    WA_FINAL-WI_FINAL_RESULT = 'PENDING'.
                  ENDIF.
                ENDIF.
                APPEND WA_FINAL TO IT_FINAL.
                CLEAR WA_FINAL.
       <b>     ENDLOOP.</b>
            CLEAR IT_SWWWIHEAD_D[].
            CLEAR IT_SIM_CONT[].
          ENDIF.
      <b>  ENDLOOP.</b>  ENDIF.

    hi sagar,
    Pls go through the following explanations for understanding abt control level processing.
    Control level processing is allowed within a LOOP over an internal table. This means that you can divide sequences of entries into groups based on the contents of certain fields.
    Internal tables are divided into groups according to the sequence of the fields in the line structure. The first column defines the highest control level and so on. The control level hierarchy must be known when you create the internal table.
    The control levels are formed by sorting the internal table in the sequence of its structure, that is, by the first field first, then by the second field, and so on. Tables in which the table key occurs at the start of the table are particularly suitable for control level processing.
    The following diagram illustrates control level processing in a sorted table, where different field contents in the first three fields are indicated by different colors:
    Each change of color in a column indicates a control level change in the corresponding hierarchy level. Within the processing block of a loop, you can use the control level statement AT to react to a control level change. This enables you to restrict statements to a certain set of lines. You can thus use the SUM statement to calculate totals from subsets of all lines.
    The AT statement introduces a statement block that you end with the ENDAT statement.
    AT <level>.
      <statement block>
    ENDAT.
    You can react to the following control level changes:
    <level>
    Meaning
    FIRST
    First line of the internal table
    LAST
    Last line of the internal table
    NEW <f>
    Beginning of a group of lines with the same contents in the field <f> and in the fields left of <f>
    END Of <f>
    End of a group of lines with the same contents in the field <f> and in the fields left of <f>
    You can use control level statements to react to control breaks in internal tables instead of programming them yourself with logical expressions. Within the loop, you must order the AT-ENDAT statement blocks according to the hierarchy of the control levels. If the internal table has the columns <f1>, <f 2>, ...., and if it is sorted by these columns, you must program the loop as follows:
    LOOP AT <itab>.
      AT FIRST. ... ENDAT.
        AT NEW <f1>. ...... ENDAT.
          AT NEW <f2 >. ...... ENDAT.
              <single line processing>
          AT END OF <f2>. ... ENDAT.
        AT END OF <f1>. ... ENDAT.
      AT LAST. .... ENDAT.
    ENDLOOP.
    The innermost hierarchy level <single line processing> processes the table lines that do not correspond to a control level change. You do not have to use all control level statements. But you must place the used ones in the above sequence. You should not use control level statements in loops where the line selection is restricted by WHERE or FROM and TO. Neither should the table be modified during the loop.
    If a control level field <fi> is not known until runtime, you can specify it dynamically as (<n i>) where <n i> contains the field of <f i>. If <n i> is empty at runtime, the criterion for changing the control level is ignored. You can restrict the search to partial fields by specifying offset and length.
    If you are working with a work area <wa>, it does not contain the current line in the AT... ENDAT statement block. All character fields to the right of the current group key are filled with asterisks (*). All other fields to the right of the current group key contain their initial value.
    Within an AT...ENDAT block, you can calculate the contents of the numeric fields of the corresponding control level using the SUM statement.
    SUM.
    You can only use this statement within a LOOP. If you use SUM in an AT - ENDAT block, the system calculates totals for the numeric fields of all lines in the current line group and writes them to the corresponding fields in the work area (see example in ). If you use the SUM statement outside an AT - ENDAT block (single entry processing), the system calculates totals for the numeric fields of all lines of the internal table in each loop pass and writes them to the corresponding fields of the work area. It therefore only makes sense to use the SUM statement in AT...ENDAT blocks.
    If the table contains a nested table, you cannot use the SUM statement. Neither can you use it if you are using a field symbol instead of a work area in the LOOP statement.
    Examples
    DATA: BEGIN OF LINE,
             COL1 TYPE C,
             COL2 TYPE I,
             COL3 TYPE I,
          END OF LINE.
    DATA ITAB LIKE HASHED TABLE OF LINE
              WITH UNIQUE KEY COL1 COL2.
    LINE-COL1 = 'A'.
    DO 3 TIMES.
      LINE-COL2 = SY-INDEX.
      LINE-COL3 = SY-INDEX ** 2.
      INSERT LINE INTO TABLE ITAB.
    ENDDO.
    LINE-COL1 = 'B'.
    DO 3 TIMES.
      LINE-COL2 = 2 * SY-INDEX.
      LINE-COL3 = ( 2 * SY-INDEX ) ** 2.
      INSERT LINE INTO TABLE ITAB.
    ENDDO.
    SORT ITAB.
    LOOP AT ITAB INTO LINE.
      WRITE: / LINE-COL1, LINE-COL2, LINE-COL3.
      AT END OF COL1.
        SUM.
        ULINE.
        WRITE: / LINE-COL1, LINE-COL2, LINE-COL3.
        SKIP.
      ENDAT.
      AT LAST.
        SUM.
        ULINE.
        WRITE: / LINE-COL1, LINE-COL2, LINE-COL3.
      ENDAT.
    ENDLOOP.
    The output is:
    A 1 1
    A 2 4
    A          3          9
    A          6         14
    B          2          4
    B 4 16
    B 6 36
    B         12         56
            18         70
    The program creates a hashed table ITAB, fills it with six lines, and sorts it. In the LOOP - ENDLOOP block, the work area LINE is output for each loop pass. The first field of the table key, COL1, is used for control level processing. The total for all numeric fields is always calculated when the contents of COL1 change and when the system is in the last loop pass.
    DATA: BEGIN OF LINE,
            CARRID   TYPE SBOOK-CARRID,
            CONNID   TYPE SBOOK-CONNID,
            FLDATE   TYPE SBOOK-FLDATE,
            CUSTTYPE TYPE SBOOK-CUSTTYPE,
            CLASS    TYPE SBOOK-CLASS,
            BOOKID   TYPE SBOOK-BOOKID,
          END OF LINE.
    DATA ITAB LIKE SORTED TABLE OF LINE WITH UNIQUE KEY TABLE LINE.
    SELECT CARRID CONNID FLDATE CUSTTYPE CLASS BOOKID
           FROM SBOOK INTO CORRESPONDING FIELDS OF TABLE ITAB.
    LOOP AT ITAB INTO LINE.
      AT FIRST.
        WRITE / 'List of Bookings'.
        ULINE.
      ENDAT.
        AT NEW CARRID.
          WRITE: / 'Carrid:', LINE-CARRID.
        ENDAT.
          AT NEW CONNID.
            WRITE: / 'Connid:', LINE-CONNID.
          ENDAT.
            AT NEW FLDATE.
              WRITE: / 'Fldate:', LINE-FLDATE.
            ENDAT.
              AT NEW CUSTTYPE.
                WRITE: / 'Custtype:', LINE-CUSTTYPE.
              ENDAT.
                   WRITE: / LINE-BOOKID, LINE-CLASS.
                AT END OF CLASS.
                  ULINE.
                ENDAT.
    ENDLOOP.
    In this example, the sorted internal table ITAB is filled with data from the database table SBOOK using the Open SQL statement SELECT. The sequence of the columns in the internal table defines the control level hierarchy. Since the table key is the entire line, the sort sequence and the control level hierarchy are the same. The sequence of the AT-ENDAT blocks within the LOOP and ENDLOOP statements is important.
    The output is as follows:
    List of Bookings
    Carrid: AA
    Connid: 0017
    Fldate: 1998/11/22
    Custtype: B
    00063509 C
    00063517 C
    00063532 F
    00063535 F
    Custtype: P
    00063653 C
    00063654 C
    00063668 F
    00063670 F
    Fldate: 1998/29/11
    Custtype: B
    00064120 C
    00064121 C
    and so on.
    <b>pls reward if helpful.</b>

  • CBO (optimizer) nest-loop join question

    OS: Red Hat Linux
    DB: 11gR1
    I have gotten two conflicting answers while reading books by Don Burleson and Dan Hotka. It has to do with the CBO and nested-joins:
    One says the CBO will choose the 'smaller' table as the driving table, the other states that the 'larger' table will be the driving table. And both stick by this philosophy as the preferred goal of any SQL Tuning -- that is, one states that the 'smaller' table should be the driving table. The other says the 'larger' table should be the driving table.
    I had always thought that the 'smaller' table should be the driving table. That in a nested loop the driving will not likely use an index even. Who is correct? (I am not going to say who said what, btw). :-)
    But I got to let one of them know they got a 'typo' ... :-)
    Thx.

    user601798 wrote:
    It is an over-simplistic scenario but, as I mentioned, if all other things are 'equal' -- which would include 'access time/work', then I think the small table as the driving table has the advantage.
    It is not possible for +"*all* other things to be equal"+. (my emphasis).
    If by +'access time/work'+ you mean the total is the same then it doesn't matter which table is first, the time/work is the same either way round.
    If you want to say that the +'access time/work'+ for acquiring the first rowsource is the same for both paths, and the +'access time/work'+ for acquiring related rows from the second table is the same FOR EACH DRIVING ROW, then the total +'access time/work'+ will be difference, and it would be better to start with the smaller table. (The example by Salman Qureshi above: Re: CBO (optimizer) nest-loop join question would apply.)
    On the other hand, and ignoring any idea of "all other things being equal", smaller tables tend to have smaller indexes, so if your smaller rowsource comes from a smaller table then acquiring those rows may be cheaper than acquiring rows from a larger table - which leads to the observation that (even with perfectly precise indexing):
    <ul>
    smaller number of rows * larger unit cost to find related rows
    </ul>
    may produce a larger value than
    <ul>
    larger number of rows * smaller unit cost to find related rows
    </ul>
    Regards
    Jonathan Lewis
    http://jonathanlewis.wordpress.com
    http://www.jlcomp.demon.co.uk
    A general reminder about "Forum Etiquette / Reward Points": http://forums.oracle.com/forums/ann.jspa?annID=718
    If you never mark your questions as answered people will eventually decide that it's not worth trying to answer you because they will never know whether or not their answer has been of any use, or whether you even bothered to read it.
    It is also important to mark answers that you thought helpful - again it lets other people know that you appreciate their help, but it also acts as a pointer for other people when they are researching the same question, moreover it means that when you mark a bad or wrong answer as helpful someone may be prompted to tell you (and the rest of the forum) what's so bad or wrong about the answer you found helpful.

  • Alternative for nested loops

    Hi Gurus,
    I have the following problem :
    There are 2 internal tables namely 1 &2.
    Now there is a field in table 1 'AUGBL' which should be equal to  field in Table2-BELNR.
    Now if there is a match between TABLE1-AUGBL and TABLE2-BELNR,
    so we move to table 2 to look for 'augbl' associated with 'belnr' in the same table.
    Then I have to give the following logic -
    If table2-belnr = table2-augbr,
       Then do nothing.
    Else.
    Check, for the Augbl which will equal Belnr in a different position in table 2.
    For ex:
    Table1-AUGBL = 2.
    So now we have to search a field when Table1-augbl = Table2-belnr = 2.
    Now for this record in table2, there are 2 conditions:
    When Table2-augbl = 2, (in which case we do nothing)
    or,
    Table2-augbl NE 2, or Table2-augbl = 3.
    In the latter case,  there will be another field in Table2-BELNR = 3. So we go to this record now and check for the associated AUGBL and do the same checks above.
    We keep on continuing for this till the time we do not get the Table2-belnr = Table2-augbl in the end for the same record.
    Now I want to achieve this without using nested loop.
    Kindly help as I already have wated a lot of time.
    Please let me know if there are any clarifications.

    Hey..
    Before u get the data into two internal tables through SELECT stmts.
    U can use JOIN instead of two SELECT stmts ..that wud fetch the data into single internal table..
    and that may ease ur validations and further process..
    try this out..
    Thanks and Regards,
    KC

  • Bulk collect with Nested loops

    Hi I've a requirement like this
    I need to pull request nos from table a(Master table)
    For every request no I need to pull request details from table b(Detail Table)
    For every request no I need to pull contact details from table c
    For every request no I need to pull customer data table d and I need to create a flat file with that data so I'm using utl_file in normal query criterion because of nested loops it's taking lot of time so I want to use bulk collect with dynamic query option:
    Sample code
    =======
    create or replace procedure test(region varchar2) as
    type tablea_request_typ is table of varchar2(10);
    tablea_data tablea_request_typ;
    type tableb_request_typ is table of varchar2(1000);
    tableb_data tableb_request_typ;
    type tablec_request_typ is table of varchar2(1000);
    tablec_data tablec_request_typ;
    type tabled_request_typ is table of varchar2(1000);
    tabled_data tabled_request_typ;
    stmta varchar2(32000);
    stmtb varchar2(32000);
    stmtc varchar2(32000);
    stmtd varchar2(32000);
    rcura SYS_REFCURSOR;
    rcurb SYS_REFCURSOR;
    rcurc SYS_REFCURSOR;
    rcurd SYS_REFCURSOR;
    begin
    stmta:='select  request_no from tablea where :region'||'='NE';
    stmtb:='select  request_no||request_detail1||request_detail2 stringb  from table b where :region'||'='NE';
    stmtc:='select contact1||contact2||contact3||contact4  stringc from table c where :region'||'='NE';
    stmtd:='select customer1||customer2||customer3||customer4  stringd  from table c where :region'||'='NE';
    OPEN rcura for stmta;
      LOOP
      FETCH rcura BULK COLLECT INTO request_no
      LIMIT 1000;
      FOR  f in 1..request_no.count
    LOOP
    --Tableb
        OPEN rcurb for stmtb USING substr(request_no(f),1,14);
      LOOP
      FETCH rcurb BULK COLLECT INTO tableb_data
    for i in 1..tableb_data.count
    LOOP
    utl_file(...,tableb_data(i));
    END LOOP;
        EXIT WHEN rcurb%NOTFOUND;
      END LOOP;
    -- Tablec
    OPEN rcurc for stmtc USING substr(request_no(f),1,14);
      LOOP
      FETCH rcurb BULK COLLECT INTO tablec_data
    for i in 1..tablec_data.count
    LOOP
    utl_file(...,tablec_data(i));
    END LOOP;
        EXIT WHEN rcurc%NOTFOUND;
      END LOOP;
    -- Tabled
    OPEN rcurd for stmtd USING substr(request_no(f),1,14);
      LOOP
      FETCH rcurd BULK COLLECT INTO tabled_data
    for i in 1..tabled_data.count
    LOOP
    utl_file(...,tabled_data(i));
    END LOOP;
        EXIT WHEN rcurd%NOTFOUND;
      END LOOP;
      END LOOP;
        EXIT WHEN rcura%NOTFOUND;
      END LOOP;
    exception
    when other then
    dbms_output.put_line(sqlerrm);
    end;I 'm using code mentioned above but request nos are repeating as if it's an infinete loop ?for ex if request no is 222 It should run once but here it's running more than once?
    How to pass bind parameters say in my case region?
    Are there any alternate solutions to run it faster apart from using bulk collect?
    Right now I'm using explicit cursor with for loop which is taking lot of time ?so is this better sol?
    Thanks,
    Mahender
    Edited by: BluShadow on 24-Aug-2011 08:52
    added {noformat}{noformat} tags. Please read {message:id=9360002} to learn to format your code/data yourself.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

        Use Parameterized cursor :
    CREATE OR REPLACE PROCEDURE test(region varchar2)
    AS
      type tablea_request_typ is table of varchar2(10);
      type tableb_request_typ is table of varchar2(1000); 
      type tablec_request_typ is table of varchar2(1000);
      type tabled_request_typ is table of varchar2(1000);
      tablea_data tablea_request_typ;
      tableb_data tableb_request_typ;
      tablec_data tablec_request_typ;
      tabled_data tabled_request_typ;
       CURSOR rcura(v_region  VARCHAR2(100))
       IS
       select  request_no from tablea where region = v_region;
       CURSOR rcurb(v_input  VARCHAR2(100))
       IS
       select  request_no||request_detail1||request_detail2 stringb  from table b where request_num = v_input;
       CURSOR rcurc(v_input  VARCHAR2(100))
       IS
       select  select contact1||contact2||contact3||contact4  stringc from table c where request_num = v_input;
       CURSOR rcurd(v_input  VARCHAR2(100))
       IS
       select  select customer1||customer2||customer3||customer4  stringd  from table c where request_num = v_input;
    BEGIN
    OPEN rcura('NE');
    LOOP
        FETCH rcura BULK COLLECT INTO request_no  LIMIT 1000;
        FOR  f in 1..request_no.count
        LOOP
           --Tableb
           OPEN rcurb(substr(request_no(f),1,14));
           LOOP
              FETCH rcurb BULK COLLECT INTO tableb_data
              for i in 1..tableb_data.count
              LOOP
                  utl_file(...,tableb_data(i));
              END LOOP;
              EXIT WHEN rcurb%NOTFOUND;
           END LOOP;
           -- Tablec
           OPEN rcurc (substr(request_no(f),1,14));
           LOOP
              FETCH rcurb BULK COLLECT INTO tablec_data
              for i in 1..tablec_data.count
              LOOP
                 utl_file(...,tablec_data(i));
              END LOOP;
              EXIT WHEN rcurc%NOTFOUND;
           END LOOP;
           -- Tabled
           OPEN rcurd ( substr(request_no(f),1,14) );
           LOOP
              FETCH rcurd BULK COLLECT INTO tabled_data
              for i in 1..tabled_data.count
              LOOP
               utl_file(...,tabled_data(i));
              END LOOP;
              EXIT WHEN rcurd%NOTFOUND;
           END LOOP;
      END LOOP;
    EXIT WHEN rcura%NOTFOUND;
    END LOOP;
    EXCEPTION
    WHEN OTHERS THEN
       dbms_output.put_line(dbms_utility.format_error_backtrace);
    END;
    /Hope this helps. If not, post your table structures...

  • Nested Loop/Repeat Region, PHP

    Hello,
    My conundrum is trying to gather information from 4 different record sets and do some separate nested loops
    There is one record per project
    There is one client per project
    There may be more than one staff member per project
    There may be more that one consultant per project
    The MySQL schema is as follows. ( Sorry but there are 7 of them)
    mysql> describe ND_assign_consultant;
    +---------------+------------------+------+-----+---------+----------------+
    | Field         | Type             | Null | Key | Default | Extra          |
    +---------------+------------------+------+-----+---------+----------------+
    | assign_pro_id | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
    | project_id    | varchar(8)       | NO   |     |         |                |
    | architect_id  | varchar(11)      | NO   |     |         |                |
    +---------------+------------------+------+-----+---------+----------------+
    mysql> describe ND_assign_project;
    +---------------+------------------+------+-----+---------+-------+
    | Field         | Type             | Null | Key | Default | Extra |
    +---------------+------------------+------+-----+---------+-------+
    | assign_pro_id | int(10) unsigned | NO   |     | 0       |       |
    | client_id     | varchar(11)      | YES  |     | NULL    |       |
    | project_id    | varchar(11)      | YES  |     | NULL    |       |
    +---------------+------------------+------+-----+---------+-------+
    mysql> describe ND_assign_staff;
    +--------------+------------------+------+-----+---------+----------------+
    | Field        | Type             | Null | Key | Default | Extra          |
    +--------------+------------------+------+-----+---------+----------------+
    | assign_id    | int(11) unsigned | NO   | PRI | NULL    | auto_increment |
    | project_id   | char(8)          | NO   |     |         |                |
    | staff_id     | char(4)          | NO   |     |         |                |
    | stake_holder | char(1)          | YES  |     | 0       |                |
    +--------------+------------------+------+-----+---------+----------------+
    mysql> describe ND_client;
    +--------------+---------------------------+------+-----+---------+----------------+
    | Field        | Type                      | Null | Key | Default | Extra          |
    +--------------+---------------------------+------+-----+---------+----------------+
    | client_id    | int(10) unsigned zerofill | NO   | PRI | NULL    | auto_increment |
    | title        | varchar(20)               | YES  |     | NULL    |                |
    | first_Cname  | varchar(30)               | NO   |     |         |                |
    | last_Cname   | varchar(30)               | NO   |     |         |                |
    | company      | varchar(80)               | YES  |     | NULL    |                |
    | phone        | varchar(12)               | YES  |     | NULL    |                |
    | mobile       | varchar(12)               | YES  |     | NULL    |                |
    | fax          | varchar(12)               | YES  |     | NULL    |                |
    | email        | varchar(80)               | YES  |     | NULL    |                |
    | road_type    | varchar(20)               | YES  |     | NULL    |                |
    | street       | varchar(100)              | YES  |     | NULL    |                |
    | city         | varchar(80)               | YES  |     | NULL    |                |
    | State        | char(3)                   | YES  |     | NULL    |                |
    | postcode     | varchar(4)                | YES  |     | NULL    |                |
    | int_city     | varchar(80)               | YES  |     | NULL    |                |
    | int_state    | varchar(80)               | YES  |     | NULL    |                |
    | int_postcode | varchar(5)                | YES  |     | NULL    |                |
    | country      | varchar(40)               | YES  |     | NULL    |                |
    | comments     | text                      | YES  |     | NULL    |                |
    +--------------+---------------------------+------+-----+---------+----------------+
    mysql> describe ND_consultant;
    +-----------------+------------------+------+-----+---------+----------------+
    | Field           | Type             | Null | Key | Default | Extra          |
    +-----------------+------------------+------+-----+---------+----------------+
    | architect_id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
    | consultant_type | varchar(40)      | NO   |     |         |                |
    | first_name      | varchar(30)      | YES  |     | NULL    |                |
    | last_name       | varchar(30)      | YES  |     | NULL    |                |
    | company         | varchar(80)      | YES  |     | NULL    |                |
    | licence         | varchar(20)      | YES  |     | NULL    |                |
    | phone           | varchar(12)      | YES  |     | NULL    |                |
    | mobile          | varchar(12)      | YES  |     | NULL    |                |
    | fax             | varchar(12)      | YES  |     | NULL    |                |
    | email           | varchar(80)      | YES  |     | NULL    |                |
    | website         | varchar(150)     | YES  |     | NULL    |                |
    | street          | varchar(100)     | YES  |     | NULL    |                |
    | city            | varchar(80)      | YES  |     | NULL    |                |
    | state           | char(3)          | YES  |     | NULL    |                |
    | postcode        | varchar(4)       | YES  |     | NULL    |                |
    | region          | varchar(40)      | YES  |     | NULL    |                |
    | regular         | char(1)          | YES  |     | NULL    |                |
    +-----------------+------------------+------+-----+---------+----------------+
    17 rows in set (0.00 sec)
    mysql> describe ND_project;
    +----------------+-----------------+------+-----+-------------------+--------------------- --------+
    | Field          | Type            | Null | Key | Default           | Extra                       |
    +----------------+-----------------+------+-----+-------------------+--------------------- --------+
    | project_id     | int(6) unsigned | NO   | PRI | NULL              | auto_increment              |
    | listed         | timestamp       | NO   |     | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
    | deadline       | varchar(25)     | YES  |     | NULL              |                             |
    | contact        | varchar(30)     | YES  |     | NULL              |                             |
    | project_type   | varchar(20)     | YES  |     | NULL              |                             |
    | quote          | decimal(10,0)   | YES  |     | NULL              |                             |
    | invoice        | char(3)         | YES  |     | NULL              |                             |
    | invoice_number | varchar(8)      | YES  |     | NULL              |                             |
    | details        | text            | YES  |     | NULL              |                             |
    | status         | varchar(20)     | YES  |     | NULL              |                             |
    | streetN        | varchar(20)     | YES  |     | NULL              |                             |
    | pro_street     | varchar(100)    | YES  |     | NULL              |                             |
    | pro_city       | varchar(80)     | YES  |     | NULL              |                             |
    | pro_state      | char(3)         | YES  |     | NULL              |                             |
    | pro_postcode   | varchar(4)      | YES  |     | NULL              |                             |
    +----------------+-----------------+------+-----+-------------------+--------------------- --------+
    mysql> describe ND_staff;
    +-------------+----------------------+------+-----+---------+----------------+
    | Field       | Type                 | Null | Key | Default | Extra          |
    +-------------+----------------------+------+-----+---------+----------------+
    | staff_id    | smallint(5) unsigned | NO   | PRI | NULL    | auto_increment |
    | f_name      | varchar(30)          | NO   |     |         |                |
    | l_name      | varchar(30)          | NO   |     |         |                |
    | email       | varchar(80)          | NO   |     |         |                |
    | mobile      | varchar(12)          | NO   |     |         |                |
    | extension   | char(3)              | NO   |     |         |                |
    | username    | varchar(20)          | NO   | UNI |         |                |
    | password    | varchar(16)          | NO   |     |         |                |
    | rate        | int(3) unsigned      | NO   |     | 0       |                |
    | staff1      | char(1)              | YES  |     | NULL    |                |
    | staff2      | char(1)              | YES  |     | NULL    |                |
    | projects1   | char(1)              | YES  |     | NULL    |                |
    | projects2   | char(1)              | YES  |     | NULL    |                |
    | clients     | char(1)              | YES  |     | NULL    |                |
    | revisions1  | char(1)              | YES  |     | NULL    |                |
    | revisions2  | char(1)              | YES  |     | NULL    |                |
    | consultants | char(1)              | YES  |     | NULL    |                |
    | access      | char(1)              | YES  |     | NULL    |                |
    +-------------+----------------------+------+-----+---------+----------------+
    I tried to attach the php file and the CSS but they're not allowed.
    Record Sets:
    <?php
    mysql_select_db($database_neilly_davies, $neilly_davies);
    $query_qProject = "SELECT project_id, listed, quote, status, streetN, pro_street, pro_city FROM ND_project WHERE status ='In Progress' OR 'Quote'";
    $qProject = mysql_query($query_qProject, $neilly_davies) or die(mysql_error());
    $row_qProject = mysql_fetch_assoc($qProject);
    $totalRows_qProject = mysql_num_rows($qProject);
    mysql_select_db($database_neilly_davies, $neilly_davies);
    $query_qClient = "SELECT ND_client.client_id, ND_client.first_Cname, ND_client.last_Cname, ND_client.company, ND_assign_project.client_id, ND_assign_project.project_id FROM ND_client, ND_assign_project, ND_project WHERE ND_project.project_id = ND_assign_project.project_id AND ND_client.client_id = ND_assign_project.client_id";
    $qClient = mysql_query($query_qClient, $neilly_davies) or die(mysql_error());
    $row_qClient = mysql_fetch_assoc($qClient);
    $totalRows_qClient = mysql_num_rows($qClient);
    mysql_select_db($database_neilly_davies, $neilly_davies);
    $query_qStaff = "SELECT ND_staff.staff_id, ND_staff.f_name, ND_staff.l_name, ND_assign_staff.staff_id, ND_assign_staff.project_id, ND_assign_staff.stake_holder, ND_project.project_id FROM ND_staff, ND_assign_staff, ND_project WHERE ND_staff.staff_id = ND_assign_staff.staff_id AND ND_assign_staff.project_id = ND_project.project_id";
    $qStaff = mysql_query($query_qStaff, $neilly_davies) or die(mysql_error());
    $row_qStaff = mysql_fetch_assoc($qStaff);
    $totalRows_qStaff = mysql_num_rows($qStaff);
    mysql_select_db($database_neilly_davies, $neilly_davies);
    $query_qConsultant = "SELECT ND_consultant.architect_id, ND_consultant.first_name, ND_consultant.last_name, ND_consultant.company, ND_assign_consultant.architect_id, ND_assign_consultant.project_id FROM ND_consultant, ND_assign_consultant WHERE ND_consultant.architect_id = ND_assign_consultant.architect_id";
    $qConsultant = mysql_query($query_qConsultant, $neilly_davies) or die(mysql_error());
    $row_qConsultant = mysql_fetch_assoc($qConsultant);
    $totalRows_qConsultant = mysql_num_rows($qConsultant);
    ?>
    Table requiring the nested loops:
          <tr valign="top">
            <th width="90" align="left"><?php echo $row_qProject['project_id']; ?> </th>
            <td width="90" align="left"><?php echo $row_qProject['status']; ?></td>
            <td align="left"><?php echo $row_qProject['pro_street']; ?> <?php echo $row_qProject['streetN']; ?> <?php echo $row_qProject['pro_city']; ?></td>
            <td align="left"><?php echo $row_qClient['first_Cname']; ?> <?php echo $row_qClient['first_Cname']; ?><br />
                <?php echo $row_qClient['company']; ?></td>
            <td align="left"><?php echo $row_qProject['listed']; ?></td>
            <td width="6">$</td>
            <td align="right"><?php echo $row_qProject['quote']; ?></td>
            <td align="left"><?php echo $row_qStaff['f_name']; ?> <?php echo $row_qStaff['l_name']; ?></td>
            <td align="left"><?php echo $row_qStaff['stake_holder']; ?> </td>
            <td align="left"><?php echo $row_qConsultant['first_name']; ?> <?php echo $row_qConsultant['last_name']; ?><br />
                <?php echo $row_qConsultant['company']; ?> </td>
          </tr>
    <tr>
    Thanks in advance if you can point me in the right direction.
    Steve

    Tom Muck has a free Dreamweaver extension that does this: http://www.tom-muck.com/extensions/help/HorizontalLooper/. There's also a reasonably priced commercial version that does more. The link to the commercial version is at the bottom of the page on Tom's site.

  • Nested Loop in Oracle 11g

    Hi All,
    I recently upgraded my Oracle DB from 10.2.0.4 to 11.2.0.3 on Aix 6.1
    My below query is very slow after the upgrade
    select count(*) from v$lock where block > 0;
    I compared the explain plan and found that in 11g its using HASH JOIN while in 10g its using Nested Loop
    When I am giving NL hint in 11g its returning fast.
    I check almost all optimizer related DB parameters and its all are same as it in 10g.
    Has anyone faced this issue in your DB upgrade or help me to find the reason
    Thanks in advance

    user12207083 wrote:
    Thanks
    But how come explan plan change for dynamic views
    ThanksOrdered hint used in case of that query extracting from multiple tables, To define driving of that particular tables.
    There are changes in explain plan. Am in learning stage in PT, You can expect response from Jonathan Lewis
    Am just comparing those two explain plans.
    SQL> set timing on
    SQL> select count(*) from v$lock t1;
      COUNT(*)
           168
    Elapsed: 00:00:00.01
    SQL> select /*+ ordered */ count(*) from v$lock;
      COUNT(*)
           168
    Elapsed: 00:00:00.02
    SQL>
    SQL> set autotrace traceonly explain;
    SQL> set line 500
    SQL> select count(*) from v$lock t1;
    Elapsed: 00:00:00.00
    Execution Plan                          "Without HINT"
    Plan hash value: 2329815124
    | Id  | Operation                 | Name            | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT          |                 |     1 |    50 |     1 (100)| 00:00:01 |
    |   1 |  SORT AGGREGATE           |                 |     1 |    50 |            |          |
    |   2 |   NESTED LOOPS            |                 |     1 |    50 |     1 (100)| 00:00:01 |
    |*  3 |    HASH JOIN              |                 |     1 |    44 |     1 (100)| 00:00:01 |
    |*  4 |     FIXED TABLE FULL      | X$KSUSE         |     1 |    19 |     0   (0)| 00:00:01 |
    |   5 |     VIEW                  | GV$_LOCK        |    10 |   250 |     0   (0)| 00:00:01 |
    |   6 |      UNION-ALL            |                 |       |       |            |          |
    |*  7 |       FILTER              |                 |       |       |            |          |
    |   8 |        VIEW               | GV$_LOCK1       |     2 |   178 |     0   (0)| 00:00:01 |
    |   9 |         UNION-ALL         |                 |       |       |            |          |
    |* 10 |          FIXED TABLE FULL | X$KDNSSF        |     1 |   102 |     0   (0)| 00:00:01 |
    |* 11 |          FIXED TABLE FULL | X$KSQEQ         |     1 |   102 |     0   (0)| 00:00:01 |
    |* 12 |       FIXED TABLE FULL    | X$KTADM         |     1 |   102 |     0   (0)| 00:00:01 |
    |* 13 |       FIXED TABLE FULL    | X$KTATRFIL      |     1 |   102 |     0   (0)| 00:00:01 |
    |* 14 |       FIXED TABLE FULL    | X$KTATRFSL      |     1 |   102 |     0   (0)| 00:00:01 |
    |* 15 |       FIXED TABLE FULL    | X$KTATL         |     1 |   102 |     0   (0)| 00:00:01 |
    |* 16 |       FIXED TABLE FULL    | X$KTSTUSC       |     1 |   102 |     0   (0)| 00:00:01 |
    |* 17 |       FIXED TABLE FULL    | X$KTSTUSS       |     1 |   102 |     0   (0)| 00:00:01 |
    |* 18 |       FIXED TABLE FULL    | X$KTSTUSG       |     1 |   102 |     0   (0)| 00:00:01 |
    |* 19 |       FIXED TABLE FULL    | X$KTCXB         |     1 |   102 |     0   (0)| 00:00:01 |
    |* 20 |    FIXED TABLE FIXED INDEX| X$KSQRS (ind:1) |     1 |     6 |     0   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       3 - access("SADDR"="S"."ADDR")
       4 - filter("S"."INST_ID"=USERENV('INSTANCE'))
       7 - filter(USERENV('INSTANCE') IS NOT NULL)
      10 - filter(("KSQLKMOD"<>0 OR "KSQLKREQ"<>0) AND "INST_ID"=USERENV('INSTANCE') AND
                  BITAND("KSSOBFLG",1)<>0)
      11 - filter(("KSQLKMOD"<>0 OR "KSQLKREQ"<>0) AND "INST_ID"=USERENV('INSTANCE') AND
                  BITAND("KSSOBFLG",1)<>0)
      12 - filter(("KSQLKMOD"<>0 OR "KSQLKREQ"<>0) AND "INST_ID"=USERENV('INSTANCE') AND
                  BITAND("KSSOBFLG",1)<>0)
      13 - filter(("KSQLKMOD"<>0 OR "KSQLKREQ"<>0) AND "INST_ID"=USERENV('INSTANCE') AND
                  BITAND("KSSOBFLG",1)<>0)
      14 - filter(("KSQLKMOD"<>0 OR "KSQLKREQ"<>0) AND "INST_ID"=USERENV('INSTANCE') AND
                  BITAND("KSSOBFLG",1)<>0)
      15 - filter(("KSQLKMOD"<>0 OR "KSQLKREQ"<>0) AND "INST_ID"=USERENV('INSTANCE') AND
                  BITAND("KSSOBFLG",1)<>0)
      16 - filter(("KSQLKMOD"<>0 OR "KSQLKREQ"<>0) AND "INST_ID"=USERENV('INSTANCE') AND
                  BITAND("KSSOBFLG",1)<>0)
      17 - filter(("KSQLKMOD"<>0 OR "KSQLKREQ"<>0) AND "INST_ID"=USERENV('INSTANCE') AND
                  BITAND("KSSOBFLG",1)<>0)
      18 - filter(("KSQLKMOD"<>0 OR "KSQLKREQ"<>0) AND "INST_ID"=USERENV('INSTANCE') AND
                  BITAND("KSSOBFLG",1)<>0)
      19 - filter(("KSQLKMOD"<>0 OR "KSQLKREQ"<>0) AND "INST_ID"=USERENV('INSTANCE') AND
                  BITAND("KSSPAFLG",1)<>0)
      20 - filter("RADDR"="R"."ADDR")
    SQL>  select /*+ ordered */ count(*) from v$lock;                                "ORDERED HINT"
    Elapsed: 00:00:00.01
    Execution Plan                                                                 
    Plan hash value: 3174212559
    | Id  | Operation                 | Name            | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT          |                 |     1 |    50 |     1 (100)| 00:00:01 |
    |   1 |  SORT AGGREGATE           |                 |     1 |    50 |            |          |
    |   2 |   NESTED LOOPS            |                 |     1 |    50 |     1 (100)| 00:00:01 |
    |*  3 |    HASH JOIN              |                 |     1 |    44 |     1 (100)| 00:00:01 |
    |   4 |     VIEW                  | GV$_LOCK        |    10 |   250 |     0   (0)| 00:00:01 |
    |   5 |      UNION-ALL            |                 |       |       |            |          |
    |*  6 |       FILTER              |                 |       |       |            |          |
    |   7 |        VIEW               | GV$_LOCK1       |     2 |   178 |     0   (0)| 00:00:01 |
    |   8 |         UNION-ALL         |                 |       |       |            |          |
    |*  9 |          FIXED TABLE FULL | X$KDNSSF        |     1 |   102 |     0   (0)| 00:00:01 |
    |* 10 |          FIXED TABLE FULL | X$KSQEQ         |     1 |   102 |     0   (0)| 00:00:01 |
    |* 11 |       FIXED TABLE FULL    | X$KTADM         |     1 |   102 |     0   (0)| 00:00:01 |
    |* 12 |       FIXED TABLE FULL    | X$KTATRFIL      |     1 |   102 |     0   (0)| 00:00:01 |
    |* 13 |       FIXED TABLE FULL    | X$KTATRFSL      |     1 |   102 |     0   (0)| 00:00:01 |
    |* 14 |       FIXED TABLE FULL    | X$KTATL         |     1 |   102 |     0   (0)| 00:00:01 |
    |* 15 |       FIXED TABLE FULL    | X$KTSTUSC       |     1 |   102 |     0   (0)| 00:00:01 |
    |* 16 |       FIXED TABLE FULL    | X$KTSTUSS       |     1 |   102 |     0   (0)| 00:00:01 |
    |* 17 |       FIXED TABLE FULL    | X$KTSTUSG       |     1 |   102 |     0   (0)| 00:00:01 |
    |* 18 |       FIXED TABLE FULL    | X$KTCXB         |     1 |   102 |     0   (0)| 00:00:01 |
    |* 19 |     FIXED TABLE FULL      | X$KSUSE         |     1 |    19 |     0   (0)| 00:00:01 |
    |* 20 |    FIXED TABLE FIXED INDEX| X$KSQRS (ind:1) |     1 |     6 |     0   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       3 - access("SADDR"="S"."ADDR")
       6 - filter(USERENV('INSTANCE') IS NOT NULL)
       9 - filter(("KSQLKMOD"<>0 OR "KSQLKREQ"<>0) AND "INST_ID"=USERENV('INSTANCE') AND
                  BITAND("KSSOBFLG",1)<>0)
      10 - filter(("KSQLKMOD"<>0 OR "KSQLKREQ"<>0) AND "INST_ID"=USERENV('INSTANCE') AND
                  BITAND("KSSOBFLG",1)<>0)
      11 - filter(("KSQLKMOD"<>0 OR "KSQLKREQ"<>0) AND "INST_ID"=USERENV('INSTANCE') AND
                  BITAND("KSSOBFLG",1)<>0)
      12 - filter(("KSQLKMOD"<>0 OR "KSQLKREQ"<>0) AND "INST_ID"=USERENV('INSTANCE') AND
                  BITAND("KSSOBFLG",1)<>0)
      13 - filter(("KSQLKMOD"<>0 OR "KSQLKREQ"<>0) AND "INST_ID"=USERENV('INSTANCE') AND
                  BITAND("KSSOBFLG",1)<>0)
      14 - filter(("KSQLKMOD"<>0 OR "KSQLKREQ"<>0) AND "INST_ID"=USERENV('INSTANCE') AND
                  BITAND("KSSOBFLG",1)<>0)
      15 - filter(("KSQLKMOD"<>0 OR "KSQLKREQ"<>0) AND "INST_ID"=USERENV('INSTANCE') AND
                  BITAND("KSSOBFLG",1)<>0)
      16 - filter(("KSQLKMOD"<>0 OR "KSQLKREQ"<>0) AND "INST_ID"=USERENV('INSTANCE') AND
                  BITAND("KSSOBFLG",1)<>0)
      17 - filter(("KSQLKMOD"<>0 OR "KSQLKREQ"<>0) AND "INST_ID"=USERENV('INSTANCE') AND
                  BITAND("KSSOBFLG",1)<>0)
      18 - filter(("KSQLKMOD"<>0 OR "KSQLKREQ"<>0) AND "INST_ID"=USERENV('INSTANCE') AND
                  BITAND("KSSPAFLG",1)<>0)
      19 - filter("S"."INST_ID"=USERENV('INSTANCE'))
      20 - filter("RADDR"="R"."ADDR")
    SQL>

Maybe you are looking for

  • Calendar list view in IOS7 not showing times

    I have an iPhone 5 with IOS7.  I have several calendar entries that when in the list view or search view, they show "all-day" on the left hand side when in fact they are not all-day, they have specified start and end times.  This seems to happen when

  • Sales order creation with reference to quote using BAPI

    Hi All, I am trying to create a sales order with reference to quote using BAPI BAPI_SALESORDER_CREATEFROMDAT2. I am passing the Quote number and preceding doc.category (B) at the header level and at item level I am passing the quote number and the li

  • Report on Active Directory User Attributes in SCCM 2012

    I need to output a list of all users in a collection, along with certain user attributes from Active Directory. I can get part of what I need with the following query: SELECT v_FullCollectionMembership.ResourceID, v_R_User.Windows_NT_Domain0, v_R_Use

  • Why do we buy toshiba tv's????

    My tv like so many others tv's are broken after a little over a year old outside the warranty and the manufacture could care less. Same problems which mean same faulty parts which says they know and continue to put them in there tv's. Why? Cause we c

  • Attachement send with FM "SO_NEW_DOCUMENT_ATT_SEND_API1"

    I am sending XL spread sheet in "packing_list" internal table of the FM 'SO_NEW_DOCUMENT_ATT_SEND_API1'. My problem is when I try to open received attachment, "Microsoft Excel" gives me a warning message "This file is not a recognizable format". When