How can rewrite the query statement effectively

Hi gurus,

BANNER

----------------------------------------------------------------

Oracle Database 10g Release 10.2.0.4.0 - Production 64-bit

PL/SQL Release 10.2.0.4.0 - Production

CORE 10.2.0.4.0 Production

AMT for Linux: release 10.2.0.4.0 - Production

NLSRTL Version 10.2.0.4.0 - Production

Table scripts


CREATE TABLE WAREHOUSE

(

IDZONE VARCHAR2 (6 BYTE) NOT NULL,

ZONE_CREATEDATE DATE NOT NULL,

DATE OF DT_WAREHOUSE,

DATE OF DT_POSTING

)

AREA ID, ZONE_CREATEDATE is PK

CREATE TABLE ZONE_VIEW

(

IDZONE VARCHAR2 (6 BYTE) NOT NULL,

ZONE_CREATEDATE DATE NOT NULL,

ZONE_NUM NUMBER (2) NOT NULL,

DATE OF TRANX_DATE

)

ID of the AREA, ZONE_CREATEDATE, ZONE_NUM is PK

Query

SELECT ID area, zone_createdate

Of

(

SELECT ID area, zone_createdate,

MAX (CASE WHEN zone_num = 18 AND tranx_date 'n' IS NOT NULL, THEN 1 TIME zone_num = 18 AND tranx_date IS NULL THEN 0 ELSE-1 END) region_18,.

MAX (CASE WHEN zone_num = 110 AND not IS NOT NULL, THEN 1 TIME = 110 zone_num tranx_date AND tranx_date IS NULL THEN 0 ELSE-1 END) region_110,.

MAX (CASE WHEN zone_num = 135 AND tranx_date no IS NOT NULL, THEN 1 TIMES zone_num = 135 AND tranx_date IS NULL THEN 0 ELSE-1 END) region_135,.

MAX (CASE WHEN zone_num = 140 AND tranx_date 'n' IS NOT NULL, THEN 1 TIME zone_num = 140 AND tranx_date IS NULL THEN 0 ELSE-1 END) region_140

OF zone_view

GROUP BY IDZone, zone_createdate

) zrn

WHERE zrn.region_18 <>0

AND (((zrn.region_110 = 1) OR (zrn.region_110 = - 1)) AND (there IS NOT (SELECT null from warehouse w WHERE w.zoneid = zrn.zoneid AND w.zone_createdate = zrn.zone_createdate AND w.dt_warehouse IS NULL)))

AND (((zrn.region_135 = 1) AND (there IS NOT (SELECT null from warehouse w WHERE w.zoneid = zrn.zoneid AND w.zone_createdate = zrn.zone_createdate AND w.dt_posting IS NULL))) OR (zrn.region_140 = 1))

OR ((zrn.region_18 >-1) AND (zrn.region_135 = - 1) AND (zrn.region_140 < 1))

OR ((zrn.region_110 = 1) AND (zrn.region_135 = - 1) AND (zrn.region_140, <>, 0))

);

Top query runs too slowly on the real data set. Is there an effective way to rewrite the query which can perform the dough?

Any help or suggestion would be appreciated

Thanks in advance

At the time where the application may not throw anything until after he has retrieved and grouped all the ranks of zone_view. His estimate of 7.5 minutes to scan millions 639 lines really fast enough - it's 85 million lines per minute.

This seems to be where the time went. The only way that the query can be accelerated is to recover some of the conditions that must be applied before the grouping. The only obvious possibilities for this are

(a) filter values of zone_num

(b) move the audit only

NOT EXISTS (SELECT null from warehouse w WHERE w.zoneid = zrn.zoneid AND w.zone_createdate = zrn.zone_createdate AND w.dt_warehouse IS NULL)

within the group, because this condition is applied regardless of the values in calculated fields. The AREA ID, ZONE_CREATEDATE are not null, so I suggest to try:

SELECT ID area, zone_createdate

Of

(

SELECT ID area, zone_createdate,

MAX (CASE WHEN zone_num = 18 AND tranx_date 'n' IS NOT NULL, THEN 1 TIME zone_num = 18 AND tranx_date IS NULL THEN 0 ELSE-1 END) region_18,.

MAX (CASE WHEN zone_num = 110 AND not IS NOT NULL, THEN 1 TIME = 110 zone_num tranx_date AND tranx_date IS NULL THEN 0 ELSE-1 END) region_110,.

MAX (CASE WHEN zone_num = 135 AND tranx_date no IS NOT NULL, THEN 1 TIMES zone_num = 135 AND tranx_date IS NULL THEN 0 ELSE-1 END) region_135,.

MAX (CASE WHEN zone_num = 140 AND tranx_date 'n' IS NOT NULL, THEN 1 TIME zone_num = 140 AND tranx_date IS NULL THEN 0 ELSE-1 END) region_140

OF zone_view

where (IDZone, zone_createdate) NOT IN (select the zone ID, w warehouse zone_createdate WHERE w.dt_warehouse IS NULL)

and zone_num (18, 110, 135, 140)

GROUP BY IDZone, zone_createdate

) zrn

WHERE zrn.region_18 <> 0

AND ((zrn.region_110 = 1) OR (zrn.region_110 = - 1))

AND (((zrn.region_135 = 1) AND (there IS NOT (SELECT null from warehouse w WHERE w.zoneid = zrn.zoneid AND w.zone_createdate = zrn.zone_createdate AND w.dt_posting IS NULL))) OR (zrn.region_140 = 1))

OR ((zrn.region_18 >-1) AND (zrn.region_135 = - 1) AND (zrn.region_140)<>

OR ((zrn.region_110 = 1) AND (zrn.region_135 = - 1) AND (zrn.region_140 <> 0))

)

Unfortunately, if the plan of the query time estimates are correct, most of the duration of the query is spent doing a reading zone_view in a full analysis, and which will not be changed by this query.

If there are many rows for each (IDZone, zone_createdate) zone_view pair, then it is possible that an index on (area ID, zone_num, zone_createdate) would contribute to this request, especially if most (IDZone, zone_createdate) pairs are filtered with the NOT IN (select the zone ID, zone_createdate w warehouse WHERE w.dt_warehouse IS NULL). More radical but probably effective measure would be a functional on index

zone_view (zone_num, IDZone, zone_createdate, case when tranx_date is null then 0 otherwise 1 end)

and using the expression in the query box:

SELECT ID area, zone_createdate

Of

(

SELECT ID area, zone_createdate,

NVL (MAX (CASE WHEN zone_num = 18 then case when tranx_date is null, then 0 or 1 end end),-1) region_18,.

NVL (MAX (CASE WHEN zone_num = 110 then case when tranx_date is null, then 0 or 1 end end),-1) region_110,.

NVL (MAX (CASE WHEN zone_num = 135 then case when tranx_date is null, then 0 or 1 end end),-1) region_135,.

NVL (MAX (CASE WHEN zone_num = 140 then case when tranx_date is null, then 0 or 1 end end),-1) region_140

OF zone_view

where (IDZone, zone_createdate) NOT IN (select the zone ID, w warehouse zone_createdate WHERE w.dt_warehouse IS NULL)

and zone_num (18, 110, 135, 140)

GROUP BY IDZone, zone_createdate

) zrn

WHERE zrn.region_18 <> 0

AND ((zrn.region_110 = 1) OR (zrn.region_110 = - 1))

AND (((zrn.region_135 = 1) AND (there IS NOT (SELECT null from warehouse w WHERE w.zoneid = zrn.zoneid AND w.zone_createdate = zrn.zone_createdate AND w.dt_posting IS NULL))) OR (zrn.region_140 = 1))

OR ((zrn.region_18 >-1) AND (zrn.region_135 = - 1) AND (zrn.region_140)<>

OR ((zrn.region_110 = 1) AND (zrn.region_135 = - 1) AND (zrn.region_140 <> 0))

)

This gives a very different plan on my database, by performing an iteration on relevant areas of performance status:

---------------------------------------------------------

| ID | Operation | Name |

---------------------------------------------------------

|   0 | SELECT STATEMENT |              |

|*  1 |  FILTER                          |              |

|   2.   VIEW                           |              |

|*  3 |    FILTER                        |              |

|   4.     HASH GROUP BY.              |

|   5.      ANTI NESTED LOOPS.              |

|   6.       INLIST ITERATOR.              |

|*  7 |        INDEX RANGE SCAN | ZV_F1 |

|*  8 |       TABLE ACCESS BY INDEX ROWID | WAREHOUSE |

|*  9 |        INDEX UNIQUE SCAN | WAREHOUSE_PK |

| * 10 |   TABLE ACCESS BY INDEX ROWID | WAREHOUSE |

| * 11 |    INDEX UNIQUE SCAN | WAREHOUSE_PK |

---------------------------------------------------------

Your plan will be different because you have data volumes (I didn't create millions of lines of test data)

It would be useful to know how many rows there are in the WAREHOUSE, how many distinct (IDZone, zone_createdate) pairs there are in zone_view and the number of rows actually returns the query, and how much is NOT IN (select the zone ID, w zone_createdate warehouse WHERE w.dt_warehouse IS NULL) because these relative numbers determine how these approaches are.

If there is a table containing all of the (area ID, zone_createdate) pairs which could take place in zone_view, which would have may another possible approach:

First filter possible pairs against NOT IN (select the zone ID, w warehouse zone_createdate WHERE w.dt_warehouse IS NULL)

Then attach them to the zone_view to retrieve only the rows in the filtered (IDZone, zone_createdate) pairs.

Good luck.

Tags: Database

Similar Questions

  • How to rewrite the sql statement?

    Hello my query goes like this:

    Select a, b, c
    from (select 5A, b null, null double c
    Union of all the
    Select null, 4, the double null
    Union of all the
    Select 10, 3, double null) test_tab;

    and I want to get the result

    5 null null
    null null 4
    10 null null
    3 null null

    How can I rewrite the query without changing the structure of a table?

    Kind regards
    Igor

    Hello

    A way

    select a, null b, null c from test_tab where a is not null
    union all
    select null, b, null from test_tab where b is not null
    union all
    select null, null, c from test_tab where c is not null
    

    Concerning
    Anurag

  • How to rewrite the query without inline query

    Hello people,
    I have this request trying to rewrite with a single outer join. As previously with the inline its taking too much time (one day). I was wondering if this is how I rewrite. Thanks to a bouquet. I know there must be indexed on the event.
    original :
    select e.event_id,
           EVENT_STATUS_CODE,
           EVENT_TYPE_CODE,
           c.client_code,
           trunc(DATE_EXTRACTED),
           trunc(DATE_SUBMITTED),
           trunc(CLS.DATE_RETURNED),
           trunc(DATE_TYPED),
           trunc(REJECT_DATE),
           SUM_BILLED "bill_ttl",
           SUM_PAID,
           SUM_AMOUNT "Recoveries",
           trunc(DATE_OF_INCIDENT),
           recspec.USER_REAL_NAME,
           recspec.LEVEL_B_CODE,
           trunc(STAGE_CREATED_DATE),
           REJECT_CODE,
           ISO_ERROR
      FROM EVENT E, 
           CLIENT C, 
           MV_RECOVERYDET_EVENT_SUM MV_R,
           CLS_SEND CLS,
           MV_BILLDETAIL_EVENT_SUM MV_BDE,
           (SELECT EVENT_ID, USER_REAL_NAME, LEVEL_B_CODE
              FROM END_USER EU, EVENT_END_USER EEU
             WHERE EEU.END_USER_ID = EU.END_USER_ID
               AND OWNER_FLAG = 'Y') recspec
    WHERE E.EVENT_ID = MV_R.EVENT_ID(+)
       AND E.EVENT_ID = MV_BDE.EVENT_ID(+)
       AND E.EVENT_ID = recspec.EVENT_ID(+) 
       AND E.EVENT_ID = CLS.EVENT_ID(+)
       AND E.CLIENT_ID = C.CLIENT_ID
        AND E.CLIENT_ID = '1078';
    
    
    After rewritting
    
    select e.event_id,
           EVENT_STATUS_CODE,
           EVENT_TYPE_CODE,
           c.client_code,
           trunc(DATE_EXTRACTED),
           trunc(DATE_SUBMITTED),
           trunc(CLS.DATE_RETURNED),
           trunc(DATE_TYPED),
           trunc(REJECT_DATE),
           SUM_BILLED "bill_ttl",
           SUM_PAID,
           SUM_AMOUNT "Recoveries",
           trunc(DATE_OF_INCIDENT),
           EU.USER_REAL_NAME,
          EU.LEVEL_B_CODE,
           EU.USER_REAL_NAME,
           EU.LEVEL_B_CODE,
           trunc(STAGE_CREATED_DATE),
           REJECT_CODE,
           ISO_ERROR
      FROM EVENT E, 
           CLIENT C, 
           MV_RECOVERYDET_EVENT_SUM MV_R,
           CLS_SEND CLS,
           MV_BILLDETAIL_EVENT_SUM MV_BDE,
            END_USER EU, EVENT_END_USER EEU
          
    WHERE E.EVENT_ID = MV_R.EVENT_ID(+)
       AND E.EVENT_ID = MV_BDE.EVENT_ID(+)
       --AND E.EVENT_ID = recspec.EVENT_ID(+) 
       AND E.EVENT_ID = CLS.EVENT_ID(+)
       AND E.CLIENT_ID = C.CLIENT_ID
       AND 
              EEU.END_USER_ID = EU.END_USER_ID
              AND EEU.EVENT_ID(+) = E.EVENT_ID
               AND OWNER_FLAG = 'Y'
        AND E.CLIENT_ID = '1078';
    
    ?
    Published by: user11961230 on May 2, 2012 12:28

    PX stuff, it's just the 'pipes' oracle uses to divide your table into pieces and the pieces of transformation. You don't have much control that beyond doing Oracle use parallel queries or not. I guess that you can specify a degree, but this isn't your problem, anyway. But if you're curious, PX is mentioned here. http://docs.Oracle.com/CD/B12037_01/server.101/b10752/ex_plan.htm

    Using index becomes a little more complicated with outer joins, because they return the rows that do not match the table conduct. If the index will be useful on the tables of conduct. It is possible to what I was looking to take advantage of the index because each row of the table is returned to the outer join. If you want to limit who then you need some sort of filter condition and an index on that column filter would be useful.

    Published by: watch on 2 may 2012 17:20

  • How can I purchase just after effects cc, not the cloud all creative/package?

    How can I purchase just after effects cc, not the cloud all creative/package?

    You can get a simple app for 19.99 USD per month.

    Pricing plans and creative Cloud membership | Adobe Creative Cloud

    Mylenium

  • How can I create a scroll effect when the manuscripts of user to the bottom of the image will be blurred?

    How can I create a scroll effect when the manuscripts of user to the bottom of the image will be blurred?

    Hello

    You can create a scrolling movement where the image fade out the scroll, you must use the tab opacity under the effects of scroll Panel.

    If you need especially be blur on the image, then you must change this image in any editing program like blurry image to make a copy of this image, then place the two images (real and blurry) on this page and use the scrolling motion or fade option to replace the images.

  • Rewrite the query with joins, and group by

    Hello

    It's an interview question.

    Table names: bookshelf_checkout
    virtual library

    And the join condition between these two tables is title

    We need to rewrite under request without using the join condition and group by clause?

    SELECT b.title,max(bc.returned_date - bc.checkout_date) "Most Days Out"
               FROM bookshelf_checkout bc,bookshelf b
               WHERE bc.title(+)=b.title
               GROUP BY b.title;
    When I was in College, I read most of SELECT statements can be replaced by operations base SQL (DEFINE the OPERATORS). Now, I am rewriting the query with SET operators, but not able to get the exact result.

    Kindly help me on this.

    Thank you
    Suri

    Something like that?

      1  WITH books AS (
      2  SELECT 'title 1' title FROM dual UNION ALL
      3  SELECT 'title 2' FROM dual UNION ALL
      4  SELECT 'title 3' FROM dual ),
      5  bookshelf AS (
      6  SELECT 'title 1' title, DATE '2012-05-01' checkout_date, DATE '2012-05-15' returned_date FROM dual UNION ALL
      7  SELECT 'title 1' title, DATE '2012-05-16' checkout_date, DATE '2012-05-20' returned_date FROM dual UNION ALL
      8  SELECT 'title 2' title, DATE '2012-04-01' checkout_date, DATE '2012-05-15' returned_date FROM dual )
      9  SELECT bs.title, MAX(bs.returned_date - bs.checkout_date) OVER (PARTITION BY title) FROM bookshelf bs
     10  UNION
     11  (SELECT b.title, NULL FROM books b
     12  MINUS
     13* SELECT bs.title, NULL FROM bookshelf bs)
    SQL> /
    
    TITLE   MAX(BS.RETURNED_DATE-BS.CHECKOUT_DATE)OVER(PARTITIONBYTITLE)
    ------- ------------------------------------------------------------
    title 1                                                           14
    title 2                                                           44
    title 3
    

    Lukasz

  • How to run the query on load

    Hello
    I have a form based on the table that store only 1 card. I have created a form page, but may not know how to run the query and display the record in the table. If there is no record in the table, I want that the user can use this page to create a record.
    Thanks in advance
    NRI

    Hello Nri,

    What value does P18_SCHOOL_ID?
    If you look at the State of Session (toolbar) developer. If that does not have a value, it's your problem.

    You can create a calculation before the process that gives the correct value. (In one case more often, you have a report and when you click on the link change that id is activated and you see the recording in your form)

    Dimitri

  • How can I print a statement for my adobe account?

    How can I print a statement for my adobe account?

    I found the answer on the help. 'Manage accounts' and print the pdf.

  • How to frame the query?

    Uses oracle ebs r12

    I have a table of data is

    Operation_seq Type statusflag SeqNum
    1 10A Y
    2 20 b Y
    3 30 c Y
    4 40 D Y
    5 50 e N
    6 60 f Y

    I want to write a query in which I want to take only 1 record operation_seq = 50 and Statusflag is N and all other interventions seq status is there.

    My query must return only 50 operation when the status of 50 is N and any other status is Y.

    Help, please.

    Thank you
    Lavan

    LAVANKV wrote:
    This statusflag can be (null or N), then how to frame the query.

    Simply wrap the statusflag with NVL column, you should be good.

    SQL> with t
      2  as
      3  (
      4  select 1 seqnum, 10 operation_seq, 'a' type, 'Y' statusflag from dual union all
      5  select 2 seqnum, 20 operation_seq, 'b' type, 'Y' statusflag from dual union all
      6  select 3 seqnum, 30 operation_seq, 'c' type, 'Y' statusflag from dual union all
      7  select 4 seqnum, 40 operation_seq, 'd' type, 'Y' statusflag from dual union all
      8  select 5 seqnum, 50 operation_seq, 'e' type, '' statusflag from dual union all
      9  select 6 seqnum, 60 operation_seq, 'f' type, 'Y' statusflag from dual
     10  )
     11  select seqnum, operation_seq, type, statusflag
     12    from (
     13            select t.*, count(decode(statusflag, 'Y', 1, null)) over() cnt_1, count(*) over() cnt_2
     14              from t
     15         )
     16   where operation_seq = 50
     17     and nvl(statusflag, 'N') = 'N'
     18     and cnt_2-cnt_1 = 1
     19  /
    
        SEQNUM OPERATION_SEQ T S
    ---------- ------------- - -
             5            50 e
    
  • How can position the keyboard to the bottom of the screen?

    How can position the keyboard to the bottom of the screen? Please see screenshot below, the keyboard is not at the bottom of the screen.

    Press and hold the keyboard at the bottom right of the keyboard icon. A window pop up that will have two options - Split and the Dock. Click on the option to dock alongside re your keyboard at the bottom of the screen.

    See you soon,.

    GB

  • How can identify the real space in my SGPT123 Tablet?

    Hello

    How can identify the real space in my Xperia Tablet? I can see only 10.0 GB, if suppose has 16 GB, where's the rest?

    A space is medical, the Android operating system and recovery Partition.

  • Columns of folder: by default, how can return the first column 'Name' without having to move it manually every time?

    Something's happened awhile and when I create a folder which appears the first column is the column 'Date modified '. By default, how can return the first column 'Name' without having to move it manually every time?

    Hello

    I suggest you to visit these links and check if it helps:

    http://Windows.Microsoft.com/en-us/Windows-Vista/working-with-files-and-folders#section_4

    http://Windows.Microsoft.com/en-us/Windows-Vista/folders-frequently-asked-questions

    It will be useful.

  • How can see the motherboard serial number in windows 7

    Salvation;

    I need how can see the serial number of the motherboard in windows 7
    I look forward to help me
    Thank you...

    You will most likely need remove the left side panel and look at the motherboard to determine the serial number.

  • How can set the background color of the status bar?

    Quote from the old forum:

    Comments: comments
    How can set the background color of the status bar?
    Posted the: July 17, 2008 02:56
     
    How can set the background color of the status bar?
    Using this code for the status bar:
    LabelField statusField = new LabelField ("Good Morning", LabelField.USE_ALL_WIDTH |) LabelField.NON_FOCUSABLE | LabelField.HCENTER)
    {
    int _backgroundColour = Color.LIGHTGREEN;
    public void paint (Graphics g)
    {
    g.setBackgroundColor (Color.RED);
    g.Clear ();
    Super.Paint (g);
    }
    };

    Font defaultfont = Font.getDefault ();
    Police smallfont = defaultfont.derive (Font.PLAIN, 12);

    statusField.setFont (smallfont);
    setStatus (statusField);

    When I ran the code you have above, my status background color was red.  Is not what you see?  If so, please provide the BlackBerry model and software version that you are testing.  You can find this under Options.

    Or if you try to do something else, please provide details.

    I tested this in the BlackBerry Simulator included with version 4.5.0 BlackBerry JDE (4.5.0.44).

    To do this in version 4.1, first call getColor and save the current color.  Then call setColor, setting the color to the color you want to use for the background.  After this call call fillRect, starting with 0, 0 and go to the size of the field (use this.getWidth () and this.getHeight () to get this).  This must fill in the field with your specified color.

    To allow the drawing of the default content of the field call setColor once again, passing in the original color, then call super.paint.

  • ADF: How to print the query and the query passed into the class executeQueryForCollection methof impl VO parameters.

    Hello

    Kindly let me know how to print the query, and the parameters passed to it? I tried with the params parameter in super.executeQueryForCollection (qc, params, noUserParams); but could not succeed.

    I need save the query and the parameters passed to it. Kindly help.

    Thanks in advance,

    Kalpana.

    Here you go

    Coding with Passion: Oracle ADF - Debug Mode object query with parameters

Maybe you are looking for

  • Mac Mini daily external time Machine eject message

    Hello I have an external hard drive as my time machine.  Frequent messages appear, saying that the disc is not ejected correctly.  I would never want to eject then why messages?

  • Microsoft impostor scammed

    I was contacted by phone by someone who said that they were Microsoft and told me that my computer was in danger and they could solve the problem. I hope Microsoft, so I leave them in my computer. Now I find that I am accused for two lifetimes of the

  • HP laptop computer 635: WIFI on HP 635 problem

    Hello I just try my new card wlan Intel Dual Band AC 7260 2 x 2 AC + BC and I got an error that the dooesn can't BIOS supports the card. If I understand the Forums that the card works with a modded bios, but I want to avoid this approach. Is it an of

  • problems with mobile broadband

    I have X 200 with Vista. I try inserting the sim card. (I tried all positions, whereas there is no instructions on how to insert the sim card). I get the message, sim card not found, insert the sim card. Any solution to the problem? Updates? are ther

  • Strange behavior of keyboard

    Yesterday, out of nowhere, I started having a strange problem with my keyboard. When I type a comma followed by a space, there is a break for the menu items (which vary according to the software I use at the time) fall down. If I type quickly and you