Is there something more efficient than EXISTS statement?

Hi All,
I have this query:
select
waco,
ltrim(rtrim(wammcu)) as wammcu,
wadoco,
walitm, 
wadl01,
case 
when wastrx = 0 
then null 
else 
proddta.JulianToDate(wastrx) 
end 
AS wastrx,
wauom,
cast(wasoqs / 10000 as numeric (15,4)) as wasoqs,
cast(wasocn / 10000 as numeric (15,4)) as wasocn,
--THIS IS THE PART TO OPTIMIZIE
(select
 sum(cast(glaa / 100 as numeric (15,2)))
from
 proddta.f0911
where
glkco=waco and
glco =waco and
gldct='IV' and
glsblt = 'W' and
glsbl = right(replicate('0',8) + CONVERT(varchar,CONVERT(int,wadoco)),8)  and
exists
(select * from  proddta.f4095
 where
 mlanum in (3220,3260,3270,3280) and
 mlco=glco and
 mldcto=wadcto and
 mldct=gldct and
 mlcost='A1' and
 mlobj=globj)) as A1_Account 
--END OF THE PART TO OPTIMIZE
from  
proddta.f4801
where
waco='00010' and
wadcto='WO' and
wasrst='99' and
wastrx >=  114001
and exists
select 
from 
proddta.f0911
where
glkco=waco and
glco =waco and
gldct='IV' and
glsblt = 'W' and
glsbl = right(replicate('0',8) + CONVERT(varchar,CONVERT(int,wadoco)),8)  and
gldgj between  114001 and  114031
It takes a very long time to execute, my T-SQL is almost rusted, is there a way to improve the query with new costruct T-SQL has?

This is the query plan:
StmtText
  |--Compute Scalar(DEFINE:([Expr1008]=CASE WHEN [JDE_PROD].[PRODDTA].[F4801].[WASTRX]=(0.) THEN NULL ELSE [JDE_PROD].[PRODDTA].[JulianToDate](CONVERT_IMPLICIT(int,[JDE_PROD].[PRODDTA].[F4801].[WASTRX],0)) END, [Expr1020]=[Expr1018]))
       |--Nested Loops(Inner Join, OUTER REFERENCES:([JDE_PROD].[PRODDTA].[F4801].[WADCTO], [JDE_PROD].[PRODDTA].[F4801].[WADOCO], [JDE_PROD].[PRODDTA].[F4801].[WACO]))
            |--Hash Match(Right Semi Join, HASH:([JDE_PROD].[PRODDTA].[F0911].[GLSBL])=([Expr1021]), RESIDUAL:([JDE_PROD].[PRODDTA].[F0911].[GLSBL]=[Expr1021]))
            |    |--Clustered Index Seek(OBJECT:([JDE_PROD].[PRODDTA].[F0911].[F0911_PK]), SEEK:([JDE_PROD].[PRODDTA].[F0911].[GLDCT]=N'IV'),  WHERE:([JDE_PROD].[PRODDTA].[F0911].[GLDGJ]>=(114001.) AND [JDE_PROD].[PRODDTA].[F0911].[GLDGJ]<=(114031.)
AND [JDE_PROD].[PRODDTA].[F0911].[GLKCO]=N'00010' AND [JDE_PROD].[PRODDTA].[F0911].[GLCO]=N'00010' AND [JDE_PROD].[PRODDTA].[F0911].[GLSBLT]=N'W') ORDERED FORWARD)
            |    |--Compute Scalar(DEFINE:([Expr1007]=ltrim(rtrim([JDE_PROD].[PRODDTA].[F4801].[WAMMCU])), [Expr1009]=CONVERT(numeric(15,4),[JDE_PROD].[PRODDTA].[F4801].[WASOQS]/(1.000000000000000e+004),0), [Expr1010]=CONVERT(numeric(15,4),[JDE_PROD].[PRODDTA].[F4801].[WASOCN]/(1.000000000000000e+004),0),
[Expr1021]=CONVERT_IMPLICIT(nvarchar(8),right('00000000'+CONVERT(varchar(30),CONVERT(int,[JDE_PROD].[PRODDTA].[F4801].[WADOCO],0),0),(8)),0)))
            |         |--Clustered Index Scan(OBJECT:([JDE_PROD].[PRODDTA].[F4801].[F4801_PK]), WHERE:([JDE_PROD].[PRODDTA].[F4801].[WASTRX]>=(114001.) AND [JDE_PROD].[PRODDTA].[F4801].[WACO]=N'00010' AND
[JDE_PROD].[PRODDTA].[F4801].[WADCTO]=N'WO' AND [JDE_PROD].[PRODDTA].[F4801].[WASRST]=N'99'))
            |--Compute Scalar(DEFINE:([Expr1018]=CASE WHEN [Expr1031]=(0) THEN NULL ELSE [Expr1032] END))
                 |--Stream Aggregate(DEFINE:([Expr1031]=COUNT_BIG([Expr1022]), [Expr1032]=SUM([Expr1022])))
                      |--Hash Match(Right Semi Join, HASH:([JDE_PROD].[PRODDTA].[F4095].[MLOBJ])=([JDE_PROD].[PRODDTA].[F0911].[GLOBJ]), RESIDUAL:([JDE_PROD].[PRODDTA].[F4095].[MLOBJ]=[JDE_PROD].[PRODDTA].[F0911].[GLOBJ]))
                           |--Clustered Index Seek(OBJECT:([JDE_PROD].[PRODDTA].[F4095].[F4095_PK]), SEEK:([JDE_PROD].[PRODDTA].[F4095].[MLANUM]=(3.220000000000000e+003) AND [JDE_PROD].[PRODDTA].[F4095].[MLCO]=[JDE_PROD].[PRODDTA].[F4801].[WACO]
AND [JDE_PROD].[PRODDTA].[F4095].[MLDCTO]=[JDE_PROD].[PRODDTA].[F4801].[WADCTO] AND [JDE_PROD].[PRODDTA].[F4095].[MLDCT]=N'IV' OR [JDE_PROD].[PRODDTA].[F4095].[MLANUM]=(3.260000000000000e+003) AND [JDE_PROD].[PRODDTA].[F4095].[MLCO]=[JDE_PROD].[PRODDTA].[F4801].[WACO]
AND [JDE_PROD].[PRODDTA].[F4095].[MLDCTO]=[JDE_PROD].[PRODDTA].[F4801].[WADCTO] AND [JDE_PROD].[PRODDTA].[F4095].[MLDCT]=N'IV' OR [JDE_PROD].[PRODDTA].[F4095].[MLANUM]=(3.270000000000000e+003) AND [JDE_PROD].[PRODDTA].[F4095].[MLCO]=[JDE_PROD].[PRODDTA].[F4801].[WACO]
AND [JDE_PROD].[PRODDTA].[F4095].[MLDCTO]=[JDE_PROD].[PRODDTA].[F4801].[WADCTO] AND [JDE_PROD].[PRODDTA].[F4095].[MLDCT]=N'IV' OR [JDE_PROD].[PRODDTA].[F4095].[MLANUM]=(3.280000000000000e+003) AND [JDE_PROD].[PRODDTA].[F4095].[MLCO]=[JDE_PROD].[PRODDTA].[F4801].[WACO]
AND [JDE_PROD].[PRODDTA].[F4095].[MLDCTO]=[JDE_PROD].[PRODDTA].[F4801].[WADCTO] AND [JDE_PROD].[PRODDTA].[F4095].[MLDCT]=N'IV'),  WHERE:([JDE_PROD].[PRODDTA].[F4095].[MLCOST]=N'A1') ORDERED FORWARD)
                           |--Index Spool(SEEK:([JDE_PROD].[PRODDTA].[F0911].[GLKCO]=[JDE_PROD].[PRODDTA].[F4801].[WACO] AND [JDE_PROD].[PRODDTA].[F0911].[GLCO]=[JDE_PROD].[PRODDTA].[F4801].[WACO]
AND [JDE_PROD].[PRODDTA].[F0911].[GLSBL]=CONVERT_IMPLICIT(nvarchar(8),right('00000000'+CONVERT(varchar(30),CONVERT(int,[JDE_PROD].[PRODDTA].[F4801].[WADOCO],0),0),(8)),0) AND [JDE_PROD].[PRODDTA].[F0911].[GLDCT]=N'IV' AND [JDE_PROD].[PRODDTA].[F0911].[GLSBLT]=N'W'))
                                |--Compute Scalar(DEFINE:([Expr1022]=CONVERT(numeric(15,2),[JDE_PROD].[PRODDTA].[F0911].[GLAA]/(1.000000000000000e+002),0)))
                                     |--Clustered Index Scan(OBJECT:([JDE_PROD].[PRODDTA].[F0911].[F0911_PK]))
it returns 1734 rows, the tables queried contain milions of roiw

Similar Messages

  • Why is Array more efficient than flexible-size collection

    it is a bit more tricky to understand the two advantges of Array as following:
    1. access to items held in an array is often more efficient than access to the items in a comparable flexible-size collection,
    2. arrays are able to store objects or primitive -type values, but flexible -size collection can store only object.
    thanks in advance

    it is a bit more tricky to understand the two
    wo advantges of Array as following:
    1. access to items held in an array is often more
    e efficient than access to the items in a comparable
    flexible-size collection,The standard dynamic data structure (with standard I mean member of the collections framework) comparable to the array is the ArrayList. In principle the access to an element is equally efficient in both cases. (There's some overhead because you have to do a method call in the ArrayList case). It's only in very low-level algoritms you need to use arrays. In most cases ArrayList is fine.
    2. arrays are able to store objects or primitive
    ve -type values, but flexible -size collection can
    store only object.This is true with the standard collection, but there are alternative collections that can store primitives, for example,
    http://pcj.sourceforge.net/
    In the next version of Java there's a new concept call autoboxing. This means there's an implicit conversion taking place between primitive types and their corresponding wrapper class, say between int and Integer. This means you will be able to write your program AS IF you could store primitives in the standard collections.

  • When using iPhoto can I remove some of the default options such as faces or  flagged etc. There are more bits than I need for my basic use.

    When using iPhoto can I remove some of the default options such as faces or  flagged etc. from the left bar. There are more bits than I need for my basic use.

    Hello Susan,
    Not sure if I have fully understood your question but have you tried ...
    iPhoto > iPhoto help > browse help > view and organise.  Perhaps this touches on some of your needs.
    Usually, best results for questions come from posting to the forum directly related to the question, in this case iPhoto.  That tends to find the gurus
    Would you like me to ask the hosts to relocate your question?  

  • How do I change the image title when it is uploaded from iphoto to iweb. At the moment the image title is /shapeimage_1.png and I would like to put in something more relevant than just shapeimage?

    How do I change the image title when it is uploaded from iphoto to iweb. At the moment the image title is /shapeimage_2.png and I would like to put in something more relevant than just shapeimage_2?

    When you drag images from iPhoto to iWeb, iWeb retains the original filename.
    When you use a mask, iWeb creates a png file with the shapeimage name.
    So do not use a mask and crop your images before dropping them on the iWeb canvas.
    When you use an irregularly shaped mask, then png files are created. They have to be png because of the transparency of the shape.
    You can use a 3rd party application to create the png images yourself, and give them a proper name.
    Or use the published png files, rename them and drop them back onto the iWeb canvas, while first removing the previous images.

  • I just subscribed to ExportPDF. Will it begin working immediately or is there something more I should do?

    Hello. This is my first time on this forum. I just subscribed to ExportPDF. Should it begin working immediately or is there something more I should do? Thank you.

    Hi jp39,
    It can take several hours for your subscription to process fully. I just checked you account, and see that your ExportPDF subscription is, in fact, still processing. Please try to sign in again later today, and let us know if you're able to log in.
    Best,
    Sara

  • Creating a time channel in the data portal and filling it with data - Is there a more efficient way than this?

    I currently have a requirement to create a time channel in the data portal and subsequently fill it with data. I've shown below how I am currently doing it:
    Time_Ch = ChnAlloc("Time channel", 271214           , 1      ,           , "Time"         ,1                  ,1)              'Allocate time channel
    For intLoop = 1 to 271214
      ChD(intLoop,Time_Ch(0)) = CurrDateTimeReal          'Create time value
    Next
    I understand that the function to create and allocate memory for the time channel is extremely quick. However the time to store data in the channel afterwards is going to be highly dependent on the length I have assigned to the Time_Ch. In my application the length of Time_Ch is variable but could easily be in the order of 271214 or higher. Under such circumstances the time taken to fill Time_Ch is quite considerable. I am wondering whether this is the most appropriate way of doing things or whether there is a more efficient way of creating a time channel and filling it.
    Thanks very much for any help.
    Regards
    Matthew

    Hi Matthew,
    You are correct that there is a more efficient way to do this.  I'm a little confused about your "CurrDateTimeReal" assignment-- is this a constant?  Most people want a Time channel that counts up linearly in seconds or fractions of a second over the duration of the measurement.  But that looks like you would assign the same time value to all the rows of the new Time channel.
    If you want to create a "normal" Time channel that increases at a constant rate, you can use the ChnGenTime() function:
    ReturnValue = ChnGenTime(TimeChannel, GenTimeUnit, GenTimeXBeg, GenTimeXEnd, GenTimeStep, GenTimeMode, GenTimeNo)
    If you really do want a Time channel filled with all the same values, you can use the ChnLinGen() function and simply set the GenXBegin and GenXEnd parameters to be the same value:
    ReturnValue = ChnLinGen(TimeChannel, GenXBegin, GenXEnd, XNo, [GenXUnitPreset])
     In both cases you can use the Time channel you've already created (which as you say executes quickly) and point the output of these functions to that Time channel by using the Group/Channel syntax of the Time channel you created for the first TimeChannel parameter in either of the above functions.
    Brad Turpin
    DIAdem Product Support Engineer
    National Instruments

  • Linking from one PDF to another: Is there a more efficient way?

    Some background first:
    We make a large catalog (400pages) in Indesign and it's updated every year. We are a wholesale distributor and our pricing changes so we also make a price list with price ref # that corresponded with #s printed in the main catalogue.  Last year we also made this catalog interactive so that a pdf of it could be browsed using links and bookmarks. This is not too difficult using Indesign and making any adjustments in the exported PDF. Here is the part that becomes tedious and is especially so this year:
    We also set up links in the main catalog that go to the price list pdf - opening the page with the item's price ref # and prices... Here's my biggest issue - I have not found any way to do this except making links one at a time in Acrobat Pro (and setting various specifications like focus and action and which page (in the price list) to open) Last year this wasn't too bad because we used only one price list. It still took some time to go through and set up 400-500 links individually.
    This year we've simplified our linking a little by putting only one link per page but that is still 400 links. And this year I have 6 different price lists (price tiers...) to link to the main catalogue pdf. (That's in the neighborhood of 1200-1500 double clicking the link(button) to open Button Properties, click Actions tab, click Add..."Go to page view" , set link to other pdf page, click edit, change Open in to "New Window" and set Zoom.  This isn't a big deal if you only have a few Next, Previous, Home kind of buttons....but it's huge when you have hundreds of links. Surely there's a better way?
    Is there anyway in Acrobat or Indesign to more efficiently create and edit hundreds of links from one pdf to another?
    If anything is unclear and my question doesn't make sense please ask. I will do my best to help you answer my questions.
    Thanks

    George, I looked at the article talking about the fdf files and it sounds interesting. I've gathered that I could manipulate the pdf links by making an fdf file and importing that into the PDF, correct?
    Now, I wondered - can I export an fdf from the current pdf and then change what is in there and import it back into the pdf.  I've tried this (Forms>More Form Options>Manage Form Data>Export Data) and then opened the fdf in a text editor but I see nothing related to the documents links... I assume this is because the links are 'form' data to begin with - but is there away to export something with link data like that described in the article link you provided?
    Thanks

  • Is a WITH...SELECT query more efficient than a SELECT query ?

    Hi folks,
    Is the WITH...SELECT just a convenience or is it really efficient than a simple SELECT with UNION ALL ? e.g. is the following:
    with rset as (select dname,empno,ename,hiredate,sal from emp e,dept d where e.deptno=d.deptno)
    select dname,empno,ename,hiredate,sal,
    case
    when trunc(hiredate) < to_date('19800101','yyyymmdd') then 'Hired before 1980'
    when trunc(hiredate) between to_date('19800101','yyyymmdd') and to_date('19851231','yyyymmdd') then 'Hired between 1980 and 1985'
    else 'Hired after 1985'
    end as notes
    from rset
    union all
    select dname,empno,ename,hiredate,sal,
    case
    when sal < 500 then 'Salary less than 500'
    when sal between 501 and 1500 then 'Salary between 501 and 1500'
    else 'Salary greater than 1500'
    end as notes
    from rset;
    better than the following:
    select dname,empno,ename,hiredate,sal,
    case
    when trunc(hiredate) < to_date('19800101','yyyymmdd') then 'Hired before 1980'
    when trunc(hiredate) between to_date('19800101','yyyymmdd') and to_date('19851231','yyyymmdd') then 'Hired between 1980 and 1985'
    else 'Hired after 1985'
    end as notes
    from emp e,dept d where e.deptno=d.deptno
    union all
    select dname,empno,ename,hiredate,sal,
    case
    when sal < 500 then 'Salary less than 500'
    when sal between 501 and 1500 then 'Salary between 501 and 1500'
    else 'Salary greater than 1500'
    end as notes
    from emp e,dept d where e.deptno=d.deptno;
    I am a newbie at sql tuning. Apparently, the first query should be faster because it runs the actual query only once and then just works on the resultset obtained. Is this thinking correct ?
    Thanks a lot!!
    JP

    Also I tried a test here with a ten million row emp table queried five times, and explain plan showed the optimizer would read emp five times and not once.
    Re: Intresting question
    Apparently, the first query should be faster because it runs the actual query only once
    and then just works on the resultset obtained.But my test combined with Jonathan's article made me question whether materializing ten million rows somewhere would be faster than querying them five times. Somehow I doubt it.

  • In search of something more accurate than stringWidth()

    Is it possible to get the exact width of a string using AWT components from Java 1.1?
    this is close:
    FontMetrics fm = getFontMetrics(font);
    fm.stringWidth("hello");but it tends to return a value that is slightly too small because it doesn't take into account anti-aliasing or the font's italic angle. Normally, I'd just add a little bit to the end to make up for the difference, but in this case I actually need my labels to be exactly the right size for the strings they hold.
    Unfortunately, I can't use getStringBounds() because that didn't exist until Java 1.2.
    Is there another way to do it?
    thanks,
    Aaron

    Nope. Didn't work. It looks like the preferred size for a label is slightly bigger than the text inside it.
    here's the code I tried. I messed around with different layout managers and components, but got the same results.
    import java.awt.*;
    import java.awt.event.*;
    public class test extends Frame
         public static final void main(String[] args)
              new test().show();
         public void show()
              buildDlg();
              super.show();
         public void buildDlg()
              FlowLayout flo = new FlowLayout();
              flo.setHgap(0);
              flo.setVgap(0);
              this.setLayout(flo);
              this.addWindowListener(new WindowAdapter() {
                   public void windowClosing(WindowEvent e)
                        System.exit(0);
              this.add(new Label("herrre's the label"));
              this.add(new Label("2"));
              this.add(new Label("another label"));
              this.add(new Button("herrre's a button"));
              this.pack();
    }

  • Is selecting from a view more efficient than selecting from multiple tables

    Hi heres the problem
    Lets say i created a view from 2 tables (person and info). both have a ID column
    create view table_view (age,name,status,id) as
    select a.age, a.name, b.status, b.id
    from person a, info.b
    where a.id=b.idif i want to select a given range of values from these 2 tables which of the following queries would be more effective.
    select a.age, a.name, b.status, b.id
    from person a, info.b
    where a.id=b.id
    and a.id <1000
    select age, name, status, id
    from table_view
    where  id <1000

    Bear in mind that this concept of views storing the SQL text is something relative to Oracle databases and not necessarily other RDBMS products. For example, Ingres databases create "views" as tables of data on the database and therefore there is a difference between selecting from the view and selecting from the base tables.
    Oracle also has "materialized views" which differ from normal "views" because they are actually created, effectively, as tables of data and will not use the indexes of the base tables.
    In Oracle, you cannot create indexes against "views" but you can create indexes against "materialized views".

  • Looking for something more robust than global variables

    Hi,
    The company I work for makes really big deals based on the Forms we develop,
    and it makes me edgy to rely on :Global.variables to assign big amounts of money
    to a field or another.
    Maybe someone could direct me to a paper about a more robust scheme to run tests deciding what is going to happen next, like calling another form or populating another block?
    Many thanks :-)
    Message was edited by:
    JeanParis

    JeanParis,
    I did a quick Google search, but didn't find any reference material on you question so I'll give you my personal preference. Bear in mind, it truly was a "quick" search. I'm sure there is information about this topic somewhere.
    I use a Global Variable (GV) when a value is needed by significant number of Forms in the application. If the value of the is only needed by a few Forms, then I use a Parameter List. When I do use GVs, I only use them for as long as I need them. In other words, I'll assign the value of the GV to a Forms Block Item (base table or Control Block) or a parameter and then set the value of the GV to NULL. This ensures the value is only available "Globally" for as long as it is absolutely needed. This does cause a little extra work, but it make the Form safer in my opinion.
    If I simply need to have access to a "Global Variable" within the scope of a single form, I prefer to use a Form Parameter (FP). I like using using FPs over a Control Block (CB) Item because there is less overhead (attributes of a FP) than with an Item (attributes of the Item) in a CB. I know this is nit-picking, but there is a cost associated with each attribute that is loaded into memory and I like to keep this cost to a minimum. (I suppose if you sub-classed your CB Item then it would share the attributes and reduce the overhead even more). I develop Forms for the web using Forms 10g so any time I can shave off the load-time of my Form is worth it to me.
    Hope this helps.
    Craig...
    Message was edited by:
    CraigB
    Steve beat me to the punch. I like his option as well and have used this method a time or two. :-)

  • Can I publish a web page from my Mac with something more sophisticated than I-Web for my business?

    I want to construct a web page for my business. I-Web seems to be less sophisticated.  I wanted to use SiteBuilder by Yahoo, but Mac is not compatable. I have looked and have not found much, and that suggests that there are no tools to publish a web page other than I-Web.

    I don't use any of the free editors but a Google search resulted in several being available. Since they are free you could try them and stick with the one that best works for you.http://webdesign.about.com/od/macintoshhtmleditors/tp/free-macintosh-editors.htm

  • Under what circumstances are recursion more efficient than loops

    Although recursion do provide a cleaner code and often suggests a more interesting approach to a problem, it nonetheless is relatively more resource consuming for solving some of the more novice programming feats (such as facorial calculation or binary conversion). Can somebody give me an example of a more practical and efficient use of recursion?

    Can somebody give me an example
    of a more practical and efficient use of recursion?What do you mean by practical or efficient? Most tree traversal implementations are recursive since it's much easier to traverse trees using recursion.
    Kaj

  • Is FLV more efficient than m2ts as a proxy?

    FLV is considerable smaller than m2ts but I wonder if it is less taxing on the system.

    The strategy that is better is writing the code in the clearest way possible. If you're creating 10 new objects, call new 10 times.

  • Is there anything more amusing than

    it being 10F outside and people shivering to death while smoking for 5 minutes
    damn am i glad i never started

    it being 10F outside and people shivering to death
    while smoking for 5 minutes
    damn am i glad i never startedI'm a well-known non-smoker. I only smoke when people
    trust me not to smoke and hand me their cigarettes to
    hold until they're back from the toilet. By the time
    they're back, the cigarettes are almost gone. I love
    the looks on their faces...lol, i haven't had a good cigar in a long time either, damn i want one now

Maybe you are looking for

  • New Development - No Infrastructure!

    We have moved into a new development and did have an engineer visit scheduled for yesterday to install our new line. The appointment was between 1-6pm, I called at 3pm and was told he was coming, I then call again at 5.15pm and was told the engineer

  • My iPOd 8G no longer connects to my home wifi?!

    It seems like this is a common problem. Apparently I should not have upgraded to OS4. I can not believe that my Touch is just another MP3 player... but it cost a lot more. I have reset my wifi key, reset my iPod, followed every suggestion. I am reall

  • Outgoing mail server will work on Iphone but not Mail on Macbook

    My POP account will send mail on my iphone no problem, but on the mail program on my macbook it times out. All the account information is identical. The mail program keeps telling the server does not support port 995, but on the Iphone it does. I hav

  • Hp pavilion 1012tu usb 2.0 ports are not working

    my hp pavilion 1012tu USB 2.0 ports are not working only the 3.0 port is working

  • DVD burning - safe to run in background?

    Hi Guys, Is it safe to carry on using my computer while iDVD is running and encoding/burning something? I used to leave the DVD burning over night but now this isn't possible. Doesn't interfere with the encoding/burning process if I continue to use t