Can you optimize this sql?

Hi,
I believe that this sql can be improved, but honestly i don't know how.
               Select * From Ctb_Mov m Where m.CodEmp = 1 and m.Plano='G' and
               Cg Between '211' and '211'
               and cx between '1' and '9999999'
               and (M.GRUPO is NULL or
              M.GRUPO in (select m1.GRUPO
                                    from ctb_mov M1
                                    where M1.CODEMP = m.codemp and
                                              M1.PLANO = m.plano and
                                              M1.cg = M.cg and
                                              M1.cx = M.cx and
                                              M1.GRUPO = M.GRUPO and
                                              M1.datamov <= to_date('17092009','ddmmyyyy') and
                                              M1.GRUPO <> 9999999
                                    group by M1.CODEMP, M1.PLANO, M1.cg,
                                                  M1.CX, M1.GRUPO
                                    having sum(M1.VLD - M1.VLC) <> 0))
Suggestions?
Regards
Jomar

[HOW TO: Post a SQL statement tuning request - template posting |http://forums.oracle.com/forums/thread.jspa?threadID=863295&tstart=0]
This thread will give a good insight on how to ask a performance tuning question in this forum. Following that will get you good answers!!

Similar Messages

  • How can i optimize this SQL

    Is there anyway i could optimize the below mentioned SQL. Since our test DB is down now, i'll be posting the EXPLAIN PLAN later.
    Is there anything i could do syntactically to optimize this sql?
    SELECT SUBSTR(STK_INF.TASK_GENRTN_REF_NBR,1,12) AS PICK_WAVE_NBR,
                     ( CASE WHEN ( SUM(STK_INF.QTY_ALLOC) > 0 ) THEN
            ROUND ( (SUM(CASE WHEN (STK_INF.NEXT_TASK_ID = 0 AND STK_INF.ALLOC_INVN_DTL_ID = 0) THEN
            STK_INF.QTY_ALLOC ELSE 0 END ) / (SUM(STK_INF.QTY_ALLOC))),2 ) * 100
            ELSE 0 END ) AS PICK_PER,
         ( CASE WHEN ( SUM(STK_INF.QTY_ALLOC) > 0 ) THEN
           ROUND( (SUM(CASE WHEN (STK_INF.NEXT_TASK_ID = 0 AND STK_INF.ALLOC_INVN_DTL_ID = 0) THEN
           STK_INF.QTY_PULLD ELSE 0 END ) / (SUM(STK_INF.QTY_ALLOC))),2 ) * 100
           ELSE 0 END ) AS TILT_PERCENT
         FROM STK_INF, TRK_DTL
         WHERE STK_INF.TASK_GENRTN_REF_CODE = '44' AND STK_INF.CARTON_NBR IS NOT NULL
          AND ((STK_INF.NEXT_TASK_ID = 0 AND STK_INF.STAT_CODE <= 90) OR (STK_INF.NEXT_TASK_ID > 0 AND STK_INF.STAT_CODE < 99))
          AND PULL_LOCN_ID = TRK_DTL.LOCN_ID(+) AND (TRK_DTL.AREA <>'C' OR TRK_DTL.AREA IS NULL)
         GROUP BY SUBSTR(STK_INF.TASK_GENRTN_REF_NBR,1,12)

    This is the EXPLAIN PLAIN i got after i issued EXECUTE DBMS_STATS.GATHER_TABLE_STATS ('schema_name','table_name'); for both the tables involved.
    The number of row returned is still 222 rows. But in the EXPLAIN PLAN it is shown as 3060 !!
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 3267659036
    | Id  | Operation               | Name     | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT        |          |  3060 |   194K|       | 16527  (10)| 00:03:19 |
    |   1 |  HASH GROUP BY          |          |  3060 |   194K|       | 16527  (10)| 00:03:19 |
    |*  2 |   FILTER                |          |       |       |       |            |          |
    |*  3 |    HASH JOIN RIGHT OUTER|          |   177K|    11M|  7344K| 16397  (10)| 00:03:17 |
    |   4 |     TABLE ACCESS FULL   | TRK_DTL |   313K|  3669K|       |  2378   (6)| 00:00:29 |
    |*  5 |     TABLE ACCESS FULL   | STK_INF |   177K|  9205K|       | 13030  (11)| 00:02:37 |
    PLAN_TABLE_OUTPUT
    Predicate Information (identified by operation id):
       2 - filter("TRK_DTL"."AREA"<>'C' OR "TRK_DTL"."AREA" IS NULL)
       3 - access("PULL_LOCN_ID"="TRK_DTL"."LOCN_ID"(+))
       5 - filter("STK_INF"."CARTON_NBR" IS NOT NULL AND
                  "STK_INF"."TASK_GENRTN_REF_CODE"='44' AND ("STK_INF"."NEXT_TASK_ID"=0 AND
                  "STK_INF"."STAT_CODE"<=90 OR "STK_INF"."NEXT_TASK_ID">0 AND
                  "STK_INF"."STAT_CODE"<99))
    22 rows selected.You mentioned about creating indexes in STK_INF table. STK_INF.NEXT_TASK_ID has 186385 distinct values out of a total 782087. Does NEXT_TASK_ID make a good candidate for a B-Tree index
    STK_INF.STAT_CODE has only four distinct values, would this make a good candidate for a Bitmap index?

  • Can You Explain This SQL Query - Inline View Included

    The query is taken from "Oracle Database 10g: SQL Fundamentals II" page 3-7 (chapter 3)
    I do not fully understand the following query:
    SELECT a.last_name, a.salary, a.department_id, b.salavg
    FROM   employees a, (SELECT   department_id,
    AVG(salary) salavg
    FROM     employees
    GROUP BY department_id) b
    WHERE  a.department_id = b.department_id
    AND    a.salary > b.salavg;
    The inline view can return several records. Can you please tell me in step by step how does this work. I understand the concept of join tables and aliases, etc. I just need to know the mechanism of this code.
    Thanks

    user11164565 wrote:
    The query is taken from "Oracle Database 10g: SQL Fundamentals II" page 3-7 (chapter 3)
    I do not fully understand the following query:
    SELECT a.last_name, a.salary, a.department_id, b.salavg
    FROM   employees a, (SELECT   department_id,
    AVG(salary) salavg
    FROM     employees
    GROUP BY department_id) b
    WHERE  a.department_id = b.department_id
    AND    a.salary > b.salavg;
    The inline view can return several records. Can you please tell me in step by step how does this work. I understand the concept of join tables and aliases, etc. I just need to know the mechanism of this code.
    The query is returning the last name, salary , department and average salary of all the departments where salary is greater than the average salary.
    HTH
    Aman....

  • Can you optimize this code with bit shifting?

    Hi there,
    I was wondering if anyone could make this code run faster, by implementing bitshifting techniques. I'd really appreciate it, and thanks!
        public void scaleImage(Image source, Image dest) { 
            int sourceWidth = source.getWidth();
            int sourceHeight = source.getHeight();
            int thumbWidth = dest.getWidth();
            int thumbHeight = dest.getHeight();
            Graphics g = dest.getGraphics();
            int dx, dy = 0;
            for (int y = 0; y < thumbHeight; y++) {
                for (int x = 0; x < thumbWidth; x++) {
                    g.setClip(x, y, 1, 1);
                    dx = x * sourceWidth / thumbWidth;
                    dy = y * sourceHeight / thumbHeight;
                    g.drawImage(source, x - dx, y - dy, Graphics.LEFT | Graphics.TOP);
        }Message was edited by:
    conlanrios

    your method reminds me this stuff:
    http://www.java-tips.org/java-me-tips/midp/displaying-images-as-thumbnails-on-j2me-devices.html
    you can have a look to this article:
    http://developers.sun.com/techtopics/mobility/reference/techart/design_guidelines/image_resizing.html

  • I don't know how I can optimize this SQL

    Dear ALL:
    I don't know how I can optimize this SQL.
    Is it possible to make a better SQL or PL/SQL?
    Please let me know your good thought.
    Thank you.
    Sincerely,
    ===========================================================
    (SELECT     A, B, C, SUM(D) as D, AVG(E) as E
    FROM      T1, T2
    WHERE     T1.timestamp BETWEEN TO_DATE('00:00:00','HH24:MI:SS')
    AND TO_DATE('01:00:00','HH24:MI:SS')
    GROUP BY A, B, C
    UNION ALL
    (SELECT     A, B, C, SUM(D) as D, AVG(E) as E
    FROM      T1, T2
    WHERE     T1.timestamp BETWEEN TO_DATE('01:00:01','HH24:MI:SS')
    AND TO_DATE('02:00:00','HH24:MI:SS')
    GROUP BY A, B, C
    UNION ALL
    (SELECT     A, B, C, SUM(D) as D, AVG(E) as E
    FROM      T1, T2
    WHERE     T1.timestamp BETWEEN TO_DATE('02:00:01','HH24:MI:SS')
    AND TO_DATE('03:00:00','HH24:MI:SS')
    GROUP BY A, B, C
    UNION ALL
    (SELECT     A, B, C, SUM(D) as D, AVG(E) as E
    FROM      T1, T2
    WHERE     T1.timestamp BETWEEN TO_DATE('03:00:01','HH24:MI:SS')
    AND TO_DATE('04:00:00','HH24:MI:SS')
    GROUP BY A, B, C
    ORDER BY A ASC, B ASC, C ASC
    ===========================================================

    Dear Warren:
    Actually, for this query, it takes a few second to complete the query.
    But, I have to create several time period and I have to optimize the SQL.
    Time period is 1 hour, 30 min, 15 min, 5 min.
    That is,
    ===========================================================
    WHERE T1.timstamp BETWEEN TO_DATE('00:00:00','HH24:MI:SS')
    AND TO_DATE('01:00:00','HH24:MI:SS')
    UNION ALL
    WHERE T1.timestamp BETWEEN TO_DATE('23:00:01','HH24:MI:SS')
    AND TO_DATE('24:00:00','HH24:MI:SS')
    ===========================================================
    WHERE T1.timstamp BETWEEN TO_DATE('00:00:00','HH24:MI:SS')
    AND TO_DATE('00:30:00','HH24:MI:SS')
    UNION ALL
    WHERE T1.timestamp BETWEEN TO_DATE('23:30:01','HH24:MI:SS')
    AND TO_DATE('24:00:00','HH24:MI:SS')
    ===========================================================
    WHERE T1.timstamp BETWEEN TO_DATE('00:00:00','HH24:MI:SS')
    AND TO_DATE('00:15:00','HH24:MI:SS')
    UNION ALL
    WHERE T1.timestamp BETWEEN TO_DATE('23:45:01','HH24:MI:SS')
    AND TO_DATE('24:00:00','HH24:MI:SS')
    ===========================================================
    WHERE T1.timstamp BETWEEN TO_DATE('00:00:00','HH24:MI:SS')
    AND TO_DATE('00:05:00','HH24:MI:SS')
    UNION ALL
    WHERE T1.timestamp BETWEEN TO_DATE('23:55:01','HH24:MI:SS')
    AND TO_DATE('24:00:00','HH24:MI:SS')
    ===========================================================
    Do you know how this SQL is optimized?
    Thank you,

  • Can anyone tell me how can i optimize this query...

    Can anyone tell me how can i optimize this query ??? :
    Select Distinct eopersona.numident From rscompeten , rscompet , rscv , eopersona , rscurso , rseduca , rsexplab , rsinteres
    Where ( ( (LOWER (rscompeten.nombre LIKE '%caracas%') AND ( rscompeten.id = rscompet.idcompeten ) AND ( rscv.id = rscompet.idcv ) AND ( eopersona.id = rscv.idpersona ) )
    OR ( (LOWER (rscurso.nombre) LIKE '%caracas%') AND ( rscv.id = rscurso.idcv ) AND ( eopersona.id = rscv.idpersona ) )
    OR ( (LOWER (rscurso.lugar) LIKE '%caracas%') AND ( rscv.id = rscurso.idcv ) AND ( eopersona.id = rscv.idpersona ) )
    OR ( (LOWER (rseduca.univinst) LIKE '%caracas%)' AND ( rscv.id = rseduca.idcv ) AND ( eopersona.id = rscv.idpersona ) )
    OR ( (LOWER (rsexplab.nombempre) LIKE '%caracas%' AND ( rscv.id = rsexplab.idcv ) AND ( eopersona.id = rscv.idpersona ) )
    OR ( (LOWER (rsinteres.descrip) LIKE '%caracas%' AND ( rscv.id = rsinteres.idcv ) AND ( eopersona.id = rscv.idpersona ) )
    OR ( (LOWER (rscv.cargoasp) LIKE '%caracas%' AND ( eopersona.id = rscv.idpersona ) )
    OR ( LOWER (eopersona.ciudad) LIKE '%caracas%' AND ( eopersona.id = rscv.idpersona )
    PLEASE IF YOU FIND SOMETHING WRONG.. PLEASE HELP ME.. this query takes me aproximatelly 10 minutes and the database is really small ( with only 200 records on each table )

    You are querying eight tables, however in any of your OR predicates you're only restricting 3 or 4 of those tables. That means that the remaining 4 or 5 tables are generating cartesian products. (n.b. the cartesian product of 5 tables with 200 rows each results in g 200^5 = 320,000,000,000 rows) Then you casually hide this behind "distinct".
    A simple restatement of your requirements looks like this:
    Select eopersona.numident
      From rscompeten,
           rscompet,
           rscv,
           eopersona
    Where LOWER (rscompeten.nombre) LIKE '%caracas%'
       AND rscompeten.id = rscompet.idcompeten
       AND rscv.id = rscompet.idcv
       AND eopersona.id = rscv.idpersona
    UNION
    Select eopersona.numident
      From rscurso ,
           rscv,
           eopersona
    Where LOWER (rscurso.nombre) LIKE '%caracas%'
       AND rscv.id = rscurso.idcv
       AND eopersona.id = rscv.idpersona
    UNION
    Select eopersona.numident
      From rscurso ,
           rscv,
           eopersona
    Where LOWER (rscurso.lugar) LIKE '%caracas%'
       AND rscv.id = rscurso.idcv
       AND eopersona.id = rscv.idpersona
    UNION
    ...From there you can eliminate redundancies as desired, but I imagine that the above will perform admirably with the data volumes you describe.

  • Where can I download this SQL-Net Client software 8.1.6.3.8

    What is the most current version of the SQL-Net Client software drivers that we should be using on our Windows Clients to hit our 8.1.6.3 server? Currently we are using 8.1.6.0.0 (per tnsping). According to the certification matrix, looks like 8.1.6.3.8, (right?)
    Destination : Windows 98,NT,2000,XP Clients
    Second, where can I download this SQL-Net Client software? And please don't tell me I have to download the entire server (I hoping, but if I do where?).
    Thanks,
    Jason
    [email protected]

    I think you might be running into the issue that:
    1)  The Yoga 2 Pro does not have a DVD player built-in, and therefore they don't include DVD playback software
    2)  Windows 8 (or 8.1) no longer includes the codecs to play DVDs and such.  You have to upgrade to the Professional edition of it.  (silly, yes).
    I would personally just grab VLC Player from videolan.org, and use that.  Works perfectly fine, and it's free.
    (Did the external USB DVD not come w/ software?  That's actually strange).

  • Regarding receiving texts as emails:  Can you apply this setting to one individual? I want to continue to receive texts from everyone else except one person!

    Regarding receiving texts as emails:  Can you apply this setting to one individual? I want to continue to receive texts from everyone else except one person!

    Don't want to block the person, just have all his texts going directly to my email so that I can maintain a continuous record of his text contacts (rather than remain in text form).
    It appears that I must select an option that makes ALL texts go to email, which I'd prefer not doing.

  • I have no audio what so ever i have seen in one of the tables where it was deleted how can you fix this i tried everything i know

    == Issue
    ==
    I have another kind of problem with Firefox
    == Description
    ==
    i have been trying to get the audio to play for 3 days now i did see where it had been deleted this is a used comp i haven't had it long can you fix this i'm at my wits end
    == Firefox version
    ==
    3.6.3
    == Operating system
    ==
    Windows NT 5.0
    == User Agent
    ==
    Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3
    == Plugins installed
    ==
    *-Default Plug-in
    *Adobe Acrobat Plug-In Version 5.10 for Netscape
    *Java(TM) Platform SE binary
    *Next Generation Java Plug-in 1.6.0_20 for Mozilla browsers
    *Network Object Plugin
    *Windows Multimedia Services DRM Store Plug-In
    *Npdsplay dll

    Hello Virginia.
    You may be having a problem with some extension or plugin that is hindering your Firefox's normal behavior. Have you tried disabling all add-ons (just to check), to see if Firefox goes back to normal?

  • I have Photoshop CS4,on how many computers can you install this program ?

    Hello,
    I got Photoshop CS4. On how many computers can you install this program ?
    Sonste

    The license and activation rights are for a single user on two computers that are not used simultaneously—such as your desktop machine and your laptop.

  • Is there anyone there? I hope there is someone who can you understand this problem and have the common sense to respond?  I open gmail. I want to save an email to one of my folders. I position my cursor over the appropriate Folder icon or by choice, to th

    Is there anyone there? I hope there is someone who can you understand this problem and have the common sense to respond?
    I open gmail. I want to save an email to one of my folders.
    I position my cursor over the appropriate Folder icon or by choice, to the Trash.
    The friendly finger pointing cursor icon changes to an arrow icon.
    The hand icon allows me flawless access to opening and/or moving emails.
    The arrow, however does not open the link.
    On the Google menu bar the cursor hand with finger opens the links to Everett (my name), Search, Images, Maps and Play.
    When I attempt to open the remaining links in the menu bar (YouTube, News, Gmail, Drive, Calendar and More) the arrow icon replaces the hand. The arrow icon does not work. It will not activate these links.  Nor does it open email messages in the Inbox.
    Usually I reset, even reboot Safire and sometimes the problem goes away, then reappears.
    Can you imagine if this condition should it happen to a tech savvy Google Support person? Perhaps one can share and make my problem go away.
    I am considering dropping Google as my mail source. Unfortunate!
    Everett Halvorsen
    [email protected]
    718.490.3824

    I have uninstalled my Access Connection, but this problem seems to persist. IBM technician have changed the wireless card of my T60, the first few days after it was changed was very fine, no problem at all. About a week later, the problem occured again, and it happened quite frequently after that occurence. Now i really have no idea what is the cause and how to solve it. Will be greatful if there is anyone that can help me.

  • I have a lenovo S410 Touch laptop -with windows 8.1 -Itunes 11.1.1 ,i am trying to connect my iphone 4s but does not connect , it shows that it wants to connect , how can you connect this?

    I have a lenovo S410 Touch laptop -with windows 8.1 -Itunes 11.1.1 ,i am trying to connect my iphone 4s by USB cable but does not connect , it shows that it wants to connect , how can you connect this?

    http://support.apple.com/kb/ts1538

  • Hello I Download Adobe Photoshop CC 2014 Last Night i INSTALLED it But it Crashes in 30-40 Sec After i Launch the Product Without Any Error Message I Need Help Can You Resolve This Problem i Tried Creative Cloud Sign Out Nd Sign iN But iT DidnT ReSolve My

    Hello I Download Adobe Photoshop CC 2014 Last Night
     i INSTALLED it But it Crashes in 30-40 Sec After i Launch the Product Without Any Error Message
    I Need Help Can You Resolve This Problem

    Lotfi are you receiving any error messages during the installation?  I would recommend reviewing your installation logs for errors.  Please see Troubleshoot install issues with log files | CC - http://helpx.adobe.com/creative-cloud/kb/troubleshoot-install-logs-cc.html for information on how to locate and interpret your installation log files.  You are welcome to post any specific errors you discover to this discussion.

  • In v.4 fonts look blurry. Can you solve this shortcoming ?

    Fonts look blurry in the overall menu in this new version of browser (v.4). I tried all the options that you specified with the ClearType an so on... It seems that the problem is not from Windows 7 because the old version looks ok. Can you solve this shortcoming ?
    Until you resolve it I'll stay with the previous version (3.6.16) which it looks really good.

    Yea, when I actually install my applications and launch them from GNOME Shell's menu or launcher the fonts look as blurry as they do when I launch them from Anjuta. Other applications look fine and with the workarounds I described above, my own applications display nicely too when launched from either GNOME Shell or Anjuta.

  • How can you search this forum without searching all the other forums

    how can you search this forum without searching all the other forums at the same time which is a big fat waste of time.

    Follow this tip to create a bookmark to a search page that searches only the forum you want or...
    Browse with Firefox and enable this Greasemonkey script, which forces all searches from a sub-forum to be local.

Maybe you are looking for

  • ITunes update 11.1.3.8 to 11.1.4 for Windows 7, 64-bit

    I have a HP Pavillion DV6, Windows 7, SP1, 64-bit.  I am also administrator and the only one who uses my computer. I recently tried to update iTunes to the 11.1.4 and it was unsuccessful and installing.  After that my old version of iTunes wouldn't c

  • Restored hard drive using Time Machine and tons of free space appeared?

    Hi all Went to install Snow Leopard yesterday, and learned I didn't have enough free space left on my Macbook. Went to clear some space and....long story short, cleared up too much stuff, Macbook wouldn't restart, had to restore from a Time Machine b

  • Single Output to Multiple Fax Numbers

    Hello         I have a scenario where a single output should be directed to 2 Fax #'s. I tried the standard way in SAP via Fax address management and it had option of entering 2 #;s. However, only 1 is being sent. Do we have some other ways of doing

  • HTTP 405 Method Not Allowed - portal30_sso.wwsso_app_admin.ls_login

    I was getting the common "no configuration found" message when I clicked on the login link from the portal homepage. So I ran the ssodatan script and now I get this error message when I try to access portal30_sso.wwsso_app_admin.ls_login: "HTTP Error

  • Broken Ipod. Any suggestions on how to fix it??

    I got an iPod touch for Christmas of 2011. I'm not sure if it has warranty but it's very cracked, the touch screen no longer works, & it doesn't charge. Any suggestions on how to fix it or get a new ipod for free or cheap?