Question

SELECT /*+ DRIVING_SITE(fcr) */
       fcr.request_id,
       DECODE
             (fcpt.user_concurrent_program_name,
              'Report Set', fcr.description,
              'Request Set Stage', fcr.description,
              fcpt.user_concurrent_program_name
             ) user_concurrent_program_name,
       fcr.description, fcr.argument_text, fcr.concurrent_program_id,
       fcr.parent_request_id, fcr.actual_start_date,
       fcr.actual_completion_date,
       ROUND ((fcr.actual_completion_date - fcr.actual_start_date) * 24 * 60,
              4
             ) runtime,
       DECODE (fcr.phase_code, 'C', 'No Schedule') program_status,
       fu.user_name, frt.responsibility_name, fcr.logfile_name
  FROM apps.fnd_concurrent_requests@db_link fcr,
       apps.fnd_concurrent_programs_tl@db_link fcpt,
       apps.fnd_user@db_link fu,
       apps.fnd_responsibility_tl@db_link frt
 WHERE fcr.concurrent_program_id = fcpt.concurrent_program_id
   AND fcr.requested_by = fu.user_id
   AND fcr.responsibility_id = frt.responsibility_id
   AND fcr.responsibility_application_id = frt.application_id
   AND fcr.phase_code = 'C'
   AND fcr.status_code IN ('C', 'G', 'E', 'X')
   AND fcr.actual_completion_date >= SYSDATE - 1 / 24
   AND fcr.requested_by = 1508715
   AND fcr.request_id NOT IN (
                             SELECT parent_request_id
                               FROM apps.fnd_concurrent_requests@db_link)

I wrote the above query to fetch the details of programs that are also parent program for some other program. But for some reason this query returns no result. So instead I wrote the below query:

SELECT /*+ DRIVING_SITE(fcr) */
       fcr.request_id,
       DECODE
             (fcpt.user_concurrent_program_name,
              'Report Set', fcr.description,
              'Request Set Stage', fcr.description,
              fcpt.user_concurrent_program_name
             ) user_concurrent_program_name,
       fcr.description, fcr.argument_text, fcr.concurrent_program_id,
       fcr.parent_request_id, fcr.actual_start_date,
       fcr.actual_completion_date,
       ROUND ((fcr.actual_completion_date - fcr.actual_start_date) * 24 * 60,
              4
             ) runtime,
       DECODE (fcr.phase_code, 'C', 'No Schedule') program_status,
       fu.user_name, frt.responsibility_name, fcr.logfile_name
  FROM apps.fnd_concurrent_requests@db_link fcr,
       apps.fnd_concurrent_programs_tl@db_link fcpt,
       apps.fnd_user@db_link fu,
       apps.fnd_responsibility_tl@db_link frt
 WHERE fcr.concurrent_program_id = fcpt.concurrent_program_id
   AND fcr.requested_by = fu.user_id
   AND fcr.responsibility_id = frt.responsibility_id
   AND fcr.responsibility_application_id = frt.application_id
   AND fcr.phase_code = 'C'
   AND fcr.status_code IN ('C', 'G', 'E', 'X')
   AND fcr.actual_completion_date >= SYSDATE - 1 / 24
   AND fcr.requested_by = 1508715
   AND fcr.request_id IN (SELECT request_id FROM apps.fnd_concurrent_requests@db_link
MINUS SELECT parent_request_id FROM apps.fnd_concurrent_requests@db_link)

This query returns about 300 to 400 rows everytime. But I do not understand the difference between the two queries. Also both the queries take more than one hour to run. How to improve the efficiency?

Was it helpful?

Solution

Parent_request_id contains null values, am I right? Then the first subselect contains null values in result and NOT IN clause results in UNKNOWN, not TRUE. Compare this:

select 'found' from dual
  where 1 not in (2,3,4);

'FOUN
-----
found

and

select 'found' from dual
  where 1 not in (2,3,4, null);

no rows selected

According to efficiency - there are many factors which influence efficiency. As first I would to store your select into database which you reference with @db_link as a view and query this_view@db_link. In your select all objects are stored in remote database and optimizer is not able to examine your select right.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top