Summarize the costs with hierarchical query

Hello Oracle experts! I need some advice because I am very new to the hierarchical queries really new to Oracle. I have the following table:

CREATE TABLE routes

(

     from  VARCHAR2(15),

     to  VARCHAR2(15),

     cost NUMBER

);

INSERT INTO routes VALUES('San Francisco', 'Denver', 1000);

INSERT INTO routes VALUES('San Francisco', 'Dallas', 10000);

INSERT INTO routes VALUES('Denver', 'Dallas', 500);

INSERT INTO routes VALUES('Denver', 'Chicago', 2000);

INSERT INTO routes VALUES('Dallas', 'Chicago', 600);

INSERT INTO routes VALUES('Dallas', 'New York', 2000);

INSERT INTO routes VALUES('Chicago', 'New York', 3000);

INSERT INTO routes VALUES('Chicago', 'Denver', 2000);

I want to calculate the costs through the hierarchy, to get the following result:

FROM            TO             COST

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

San Francisco Dallas   10000   //San Francisco -> Dallas

San Francisco Denver 1000    //San Francisco -> Denver

San Francisco Chicago   10600   //San Francisco -> Dallas -> Chicago (10000 + 600)

San Francisco New York   12000   //San Francisco -> Dallas -> New York (10000 + 200)

San Francisco Chicago   3000    //San Francisco -> Denver -> Chicago (1000 + 2000)

San Francisco Dallas   1500    //San Francisco -> Denver -> Dallas (1000 + 500)

etc..

I from imagined using the CONNECT BY PRIOR statement to get the hierarchy and have written a query that runs through him:

SELECT CONNECT_BY_ROOT from, to

FROM routes

  CONNECT BY NOCYCLE PRIOR to = from;

But I have absolutely no idea how summarize right costs, I could use some help.

Thank you for your advice.

Hello

Here's a way

SELECT DISTINCT

CONNECT_BY_ROOT from_city AS from_city

to_city

, SYS_CONNECT_BY_PATH (to_city, '->') is ARRESTED - if wanted

, XMLQUERY (SYS_CONNECT_BY_PATH (cost, '+'))

BACK CONTENT

) .getnumberval () SUCH as total_cost

CHANNELS

WHERE CONNECT_BY_ROOT from_city <> to_city

CONNECT BY NOCYCLE from_city = to_city PRIOR

ORDER BY from_city

to_city

stops

;

FROM and TO are the keywords of the Oracle, they really ugly column names.  I have changed the from_city and to_city.

Tags: Database

Similar Questions

  • How to group and summarize the values with a vertical drop of 100?

    Dear gurus
    How to group and summarize the values with a vertical drop of 100 as the data indicated below:

    Cas_Cod_ Cas_Amt_ Description
    300 1000A
    301 200 B
    302 350 C
    400 500 A
    401 100 B
    402 25

    Now the data should be grouped like this
    A (300,400) = 1500
    (301,401) B = 300
    C (302,402) = 375

    Make sure that I don't have a column as description in my table to group data on description, its here just to give u an example.

    Hello

    using mod for hundreds:

    with x as
    (
      select 300 code, 1000 amt, 'A' descr from dual union all
      select 301 code, 200 amt, 'B' descr from dual union all
      select 302 code, 350 amt, 'C' descr from dual union all
      select 400 code, 500 amt, 'A' descr from dual union all
      select 401 code, 100 amt, 'B' descr from dual union all
      select 402 code, 25 amt, 'C' descr from dual
      )
       select mod(code,100) code, sum (amt)
        from x
       group by mod(code,100);
    

    Using the mod you get the rest of a division, so mod (300,100) = 0, mod (301,100) = 1, etc.

    Herald tiomela
    http://htendam.WordPress.com

  • Help with hierarchical query

    I'm trying to parse each string inside of individual characters. For this, I used the link by the hierarchical query clause. I am not able to use connect by correctly. Here is my example.

    with the CBC as)

    Select 1: the nurse, 'abc' double union all Str

    Select 2: the nurse, '123' Str of all union double

    Select 3: the nurse, "pqr xyz" dual union all Str

    Select option 4: the nurse, 'john doe' double Str

    )

    Select the level, homobasidiomycetes, substr(s.str,level,1) as chr

    s of the CBC

    connect nocycle level < = length (homobasidiomycetes)

    /

    The above query returns 3 028 lines when I want that 21. Adding a distinct to select, it's what I want.

    with the CBC as)

    Select 1: the nurse, 'abc' double union all Str

    Select 2: the nurse, '123' Str of all union double

    Select 3: the nurse, "pqr xyz" dual union all Str

    Select option 4: the nurse, 'john doe' double Str

    )

    Select distinct level, homobasidiomycetes, substr(s.str,level,1) as chr

    s of the CBC

    connect nocycle level < = length (homobasidiomycetes)

    order by str, level

    /

    For a large data set I could end up with several million rows before the separate would lead. So, how can I restrict the connection by clause to go within each line.

    Assuming that the AI is the primary key, you could do this:

    with src as (
      select 1 as rn, 'abc' as str from dual union all
      select 2 as rn, '123' as str from dual union all
      select 3 as rn, 'pqr xyz' as str from dual union all
      select 4 as rn, 'john doe' as str from dual
    )
    select level,
          s.str,
          substr(s.str,level,1) as chr
    from src s
    connect by level <= length(s.str)
              and prior rn = rn
              and prior dbms_random.value is not null;
    

    See DBMS_RANDOM.value in a hierarchical solution for string to table? for an exchange of views around the case.

  • Getting the line without the use of hierarchical query values

    Hi all


    I want to know the hierarchical values without using a hierarchical query. I have two tables EMP, DEPT

    EMP table is to have two columns (empid, mgrid)
    DEPT table is to have two columns (deptid, empid)

    Data of the EMP

    1,
    2, 1
    3, 2
    4, 3

    Data DEPT

    10, 1

    Each time, I gave deptid = 10, I need to know the this deptid empid then who is this empid (child levels as well). In this case, the output should be
    1
    2
    3
    4

    I don't want to use hierarchical query.

    Thanks in advance.


    Thank you
    PAL

    You can use the RECURSIVE subquery, if you are 11 GR 2, like this

    SQL> with EMP (empid,mgrid) as
      2  (
      3  select 1,null from dual union all
      4  select 2, 1 from dual union all
      5  select 3, 2 from dual union all
      6  select 4, 3 from dual
      7  ),
      8  dept(deptid,empid) as
      9  (
     10  select 10, 1  from dual
     11  ),
     12  t(empid,mgrid) as
     13  (
     14  select empid,mgrid
     15  from emp e
     16  where empid in (
     17      select d.empid
     18      from dept d
     19      where deptid = 10
     20                  )
     21  union all
     22  select e.empid,e.mgrid
     23  from emp e, t
     24  where e.mgrid = t.empid
     25  )
     26  select *
     27  from t;
    
         EMPID      MGRID
    ---------- ----------
             1
             2          1
             3          2
             4          3
    

    Yet, the question is valid - why can't use you a hierarchical query?

    Published by: JAC on May 29, 2013 12:37

  • How to use order by with hierarchical query

    I have a hierarchical query basically he brings an organization chart. We start with the Manager id, get everything that employees of the person. If the employee is also a Manager I want to get the employees of that person and turn them right after that person. I don't bother with the entire query but relevant part is:
           START WITH em.mgr_id = pi_mgr_id
          CONNECT BY nocycle PRIOR em.emp_id = em.mgr_id;
    Where pi_mgr_id is a parameter passed to the procedure and the em is the alias of the emp_mgr_relationship table that contains emp_id and mgr_id. It works very well. What I want now is for employees who work for the same Manager appear in the order of name. The table that contains the names of the employees is an alias as pe and the name column is called name1. I added the following:
           START WITH em.mgr_id = pi_mgr_id
          CONNECT BY nocycle PRIOR em.emp_id = em.mgr_id
            order by pe.name1;
    But what to put the entire list in the order of name. What I want is for the employees who work for the same manager be in name order. We're going to the manager that I want to the body is named Frank. I want to get it
    EMP_NAME    MGR_NAME
    Allen       Frank
    Beth        Frank
    Alex        Beth
    Charles     Beth
    Ed          Beth
    Dean        Frank
    George      Frank
    Benny       George
    David       George
    Sam         George
    Dan         Sam
    Harry       Sam
    John        Sam
    Terry       George
    James       Frank
    Ken         Frank
    Mike        Ken
    Warren      Ken
    How can I get the list in order?

    Published by: kendenny on July 28, 2010 07:31

    Make use of the ORDER of Friars and SŒURS clause in the hierarchical queries to define the order of child columns.

    START WITH em.mgr_id = pi_mgr_id
          CONNECT BY nocycle PRIOR em.emp_id = em.mgr_id
            *order siblings by name1;*
    
  • Problem with hierarchical query in function PL\SQL

    I have a simple table containing the ID of the parent

    -Create table

    create the table1 table:

    (

    ID NUMBER (12) not null,

    year number 4.

    month NUMBER (2),

    parent_id NUMBER (12)

    );

    -Create/recreate primary, unique and foreign key constraints

    change the table1 table:

    Add primary key constraint PK_TABLE1 (ID);

    change the table1 table:

    Add the foreign key constraint FK_TABLE1_PARENT (PARENT_ID)

    reference TABLE1 (ID);

    data:

    Insert into TABLE1 (id, year, month, parent_id)

    values (5, 2015, 12, 3);

    Insert into TABLE1 (id, year, month, parent_id)

    values (6 (2015), 12, 4);

    Insert into TABLE1 (id, year, month, parent_id)

    values (3 (2015), 11, 1);

    Insert into TABLE1 (id, year, month, parent_id)

    values (4 (2015), 11, 2);

    Insert into TABLE1 (id, year, month, parent_id)

    values (1, 2015, 10, null);

    Insert into TABLE1 (id, year, month, parent_id)

    values (2 (2015), 10, null);

    commit;

    and query

    with h as

    (select t.id, t.year, t.month, CONNECT_BY_ROOT t.id as parent_id from table1 t

    where t.year = 2015 and t.month = 12

    and CONNECT_BY_ROOT t.year = 2015 and CONNECT_BY_ROOT t.month = 10

    connect by prior t.id = t.parent_id)

    Select * from:

    Join table1 t left t.id = h.parent_id;

    It works, but when I put this request in the procedure pl\sql

    create or replace procedure is get_report (p_cur_out on sys_refcursor)

    Start

    Open the p_cur_out for

    with h as

    (select t.id, t.year, t.month, CONNECT_BY_ROOT t.id as parent_id from table1 t

    where t.year = 2015 and t.month = 12

    and CONNECT_BY_ROOT t.year = 2015 and CONNECT_BY_ROOT t.month = 10

    connect by prior t.id = t.parent_id)

    Select * from:

    Join table1 t left t.id = h.parent_id;             

    end get_report;

    /

    They do not compile. And in the fall, with the exception

    Errors of compilation for the PC of the PROCEDURE. GET_REPORT

    [Error: PL/SQL: ORA-00600: internal error code, arguments: [qctcte1], [0], [], [], [], [], [], [], [], [], []]

    Online: 6

    Text: with h as

    Error: PL/SQL: statement ignored

    Online: 6

    Text: with h as

    My version of oracle

    1Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production
    2PL/SQL Release 11.2.0.3.0 - Production
    3CORE Production 11.2.0.3.0
    4AMT for Linux: Version 11.2.0.3.0 - Production
    5NLSRTL Version 11.2.0.3.0 - Production

    What is the problem with my request? Or database? How to solve this problem?

    If you have access to MOS, you can search the reason of it. If you are using left join syntax instead of joining ANSI, owner Oracle procedure compiles and returns the result.

  • What is the problem with this query?

    Hello

    I need some advice on how to change the following query (with perhaps some analytical function) to speed it up. Currently, it takes 6 + minutes. This query is executed in response to a request from the front-end application and 6 + min is certainly unacceptable.

    I am trying to provide as much information I can think, but if more information is needed, please let me know.

    I have a table called "wave_result". It contains millions of rows. PK is Wave_Id, Version_nbr, node_nbr and prod_nbr. For each 'wave_id + node_NBR + prod_nbr' there are several versions (version_nbr). In the following query, I try to extract a line with MAX version_nbr for combination of ' wave_id + node_NBR + prod_nbr.

    H3. Request:
    SELECT ip1.fnln_cat,
                ip1.sub_cat,
                ip1.bus_cat,
                NVL (SUM (ip1.lsu), 0) val
        FROM ideal_prod ip1, ideal_store s, wave_result wr
       WHERE  wr.wave_id = 51
             AND wr.prod_nbr = ip1.prod_nbr
             AND wr.wave_id = ip1.wave_id
             AND wr.version_nbr =
                    (SELECT MAX (wr1.version_nbr)
                       FROM wave_result wr1
                      WHERE   wr1.wave_id = wr.wave_id
                            AND wr1.node_nbr = wr.node_nbr
                            AND wr1.prod_nbr = wr.prod_nbr)
             AND NVL (wr.ovrd_dcsn_nm, wr.dcsn_nm) = 'Add'
             AND s.wave_id = wr.wave_id
             AND s.node_nbr = wr.node_nbr 
    GROUP BY ip1.fnln_cat, ip1.sub_cat, ip1.bus_cat
    H3. Rank of charges:
    ========
    "wave_result" is the largest table with millions of rows.
    Table                Total Rows       Rows for wave_id = 51
    Ideal_prod           188K             38K
    Ideal_store          3K               574
    Wave_result          90M              19M
    H3. Stats
    are updated almost daily by the DBA (not sure if that's a good or bad).

    H3. Explain the Plan:
    =========
    SELECT STATEMENT ALL_ROWS Cost: 330,737 Bytes: 401,787 Cardinality: 14,881 
         12 HASH GROUP BY Cost: 330,737 Bytes: 401,787 Cardinality: 14,881 
              11 VIEW VIEW SYS.VM_NWVW_2 Cost: 330,737 Bytes: 401,787 Cardinality: 14,881 
                   10 FILTER 
                        9 HASH GROUP BY Cost: 330,737 Bytes: 2,425,603 Cardinality: 14,881 
                             8 HASH JOIN Cost: 327,183 Bytes: 41,233,784 Cardinality: 252,968 
                                  1 INDEX RANGE SCAN INDEX (UNIQUE) APAPOPR.XPKIDEAL_STORE Cost: 4 Bytes: 13,202 Cardinality: 574 
                                  7 HASH JOIN Cost: 327,178 Bytes: 35,415,520 Cardinality: 252,968 
                                       5 HASH JOIN Cost: 198,619 Bytes: 18,764,328 Cardinality: 183,964 
                                            3 TABLE ACCESS BY INDEX ROWID TABLE APAPOPR.IDEAL_PROD Cost: 939 Bytes: 2,272,380 Cardinality: 37,873 
                                            4 TABLE ACCESS FULL TABLE APAPOPR.WAVE_RESULT Cost: 197,063 Bytes: 7,974,414 Cardinality: 189,867 
                                       6 INDEX RANGE SCAN INDEX (UNIQUE) APAPOPR.XPKWAVE_RESULT Cost: 82,467 Bytes: 721,495,854 Cardinality: 18,986,733 
    H3. Sample data:
    ===========
       For wave_id = 51
                     there are 28466854 rows in "wave_result" table
    
       For wave_id = 51 and node_nbr = '0201' and  prod_nbr = '0226960'
                     there are 3 rows in "wave_result" table
    H3. Version of database information are below to:
    =========================
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    PL/SQL Release 11.1.0.7.0 - Production
    CORE            11.1.0.7.0                        Production
    TNS for IBM/AIX RISC System/6000: Version 11.1.0.7.0 - Production
    NLSRTL Version 11.1.0.7.0 - Production
    Thank you very much!!

    Concerning
    For wave_id = 51
                     there are 28466854 rows in "wave_result" table
    
       For wave_id = 51 and node_nbr = '0201' and  prod_nbr = '0226960'
                     there are 3 rows in "wave_result" table
    

    As you mentioned that this particular request is called by a front screen, how different search criteria you get it to show on the front end?
    Assuming that if the user is searching just of wave_id = 51 which lines returns to 28466854, it is certainly not a good approach to go look up many records to put end Front end is very light and can not hold many records and will be finally the web server will throw off out of memory exception. Always a limit on the number of records that you retrieve from the database and display it on the front plane.
    OR
    The second case where the user makes a search by wave_id, node_nbr and prod_nbr, even if she returns to 3 lines, behind the scens, he still made a full scan on the wave_result table. If we go with analytical function, we can reduce a sweep of extra table on the wave_result table. Also the table has millions of lines and the max (version_nbr) seems to be a frequently used on this table sub query. While inserting a record into the table wave_result, you must probably have a calculated value that will tell you its value max and you will choose just the rank of this value, instead of at each time max(). something like below...

    SELECT ip1.fnln_cat,
                ip1.sub_cat,
                ip1.bus_cat,
                NVL (SUM (ip1.lsu), 0) val
        FROM ideal_prod ip1, ideal_store s, wave_result wr
       WHERE ipl.wave_id = 51
             AND wr.prod_nbr = ip1.prod_nbr
             AND wr.wave_id = ip1.wave_id
             AND wr.wave_id = s.wave_id
             AND wr.node_nbr = s.node_nbr
             AND wr.precomputed_max_value = 'MAX'
             AND NVL (wr.ovrd_dcsn_nm, wr.dcsn_nm) = 'Add'
    GROUP BY ip1.fnln_cat, ip1.sub_cat, ip1.bus_cat;
    
  • Need help with hierarchical query

    I have a table as below by indicating the columns id and parent_id.

    ID parent_id

    ---  --------

    1

    2 1

    5 t

    4 2

    5

    6 5

    6 of 7

    Need lower o/p.

    ID parent_id

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

    4 2

    4 1

    6 of 7

    5 of 7

    Thus, the node of the hierarchical values worksheet must be kept in the value of the ID.

    Thank you!

    Hello

    One way is a request to CONNECT BY Bottom-Up :

    ID CONNECT_BY_ROOT SELECT ID

    parent_id

    TEMP

    WHERE parent_id IS NOT NULL

    START WITH id NOT IN)

    SELECT parent_id

    TEMP

    WHERE parent_id IS NOT NULL

    )

    CONNECT BY id = parent_id PRIOR

    ;

    Top-Down CONNECT BY queries, where you start with the roots and then to find children, are more common, only because they are appropriate for most problems.  Queries from the bottom to the top, where you start with leaves and then will find relatives, are equally valid and work the same way.

  • How to complete the VO with DB query values

    Query 1 = Select resultSet of table1, table2, table3;

    and we want this value to be filled in our view based entity VO1, resultSet as

    We have created the VO1 table, which is initially empty, which during the click on the button get values of query1 and store its value in a table and then fill these values one by one with loop to VO1.

    Then, we want to save these values the button validate in VO1 table;

    Now how to do this. ?? can it be done with the iterator? setAttribure one?

    Yes you can do it with the iterator. Select your values in the table. Save it to a table and then fill with loop.

  • Definition of limit of 0 in the Combobox with LOV query

    Hello

    I created a new LOV for an attribute of VO planted in merger Compensation App.

    After you add the LOV, I'm adjusting the UI indicator user limit query to 0 because I want to have the search link only when you click on the drop down menu on the user interface.

    But with the limit of request is 0, the entire query result is displayed when you click the menu drop down.

    All entries on this? I tried a few Options of LOV VO Tuning parameters but not successful.

    Thank you
    Kaja

    Kaja

    Although some of the places it is done for commercial reasons but if you still have to do it just for the sake of consistency, then this is how you can do is:
    1. create a new view of criteria that makes sure not to return all values on the VO as tell the departmentId = - 1
    2. go into your LOV and councils interface user chose this vc in the drop-down list box filter section with option.

    This will give you the expected results.

    Thank you best regards &!
    Vik

    Fusion applications Developer Relations
    http://blogs.Oracle.com/fadevrel

    Please check the appropriate response or useful response

  • Create a page with an estimate of the costs with DWCS6

    Hi all

    I need to help, once again. I create a page where the user can choose from many options and ultimately it gets the estimated costs, for example:

    Home: * drop-down list where the user can choose the kind of house they love, with different prices *-> Let's say the user chooses 'Flat', and the apartment is $ 200

    Car: * drop-down list with different kinds of car-> and here, the user chooses 'Ferrari' with a 'related' $ 2,000 value

    -----------

    Estimated total: $2200

    In a table, assuming that it is on a page, it could be:

    Category Selection $
    HouseDish200
    CarFerrari2000
    Total estimated2200

    So, what I need, it's a page where the user chooses goods or services from drop-down lists and at the end of the page you have a total estimated. In these lists, you see the name of the goods/service and next to it 'appears' value (inside a text box or something) once you make a selection.
    How does it work? I checked around but probably I used the wrong keywords... because I couldn't find anything! ;(

    Thanks in advance!

    What you understand about the JS Fiddle I gave you?

    • HTML form,
    • CSS for shape, style
    • function jQuery to calculate the values of the form input.  jQuery code goes inside

      Nancy O.

  • What is the problem with this query? My head is numb!

    Can someone tell me why this request;

    < cfquery datasource = "manna_premier" name = "qGetstats" >
    SELECT the user name,
    UserFirstName,
    UserLastName,
    LastLogin,
    TotalLogins,
    UserZone,
    TM_Name
    USERS
    WHERE UserID = ' #. TM_log UserID # '.
    < / cfquery >

    generates this error message;

    Run database query error.

    [Macromedia] [SequeLink JDBC Driver] [ODBC Socket] [Microsoft] [ODBC Microsoft Access driver] Too few parameters. 1 expected.
    The error occurred in D:\Inetpub\mannapremier\TM_log_report2.cfm: line 28
    26 :         TM_Name
    27 : FROM Users
    28 : WHERE UserID = "#TM_log.UserID#"
    29 : </cfquery>
    30 : 
    

    SQLSTATE07002
    SQLSELECT the user ID, UserFirstName UserLastName, LastLogin, TotalLogins, UserZone, TM_Name FROM USERS WHERE UserID = '10120.
    VENDORERRORCODE-3010
    DATASOURCEmanna_premier

    I see that my variable WHERE comes through but the domain name is not working. I'm sure that the answer is obvious, but it drives me crazy!

    Help, please!

    I tried and got this result;

    No, you now use different data. Now, the user ID is empty, while she was 10120 first.

    The only problem seems to be double quotes. To check this, test with

    WHERE UserID = 10120
    

    I'm assuming that the userID field to be an integer. If it is text, then use single quotes (not!), as in

    WHERE UserID = '#TM_log.UserID#'
    
  • What is the problem with this query in the source

    A blank page is region 2. Region1: enter rec_no (-rec_no is varchar2) region2:hide and show that displays one record based on rec_ no region1 entered.
    The problem is that I get the following error

    ORA-06550: line 1, column 7: PLS-00428: an INTO clause in this SELECT statement

    Here's my simple query in a process of pl/sql
    Start
    Select rec_no, rec_name from mytable where rec_no = upper(:P16_rec_no);
    end;

    Why? The same query works under the sql command.

    what I'm trying to accompolish here, it is because he has given huge if I want to display hide also multiples, regions and allow users to update each region as a result. Help, please. It kills me that I just can't understand what is causing the problem to the query. Thank you.

    Hello

    The list is set to the field EMPLOYEE_ID itself? What is the primary key of the table? In my example, DEPTNO is the primary key and I used the element generated by the wizard page to display the list. The parameters of the Source of the item itself or the column DEPTNO and database so that the process "process line...". "to identify the updated row.

    Andy

  • What is the problem with this query? exception does not work.

    DECLARE
    v_employee_id EMPLOYEES. EMPLOYEE_ID % TYPE;
    v_last_name EMPLOYEES. LAST_NAME % TYPE;
    v_salary EMPLOYEES. % SALARY TYPE.
    e_invalid_emp EXCEPTION;
    BEGIN
    SELECT last_name, salary v_employee_id, v_last_name, v_salary, employe_id
    EMPLOYEES where employee_id = & employee_id;

    IF SQL % NOTFOUND THEN
    RAISE e_invalid_emp;
    END IF;

    DBMS_OUTPUT. Put_line(v_employee_id||) e '|| v_last_name | » '|| v_salary);

    EXCEPTION
    WHEN e_invalid_emp THEN
    DBMS_OUTPUT. Put_line ("' employee not found...");
    END;
    /
  • PIO, LIO and the cost of an Oracle query

    Hi guys,.

    Here are the definitions I've read to

    [http://www.orafaq.com/wiki | http://www.orafaq.com/wiki]

    PIO or physical i/o refers to the reading and writing from/to the disk.
    LIO or e/s logic refers to the reading and writing to/from memory (for example, / from the SGA buffer Cache)

    Basically, what I've read, the COST is measured in PIOs.

    If we had a query that returns to 20 lines, and:

    2 rows of 20 found in datablock X in the buffer cache
    4 lines of 20 found in datablock Y in the buffer cache

    2 rows of 20 found in datablock has the disk
    2 rows of 20 have been found in datablock B on disk
    2 rows of 20 found in datablock C disk
    2 rows of 20 have been found in datablock D disk
    6 rows of 20 found in datablock E disk

    then it would be correct to say that LIO is 2 and PIO is 5?

    And it looks like the cost of this operation was 5. Is this correct?

    Thank you

    The cost formula that you are citing the book is used to calculate the cost of access to a single table to a path indexed using a b-tree index.

    From the perspective of the optimizer, the cost of a more complex query consists of three components:
    A component of the CPU
    A component based on the number of unique block reads predicted
    A component based on the number of multiple blocks bed predicted.

    In the case of 'single table by index b-tree'-, we can assume that the CPU component is tiny (and it will be nil in any case in 8i or 9i if you have not enabled the CPU cost); and there will be no close readings. So for this path, the only component is the one-piece readings, and it's the formula gives number of Wolfgang Breitling.

    Technically, the cost of a query SO time for the query to execute measured in units strange slighltly. In 10g implementation plan makes this explicit by including a TIME column in the table of the plan; and you can see that this time column is always COST * sreadtim / 1000, where sreadtim is the time for a single block of reading as recorded, or a derivative, sys.aux_stats$.

    Concerning
    Jonathan Lewis
    http://jonathanlewis.WordPress.com
    http://www.jlcomp.demon.co.UK

    "The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge." Stephen Hawking.

Maybe you are looking for