[sql performance] inline view , group by , max, join

Hi. everyone.
I have a question with regard to "group by" inline view ,
max value, join, and sql performance.
I will give you simple table definitions in order for you
to understand my intention.
Table A (parent)
C1
C2
C3
Table B (child)
C1
C2
C3
C4 number type(sequence number)
1. c1, c2, c3 are the key columns of tabla A.
2. c1, c2, c3, c4 are the key columns of table B.
3. table A is the parent table of Table B.
4. c4 column of table b is the serial number.
(c4 increases from 1 by "1" regarding every (c1,c2,c3)
the following is the simple example of the sql query.
select .................................
from table_a,
(select c1, c2, c3, max(c4)
from table_b
group by c1, c2, c3) table_c
where table_a.c1 = table_c.c1
and table_a.c2 = table_c.c2
and table_a.c3 = table_c.c3
The real query is not simple as above. More tables come
after "the from clause".
Table A and table B are big tables, which have more than
100,000,000 rows.
The response time of this sql is very very slow
as everyone can expect.
Are there any solutions or sql-tips about the late response-time?
I am considering adding a new column into "Table B" in
order to identify the row, which has max serial number.
At this point, I am not sure adding a column is a good
thing in terms of every aspect.
I will be waiting for your advice and every response
will be appreciated even if it is not the solution.
Have a good day.
HO.
Message was edited by:
user507290

For such big sources check that
1) you use full scans, hash joins or at least merge joins
2) you scan your source data as less as possible. In the best case each necessary table only once (for example not using exists clause to effectively scan all table via index scan).
3) how much time you are spending on sorts and hash joins (either from v$session_longops directly or some tool that visualises this info). If you are using workarea_size_policy = auto, probably you can switch to manual for this particular select and adjust sort_area_size and hash_area_size big enough to do as less as possible sorts on disk
4) if you have enough free resources i.e. big box probably you can consider using some parallelism
5) if your full scans are taking big time check what is your db_file_multiblock_read_count, probably increasing it for this select will give some gain.
6) run trace and check on what are you waiting for
7) most probably your problem is IO bound so probably you can do something from OS side to make IO faster
8) if your query now is optimized as much as you can, disks are running as mad and you are using all RAM then probably it is the most you can get out of your box :)
9) if nothing helps then you can start thinking about precalculations either using your idea about derived column or some materialized views.
10) I hope you have a test box and at least point (9) do firstly on it and see whether it helps.
Gints Plivna
http://www.gplivna.eu

Similar Messages

  • Need help with SQL Query with Inline View + Group by

    Hello Gurus,
    I would really appreciate your time and effort regarding this query. I have the following data set.
    Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
    1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*20.00*-------------19
    1234567----------11223--------------7/5/2008-----------Adjustment for bad quality---------44345563------------------A-----------------10.00------------19
    7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
    4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765--------------------I---------------------30.00-------------19
    Please Ignore '----', added it for clarity
    I am trying to write a query to aggregate paid_amount based on Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number and display description with Invoice_type 'I' when there are multiple records with the same Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number. When there are no multiple records I want to display the respective Description.
    The query should return the following data set
    Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
    1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*10.00*------------19
    7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
    4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765-------------------I---------------------30.00--------------19
    The following is my query. I am kind of lost.
    select B.Description, A.sequence_id,A.check_date, A.check_number, A.invoice_number, A.amount, A.vendor_number
    from (
    select sequence_id,check_date, check_number, invoice_number, sum(paid_amount) amount, vendor_number
    from INVOICE
    group by sequence_id,check_date, check_number, invoice_number, vendor_number
    ) A, INVOICE B
    where A.sequence_id = B.sequence_id
    Thanks,
    Nick

    It looks like it is a duplicate thread - correct me if i'm wrong in this case ->
    Need help with SQL Query with Inline View + Group by
    Regards.
    Satyaki De.

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

  • Try this one again, outer join with inline views

    Posted this before and got no response from anyone. Can anyone advise ?
    does anyone have an example of inline views combined with outer joins in the same statement ? - am currently converting app from sqlserver to oracle and sqlserver view has many left outer joins in from the same table as well as part of the outer join conditions being a subquery e.g.
    select ...
    from a left outer join b left outer join c
    on a.col = b.col and
    c.col = a.col and
    a.othercol = ((select ..
    from d
    where ...)
    OR (select ...
    from e
    where ...))
    where ....
    sometimes they are just mutliple part left outer joins but as many as 10. I guess I have to convert these to inline views then outer join to that, but not 100% sure. There may be a better way ?
    null

    select ...
    from a,b,(select ...) dummyTable
    where a.col = b.col(+)
    AND a.col = dummyTable (+)
    AND b.col = c.col(+)
    AND ....

  • Fine tuning oracle inline view

    Hi All,
    i have a sql query (inline view) which is taking very long time (16 mins Approx) in our environment (Oracle 8.1.7 on Sun).
    Can anyone have any idea to either fine tune the query OR convert it into PL/SQL.
    Query:
    SELECT DISTINCT ML.MFG_LEVEL,          
    SUBSTR(ML.PROCESS_DESC,
    INSTR(ML.PROCESS_DESC, '_', 1, 2) + 1) AS FACILITY,
    SUBSTR(ML.PROCESS_DESC, 1, INSTR(ML.PROCESS_DESC, '_') - 1) AS PACKAGE_NAME,
    SUBSTR(ML.PROCESS_DESC,
    INSTR(ML.PROCESS_DESC, '_') + 1,
    INSTR(ML.PROCESS_DESC, '_', 1, 2) -
    INSTR(ML.PROCESS_DESC, '_') - 1) AS BASIC_TYPE,
    BT.BATCH_TIME_MEAN / BS.BATCH_SIZE AS RUNTIME_BASE,
    ML.TASK_DESC,
    ML.RESOURCE_DESC AS RESOURCE_NAME,
    ML.PROCESS_DESC
    FROM (SELECT DISTINCT RP.VALUE AS MFG_LEVEL,
    TM.TASK_DESC,
    RM.RESOURCE_DESC,
    PC.PROCESS_DESC
    FROM DWH_MCD.TASK_MASTER TM,
    DWH_MCD.TASK_PARAMETER_MASTER TP,
    DWH_MCD.RESOURCE_MASTER RM,
    DWH_MCD.PROCESS_PLAN PP,
    DWH_MCD.PROCESS PC,
    DWH_MCD.RESOURCE_PARAMETER RP,
    DWH_MCD.PARAMETER_TYPE PT
    WHERE PC.PROCESS_ID = PP.PROCESS_ID AND PP.TASK_ID = TM.TASK_ID AND
    TM.TASK_ID = TP.TASK_ID AND TP.RESOURCE_ID = RM.RESOURCE_ID AND
    RP.RESOURCE_ID = RM.RESOURCE_ID AND
    PT.PARAMETER_TYPE_ID = RP.PARAMETER_TYPE_ID AND
    PT.PARAMETER_TYPE_ID = 220037 -- AREA i.e MFG_LEVEL
    AND(TM.TASK_DESC NOT LIKE '%SUBCON%' OR
    PC.PROCESS_DESC NOT LIKE '%VF%')) ML,
    (SELECT DISTINCT TP.VALUE AS BATCH_TIME_MEAN,
    TM.TASK_DESC,
    RM.RESOURCE_DESC,
    PC.PROCESS_DESC
    FROM DWH_MCD.TASK_MASTER TM,
    DWH_MCD.TASK_PARAMETER_MASTER TP,
    DWH_MCD.RESOURCE_MASTER RM,
    DWH_MCD.PROCESS_PLAN PP,
    DWH_MCD.PROCESS PC,
    DWH_MCD.RESOURCE_PARAMETER RP,
    DWH_MCD.PARAMETER_TYPE PT
    WHERE PC.PROCESS_ID = PP.PROCESS_ID AND PP.TASK_ID = TM.TASK_ID AND
    TM.TASK_ID = TP.TASK_ID AND TP.RESOURCE_ID = RM.RESOURCE_ID AND
    RP.RESOURCE_ID = RM.RESOURCE_ID AND
    PT.PARAMETER_TYPE_ID = TP.PARAMETER_TYPE_ID AND
    PT.PARAMETER_TYPE_ID = 220030 -- BATCH TIME MEAN
    AND(TM.TASK_DESC NOT LIKE '%SUBCON%' OR
    PC.PROCESS_DESC NOT LIKE '%VF%')) BT,
    (SELECT DISTINCT TP.VALUE AS BATCH_SIZE,
    TM.TASK_DESC,
    RM.RESOURCE_DESC,
    PC.PROCESS_DESC
    FROM DWH_MCD.TASK_MASTER TM,
    DWH_MCD.TASK_PARAMETER_MASTER TP,
    DWH_MCD.RESOURCE_MASTER RM,
    DWH_MCD.PROCESS_PLAN PP,
    DWH_MCD.PROCESS PC,
    DWH_MCD.RESOURCE_PARAMETER RP,
    DWH_MCD.PARAMETER_TYPE PT
    WHERE PC.PROCESS_ID = PP.PROCESS_ID AND PP.TASK_ID = TM.TASK_ID AND
    TM.TASK_ID = TP.TASK_ID AND TP.RESOURCE_ID = RM.RESOURCE_ID AND
    RP.RESOURCE_ID = RM.RESOURCE_ID AND
    PT.PARAMETER_TYPE_ID = TP.PARAMETER_TYPE_ID AND
    PT.PARAMETER_TYPE_ID = 220008 -- BATCH SIZE
    AND(TM.TASK_DESC NOT LIKE '%SUBCON%' OR
    PC.PROCESS_DESC NOT LIKE '%VF%')) BS
    WHERE ML.TASK_DESC = BT.TASK_DESC AND ML.RESOURCE_DESC = BT.RESOURCE_DESC AND
    ML.PROCESS_DESC = BT.PROCESS_DESC AND ML.TASK_DESC = BS.TASK_DESC AND
    ML.RESOURCE_DESC = BS.RESOURCE_DESC AND
    ML.PROCESS_DESC = BS.PROCESS_DESC;
    Please feel free to ask me for more information if needed.
    Thank You.
    Best Regards,
    Jawahar.

    Jawahar,
    Before you run this sql statement analyse those tables which you use in that query using dbms_utility.analyse_schema() then create one Mview for that query. Before you do all this use "Explain Plan for" this query and observe the statistics. See you need to create a table for Explain Plan. You can find that script in ORACLE_HOME/rdbms/admin/utlxplan.sql
    Kamalesh JK
    jkkstar inc

  • Poor performance: portal report using inline views

    I have created a portal report that uses inline views that performs terribly. It has 6 inline views. When I cut out half the views, the performance doubles. When I run the same query in sql + on my portal database with all the views, I get the results back instantly. Any ideas on what is causing the performance hit in portal? Any ideas on a remedy?

    More info
    SELECT patch_no, count(*) frequency
    FROM users_requests
    WHERE patchset IN (SELECT arps2.patchset_name
    FROM aru_bugfix_relationships abr, aru_bugfixes ab, aru_status_codes ac,
    aru_patchsets arps, aru_patchsets arps2
    WHERE arps.patchset_name = '11i.FIN_PF.E'
    AND abr.bugfix_id = ab.bugfix_id
    AND arps.bugfix_id = ab.bugfix_id
    AND abr.relation_type = ac.status_id
    AND arps2.bugfix_id = abr.related_bugfix_id
    AND abr.relation_type IN (601, 602))
    AND included ='Y'
    GROUP BY patch_no
    order by frequency desc, patch_no
    Runs < 1 sec from SQL navigator and from portal (if i hardcode the value for fampack.
    Takes ~50 secs if i replace with :fampack and set default value to 11i.FIN_PF.D

  • Improve performance of  an inline view query

    All,
    I have a unique situation where I have to limit the number of rows based on group. so I created an Inline view and applied a limit on it.
    ex:
    SELECT col_A, col_B FROM ( SELECT col_a, count(*) FROM tab_a WHERE col_a = 'XXX' GROUP BY col_a) ROWNUM <-10.
    but this design was rejected, because it seems to have a great impact on performance due to inline view.
    Also I cant set a rowlimit directly on the query because GROUP BY clause is used in the select.
    When the rownum is directly applied in the WHERE, first it limits the rows and then it makes a GROUP, so when user asks to retrieve 10 records, it may show less than 10 rows because of the grouping.
    please help to find a alternative solution which helps to get the expected result set and same time without loosing performance.

    Hi,
    The sql you gave us is not valid. There is no "col_b" in your inline view, there is no "where" before "rownum<10", and the inline view returns only one row.
    Try to produce a reproducible scenario with scott.emp and scott.dept generated by $ORACLE_HOME/rdbms/admin/utlsampl.sql
    Regards
    Laurent

  • What is the best way to replace the Inline Views for better performance ?

    Hi,
    I am using Oracle 9i ,
    What is the best way to replace the Inline Views for better performance. I see there are lot of performance lacking with Inline views in my queries.
    Please suggest.
    Raj

    WITH plus /*+ MATERIALIZE */ hint can do good to you.
    see below the test case.
    SQL> create table hx_my_tbl as select level id, 'karthick' name from dual connect by level <= 5
    2 /
    Table created.
    SQL> insert into hx_my_tbl select level id, 'vimal' name from dual connect by level <= 5
    2 /
    5 rows created.
    SQL> create index hx_my_tbl_idx on hx_my_tbl(id)
    2 /
    Index created.
    SQL> commit;
    Commit complete.
    SQL> exec dbms_stats.gather_table_stats(user,'hx_my_tbl',cascade=>true)
    PL/SQL procedure successfully completed.
    Now this a normal inline view
    SQL> select a.id, b.id, a.name, b.name
    2 from (select id, name from hx_my_tbl where id = 1) a,
    3 (select id, name from hx_my_tbl where id = 1) b
    4 where a.id = b.id
    5 and a.name <> b.name
    6 /
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=7 Card=2 Bytes=48)
    1 0 HASH JOIN (Cost=7 Card=2 Bytes=48)
    2 1 TABLE ACCESS (BY INDEX ROWID) OF 'HX_MY_TBL' (TABLE) (Cost=3 Card=2 Bytes=24)
    3 2 INDEX (RANGE SCAN) OF 'HX_MY_TBL_IDX' (INDEX) (Cost=1 Card=2)
    4 1 TABLE ACCESS (BY INDEX ROWID) OF 'HX_MY_TBL' (TABLE) (Cost=3 Card=2 Bytes=24)
    5 4 INDEX (RANGE SCAN) OF 'HX_MY_TBL_IDX' (INDEX) (Cost=1 Card=2)
    Now i use the with with the materialize hint
    SQL> with my_view as (select /*+ MATERIALIZE */ id, name from hx_my_tbl where id = 1)
    2 select a.id, b.id, a.name, b.name
    3 from my_view a,
    4 my_view b
    5 where a.id = b.id
    6 and a.name <> b.name
    7 /
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=8 Card=1 Bytes=46)
    1 0 TEMP TABLE TRANSFORMATION
    2 1 LOAD AS SELECT
    3 2 TABLE ACCESS (BY INDEX ROWID) OF 'HX_MY_TBL' (TABLE) (Cost=3 Card=2 Bytes=24)
    4 3 INDEX (RANGE SCAN) OF 'HX_MY_TBL_IDX' (INDEX) (Cost=1 Card=2)
    5 1 HASH JOIN (Cost=5 Card=1 Bytes=46)
    6 5 VIEW (Cost=2 Card=2 Bytes=46)
    7 6 TABLE ACCESS (FULL) OF 'SYS_TEMP_0FD9D6967_3C610F9' (TABLE (TEMP)) (Cost=2 Card=2 Bytes=24)
    8 5 VIEW (Cost=2 Card=2 Bytes=46)
    9 8 TABLE ACCESS (FULL) OF 'SYS_TEMP_0FD9D6967_3C610F9' (TABLE (TEMP)) (Cost=2 Card=2 Bytes=24)
    here you can see the table is accessed only once then only the result set generated by the WITH is accessed.
    Thanks,
    Karthick.

  • Improve Performance on Inline view Query

    All,
    I have a unique situation where I have to limit the number of rows based on group. so I created an Inline view and applied a limit on it.
    ex:
    SELECT col_A, col_B FROM ( SELECT col_a, count(*) FROM tab_a WHERE col_a = 'XXX' GROUP BY col_a) ROWNUM <-10.
    but this design was rejected, because it seems to have a great impact on performance due to inline view.
    Also I cant set a rowlimit directly on the query because GROUP BY clause is used in the select.
    When the rownum is directly applied in the WHERE, first it limits the rows and then it makes a GROUP, so when user asks to retrieve 10 records, it may show less than 10 rows because of the grouping.
    please help to find a alternative solution which helps to get the expected result set and same time without loosing performance

    but this design was rejected, because it seems to have a great impact on performance due to inline view.What proof was offered that this query performed badly. There is nothing inherently non-performant about in-line views. I would demand to see some evidence that this query uses an unreasonable amount of system resource.
    However, you could try this:
    SELECT t.col1, avg(t.col2)
    FROM   t1 t
    WHERE  t.col1 IN ( SELECT DISTINCT x.col1
                       FROM   t1 x
                       WHERE  col3 = 'XXX'
                       AND    rownum <=10 )
    GROUP  BY t.col1
    /I assume your example is not derived from your real code (otherwise the WHERE clause would restrict the inline query to one returned row - problem solved!)
    Cheers, APC

  • SQL Performance issue: Using user defined function with group by

    Hi Everyone,
    im new here and I really could need some help on a weird performance issue. I hope this is the right topic for SQL performance issues.
    Well ok, i create a function for converting a date from timezone GMT to a specified timzeone.
    CREATE OR REPLACE FUNCTION I3S_REP_1.fnc_user_rep_date_to_local (date_in IN date, tz_name_in IN VARCHAR2) RETURN date
    IS
    tz_name VARCHAR2(100);
    date_out date;
    BEGIN
    SELECT
    to_date(to_char(cast(from_tz(cast( date_in AS TIMESTAMP),'GMT')AT
    TIME ZONE (tz_name_in) AS DATE),'dd-mm-yyyy hh24:mi:ss'),'dd-mm-yyyy hh24:mi:ss')
    INTO date_out
    FROM dual;
    RETURN date_out;
    END fnc_user_rep_date_to_local;The following statement is just an example, the real statement is much more complex. So I select some date values from a table and aggregate a little.
    select
    stp_end_stamp,
    count(*) noi
    from step
    where
    stp_end_stamp
    BETWEEN
    to_date('23-05-2009 00:00:00','dd-mm-yyyy hh24:mi:ss')      
    AND
    to_date('23-07-2009 00:00:00','dd-mm-yyyy hh24:mi:ss')
    group by
    stp_end_stampThis statement selects ~70000 rows and needs ~ 70ms
    If i use the function it selects the same number of rows ;-) and takes ~ 4 sec ...
    select
    fnc_user_rep_date_to_local(stp_end_stamp,'Europe/Berlin'),
    count(*) noi
    from step
    where
    stp_end_stamp
    BETWEEN
    to_date('23-05-2009 00:00:00','dd-mm-yyyy hh24:mi:ss')      
    AND
    to_date('23-07-2009 00:00:00','dd-mm-yyyy hh24:mi:ss')
    group by
    fnc_user_rep_date_to_local(stp_end_stamp,'Europe/Berlin')I understand that the DB has to execute the function for each row.
    But if I execute the following statement, it takes only ~90ms ...
    select
    fnc_user_rep_date_to_gmt(stp_end_stamp,'Europe/Berlin','ny21654'),
    noi
    from
    select
    stp_end_stamp,
    count(*) noi
    from step
    where
    stp_end_stamp
    BETWEEN
    to_date('23-05-2009 00:00:00','dd-mm-yyyy hh24:mi:ss')      
    AND
    to_date('23-07-2009 00:00:00','dd-mm-yyyy hh24:mi:ss')
    group by
    stp_end_stamp
    )The execution plan for all three statements is EXACTLY the same!!!
    Usually i would say, that I use the third statement and the world is in order. BUT I'm working on a BI project with a tool called Business Objects and it generates SQL, so my hands are bound and I can't make this tool to generate the SQL as a subselect.
    My questions are:
    Why is the second statement sooo much slower than the third?
    and
    Howcan I force the optimizer to do whatever he is doing to make the third statement so fast?
    I would really appreciate some help on this really weird issue.
    Thanks in advance,
    Andi

    Hi,
    The execution plan for all three statements is EXACTLY the same!!!Not exactly. Plans are the same - true. They uses slightly different approach to call function. See:
    drop table t cascade constraints purge;
    create table t as select mod(rownum,10) id, cast('x' as char(500)) pad from dual connect by level <= 10000;
    exec dbms_stats.gather_table_stats(user, 't');
    create or replace function test_fnc(p_int number) return number is
    begin
        return trunc(p_int);
    end;
    explain plan for select id from t group by id;
    select * from table(dbms_xplan.display(null,null,'advanced'));
    explain plan for select test_fnc(id) from t group by test_fnc(id);
    select * from table(dbms_xplan.display(null,null,'advanced'));
    explain plan for select test_fnc(id) from (select id from t group by id);
    select * from table(dbms_xplan.display(null,null,'advanced'));Output:
    PLAN_TABLE_OUTPUT
    Plan hash value: 47235625
    | Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |      |    10 |    30 |   162   (3)| 00:00:02 |
    |   1 |  HASH GROUP BY     |      |    10 |    30 |   162   (3)| 00:00:02 |
    |   2 |   TABLE ACCESS FULL| T    | 10000 | 30000 |   159   (1)| 00:00:02 |
    Query Block Name / Object Alias (identified by operation id):
       1 - SEL$1
       2 - SEL$1 / T@SEL$1
    Outline Data
      /*+
          BEGIN_OUTLINE_DATA
          FULL(@"SEL$1" "T"@"SEL$1")
          OUTLINE_LEAF(@"SEL$1")
          ALL_ROWS
          OPTIMIZER_FEATURES_ENABLE('10.2.0.4')
          IGNORE_OPTIM_EMBEDDED_HINTS
          END_OUTLINE_DATA
    Column Projection Information (identified by operation id):
       1 - (#keys=1) "ID"[NUMBER,22]
       2 - "ID"[NUMBER,22]
    34 rows selected.
    SQL>
    Explained.
    SQL>
    PLAN_TABLE_OUTPUT
    Plan hash value: 47235625
    | Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |      |    10 |    30 |   162   (3)| 00:00:02 |
    |   1 |  HASH GROUP BY     |      |    10 |    30 |   162   (3)| 00:00:02 |
    |   2 |   TABLE ACCESS FULL| T    | 10000 | 30000 |   159   (1)| 00:00:02 |
    Query Block Name / Object Alias (identified by operation id):
       1 - SEL$1
       2 - SEL$1 / T@SEL$1
    Outline Data
      /*+
          BEGIN_OUTLINE_DATA
          FULL(@"SEL$1" "T"@"SEL$1")
          OUTLINE_LEAF(@"SEL$1")
          ALL_ROWS
          OPTIMIZER_FEATURES_ENABLE('10.2.0.4')
          IGNORE_OPTIM_EMBEDDED_HINTS
          END_OUTLINE_DATA
    Column Projection Information (identified by operation id):
       1 - (#keys=1) "TEST_FNC"("ID")[22]
       2 - "ID"[NUMBER,22]
    34 rows selected.
    SQL>
    Explained.
    SQL> select * from table(dbms_xplan.display(null,null,'advanced'));
    PLAN_TABLE_OUTPUT
    Plan hash value: 47235625
    | Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |      |    10 |    30 |   162   (3)| 00:00:02 |
    |   1 |  HASH GROUP BY     |      |    10 |    30 |   162   (3)| 00:00:02 |
    |   2 |   TABLE ACCESS FULL| T    | 10000 | 30000 |   159   (1)| 00:00:02 |
    Query Block Name / Object Alias (identified by operation id):
       1 - SEL$F5BB74E1
       2 - SEL$F5BB74E1 / T@SEL$2
    Outline Data
      /*+
          BEGIN_OUTLINE_DATA
          FULL(@"SEL$F5BB74E1" "T"@"SEL$2")
          OUTLINE(@"SEL$2")
          OUTLINE(@"SEL$1")
          MERGE(@"SEL$2")
          OUTLINE_LEAF(@"SEL$F5BB74E1")
          ALL_ROWS
          OPTIMIZER_FEATURES_ENABLE('10.2.0.4')
          IGNORE_OPTIM_EMBEDDED_HINTS
          END_OUTLINE_DATA
    Column Projection Information (identified by operation id):
       1 - (#keys=1) "ID"[NUMBER,22]
       2 - "ID"[NUMBER,22]
    37 rows selected.

  • [SQL] inline view and order by on oracle 8.0.5

    Hi everyone.
    I am trying to sort data inside "inline view"
    on "Oracle8 Release 8.0.5.0.0 - Production".
    However, it did not work. Is this an oracle-bug?
    I got the oracle error , "ORA-00907".
    The sql script is like this:
    select ..............
    from (select ..... from .. where .... order by ...)
    where rownum <11
    However, the "exactly" same sql has no problem
    on "Oracle8i Enterprise Edition Release 8.1.7.0.0".
    Every response will be greatly appreciated.
    Thanks in advance.
    Ho.

    Order by cannot be used in a subquery while for inline view it is supported but in Oracle8i, release 8.1 and up
    Khurram

  • Question regarding an inline view or function inside SQL

    Hi All,
    I want to know whether using an inline view with in an sql query is better or a function call within the sql query is better.
    When I check the explain plan in both the case I can see no difference in the cost.
    Appreciate your valuable suggestions on this.
    Thanks,
    Maddy K.

    Hi, Maddy,
    It depends. The answer to this kind of question is always "it depends" on several factors. It would help if you gave a specific example.
    In general, a function is not an alternative to an in-line view. They're so different, that I suspect I don't really understand the question. Also, I don't understand why you're concerened with in-line views, and not with, for example, regular views or WITH clause sub-queries.
    In general, calling user-defined functions from SQL statements is slow. If there's a simple way to get the same results without calling a user-defined function, then it will probably be faster not to call the function.
    Don't pay much attention to the cost that explain plan gives it. It doesn't mean much to you.

  • Does an inline view execute before the rest of the select?

    Hi,
    The O'Reilly book Mastering Oracle Sql defines an inline view simply as a
    subquery in a select FROM clause. This conforms to the definitions in
    the Oracle 9i and 10g docs.
    But unlike the Oracle docs, the O'Reilly book says the inline view is,
    like a WITH clause, executed before the rest of the query. I can't see
    how this can be done unless the inline view makes no reference to
    other tables joined in the FROM clause.
    Is there a species of inline view in 9i/10g that IS restricted as above -
    no refs to other tables in the FROM clause - and what is it called?
    Thanks for any help.
    Ken Quirici

    As explained above, Oracle can choose to merge the query if feasible to do so. Look at the two queries and their plans below. The plan in second query changes to creating a temporary VIEW since in that case, Oracle is unable to perform the merge:
    SQL> select *
      2          from scott.emp e,
      3                  (select * from scott.dept d where d.deptno = 10) dd
      4  where
      5          e.deptno = dd.deptno
      6  /
         EMPNO ENAME      JOB              MGR HIREDATE           SAL       COMM     DEPTNO     DEPTNO DNAME          LOC
          7782 CLARK      MANAGER         7839 09-JUN-1981       2450                    10         10 ACCOUNTING     NEW YORK
          7839 KING       PRESIDENT            17-NOV-1981       5000                    10         10 ACCOUNTING     NEW YORK
          7934 MILLER     CLERK           7782 23-JAN-1982       1300                    10         10 ACCOUNTING     NEW YORK
    3 rows selected.
    Execution Plan
    Plan hash value: 3570059291
    | Id  | Operation                    | Name           | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT             |                |     3 |   171 |     2   (0)| 00:00:01 |
    |   1 |  NESTED LOOPS                |                |     3 |   171 |     2   (0)| 00:00:01 |
    |   2 |   TABLE ACCESS BY INDEX ROWID| DEPT           |     1 |    20 |     1   (0)| 00:00:01 |
    |*  3 |    INDEX UNIQUE SCAN         | PK_DEPT        |     1 |       |     0   (0)| 00:00:01 |
    |   4 |   TABLE ACCESS BY INDEX ROWID| EMP            |     3 |   111 |     1   (0)| 00:00:01 |
    |*  5 |    INDEX RANGE SCAN          | IDX_EMP_DEPTNO |     3 |       |     0   (0)| 00:00:01 |
    SQL> select *
      2          from scott.emp e,
      3                  (select * from scott.dept d where d.deptno = 10 and rownum > 0) dd
      4  where
      5          e.deptno = dd.deptno
      6  /
         EMPNO ENAME      JOB              MGR HIREDATE           SAL       COMM     DEPTNO     DEPTNO DNAME          LOC
          7782 CLARK      MANAGER         7839 09-JUN-1981       2450                    10         10 ACCOUNTING     NEW YORK
          7839 KING       PRESIDENT            17-NOV-1981       5000                    10         10 ACCOUNTING     NEW YORK
          7934 MILLER     CLERK           7782 23-JAN-1982       1300                    10         10 ACCOUNTING     NEW YORK
    3 rows selected.
    Execution Plan
    Plan hash value: 1670713873
    | Id  | Operation                       | Name           | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT                |                |     5 |   280 |     2   (0)| 00:00:01 |
    |   1 |  NESTED LOOPS                   |                |     5 |   280 |     2   (0)| 00:00:01 |
    |   2 |   VIEW                          |                |     1 |    19 |     1   (0)| 00:00:01 |
    |   3 |    COUNT                        |                |       |       |            |          |
    |*  4 |     FILTER                      |                |       |       |            |          |
    |   5 |      TABLE ACCESS BY INDEX ROWID| DEPT           |     1 |    20 |     1   (0)| 00:00:01 |
    |*  6 |       INDEX UNIQUE SCAN         | PK_DEPT        |     1 |       |     0   (0)| 00:00:01 |
    |   7 |   TABLE ACCESS BY INDEX ROWID   | EMP            |     5 |   185 |     1   (0)| 00:00:01 |
    |*  8 |    INDEX RANGE SCAN             | IDX_EMP_DEPTNO |     5 |       |     0   (0)| 00:00:01 |
    SQL> disconnect
    Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
    With the Partitioning, OLAP and Data Mining options
    SQL>
    can it, in it's WHERE clause, reference other tables in the FROM clause?No. it cannot. but as said above, tha may not stop Oracle from merging the queries.
    SQL> select *
      2          from scott.emp e,
      3                  (select * from scott.dept d where d.deptno = 10 and e.sal > 1000) dd
      4  where
      5          e.deptno = dd.deptno
      6  /
                    (select * from scott.dept d where d.deptno = 10 and e.sal > 1000) dd
    ERROR at line 3:
    ORA-00904: "E"."SAL": invalid identifier
    SQL>

  • Inline View

    I am working in very important sector in Canada and using Oracle widely. There is a group of experienced managers and developer who discourage to use inline views. They have some reasons in addition to (may be misleading) information pass on by Oracle. According to them Inline views are �devils work�. It gives wrong results and poor in performance. They also refer an oracle bug, which I believe is a misleading info by Oracle (probably same guy).
    http://metalink.oracle.com/metalink/plsql/showdoc?db=Bug&id=1227266
    I have posted a question against that bug to Oracle (metalink.oracle.com) PL/SQL FORUM. I think Note:118978.1 is right and if we incorporate aliases we will never face problem. I have widely used inline views and never faced wrong results. In my opinion Inline views made life simple and easy. Its performance is excellent and save a lot of time rather to write multiple SQLs, which make the maintenance job difficult. Considering you an authority on Oracle. I want to seek expert opinion about Inline view. Please keep in mind that here we use lot of SQLs just to avoid inline views and some time convert some SQLs into real Views just to get rid of inline view. Your note could help me to convince my manager to allows us to use inline views.
    Regards,
    Amer

    I need comments from other experts using metlinks but some how not getting any response.Because it's pointless. If your managers and colleagues don't trust you why the heck should they listen to a bunch of nobodies like us> You've got Tom Kyte on your side, he's the Oracle VP of database technology, he's the biggest howitzer in the field. If they go up against him they're going to be flattened.
    Unfortunately there is no cure for human stupidity (I speak as a long term sufferer), and in my experience people with entrenched positions are rarely willing to admit that they were wrong. Particularly when any outsider can see that they are obviously wrong.
    As I see it, you have two choices:
    (1) Knuckle down, don't use inline views.
    (2) Be assertive, use inline views. When challenged demand that they both prove that your implementation is buggy and provide an adequate alternative (as performant, as easy to understand, more reliable).
    Be aware that if you take line (2) you must ensure your code is bulletproof: test it rigourously. By forcing them to look at the code, you can undermine their arguments with fact, an ounce of which is worth a ton of opinion.
    Cheers, APC

  • Difference between INLINE view and WITH clause

    Can anyone plz explain me about the performance difference between the below queries?
    Query using INLINE view:
    SELECT e.ename AS employee_name,
    dc.dept_count AS emp_dept_count
    FROM emp e,
    (SELECT deptno, COUNT(*) AS dept_count
    FROM emp
    GROUP BY deptno) dc
    WHERE e.deptno = dc.deptno;
    Query using WITH clause:
    WITH dept_count AS (
    SELECT deptno, COUNT(*) AS dept_count
    FROM emp
    GROUP BY deptno)
    SELECT e.ename AS employee_name,
    dc.dept_count AS emp_dept_count
    FROM emp e,
    dept_count dc
    WHERE e.deptno = dc.deptno;

    Here's another one:
    http://www.oracle-base.com/articles/misc/WithClause.php
    And, here on this forum you will see that the WITH-clause is heavily used by all of us in order to generate some sample data (when OP's don't care to post CREATE TABLE + INSERT INTO statements).
    The WITH clause enables you as well to 'pretend' you have a table and demonstrate a solution very quickly, without doing actual DDL .
    As for the performance difference:
    We would need to know your database version and many other things.
    See:
    HOW TO: Post a SQL statement tuning request - template posting
    for step by step instructions you can (and should) explore yourself.

Maybe you are looking for

  • Authorize computer in Adobe Digital Editions

    Can multiple users authorize one computer on different windows login accounts?  Several family members in our household have adobe IDs + library cards.  When I connect my NOOK color to transfer an ebook within Adobe Digital Editions, it compares the

  • I cannot get Firefox to open so I can browse.

    Firefox will no long open up to browse. It has been getting slower and slower and tonight it will not open at all. I tried to download it but it keeps telling me I have to close it first in order to install. Close what? It's not running. I tried to u

  • Native Monitor DPI?

    I just got the Apple 30" display and can't seem to find the native dpi of the monitor. I'm not talking about the resolution. I"m fairly new to Mac and my old monitors running in Windows was at 96 dpi. I'm trying to find out so I can set Photoshop up

  • Time in my mac changes after switching to Windows with Boot camp

    Hi there.. I don't know whether this is normal, but every time I switch from Windows back to Mac OS (Using Boot camp-all versions I've tried have this flaw, it hasn't appeared in case of Parallels), system time changes in one hour ahead. Can anybody

  • Clearing with out posting

    Hi, I am doing overpayment for a contract in CML. I want to generate a clearing document with out posting to clear existing open items. Could you please me and let me know if you want any other details. Thanks Gowri.