How do i improve this query

hi all... hre is the following qurey .. that retrieves close to 310 records.. how to improve this further? i definitely need distinct clause here if i remove i willget duplicates
query
SELECT DISTINCT usr_id, pvlg_dim_nb
                      FROM hds01.usr_xref ux, hds01.hds_fct hf
                     WHERE ux.sys_id = 'ACCESS'
                       AND ux.usr_dim_nb = hf.usr_dim_nb
                       AND hf.pvlg_dim_nb <> 0
                       AND hf.prod_dim_nb <> 0
                       AND hf.cust_dim_nb <> 0
                       AND hf.sbj_gp_dim_nb = 0
                       AND hf.obj_gp_dim_nb = 0
                      -- AND hf.rsrc_dim_nb = 0
                       AND hf.obj_cstr_dim_nb = 0
                       AND hf.role_dim_nb = 0
                       AND hf.srv_dim_nb = 0
                      and ux.usr_dim_nb=2598
                            plan
| Id  | Operation                      | Name         | Rows  | Bytes | Cost (%CPU)| Time     |
|   0 | SELECT STATEMENT               |              |     1 |    51 |   612   (1)| 00:00:08 |
|   1 |  HASH UNIQUE                   |              |     1 |    51 |   612   (1)| 00:00:08 |
|   2 |   MERGE JOIN CARTESIAN         |              |  9738 |   484K|   611   (1)| 00:00:08 |
|*  3 |    TABLE ACCESS BY INDEX ROWID | USR_XREF     |     1 |    25 |     2   (0)| 00:00:01 |
|*  4 |     INDEX RANGE SCAN           | USR_XREF_FK1 |     2 |       |     1   (0)| 00:00:01 |
|   5 |    BUFFER SORT                 |              |  9738 |   247K|   609   (1)| 00:00:08 |
|*  6 |     TABLE ACCESS BY INDEX ROWID| HDS_FCT      |  9738 |   247K|   609   (1)| 00:00:08 |
|*  7 |      INDEX RANGE SCAN          | HDS_FCT_FK4  | 10253 |       |    23   (0)| 00:00:01 |
Predicate Information (identified by operation id):
   3 - filter("UX"."SYS_ID"='ACCESS')
   4 - access("UX"."USR_DIM_NB"=259)
   6 - filter("HF"."PROD_DIM_NB"<>0 AND "HF"."PVLG_DIM_NB"<>0 AND
              "HF"."CUST_DIM_NB"<>0 AND "HF"."SBJ_GP_DIM_NB"=0 AND "HF"."OBJ_GP_DIM_NB"=0 AND
              "HF"."OBJ_CSTR_DIM_NB"=0 AND "HF"."ROLE_DIM_NB"=0 AND "HF"."SRV_DIM_NB"=0)
   7 - access("HF"."USR_DIM_NB"=259)

Can you provide some more information regarding:
-Database version?
-Data selectivity?
-Indexes?
-Table statistics?

Similar Messages

  • How can i improve this query.

    Hi guys i am beginner , just wanted to know some info , how can i improve this query ..
    select *
    from tableA A, viewB B,
    where A.key = B.key
    and a.criteria1 = '111'
    and a.criteria2 = some_funtion(a.key)
    one more thing should function should be on left side of equal sign.
    will a join make it better or something else is needed more than that .

    952936 wrote:
    Hi guys i am beginner , just wanted to know some info , how can i improve this query ..
    select *
    from tableA A, viewB B,
    where A.key = B.key
    and a.criteria1 = '111'
    and a.criteria2 = some_funtion(a.key)
    one more thing should function should be on left side of equal sign.
    will a join make it better or something else is needed more than that .If you are a beginner try to learn the ANSI Syntax. This will help you a lot to write better queries.
    Your select would look like this in ANSI.
    select *
    from tableA A
    JOIN viewB B ON A.key = B.key
    WHERE a.criteria1 = '111'
    and a.criteria2 = some_function(a.key);The good thing here is that this separates the typical joining part of the select from the typical filter criteria.
    The other syntax very often let you forget one join. Just because there are so many tables and so many filters, that you just don't notice correctly anymore what was join and what not.
    If you notice that the number of column is not what you expect, you can easiely modify the query and compare the results.
    example A
    Remove View B from the query (temporarily comment it out).
    select *
    from tableA A
    --JOIN viewB B ON A.key = B.key
    WHERE a.criteria1 = '111'
    and a.criteria2 = some_funtion(a.key)
    example B
    You notice, that values from A are missing. Maybe because there is no matching key in ViewB? Then change the join to an outer join.
    select *
    from tableA A
    LEFT OUTER JOIN viewB B ON A.key = B.key
    WHERE a.criteria1 = '111'
    and a.criteria2 = some_funtion(a.key)(The outer keyword is optional, left join would be enough).

  • How I can change this query, so I can display the name and scores in one r

    How I can change this query, so I can add the ID from the table SPRIDEN
    as of now is giving me what I want:
    1,543     A05     24     A01     24     BAC     24     BAE     24     A02     20     BAM     20in one line but I would like to add the id and name that are stored in the table SPRIDEN
    SELECT sortest_pidm,
           max(decode(rn,1,sortest_tesc_code)) tesc_code1,
           max(decode(rn,1,score)) score1,
           max(decode(rn,2,sortest_tesc_code)) tesc_code2,
           max(decode(rn,2,score)) score2,
           max(decode(rn,3,sortest_tesc_code)) tesc_code3,
           max(decode(rn,3,score))  score3,
           max(decode(rn,4,sortest_tesc_code)) tesc_code4,
           max(decode(rn,4,score))  score4,
           max(decode(rn,5,sortest_tesc_code)) tesc_code5,
           max(decode(rn,5,score))  score5,
           max(decode(rn,6,sortest_tesc_code)) tesc_code6,
           max(decode(rn,6,score))  score6        
      FROM (select sortest_pidm,
                   sortest_tesc_code,
                   score,
                  row_number() over (partition by sortest_pidm order by score desc) rn
              FROM (select sortest_pidm,
                           sortest_tesc_code,
                           max(sortest_test_score) score
                      from sortest,SPRIDEN
                      where
                      SPRIDEN_pidm =SORTEST_PIDM
                    AND   sortest_tesc_code in ('A01','BAE','A02','BAM','A05','BAC')
                     and  sortest_pidm is not null 
                    GROUP BY sortest_pidm, sortest_tesc_code))
                    GROUP BY sortest_pidm;
                   

    Hi,
    That depends on whether spriden_pidm is unique, and on what you want for results.
    Whenever you have a problem, post a little sample data (CREATE TABLE and INSERT statements, relevamnt columns only) for all tables, and the results you want from that data.
    If you can illustrate your problem using commonly available tables (such as those in the scott or hr schemas) then you don't have to post any sample data; just post the results you want.
    Either way, explain how you get those results from that data.
    Always say which version of Oracle you're using.
    It looks like you're doing something similiar to the following.
    Using the emp and dept tables in the scott schema, produce one row of output per department showing the highest salary in each job, for a given set of jobs:
    DEPTNO DNAME          LOC           JOB_1   SAL_1 JOB_2   SAL_2 JOB_3   SAL_3
        20 RESEARCH       DALLAS        ANALYST  3000 MANAGER  2975 CLERK    1100
        10 ACCOUNTING     NEW YORK      MANAGER  2450 CLERK    1300
        30 SALES          CHICAGO       MANAGER  2850 CLERK     950On each row, the jobs are listed in order by the highest salary.
    This seems to be analagous to what you're doing. The roles played by sortest_pidm, sortest_tesc_code and sortest_test_score in your sortest table are played by deptno, job and sal in the emp table. The roles played by spriden_pidm, id and name in your spriden table are played by deptno, dname and loc in the dept table.
    It sounds like you already have something like the query below, that produces the correct output, except that it does not include the dname and loc columns from the dept table.
    SELECT    deptno
    ,       MAX (DECODE (rn, 1, job))     AS job_1
    ,       MAX (DECODE (rn, 1, max_sal))     AS sal_1
    ,       MAX (DECODE (rn, 2, job))     AS job_2
    ,       MAX (DECODE (rn, 2, max_sal))     AS sal_2
    ,       MAX (DECODE (rn, 3, job))     AS job_3
    ,       MAX (DECODE (rn, 3, max_sal))     AS sal_3
    FROM       (
               SELECT    deptno
               ,          job
               ,          max_sal
               ,          ROW_NUMBER () OVER ( PARTITION BY  deptno
                                              ORDER BY          max_sal     DESC
                                )         AS rn
               FROM     (
                             SELECT    e.deptno
                       ,           e.job
                       ,           MAX (e.sal)     AS max_sal
                       FROM      scott.emp        e
                       ,           scott.dept   d
                       WHERE     e.deptno        = d.deptno
                       AND           e.job        IN ('ANALYST', 'CLERK', 'MANAGER')
                       GROUP BY  e.deptno
                       ,           e.job
    GROUP BY  deptno
    ;Since dept.deptno is unique, there will only be one dname and one loc for each deptno, so we can change the query by replacing "deptno" with "deptno, dname, loc" throughout the query (except in the join condition, of course):
    SELECT    deptno, dname, loc                    -- Changed
    ,       MAX (DECODE (rn, 1, job))     AS job_1
    ,       MAX (DECODE (rn, 1, max_sal))     AS sal_1
    ,       MAX (DECODE (rn, 2, job))     AS job_2
    ,       MAX (DECODE (rn, 2, max_sal))     AS sal_2
    ,       MAX (DECODE (rn, 3, job))     AS job_3
    ,       MAX (DECODE (rn, 3, max_sal))     AS sal_3
    FROM       (
               SELECT    deptno, dname, loc          -- Changed
               ,          job
               ,          max_sal
               ,          ROW_NUMBER () OVER ( PARTITION BY  deptno      -- , dname, loc     -- Changed
                                              ORDER BY          max_sal      DESC
                                )         AS rn
               FROM     (
                             SELECT    e.deptno, d.dname, d.loc                    -- Changed
                       ,           e.job
                       ,           MAX (e.sal)     AS max_sal
                       FROM      scott.emp        e
                       ,           scott.dept   d
                       WHERE     e.deptno        = d.deptno
                       AND           e.job        IN ('ANALYST', 'CLERK', 'MANAGER')
                       GROUP BY  e.deptno, d.dname, d.loc                    -- Changed
                       ,           e.job
    GROUP BY  deptno, dname, loc                    -- Changed
    ;Actually, you can keep using just deptno in the analytic PARTITION BY clause. It might be a little more efficient to just use deptno, like I did above, but it won't change the results if you use all 3, if there is only 1 danme and 1 loc per deptno.
    By the way, you don't need so many sub-queries. You're using the inner sub-query to compute the MAX, and the outer sub-query to compute rn. Analytic functions are computed after aggregate fucntions, so you can do both in the same sub-query like this:
    SELECT    deptno, dname, loc
    ,       MAX (DECODE (rn, 1, job))     AS job_1
    ,       MAX (DECODE (rn, 1, max_sal))     AS sal_1
    ,       MAX (DECODE (rn, 2, job))     AS job_2
    ,       MAX (DECODE (rn, 2, max_sal))     AS sal_2
    ,       MAX (DECODE (rn, 3, job))     AS job_3
    ,       MAX (DECODE (rn, 3, max_sal))     AS sal_3
    FROM       (
                   SELECT    e.deptno, d.dname, d.loc
              ,       e.job
              ,       MAX (e.sal)     AS max_sal
              ,       ROW_NUMBER () OVER ( PARTITION BY  e.deptno
                                           ORDER BY       MAX (sal)     DESC
                                          )       AS rn
              FROM      scott.emp    e
              ,       scott.dept   d
              WHERE     e.deptno        = d.deptno
              AND       e.job                IN ('ANALYST', 'CLERK', 'MANAGER')
                  GROUP BY  e.deptno, d.dname, d.loc
              ,       e.job
    GROUP BY  deptno, dname, loc
    ;This will work in Oracle 8.1 and up. In Oracle 11, however, it's better to use the SELECT ... PIVOT feature.

  • Hello there,  there is a rare window that keeps popping up every time i start Logic.  I'd like to send a screenshot... anyway, it's a "tempo" window with strange layout about midi effects and so,.... is it normal?  How can i improve this?  Thanks.

    hello there,  there is a rare window that keeps popping up every time i start Logic.  It's a "tempo" window with strange layout about midi effects and so,.... is it normal?  How can i improve this?  Thanks.

    Hmm, that's some sort of MIDI Arpeggiator setup in your environment. Strange that you don't know it, this has to be custom-installed, it is not part of the standard setup.
    You can do two things about it:
    1.unlock your current screenset (shift-L), then close the (Bass Driver) window, then relock the screenset (shift-L). Next time you open up this project you won't see the Bass Driver, but it is still in the project.
    2. You can remove the whole page: open the Environment (cmd-8), then go to the dropdown menu arrow top left of the Environment window and select the Bass Driver layer. If it is selected, dropdown again and choose Delete. Now Save your project under a different name (Save As...), so that you still keep the Bass Driver setup in the original project. If you don't need to keep it, you can simply Save.

  • Finally upgraded to Lions OSX. The Mac screen is now hard to view as everything has a grey tinge. How can I improve this? Tried

    Finally took the plungs and upgraded to Lion OSx so that I could access icloud. Everything worked ok but I now find it difficult to view the screen. Everything has a grey tinge and with my poor eyesight it's really frustrating. Zooming in is ok but I would really like more contrast. What was wrong with crisp white and deep black? Have tried to change the profiles in System Preferences but it's confusing to follow and after 3 attempts I still don't like any of the profiles. My photos all have an unnatural colour now. How can I improve this and bring everything back to 'normal'? Whose 'bright' (?) idea was it to make everyting grey and why???

    Thanks. Very helpful. It's now less of a strain for me. But the fonts are still too pale. I really need to be able to read words that are black. In Mail, the sender and headings are dark enough, but the content is still too light for me to read without straining. Any other suggestions?

  • How I can change this query

    How I can change this query, I got it from someone on the list, and it works just fine, Thank you! but I can not hardcode the data, the data is actually in a repiting table
    SARAPPD_PIDM, SARAPPD_TERM_CODE_ENTRY, SARAPPD_APPL_NO 1 SARAPPD_SEQ_NO
    We can have a person with one record another one with two or three, we just don't know, each record have a sequence number SARAPPD_SEQ_NO
    this SARAPPD_PIDM = 2232040 with will a paramater pass to the function (SARAPPD_PIDM = p_pidm)
    excuse my ignorance, but I just don't have experience with this kind of queries..
    with t as ( -- sample data
        select 2232040     SARAPPD_PIDM,  200990 SARAPPD_TERM_CODE_ENTRY, 1 SARAPPD_APPL_NO, 1 SARAPPD_SEQ_NO,   to_date('12/03/2008','mm/dd/yyyy') sARAPPD_APDC_DATE,  'S*'     SARAPPD_APDC_CODE from dual union all
        select 2232040     ,200990     ,1    ,2     ,to_date('12/08/2008','mm/dd/yyyy'),     'D1' from dual union all
        select 2232040     ,200990     ,1    ,3    ,to_date('03/18/2009','mm/dd/yyyy'),  'S*'  from dual union all
        select 2232040    ,200990     ,1    ,4     ,to_date('03/29/2009','mm/dd/yyyy')     ,'WL' from dual union all
        select 2232040    ,200990     ,1    ,4     ,to_date('03/27/2009','mm/dd/yyyy')     ,'WL' from dual
        ) -- end sample data
        SELECT * FROM (
        SELECT
       A.SARAPPD_PIDM,
       A.SARAPPD_APDC_CODE,
       A.sarappd_apdc_date,
       ROW_NUMBER() OVER (PARTITION BY SARAPPD_PIDM, SARAPPD_TERM_CODE_ENTRY ORDER BY SARAPPD_APDC_DATE
       DESC) row_num
       ,lead (SARAPPD_APDC_DATE,1) over (ORDER BY SARAPPD_APDC_DATE) AS next_date
       FROM t A
       where
        SARAPPD_PIDM = 2232040
         AND sarappd_apdc_code IN ('SA', 'FA', 'S-', 'F-', 'RF', 'F*','AD', 'W-', 'R2', 'S*', 'HF', 'WL','HD', 'R1', 'HS', 'D2', 'W+')
       where  next_date >= to_date('3/27/2009','mm/dd/yyyy');Edited by: user648177 on May 1, 2009 8:52 AM

    Thank you
    I am getting this result
    SARAPPD_PIDM     SARAPPD_APDC_CODE              SARAPPD_APDC_DATE     SARADAP_ADMT_CODE     ROW_NUM               NEXT_DATE
    2232040                                   S*            12/03/2008 16:30:45     D1                                    3                  03/18/2009 08:58:06
    2232040                                   S*            03/18/2009 08:58:06     D1                                      2                 03/21/2009 13:53:23I only want to retrieve the one with the max date ( 03/18/2009 08:58:06)
    I try to add the
    and SARAPPD_SEQ_NO = (select max(b.SARAPPD_SEQ_NO)
                                   from SARAPPD b
                                   where SARAPPD_pidm = b.SARAPPD_pidm)
    {code}
    {code}
    but it did not work
    {code}
    SELECT *
      FROM (SELECT A.SARAPPD_PIDM,
                   A.SARAPPD_APDC_CODE,
                   A.sarappd_apdc_date,
                   saradap_admt_code,
                   ROW_NUMBER() OVER(PARTITION BY SARAPPD_PIDM, SARAPPD_TERM_CODE_ENTRY ORDER BY SARAPPD_APDC_DATE DESC) row_num,
                   lead(SARAPPD_APDC_DATE, 1) over(ORDER BY SARAPPD_APDC_DATE) AS next_date
              FROM saturn.sarappd A, SARADAP
             where SARAPPD_PIDM = 2232040
               and SARADAP_PIDM = SARAPPD_PIDM
               AND saradap_term_code_entry = SARAPPD_TERM_CODE_ENTRY
               AND SARADAP_APPL_NO = A.SARAPPD_APPL_NO
               --         and SARAPPD_SEQ_NO = (select max(b.SARAPPD_SEQ_NO)
                --                    from SARAPPD b
                --                    where SARAPPD_pidm = b.SARAPPD_pidm)
               AND sarappd_apdc_code IN
                   ('SA', 'FA', 'S-', 'F-', 'RF', 'F*', 'AD', 'W-', 'R2', 'S*', 'HF', 'WL', 'HD', 'R1', 'HS', 'D2', 'W+'))
    Where next_date <=       saturn_midd.utlq.f_get_adm_freeze_date(saradap_admt_code)
    {code}
    i now that if I add and row_num=2 it will work, but this is just an example I don't know the row_num of all the records
    Edited by: user648177 on May 4, 2009 5:57 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to speed up this query?

    I have created a demo table:
    create table demo1(d date);
    and insert some data to table:
    begin
    -- add 6000000 rows
    for i in 1..1000000 loop
    insert into demo1 values(trunc(sysdate-i));
    insert into demo1 values(trunc(sysdate-i));
    insert into demo1 values(trunc(sysdate-i));
    insert into demo1 values(trunc(sysdate-i));
    insert into demo1 values(trunc(sysdate-i));
    insert into demo1 values(trunc(sysdate-i));
    end loop;
    commit;
    end;
    The query
    select * from demo1
    where d=to_date('25.10.2004','DD.MM.YYYY')
    executed three times faster than
    select from demo1 where d=trunc(sysdate-1);
    Why? How to speed up this query if I do not want to use index?
    I have created index:
    create index demo1_indx on demo1(d);
    Execution time of queries became identical (for this volume of data).

    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - Production
    With the Partitioning, OLAP and Data Mining options
    SQL> create table demo1(d date);
    Table created.
    SQL> begin
    2 for i in 1..1000000 loop
    3 insert into demo1 values(trunc(sysdate-i));
    4 insert into demo1 values(trunc(sysdate-i));
    5 insert into demo1 values(trunc(sysdate-i));
    6 insert into demo1 values(trunc(sysdate-i));
    7 insert into demo1 values(trunc(sysdate-i));
    8 insert into demo1 values(trunc(sysdate-i));
    9 insert into demo1 values(trunc(sysdate-i));
    10 insert into demo1 values(trunc(sysdate-i));
    11 end loop;
    12 commit;
    13 end;
    14 /
    PL/SQL procedure successfully completed.
    SQL> alter session set timed_statistics=true;
    Session altered.
    SQL> alter session set sql_trace=true;
    Session altered.
    SQL> set timing on;
    SQL> set autotrace on;
    SQL> select * from demo1 where d='25.10.2004';
    D
    25.10.04
    25.10.04
    25.10.04
    25.10.04
    25.10.04
    25.10.04
    25.10.04
    25.10.04
    8 rows selected.
    Elapsed: 00:00:10.70
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=3285 Card=159 Byte
    s=1431)
    1 0 TABLE ACCESS (FULL) OF 'DEMO1' (TABLE) (Cost=3285 Card=159
    Bytes=1431)
    Statistics
    29 recursive calls
    1 db block gets
    28988 consistent gets
    13030 physical reads
    1035300 redo size
    453 bytes sent via SQL*Net to client
    508 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    8 rows processed
    SQL> select * from demo1 where d='25.10.2004';
    D
    25.10.04
    25.10.04
    25.10.04
    25.10.04
    25.10.04
    25.10.04
    25.10.04
    25.10.04
    8 rows selected.
    Elapsed: 00:00:03.35
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=3285 Card=159 Byte
    s=1431)
    1 0 TABLE ACCESS (FULL) OF 'DEMO1' (TABLE) (Cost=3285 Card=159
    Bytes=1431)
    Statistics
    0 recursive calls
    0 db block gets
    14441 consistent gets
    12837 physical reads
    0 redo size
    453 bytes sent via SQL*Net to client
    508 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    8 rows processed
    SQL> select * from demo1 where d='25.10.2004';
    D
    25.10.04
    25.10.04
    25.10.04
    25.10.04
    25.10.04
    25.10.04
    25.10.04
    25.10.04
    8 rows selected.
    Elapsed: 00:00:04.95
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=3285 Card=159 Byte
    s=1431)
    1 0 TABLE ACCESS (FULL) OF 'DEMO1' (TABLE) (Cost=3285 Card=159
    Bytes=1431)
    Statistics
    0 recursive calls
    0 db block gets
    14441 consistent gets
    12757 physical reads
    0 redo size
    453 bytes sent via SQL*Net to client
    508 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    8 rows processed
    SQL> select * from demo1 where d='25.10.2004';
    D
    25.10.04
    25.10.04
    25.10.04
    25.10.04
    25.10.04
    25.10.04
    25.10.04
    25.10.04
    8 rows selected.
    Elapsed: 00:00:03.82
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=3285 Card=159 Byte
    s=1431)
    1 0 TABLE ACCESS (FULL) OF 'DEMO1' (TABLE) (Cost=3285 Card=159
    Bytes=1431)
    Statistics
    0 recursive calls
    0 db block gets
    14441 consistent gets
    12752 physical reads
    0 redo size
    453 bytes sent via SQL*Net to client
    508 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    8 rows processed
    SQL> select * from demo1 where d=trunc(sysdate-3);
    D
    25.10.04
    25.10.04
    25.10.04
    25.10.04
    25.10.04
    25.10.04
    25.10.04
    25.10.04
    8 rows selected.
    Elapsed: 00:00:17.53
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=3696 Card=159 Byte
    s=1431)
    1 0 TABLE ACCESS (FULL) OF 'DEMO1' (TABLE) (Cost=3696 Card=159
    Bytes=1431)
    Statistics
    6 recursive calls
    0 db block gets
    14503 consistent gets
    12758 physical reads
    0 redo size
    453 bytes sent via SQL*Net to client
    508 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    8 rows processed
    SQL> select * from demo1 where d=trunc(sysdate-3);
    D
    25.10.04
    25.10.04
    25.10.04
    25.10.04
    25.10.04
    25.10.04
    25.10.04
    25.10.04
    8 rows selected.
    Elapsed: 00:00:15.82
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=3696 Card=159 Byte
    s=1431)
    1 0 TABLE ACCESS (FULL) OF 'DEMO1' (TABLE) (Cost=3696 Card=159
    Bytes=1431)
    Statistics
    0 recursive calls
    0 db block gets
    14441 consistent gets
    12753 physical reads
    0 redo size
    453 bytes sent via SQL*Net to client
    508 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    8 rows processed
    SQL> select * from demo1 where d=trunc(sysdate-3);
    D
    25.10.04
    25.10.04
    25.10.04
    25.10.04
    25.10.04
    25.10.04
    25.10.04
    25.10.04
    8 rows selected.
    Elapsed: 00:00:14.56
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=3696 Card=159 Byte
    s=1431)
    1 0 TABLE ACCESS (FULL) OF 'DEMO1' (TABLE) (Cost=3696 Card=159
    Bytes=1431)
    Statistics
    0 recursive calls
    0 db block gets
    14441 consistent gets
    12758 physical reads
    0 redo size
    453 bytes sent via SQL*Net to client
    508 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    8 rows processed
    SQL> select * from demo1 where d=trunc(sysdate-3);
    D
    25.10.04
    25.10.04
    25.10.04
    25.10.04
    25.10.04
    25.10.04
    25.10.04
    25.10.04
    8 rows selected.
    Elapsed: 00:00:11.84
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=3696 Card=159 Byte
    s=1431)
    1 0 TABLE ACCESS (FULL) OF 'DEMO1' (TABLE) (Cost=3696 Card=159
    Bytes=1431)
    Statistics
    0 recursive calls
    0 db block gets
    14441 consistent gets
    12757 physical reads
    0 redo size
    453 bytes sent via SQL*Net to client
    508 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    8 rows processed
    SQL> alter session set sql_trace=false;
    Session altered.
    Elapsed: 00:00:00.00
    SQL> alter session set timed_statistics=false;
    Session altered.
    Elapsed: 00:00:00.01
    SQL>

  • How do I correct this query ?

    here is a query:
    select roleid from Apps_USERROLE where guid in (select guid from Apps_USER_MASTER order by userid)
    This does not work ...because the internal subquery retruns multiple result.
    How do I correct this query ?

    Satish Kandi wrote:
    select roleid from Apps_USERROLE where guid in (select guid from Apps_USER_MASTER order by userid)ORDER BY clause is not supported in subqueries since it makes no sense.
    If you want an ordered result set, you need add order by clause to the main query.
    select roleid from Apps_USERROLE where guid in (select guid from Apps_USER_MASTER)
    order by roleid;
    HTH...we have a problem then . Apps_USER_MASTER has userid as primary key .
    select guid from Apps_USER_MASTER => this could give duplicate guid then .

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

  • How to improve this query speed ?....help me

    How to improve the query speed. Any hints can u suggest in the query or any correction. Here i am using sample tables for checking purpose, When i am trying with my original values, this type of query taking longer time to run
    select ename,sal,comm from emp where(comm is null and &status='ok') or (comm is not null and &status='failed');
    Thanx in advance
    prasanth a.s.

    What about
    select ename,sal,comm from emp where comm is null and &status='ok'
    union all
    select ename,sal,comm from emp where comm is not null and &status='failed';
    Regards
    Vaishnavi

  • How to improve this query?

    Hi Friends,
    The table ITEM_COST_STG_TBL contains the following details of the items.
    CREATE TABLE ITEM_COST_STG_TBL(item_org,item_name,item_cost)
    AS
    SELECT 1234 item_org,'I1' item_name,5 item_cost FROM DUAL UNION ALL
    SELECT 1235 item_org,'I1' item_name,5 item_cost FROM DUAL UNION ALL
    SELECT 1236 item_org,'I1' item_name,10 item_cost FROM DUAL UNION ALL
    SELECT 1234 item_org,'I2' item_name,5 item_cost FROM DUAL UNION ALL
    SELECT 1235 item_org,'I2' item_name,5 item_cost FROM DUAL UNION ALL
    SELECT 1236 item_org,'I2' item_name,10 item_cost FROM DUAL
    ) As you can see from the data above,an item may belong to more than one organization.
    For each item, i want to pick all the records of that item whose cost is greater than the minimum cost of that item.
    For this i have wrriten the following query
    SELECT *
    FROM
    SELECT item_org
              ,item_name
              ,item_cost
              ,MIN(item_cost) OVER (PARTITION BY item_name ORDER BY item_cost) MIN_COST
    FROM ITEM_COST_STG_TBL
    WHERE item_cost > min_costIn the above query,the analytic version of the MIN function executes for all the records of the same item even though the MIN value is same.
    Is there a way such that MIN() value is executed once for an item and then comparing the item price with the MIN price?
    The reason why i am looking for this,currently i am executing this query on a table which has very few records.But in the real time the table might be containing 11-12 lakhs of records.

    What about this:
    SELECT     ITEM_ORG
    ,     ITEM_NAME
    ,     ITEM_COST
    FROM     ITEM_COST_STG_TBL ICS
    WHERE      ITEM_COST >      (
                        SELECT      MIN(ITEM_COST)
                        FROM      ITEM_COST_STG_TBL ICSI
                        WHERE      ICSI.ITEM_NAME = ICS.ITEM_NAME
                        GROUP BY ITEM_NAME
                   )HTH!
    *:EDIT:*
    Your query might be the most efficient, based on the current explain plans:
    Explain plan your query:
    | Id  | Operation           | Name              | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT    |                   |     6 |   258 |     3  (34)| 00:00:01 |
    |*  1 |  VIEW               |                   |     6 |   258 |     3  (34)| 00:00:01 |
    |   2 |   WINDOW SORT       |                   |     6 |   180 |     3  (34)| 00:00:01 |
    |   3 |    TABLE ACCESS FULL| ITEM_COST_STG_TBL |     6 |   180 |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - filter("ITEM_COST">"MIN_COST")Explain plan my query:
    | Id  | Operation             | Name              | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT      |                   |     1 |    30 |     4   (0)| 00:00:01 |
    |*  1 |  FILTER               |                   |       |       |            |          |
    |   2 |   TABLE ACCESS FULL   | ITEM_COST_STG_TBL |     6 |   180 |     2   (0)| 00:00:01 |
    |   3 |   SORT GROUP BY NOSORT|                   |     1 |    17 |     2   (0)| 00:00:01 |
    |*  4 |    TABLE ACCESS FULL  | ITEM_COST_STG_TBL |     1 |    17 |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - filter("ITEM_COST"> (SELECT /*+ */ MIN("ITEM_COST") FROM
                  "ITEM_COST_STG_TBL" "ICSI" WHERE "ICSI"."ITEM_NAME"=:B1 GROUP BY "ITEM_NAME"))
       4 - filter("ICSI"."ITEM_NAME"=:B1)Edited by: Centinul on Jun 26, 2009 7:34 AM

  • How can we rewrite this query for better performance

    Hi All,
    The below query is taking more time to run. Any ideas how to improve the performance by rewriting the query using NOT EXITS or any other way...
    Help Appreciated.
    /* Formatted on 2012/04/25 18:00 (Formatter Plus v4.8.8) */
    SELECT vendor_id
    FROM po_vendors
    WHERE end_date_active IS NULL
    AND enabled_flag = 'Y'
    and vendor_id NOT IN ( /* Formatted on 2012/04/25 18:25 (Formatter Plus v4.8.8) */
    SELECT vendor_id
    FROM po_headers_all
    WHERE TO_DATE (creation_date) BETWEEN TO_DATE (SYSDATE - 365)
    AND TO_DATE (SYSDATE))
    Thanks

    Try this one :
    This will help you for partial fetching of data
    SELECT /*+ first_rows(50) no_cpu_costing */
    vendor_id
    FROM po_vendors
    WHERE end_date_active IS NULL
    AND enabled_flag = 'Y'
    AND vendor_id NOT IN (
    SELECT vendor_id
    FROM po_headers_all
    WHERE TO_DATE (creation_date) BETWEEN TO_DATE (SYSDATE - 365)
    AND TO_DATE (SYSDATE))
    overall your query is also fine, because, the in this query the subquery always contain less data compare to main query.

  • How to performance tune this query

    I need some inputs on how to do performance tuning on this query to improve performance.
    It takes around 45 secs to run. Is it possible to make any improvements in this by putting hints or writing in another way?
    select count(*)
    as nCount from A ,
    B ,
    C
    WHERE A.COL1 = B.COL1 AND
    A.COl2 <> 'COM' AND
    B.COL2 = C.COL1 AND
    B.COl3 IS NULL AND
    B.COL4 = 'TEST'
    This is the query plan:
    Operation Object Name Rows Bytes Cost Object Node In/Out PStart PStop
    SELECT STATEMENT Optimizer Mode=CHOOSE 1 51
    SORT AGGREGATE 1 37
    HASH JOIN 48 K 1 M 51
    TABLE ACCESS FULL A 68 K 998 K 32
    NESTED LOOPS 98 K 2 M 5
    TABLE ACCESS BY INDEX ROWID B 142 K 2 M 4
    INDEX SKIP SCAN XIF37B 142 K 6
    INDEX UNIQUE SCAN XPKC 1 5

    Mcka
    As well as EXPLAIN PLAN, let us know what proportion of rows are visited by this query. It may be that it is not using a full table scan when it should (or vice versa).
    And of course we'd need to know what indexes are available, and how selective they are for the predicated you have in this query ...
    Regards Nigel

  • How do I get this query into Discoverer Plus

    Hi all,
    I have the following query:
    SELECT h.hrs, NVL(Quantity, 0) Quantity
    FROM (SELECT TRIM(to_char(LEVEL - 1, '00')) hrs
    FROM dual
    CONNECT BY LEVEL < 25) h
    LEFT JOIN (SELECT TO_CHAR(event_date, 'HH24') AS during_hour,
    COUNT(*) Quantity
    FROM user_activity u
    WHERE event_date BETWEEN
    to_date('15-JUN-2010 14:00:00', 'DD-MON-YYYY HH24:MI:SS') AND
    to_date('16-JUN-2010 13:59:59', 'DD-MON-YYYY HH24:MI:SS')
    AND event = 'user.login'
    GROUP BY TO_CHAR(event_date, 'HH24')) t
    ON (h.hrs = t.during_hour)
    ORDER BY h.hrs;
    Which produces the number of actions performed (from an event table, user_activity) grouped by the hour of the day they occurred (including displaying hours that have zero records - this bit is important!). I want to be able to put this into Discoverer plus as a worksheet, but I'm having trouble trying to figure out how.
    I was able to create a custom folder in Administrator for the select from DUAL, but I cannot link it to the user_activity table because there's no relationship between to two tables to create a join.
    The user_activity table is:
    USER_ID - VARCHAR2(8 CHAR)
    EVENT_DATE - DATE
    EVENT - VARCHAR2(100 CHAR)
    The custom folder is this part of the SQL:
    SELECT TRIM(to_char(LEVEL - 1, '00')) hrs FROM dual CONNECT BY LEVEL < 25
    Any suggestions would be greatly appreciated.
    Thanks.
    Edited by: Cyntech on Aug 12, 2010 10:41 AM

    KK wrote:
    hi,
    In the custom folder we can join tables,but the thing is you said ther is no join between them.
    I would suggest you to built this query into a view and use this view in the DUAL table by writing inline query or subquery what ever way.
    This is the only possibility i can think off.
    Hope it helps you.
    By,
    KKHi,
    Thanks for the reply, though I'm not sure that I understand what you are suggesting.
    Which query would you turn into a view? If you are referring to the select from dual, then how would the view be any different from the custom folder? You still would not be able to join it to user_activity as there are no common columns.
    Edited by: Cyntech on Aug 12, 2010 2:49 PM

  • How can i improve this 2min countdown timer?

    Hello
    I'm trying to see if anyone has any ideas on how to improve this simple 2 minute countdown timer.  All suggestions are welcome!
    Thanks in advance!
    -noviceLabVIEWuser
    Solved!
    Go to Solution.
    Attachments:
    2min Countdown Timer.vi ‏38 KB

    As an alternative, I used a case structure to eliminate some calculations for Sample Time while Air Time is counting down and vice versa.  I don't know if this is necessarily better.  Your original code was simple and it worked fine.
    False case showing:                                          ​                                 True case showing:
    - tbob
    Inventor of the WORM Global

Maybe you are looking for