Tuning querying and indirection

We have a legacy design where everything is highly normalized, even in the object model, and uses indirection for all contained parts of an object. This works well for most of the needs in the application. However, we are trying to perform a calculation that starts with a result set of root objects and navigates through the owned parts of the root object (1 to many relationships AND 1 to 1 relationships) to calculate an aggregate value. Depending on the business rules and the state of the root object, different parts of the root object are required when doing the calculation for the aggregated sum (hence the difficulty of using partial object reads via ReportQuery).
Is there any way to tune a query to trigger indirection on an object for all its owned parts (i.e. load them into memory immediately)? Loading everything into memory when we query for the root objects would be fine. Delayed querying would be more expensive, we believe. We also don't want to change the descriptors globally because indirection is appropriate for many of the other scenarios in the code.
Other recommendations for doing the calculation without the overhead of indirection and its multitude of queries would also be appreciated.

TopLink provide its "batch reading" feature to optmized the loading of a large graph of objects. The main cost in traversing a large graph of objects is that you get a lot of small queries. Refer to the documentation section on batch reading and the query API addBatchReadAttribute.
If you have A->1-m->B->1-1->C and initially read n As that each have m Bs, normally reading will require 1+n+n*m queries (if n was 100 and m 10 = 1101). With batch reading this can be converted to 3 queries giving a huge performance benifit.
To force indirection to fire to a certain level, you can either walk your object yourself, or call the TopLink API, copyObject(level) to force instantiation.

Similar Messages

  • SQL QUERY TUNING(PARTITONS AND JOIN)

    Hello
    My below query is taking very long time to execute ..here is the query and explain plan
    EXPLAIN PLAN FOR select w.ref_no,a.*
    from table1 a left outer join table2 w
    on(a.emp_id=w.emp_id)
    where a.joining_date=20090205 ;
    PLAN_TABLE_OUTPUT
    | Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Pstart| Pstop |
    | 0 | SELECT STATEMENT | | 2415K| 504M| | 226K (2)| | |
    |* 1 | HASH JOIN OUTER | | 2415K| 504M| 488M| 226K (2)| | |
    |* 2 | TABLE ACCESS BY INDEX ROWID| table1 | 2415K| 460M| | 77975 (1)| | |
    |* 3 | INDEX RANGE SCAN | table1_joining_ DATE | 2441K| | | 6463 (2)| | |
    | 4 | PARTITION RANGE ALL | | 39M | 718M| | 64745 (2)| 1 | 4 |
    | 5 | TABLE ACCESS FULL | table2 | 39M | 718M| | 64745 (2)| 1 | 4 |
    table 2 has 40 million rows
    Table2 structure
    emp_id
    ref_no
    Project_id
    Partitoned on Project_id, Project_id is nowhere used on the above query
    Table1 Structure
    emp_id
    joining_date
    other columns
    Is indexed on joining_date, not partitioned
    Please advise

    The CBO has estimated that you have 2415K table1 rows where joining_date = 20090205. (By the way: is this really a number?!)
    Is this estimate accurate?
    Please add some more information:
    - Which version do you use
    - How long is "very long time"?
    - How many does your query return
    - information as described in this thread: When your query takes too long ...
    Regards,
    Rob.

  • Using different hierarchy in a query and last value error

    Hi guys,
    there is a hierarchy for customers in the 0Customer Infoobject which I should use in my query.
    I have activated the hierarchy in the query and now some results are not appearing but red crosses "x" are shown.
    And the error message: The function Calculate Results as ... could not be applied everywhere.
    I know that I am using the result as "last value" for some columns because I need them there (for example: to determine the last value for the credit limit of the current month). I think these columns where I am using the last value calculation are only affected.
    I mean my query has a lot of characteristics and key figures and I was told that a hiearchy for customers which is available should be used. But now there are these red crosses.
    I don´t see any other solution as not to use this specific hierarchy.
    Has anybody a suggestion what could be an argument to use or not to use a hierarchy?
    Is it sometimes like in my case that a hierarchy is not possible to use?
    Thanks in advance!

    Hi,
    say for example your customer hierarchy is customers grouped under region. You can maintain this region as one of the attribute of customer and you can display this attribute in the report. Indirectly, this will give similar output to that of hierarchy.
    But lot depends on how your hierarchy is formed, before commenting whether it can be moved to master data attributes.
    Thanks.

  • Help with tuning query

    Hi All,
    I have the following query which seems to be blowing our temp tablespace.
    Can anyone help me in tuning this?
    The query and explian plan are below.
    Thanks for all your help
    select trim(b.pnr_reference) || ',"' || to_char(b.booking_date, 'DD-MON-YY') || '","' || trim(p.title) || '","' ||
    trim(p.forename) || '","' || trim(p.surname) || '
    ","' || trim(p.email) || '","' || trim(b.home_phone) || '","' || trim(b.address_line_1) || '","' ||
    trim(b.address_line_2) || '","' || trim(b.address_line_3)
    || '","' || trim(b.postcode) || '","' || trim(b.country_code) || '","' || null || '","' || -- frequent flyer number
    trim(b.promo_opt_in) || '","' || trim(bsout.flight_number) || '","' || to_char(bsout.departure_date, 'DD-MON-YY') || '","' ||trim(bsret.flight_number) ||
    '","' || to_char(bsret.departure_date, 'DD-MON-YY') || ' ","' || pax_cnt.num_adults || '","' || pax_cnt.num_children || '","' || pax_cnt.num_infants || '","' ||fares_by_booking.gross_fare_adult || '","' || fares_by_booking.gross_fare_child || '","' ||fares_by_booking.gross_fare_infant || '","' || fares_by_booking.total_gross_fare || '","' || trim(ps.fare_basis) || '","' ||trim(ps1.fare_basis) || '","' || null || '","' || -- user_id null || '","' || -- ip_address
    fares_by_booking.currency || '","' || trim(bsout.dep_airport_code) || '","' ||trim(bsout.dest_airport_code) || '","' ||fares_by_booking.gross_fare_adult*ex.exchange_rate || '","' || null || '","' || -- iata_no
    trim(b.other_opt_in) || '","' || c.returned || '","' || c.not_available ||'","' || c.on_request || '","' || c.matched || '"
    ,"' || trim(c.location_code) || '","' || to_char(c.pickup_date, 'DD-MON-YY') || '","' || to_char(c.return_date, 'DD-MON-YY') || '","' || c.period || '","' ||
    trim(cb.book_ref) || '","' || cb.car_num || '","' ||
    c.avail_warn_code || '","' || c.avail_err_code || '",
    "' || c.res_warn_code || '","' || c.res_err_code |
    | '"' from bookings b, car_hire_transactions c, car_hire_bookings cb, pax p, booking_sectors bsout, booking_sectors bsret, pax_sectors ps, pax_sectors ps1,
    exchange_rates ex, (select b2.booking_id, sum(decode(p2.pax_type,'A',1,0)) num_adults, sum(decode(p2.pax_type,'C',1,0)) num_children, sum(decode(p2.pax_type,'I',1
    ,0)) num_infants from pax p2, bookings b2
    where b2.booking_id = p2.booking_id and b2.booking_date
    between TO_DATE('08-08-2005/00:00', 'DD-MM-YYYY/HH24:MI') and TO_DATE('15-08-2005/00:00', 'DD-MM-YYYY/HH24:MI') group by
    b2.booking_id) pax_cnt, (select booking_id, currency, sum(gross_fare_adult) gross_fare_adult,
    sum(gross_fare_child) gross_fare_child, sum(gross_fare_infant) gross_fare_infant,sum(total_gross_fare) total_gross_fare from (select b3.booking_id booking_id, ps3.sector_seq,
    ps3.currency_code currency, max(decode(p3.pax_type,'A',ps3.gross_fare,0)) gross_fare_adult,
    max(decode(p3.pax_type,'C',ps3.gross_fare,0)) gross_fare_child
    , max(decode(p3.pax_type,'I',ps3.gross_fare,0
    )) gross_fare_infant, sum(ps3.gross_fare) total_gross_fare from pax p3,pax_sectors ps3, bookings b3 where b3.booking_id = p3.booking_id and b3.booking_id = ps3.booking_id and p3.pax_seq = ps3.pax_seq and b3.booking_date between TO_DATE('08-08-2005/00:00', 'DD-MM-Y
    YYY/HH24:MI') and TO_DATE('15-08-2005/00:00', 'DD-MM-YYYY/HH24:M
    I') group by b3.booking_id, ps3
    .currency_code, ps3.sector_seq) fares_by_sector group by booking_id, currency) fares_by_booking where
    b.booking_date between TO_DATE('08-08-2005/00:00', 'DD-MM-YYYY/
    HH24:MI') and TO_DATE('15-08-2005/00:00', 'DD-MM-YYYY/HH24:MI')
    and b.car_hire_id = c.car_hire_id(+) and c.car_hire_id = cb.
    car_hire_id(+) and p.booking_id = b.booking_id and p.pax_seq
    = 1 and b.booking_id = bsout.booking_id and bsout.sector_seq = 1 and b.booking_id = bsret.booking_id(+) and bsret.sector_seq(+) = 2 and p.booking_id = ps.booking_id and p.pax_seq
    = ps.pax_seq and ps.sector_seq = 1 and p.booking_id = ps1.booking_id(+) and p.pax_seq = ps1.pax_seq(+) and ps1.sector_seq(+) = 2 and b.booking_id = pax_cnt.booking_id and b.booking_id = fares_by_booking.booking_id and ex.currency_from = fares_by_booking.currency and ex.currency_to = 'GBP' and ex.date_entered = (select max(ex2.date_entered) from exchange_rates ex2 where currency_from = fares_by_booking.currency and currency_to = 'GBP' and ex2.date_entered < b.booking_date)
    Explain plan
    11:34:28 sqlpplus> /
    Elapsed: 00:00:00.00
    Execution Plan
    0
    SELECT STATEMENT Optimizer=CHOOSE (Cost=16 Card=1 Bytes=973)
    1 0
    HASH JOIN (OUTER) (Cost=16 Card=1 Bytes=973)
    2 1
    HASH JOIN (Cost=9 Card=1 Bytes=958)
    3 2
    NESTED LOOPS (OUTER) (Cost=6 Card=1 Bytes=902)
    4 3
    NESTED LOOPS (Cost=6 Card=1 Bytes=871)
    5 4
    NESTED LOOPS (OUTER) (Cost=6 Card=1 Bytes=812)
    6 5
    NESTED LOOPS (Cost=6 Card=1 Bytes=753)
    7 6
    NESTED LOOPS (Cost=6 Card=1 Bytes=533)
    8 7
    NESTED LOOPS (OUTER) (Cost=6 Card=1 Bytes=475)
    9 8
    NESTED LOOPS (Cost=6 Card=1 Bytes=429)
    10 9
    NESTED LOOPS (Cost=6 Card=1 Bytes=412)
    11 10
    VIEW (Cost=6 Card=1 Bytes=75)
    12 11
    SORT (GROUP BY) (Cost=6 Card=1 Bytes=84)
    13 12
    VIEW (Cost=6 Card=1 Bytes=84)
    14 13
    SORT (GROUP BY) (Cost=6 Card=1 Bytes=118)
    15 14
    FILTER
    16 15
    TABLE ACCESS (BY INDEX ROWID) OF 'PAX_SECTORS'
    17 16
    NESTED LOOPS (Cost=4 Card=1 Bytes=118)
    18 17
    NESTED LOOPS (Cost=4 Card=1 Bytes=60)
    19 18
    VIEW OF 'index$_join$_017' (Cost=4 Card=1
    Bytes=31)
    20 19
    HASH JOIN
    21 20
    INDEX (FAST FULL SCAN) OF 'BOO_PK' (UN
    IQUE) (Cost=1 Card=1 Bytes=31)
    22 20
    INDEX (FAST FULL SCAN) OF 'BOO_SHARES_
    UID_UK' (UNIQUE) (Cost=1 Card=1 Bytes=31)
    23 18
    TABLE ACCESS (BY INDEX ROWID) OF 'PAX'
    24 23
    INDEX (RANGE SCAN) OF 'PAX_PK' (UNIQUE)
    25 17
    INDEX (RANGE SCAN) OF 'PXS_PAX_FK_I' (NON-UN
    IQUE)
    26 10
    TABLE ACCESS (BY INDEX ROWID) OF 'BOOKINGS'
    27 26
    INDEX (UNIQUE SCAN) OF 'BOO_PK' (UNIQUE)
    28 9
    TABLE ACCESS (BY INDEX ROWID) OF 'EXCHANGE_RATES'
    29 28
    INDEX (UNIQUE SCAN) OF 'EXR_PK' (UNIQUE)
    30 29
    SORT (AGGREGATE)
    31 30
    FIRST ROW (Cost=2 Card=284 Bytes=3692)
    32 31
    INDEX (RANGE SCAN (MIN/MAX)) OF 'EXR_PK' (UNIQUE) (C
    ost=2 Card=200)
    33 8
    TABLE ACCESS (BY INDEX ROWID) OF 'BOOKING_SECTORS'
    34 33
    INDEX (UNIQUE SCAN) OF 'BKS_PK' (UNIQUE)
    35 7
    TABLE ACCESS (BY INDEX ROWID) OF 'BOOKING_SECTORS'
    36 35
    INDEX (UNIQUE SCAN) OF 'BKS_PK' (UNIQUE)
    37 6
    TABLE ACCESS (BY INDEX ROWID) OF 'PAX'
    38 37
    INDEX (UNIQUE SCAN) OF 'PAX_PK' (UNIQUE)
    39 5
    TABLE ACCESS (BY INDEX ROWID) OF 'PAX_SECTORS'
    40 39
    INDEX (UNIQUE SCAN) OF 'PXS_UK' (UNIQUE)
    41 4
    TABLE ACCESS (BY INDEX ROWID) OF 'PAX_SECTORS'
    42 41
    INDEX (UNIQUE SCAN) OF 'PXS_UK' (UNIQUE)
    43 3
    TABLE ACCESS (BY INDEX ROWID) OF 'CAR_HIRE_TRANSACTIONS'
    44 43
    INDEX (UNIQUE SCAN) OF 'CHT_PK' (UNIQUE)
    45 2
    VIEW (Cost=3 Card=1 Bytes=56)
    46 45
    SORT (GROUP BY) (Cost=3 Card=1 Bytes=47)
    47 46
    FILTER
    48 47
    TABLE ACCESS (BY INDEX ROWID) OF 'PAX'
    49 48
    NESTED LOOPS (Cost=1 Card=1 Bytes=47)
    50 49
    TABLE ACCESS (BY INDEX ROWID) OF 'BOOKINGS' (Cost=1 Card=1 Bytes
    =31)
    51 50
    INDEX (SKIP SCAN) OF 'BOO_SHARES_UID_UK' (UNIQUE)
    52 49
    INDEX (RANGE SCAN) OF 'PAX_PK' (UNIQUE)
    53 1
    TABLE ACCESS (FULL) OF 'CAR_HIRE_BOOKINGS' (Cost=6 Card=7 Bytes=105)

    Hi Guys,
    As requested here is the formatted sql.
    We are using pga_aggregate_target which is set to 25165824. I dont know if this is relevant but the sort_area_size is set to 524288.
    Thanks
    SQL
    SELECT trim(b.pnr_reference) || ',"' || to_char(b.booking_date, 'DD-MON-YY')
    || '","' || trim(p.title) || '","' || trim(p.forename) || '","' ||
    trim(p.surname) || '","' || trim(p.email) || '","' || trim(b.home_phone)
    || '","' || trim(b.address_line_1) || '","' || trim(b.address_line_2)
    || '","' || trim(b.address_line_3) || '","' || trim(b.postcode) ||
    '","' || trim(b.country_code) || '","' || null || '","' || trim(
    b.promo_opt_in) || '","' || trim(bsout.flight_number) || '","' ||
    to_char(bsout.departure_date, 'DD-MON-YY') || '","' || trim(
    bsret.flight_number) || '","' || to_char(bsret.departure_date,
    'DD-MON-YY') || '","' || pax_cnt.num_adults || '","' ||
    pax_cnt.num_children || '","' || pax_cnt.num_infants || '","' ||
    fares_by_booking.gross_fare_adult || '","' ||
    fares_by_booking.gross_fare_child || '","' ||
    fares_by_booking.gross_fare_infant || '","' ||
    fares_by_booking.total_gross_fare || '","' || trim(ps.fare_basis) ||
    '","' || trim(ps1.fare_basis) || '","' || null || '","' || null || '","'
    || fares_by_booking.currency || '","' || trim(bsout.dep_airport_code)
    || '","' || trim(bsout.dest_airport_code) || '","' ||
    fares_by_booking.gross_fare_adult * ex.exchange_rate || '","' || null
    || '","' || trim(b.other_opt_in) || '","' || c.returned || '","' ||
    c.not_available || '","' || c.on_request || '","' || c.matched || '","'
    || trim(c.location_code) || '","' || to_char(c.pickup_date, 'DD-MON-YY'
    ) || '","' || to_char(c.return_date, 'DD-MON-YY') || '","' || c.period
    || '","' || trim(cb.book_ref) || '","' || cb.car_num || '","' ||
    c.avail_warn_code || '","' || c.avail_err_code || '","' ||
    c.res_warn_code || '","' || c.res_err_code || '"'
    FROM bookings b, car_hire_transactions c, car_hire_bookings cb, pax p,
    booking_sectors bsout, booking_sectors bsret, pax_sectors ps,
    pax_sectors ps1, exchange_rates ex, (SELECT b2.booking_id, sum(
    decode(p2.pax_type, 'A', 1,
    0)) num_adults, sum(
    decode(p2.pax_type, 'C', 1,
    0)) num_children,
    sum(decode(p2.pax_type,
    'I', 1, 0)) num_infants
    FROM pax p2, bookings b2
    WHERE b2.booking_id = p2.booking_id
    AND b2.booking_date BETWEEN to_date('08-08-2005/00:00',
    'DD-MM-YYYY/HH24:MI') AND to_date('15-08-2005/00:00',
    'DD-MM-YYYY/HH24:MI')
    GROUP BY b2.booking_id) pax_cnt, (SELECT booking_id, currency,
    sum(gross_fare_adult)
    gross_fare_adult,
    sum(gross_fare_child)
    gross_fare_child,
    sum(gross_fare_infant)
    gross_fare_infant,
    sum(total_gross_fare)
    total_gross_fare
    FROM (SELECT b3.booking_id booking_id, ps3.sector_seq,
    ps3.currency_code currency, max(decode(p3.pax_type,
    'A', ps3.gross_fare, 0)) gross_fare_adult, max(
    decode(p3.pax_type, 'C', ps3.gross_fare, 0))
    gross_fare_child, max(decode(p3.pax_type, 'I',
    ps3.gross_fare, 0)) gross_fare_infant, sum(
    ps3.gross_fare) total_gross_fare
    FROM pax p3, pax_sectors ps3, bookings b3
    WHERE b3.booking_id = p3.booking_id
    AND b3.booking_id = ps3.booking_id
    AND p3.pax_seq = ps3.pax_seq
    AND b3.booking_date BETWEEN to_date(
    '08-08-2005/00:00', 'DD-MM-YYYY/HH24:MI') AND
    to_date('15-08-2005/00:00', 'DD-MM-YYYY/HH24:MI')
    GROUP BY b3.booking_id, ps3.currency_code,
    ps3.sector_seq) fares_by_sector
    GROUP BY booking_id, currency) fares_by_booking
    WHERE b.booking_date BETWEEN to_date('08-08-2005/00:00',
    'DD-MM-YYYY/HH24:MI') AND to_date('15-08-2005/00:00',
    'DD-MM-YYYY/HH24:MI')
    AND b.car_hire_id = c.car_hire_id (+)
    AND c.car_hire_id = cb.car_hire_id (+)
    AND p.booking_id = b.booking_id
    AND p.pax_seq = 1
    AND b.booking_id = bsout.booking_id
    AND bsout.sector_seq = 1
    AND b.booking_id = bsret.booking_id (+)
    AND bsret.sector_seq (+) = 2
    AND p.booking_id = ps.booking_id
    AND p.pax_seq = ps.pax_seq
    AND ps.sector_seq = 1
    AND p.booking_id = ps1.booking_id (+)
    AND p.pax_seq = ps1.pax_seq (+)
    AND ps1.sector_seq (+) = 2
    AND b.booking_id = pax_cnt.booking_id
    AND b.booking_id = fares_by_booking.booking_id
    AND ex.currency_from = fares_by_booking.currency
    AND ex.currency_to = 'GBP'
    AND ex.date_entered = (SELECT max(ex2.date_entered)
    FROM exchange_rates ex2
    WHERE currency_from = fares_by_booking.currency
    AND currency_to = 'GBP'
    AND ex2.date_entered < b.booking_date)
    explain_plan
    Execution Steps:
    Step # Step Name
    41 SELECT STATEMENT
    40 FILTER
    36 NESTED LOOPS [OUTER]
    33 NESTED LOOPS
    30 HASH JOIN [OUTER]
    28 NESTED LOOPS [OUTER]
    25 HASH JOIN
    23 HASH JOIN [OUTER]
    21 HASH JOIN
    15 HASH JOIN
    5 HASH JOIN
    3 HASH JOIN
    1 CAM_OWNER.PAX_SECTORS TABLE ACCESS [FULL]
    2 CAM_OWNER.PAX TABLE ACCESS [FULL]
    4 CAM_OWNER.BOOKINGS TABLE ACCESS [FULL]
    14 . VIEW
    13 SORT [GROUP BY]
    12 . VIEW
    11 SORT [GROUP BY]
    10 HASH JOIN
    8 HASH JOIN
    6 CAM_OWNER.BOOKINGS TABLE ACCESS [FULL]
    7 CAM_OWNER.PAX_SECTORS TABLE ACCESS [FULL]
    9 CAM_OWNER.PAX TABLE ACCESS [FULL]
    20 . VIEW
    19 SORT [GROUP BY]
    18 HASH JOIN
    16 CAM_OWNER.BOOKINGS TABLE ACCESS [FULL]
    17 CAM_OWNER.PAX TABLE ACCESS [FULL]
    22 CAM_OWNER.PAX_SECTORS TABLE ACCESS [FULL]
    24 CAM_OWNER.EXCHANGE_RATES TABLE ACCESS [FULL]
    27 CAM_OWNER.CAR_HIRE_TRANSACTIONS TABLE ACCESS [BY INDEX ROWID]
    26 CAM_OWNER.CHT_PK INDEX [UNIQUE SCAN]
    29 CAM_OWNER.CAR_HIRE_BOOKINGS TABLE ACCESS [FULL]
    32 CAM_OWNER.BOOKING_SECTORS TABLE ACCESS [BY INDEX ROWID]
    31 CAM_OWNER.BKS_PK INDEX [UNIQUE SCAN]
    35 CAM_OWNER.BOOKING_SECTORS TABLE ACCESS [BY INDEX ROWID]
    34 CAM_OWNER.BKS_PK INDEX [UNIQUE SCAN]
    39 SORT [AGGREGATE]
    38 FIRST ROW
    37 CAM_OWNER.EXR_PK INDEX [RANGE SCAN (MIN/MAX)]

  • Stucked between SQL Tuning Advisor and and SQL statement

    Hi,
    There is an important query running on my system which consists
    MEMBER OF function.
    At first place let me explain why i used MEMBER OF,
    I am sending a string( eg : #123#124#125) to query and a function converts this string into a number array.
    After then I use this number array inside my sql.
    The reason I am using this structure, in order to generate a dynamic IN statement inside my sql. (IF you have any other solution that would be great)
    The most important point is; when I put this statement to SQL Tuning Advisor the response is only ORA-00932: inconsistent datatypes: expected UDT got CHAR
    Any answer will be greatly appreciated.
    Thanks

    Solomon Yakobson wrote:
    Object oriented stuff almost never provides better performance over relational. You should stay away from MEMBER OF if performance is a factor. Instead of:
    WHERE expr MEMBER OF nested-tableI'd test:
    WHERE expr IN (SELECT column_value FROM TABLE(nested-table))SY.
    expr IN (SELECT COLUMN_VALUE FROM TABLE (CAST (v_type_number_table AS type_number_table)))worked like a charm. i hope tuning advisor will like it as i do.
    thanks.

  • Need help th tuning query or re write the query--

    Hi,
    Need help to tune the below query or rewrite th query for reducing the execution time Please find the query and explain plan.
    QUERY
    explain plan FOR SELECT consumer_key,product_key,days_in_product,20100201 period_key FROM
    (SELECT consumer_key,
      product_key,
      days_in_product,
      row_number() over ( Partition BY consumer_key order by Days_in_product DESC) row_num
    FROM
      (SELECT consumer_key,
        product_key,
        SUM(no_ofdays) days_in_product
      FROM
        (SELECT pcv.consumer_key,
          pcv.product_key,
          pcv.product_consumer_valid_from,
          pcv.product_consumer_valid_to,
          DECODE (SIGN(20100201000000-product_consumer_valid_from),1,20100201000000,product_consumer_valid_from) period_start,
          DECODE (SIGN(20100228235959-product_consumer_valid_to),1,product_consumer_valid_to,20100228235959) period_end,
          CASE
            WHEN to_number(TO_CHAR(cd.activation_date,'YYYYMMDDHH24MISS')) BETWEEN 20100201000000 AND 20100228235959
            AND activation_date > to_Date(product_consumer_valid_to,'YYYYMMDDHH24MISS')
            THEN 0
            WHEN to_number(TO_CHAR(cd.activation_date,'YYYYMMDDHH24MISS')) BETWEEN 20100201000000 AND 20100228235959
            AND activation_date BETWEEN to_Date(product_consumer_valid_from,'YYYYMMDDHH24MISS') AND to_Date(product_consumer_valid_to,'YYYYMMDDHH24MISS')
            THEN
              --to_char(activation_date,'MON-YYYY')='PERIOD_ACTIVE'  and activation_date >= to_Date(product_consumer_valid_from,'YYYYMMDDHH24MISS') then
              (to_date(DECODE (SIGN(20100228235959-product_consumer_valid_to),1,product_consumer_valid_to,20100228235959),'YYYYMMDDHH24MISS') - to_date(TO_CHAR(activation_date,'YYYYMMDDHH24MISS'),'YYYYMMDDHH24MISS') )
            WHEN to_number(TO_CHAR(cd.activation_date,'YYYYMMDDHH24MISS')) < 20100201000000
            THEN (to_date(DECODE (SIGN(20100228235959-product_consumer_valid_to),1,product_consumer_valid_to,20100228235959),'YYYYMMDDHH24MISS') - to_Date(DECODE (SIGN(20100201000000-product_consumer_valid_from),1,20100201000000,product_consumer_valid_from),'YYYYMMDDHH24MISS') )
            WHEN to_number(TO_CHAR(cd.activation_date,'YYYYMMDDHH24MISS')) > 20100228235959
            THEN 0
            ELSE
              --unusual situation
              (to_date(DECODE (SIGN(20100228235959-product_consumer_valid_to),1,product_consumer_valid_to,20100228235959),'YYYYMMDDHH24MISS') - to_Date(DECODE (SIGN(20100201000000-product_consumer_valid_from),1,20100201000000,product_consumer_valid_from),'YYYYMMDDHH24MISS') )
          END No_ofDays
        FROM cimtran.product_consumer_validity pcv,
          consumer_dimension cd
        WHERE pcv.consumer_key           =cd.consumer_key
        AND product_consumer_valid_to   >= 20100201000000
        AND product_consumer_valid_from <= 20100228235959
          --and product_consumer_valid_from > '20090801000000'
        ORDER BY consumer_key,
          product_key,
          product_consumer_valid_from
        ) a
      GROUP BY consumer_key,
        product_key
      ORDER BY consumer_key,
        product_key
    ) WHERE row_num=1 ;EXPLAIN PLAN
    "PLAN_TABLE_OUTPUT"
    "Plan hash value: 3823907703"
    "| Id  | Operation                | Name                      | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |"
    "|   0 | SELECT STATEMENT         |                           |  4665K|   231M|       |   133K  (1)| 00:31:08 |"
    "|*  1 |  VIEW                    |                           |  4665K|   231M|       |   133K  (1)| 00:31:08 |"
    "|*  2 |   WINDOW SORT PUSHED RANK|                           |  4665K|   173M|   232M|   133K  (1)| 00:31:08 |"
    "|   3 |    VIEW                  |                           |  4665K|   173M|       |   104K  (1)| 00:24:18 |"
    "|   4 |     SORT GROUP BY        |                           |  4665K|   182M|   729M|   104K  (1)| 00:24:18 |"
    "|*  5 |      HASH JOIN           |                           |    13M|   533M|    65M| 44241   (1)| 00:10:20 |"
    "|   6 |       TABLE ACCESS FULL  | CONSUMER_DIMENSION        |  2657K|    35M|       |  4337   (1)| 00:01:01 |"
    "|*  7 |       TABLE ACCESS FULL  | PRODUCT_CONSUMER_VALIDITY |    13M|   351M|       | 15340   (2)| 00:03:35 |"
    "Predicate Information (identified by operation id):"
    "   1 - filter(""ROW_NUM""=1)"
    "   2 - filter(ROW_NUMBER() OVER ( PARTITION BY ""CONSUMER_KEY"" ORDER BY "
    "              INTERNAL_FUNCTION(""DAYS_IN_PRODUCT"") DESC )<=1)"
    "   5 - access(""PCV"".""CONSUMER_KEY""=""CD"".""CONSUMER_KEY"")"
    "   7 - filter(""PRODUCT_CONSUMER_VALID_FROM""<=20100228235959 AND "
    "              ""PRODUCT_CONSUMER_VALID_TO"">=20100201000000)"

    I doubt that this query can be tuned without using indexes. There is a lot of unnecessary work specified in your query, like unnecessary intermediate sorting and selecting unused columns. The cost based optimizer recognized it and skips some of that unnecessary work, it seems. For clarity's sake, I would rewrite your query like below. Note that the query is untested:
    select consumer_key
         , max(product_key) keep (dense_rank last order by days_in_product) product_key
         , max(days_in_product) days_in_product
         , 20100201 period_key
      from ( select pcv.consumer_key
                  , pcv.product_key
                  , sum
                    ( case
                      when to_number(to_char(cd.activation_date,'yyyymmddhh24miss')) between 20100201000000 and 20100228235959
                      then
                        case
                        when cd.activation_date > to_date(pcv.product_consumer_valid_to,'yyyymmddhh24miss')
                        then
                          0
                        when cd.activation_date between to_date(pcv.product_consumer_valid_from,'yyyymmddhh24miss') and to_date(product_consumer_valid_to,'yyyymmddhh24miss')
                        then
                          to_date(to_char(pcv.product_consumer_valid_to),'yyyymmddhh24miss'))
                          - to_date(to_char(activation_date,'yyyymmddhh24miss'),'yyyymmddhh24miss')
                        end
                      when to_number(to_char(cd.activation_date,'yyyymmddhh24miss')) < 20100201000000
                      then
                        to_date(to_char(pcv.product_consumer_valid_to),'yyyymmddhh24miss'))
                        - to_date(to_char(pcv.product_consumer_valid_from),'yyyymmddhh24miss'))
                      when to_number(to_char(cd.activation_date,'yyyymmddhh24miss')) > 20100228235959
                      then
                        0
                      end
                    ) days_in_product
               from cimtran.product_consumer_validity pcv
                  , consumer_dimension cd
              where pcv.consumer_key             = cd.consumer_key
                and product_consumer_valid_to   >= 20100201000000
                and product_consumer_valid_from <= 20100228235959
              group by consumer_key
                  , product_key
    group by consumer_keyRegards,
    Rob.

  • SQL that provides direct and Indirect reports

    SELECT DISTINCT J.EMPLID ,J.EMPL_RCD ,A.NAME ,J.BUSINESS_UNIT ,J.JOBCODE ,JC.DESCR ,J.DEPTID ,D.DESCR
    ,J.SUPERVISOR_ID ,J.REPORTS_TO ,J.LOCATION ,J.COMPANY ,J.PAYGROUP ,J.GP_PAYGROUP ,ED.WORKGROUP ,ED.TASKGROUP
    ,J.POSITION_NBR ,L.BUILDING, WG.INCL_ML_BRK_FLG
    FROM PS_JOBCODE_TBL JC , PS_JOB J , PS_TL_EMPL_DATA ED, PS_TL_GROUP_DTL F ,PS_TL_GRP_SECURITY S
    ,PS_PERSON_NAME A , PS_DEPT_TBL D, PS_LOCATION_TBL L, PS_TL_WRKGRP_TBL WG
    WHERE S.GROUP_ID = F.GROUP_ID
    AND F.EMPLID = J.EMPLID
    AND F.EMPL_RCD = J.EMPL_RCD
    AND F.EMPLID = A.EMPLID
    AND F.EMPLID = ED.EMPLID
    AND F.EMPL_RCD = ED.EMPL_RCD
    AND S.ROWSECCLASS = 'DPALL'
    AND J.EFFDT = ( SELECT MAX(J1.EFFDT) FROM PS_JOB J1
    WHERE J1.EMPLID = J.EMPLID
    AND J1.EMPL_RCD = J.EMPL_RCD
    AND J1.EFFDT <= '22-MAY-2012')
    AND J.EFFSEQ = ( SELECT MAX(J2.EFFSEQ) FROM PS_JOB J2
    WHERE J2.EMPLID = J.EMPLID
    AND J2.EMPL_RCD = J.EMPL_RCD
    AND J2.EFFDT = J.EFFDT )
    AND ED.EFFDT = ( SELECT MAX(ED1.EFFDT) FROM PS_TL_EMPL_DATA ED1
    WHERE ED1.EMPLID = ED.EMPLID
    AND ED1.EMPL_RCD = ED.EMPL_RCD
    AND ED1.EFFDT <= '22-MAY-2012')
    AND JC.SETID = J.SETID_JOBCODE
    AND JC.JOBCODE = J.JOBCODE
    AND JC.EFFDT = ( SELECT MAX(JC1.EFFDT) FROM PS_JOBCODE_TBL JC1
    WHERE JC1.SETID = J.SETID_JOBCODE
    AND JC1.JOBCODE = J.JOBCODE
    AND JC1.EFFDT <= '22-MAY-2012')
    AND D.SETID = J.SETID_DEPT
    AND D.DEPTID = J.DEPTID
    AND D.EFFDT = ( SELECT MAX(D1.EFFDT) FROM PS_DEPT_TBL D1
    WHERE D1.SETID = J.SETID_DEPT
    AND D1.DEPTID = J.DEPTID
    AND D1.EFFDT <= '22-MAY-2012')
    AND L.SETID = J.SETID_LOCATION
    AND L.LOCATION = J.LOCATION
    AND L.EFFDT = ( SELECT MAX(EFFDT) FROM PS_LOCATION_TBL
    WHERE SETID = L.SETID
    AND LOCATION = L.LOCATION
    AND EFFDT <= '22-MAY-2012')
    AND J.SUPERVISOR_ID LIKE '76634%'
    AND A.EMPLID <> '76634'
    AND ED.WORKGROUP = WG.WORKGROUP
    AND WG.EFFDT = (SELECT MAX(WG1.EFFDT) FROM PS_TL_WRKGRP_TBL WG1
    WHERE WG.WORKGROUP = WG1.WORKGROUP
    AND WG1.EFFDT <= '22-MAY-2012'
    AND J.EMPL_STATUS IN ('A','L','P','S')
    AND J.EFFDT <= '20-MAY-2012');
    Above SQL provides me the list of employees (only direct reports) who report to EMPLID 76634. Now I want to modify this SQL so that It will also provide me the list of employees from a lower level (indirect reports).
    For example, if employees 1, 2 report to 76634. And 3,4 report to 1. And 5,6 report to 2. I want to modify the above SQL such that it will retrieve both direct and indirect reports for 76634 i.e 1,2,3,4,5 and 6.
    As of now above SQL will retrieve only 1,2. Any thoughts?

    SQLServer uses a recursive query for this.
    Just typing "SQLServer recursive query" in a search engine will provide you with tons of examples, but I will redirect you to the source MSDN,
    http://msdn.microsoft.com/en-us/library/ms175972%28SQL.90%29.aspx
    Look for the following example
    D. Using a recursive common table expression to display multiple levels of recursion
    The following example shows the hierarchical list of managers and the employees who report to them.
    USE AdventureWorks;
    GO
    WITH DirectReports(ManagerID, EmployeeID, EmployeeLevel) AS
    SELECT ManagerID, EmployeeID, 0 AS EmployeeLevel
    FROM HumanResources.Employee
    WHERE ManagerID IS NULL
    UNION ALL
    SELECT e.ManagerID, e.EmployeeID, EmployeeLevel + 1
    FROM HumanResources.Employee e
    INNER JOIN DirectReports d
    ON e.ManagerID = d.EmployeeID
    SELECT ManagerID, EmployeeID, EmployeeLevel
    FROM DirectReports ;
    GO

  • Performance tuning query.

    hello everyone,
    pls clarify my doubts regarding the oracle sql tuning.
    I got a report which runs for 15 mins, i made the report to be run in 1.30 min in the test instance.
    in that i made 2 queries which runs for 25 sec and 27 secs and i made it into a single query and ran in 6 secs.
    data
    then i came to a fact called COST. the cost is too high in my query nearly 73k. So this query is cant even run in real instance in my office.
    I heard the reason is COST. Is it so?
    I also the referred that COST is time taken for reading a table. (lik 10ms is a default for a single block read so on....)
    if COST is the time, then how my query runs in 6 secs even though the COST is 73k?
    Then
    I reduced the cost in my query by the use of indexes which are already present in that column.
    What if i want to fetch some other column which don't have index and which i should not create index?
    In that time Does COST matters? bcz the query runs in milliseconds but the cost is 1600.
    What is behind the COST? some says dont consider COST(but my COST is 73K), some says COST is time(but my time is 6sec), Some says COST is resource utilised by database (dats y its taking much time)...
    Pls clearify..

    879090 wrote:
    hello everyone,
    pls clarify my doubts regarding the oracle sql tuning.
    I got a report which runs for 15 mins, i made the report to be run in 1.30 min in the test instance.
    in that i made 2 queries which runs for 25 sec and 27 secs and i made it into a single query and ran in 6 secs.
    data
    then i came to a fact called COST. the cost is too high in my query nearly 73k. So this query is cant even run in real instance in my office.
    I heard the reason is COST. Is it so? I would invite whoever told you that to the largest set of stairs you can find and push them down it. If they seriously decide whether queries can run or not based on the cost they should be deleted.
    I also the referred that COST is time taken for reading a table. (lik 10ms is a default for a single block read so on....)
    if COST is the time, then how my query runs in 6 secs even though the COST is 73k?
    Then
    I reduced the cost in my query by the use of indexes which are already present in that column.
    What if i want to fetch some other column which don't have index and which i should not create index?
    In that time Does COST matters? bcz the query runs in milliseconds but the cost is 1600.
    What is behind the COST? some says dont consider COST(but my COST is 73K), some says COST is time(but my time is 6sec), Some says COST is resource utilised by database (dats y its taking much time)...
    Pls clearify..The cost is a calculation. It is comprised of a number of different metrics but utlimately it is something the database used internally to decide which exectuion plan it is going to use to execute a specific query. The costs between 2 different queryies aren't really comparable (there are specific circumstances where 2 different queries can be rewritten behind the scenes to result in the same execution plan, but that's a whole different kettle of fish).
    The bottom line is that you should not use cost to tune a query - if someone tells you that you should, hit them with something non lethal but painful.

  • In oracle rac, If user query a select query and in processing data is fetched but in the duration of fetching the particular node is evicted then how failover to another node internally?

    In oracle rac, If user query a select query and in processing data is fetched but in the duration of fetching the particular node is evicted then how failover to another node internally?

    The query is re-issued as a flashback query and the client process can continue to fetch from the cursor. This is described in the Net Services Administrators Guide, the section on Transparent Application Failover.

  • What is the diff b/w logical query and physical query?

    Thanks In advance

    In OBIEE terms the logical query is how you query the BI Server, the Presentation services sends logical SQL to the BI Server, you can also write your own using JDBC , pull from BI Server using ODI etc.
    The BI Server engine takes this logical query and writes (a number of) phyiscal querie(s) to satisfy the logical request, depeninding on how your BMM and Physical layer is setup. There are a number of rules the BI Server evaluates before deciding the most appropriate Physical query to generate, rules include Physical Joins, Aggregate tales / Hierarchy levels and so on.
    Hope this helps,
    Good luck with interview :-)
    Alastair

  • Creating a print button to call a Report Query and pass filters

    If i use the REPORT QUERY option in APEX 4 to create an statement that is the same one used in an interactive report, can I create a link or button to the REPORT QUERY and pass all the session and filter information from the interactive report to the report query?
    This way I can have the interactive report screen where the user can do all sorts of modifications and such and then pass those to the REPORT QUERY so I can call that from a custom link or button.
    You may ask "why does he need another print button?"
    Answer: I am using a view that has some embedded HTML tags to format the output really nicely. The HTML download version created by the interactive reports works beautifully. The customer also wants a PDF version (meh) which does not render the HTML tags and actually echos them as part of the text. I found that I can create another view that uses the CHR function to create all the breaks and such I was doing with HTML and these do render properly in PDF. So, I figured just have 2 reports: 1 Interactive and 1 using a REPORT QUERY. I just want to call the REPORT QUERY version but use the Interactive Search form to set all the parameters.
    Or, am I over thinking this and there is an easier method?
    I made a previous post where I showed how I got the APEX printing to work and i hoped that helped someone out - fixing this issue would put the whole thing to rest.
    Thanks

    Is BI Publisher desktop (MS Word add-in) a possibility? This would allow you to use MS Word to create your output template (RTF) that would result in a properly formatted PDF. Of course, you'd have to right an updated version of the query without HTML embedded. Just thinking outside of the box.

  • Web Analysis Error -- Error while executing query and retrieving data

    Regarding Web Analysis:
    We have a number of reports that we created. yesterday they were all working fine. today we try to open them and most are generating an error.
    The error is:
    Error while executing query and retrieving data.; nested exception is:
    com.hyperion.ap.APException: [1033] Native:
    1013033[Thu Oct 22 09:08:17
    2009]server name/application name/database name/user name/Error91013033)
    ReportWriter exit abnormally
    Does anyone have any insight into what is going on?
    My version information is:
    Hyperion System 9 BI+ Analytic Administration Services 9.3.0.1.1 Build 2
    Web Analysis 9.3.0.0.0.286
    Thanks in advance for your help.
    DaveW

    Hi,
    And also click on check option by opening the query in Query designer,as Mr . Arun suggested.
    And if you get any error in checking, see the long message(detail).
    With rgds,
    Anil Kumar Sharma .P

  • How to implement Quick Query and Saved Searches in ADF?

    We are using 11gR2 ADF.
    The requirement is to enable Quick Search and save the Searches.
    In the Oracle ADF documentation, it is mentioned that
    - Create a view with view criteria named.
    - In the .jspx drag and drop the view criteria and Select Quick Query
    Upon doing the above, we see that a Search panel is getting created, but with a message 'No Search Fields Added'.
    In the named view criteria, Under 'UI Hints' we have set
    -- execution mode as Both
    -- Search region mode is Basic
    -- Show Operators in Basic
    Under 'Criteria Definition'
    the attributes are added in a group with OR condition.
    Thanks for your reply. Oracle ADF developer guide does not help!!
    If you have any other documentation that helps in implementing this Quick Query and Saved Search, your help is greatly appreciated.

    Set the following on your af:query component
    SaveQueryMode = hidden
    ModeChangeVisible = false
    This should work for you ..
    Regards,

  • Different LOVs in af:query and af:form for the same VO attribute

    Hi,
    We need to display different LOVs in af:query and af:form for the same attribute in VO.
    Is it possible to use LOV Switcher for this ?
    What condition can we use in LOV Switcher attribute to check if it is View Critearia row or VO row ?

    We have a VO attribute "User" which needs to be displayed as LOV in a Search Panel ( af:query component created using View Critearia ) and in a af:form.
    When this VO attribute is displayed in search panel, in LOV, we need to show all users.
    When this VO attribute "User" is displayed in a form for editing, in LOV, we need to show only active users.
    For this, we created two LOVs "ActiveUsersLOV" ( which shows only active users ) and "AllUsersLOV" ( which shows all users ) on VO attribute "User".
    LOVSwitcher attribute should return "ActiveUsersLOV" if the LOV is displayed in form and "AllUsersLOV" if the LOV is displayed in search panel.

  • Plz help don't know how to create a query and link it to a UDF

    hi,
    i am new to business one and however hard i am trying to use a query to link it to a UDF, it is not working. i think i am doing the whole thing wrong,so ill just post one problem i have and if any one of u can explain to me in steps i may be able to learn to link other queries and UDFs.so plz help me out .
    problem:
    i want to display the account balance of every customer/vendor whenvever i open a marketing document. i have created a UDF for the marketing documents in the title with name and description 'account balance'.
    Now how do i link the customer/vendor name field to this UDF so that the query generated will show the account balance of the corresponding customer/vendor.plz tell me in steps as to what tables to choose ,what fields to choose, what conditions and relatoins to use in a query wizard
                                                                                    thank you

    hi,
    A/R invoice
    for name UDF:
    SELECT T0.CardName FROM OCRD T0 WHERE T0.CardCode = $[OINV.CardCode]
    for balance UDF:
    SELECT T0.Balance FROM OCRD T0 WHERE T0.CardCode = $[OINV.CardCode]
    A/P invoice
    for name UDF:
    SELECT T0.CardName FROM OCRD T0 WHERE T0.CardCode = $[OPCH.CardCode]
    for balance UDF:
    SELECT T0.Balance FROM OCRD T0 WHERE T0.CardCode = $[OPCH.CardCode]
    FOR OTHER FORMS ONLY CHANGE THE END OF THE QUERY    FOR Example
    $[OPCH.CardCode]
    OPCH  is the table name, change it to other table.
    save the query and set it to customer code for refresh in A/R invoice
    save the query and set it to Vendor code for refresh in A/P invoice
    regards
    sandip

Maybe you are looking for

  • IPads turn on when plugged in to power. Is there a way to keep this from happening?

    I am a tech for a school district. We have iPads in carts and when they are plugged in they automatically turn on. This keeps them on the wireless when not in use which uses up our wireless ports. Is there a way to keep them from turning on when plug

  • Balance Carryforward F_16

    Hi, I am suppose to run balance carry forward to the fiscal year 2009 and than I have to check weather is there any difference in Balance sheet. Can anybody tell me, how can I examine the balance sheet to find out differences (if any) after running F

  • Download Assistant gives error

    I'm trying to get the pse11 trial and i download and install the download assistant but when I try to open it I get an error and it says it is misconfigured. How to solve?

  • Graphics look bad on pause at end of chapters

    I've created a presentation in Keynote that I've exported as a QT movie and imported into DVDSP. Since the presentation will be manually advanced via remote control, I've set infinite pauses at the start of each chapter. My problem is that when the p

  • Kernel Panic with 2.6.12.1-2

    I was running 2.6.12.1-1 with no problems. Running pacman -Suy this morning donwloaded 2.6.12.1-2 which I installed. When booting it aborts with a kernel panic and a message that it can't mount /dev/hda2 and/or there's a bad block.  I'm able to boot