Selection of the records that have no referencing records at a small price

I try to get records that has no records of references. Here's the script and test the query I wrote to get the result.
I can get result, but my problem is to lower the cost. This table has more than 50,000 rows. Hope someone can guide me to write a better query.

create table ot_req (rh_sysid rh_txn_type VARCHAR2 (NO.4), rh_ref_sys_id (5), (4), rh_ref_txn_cod VARCHAR2 (5));

INSERT INTO ot_req VALUES (800, 'MR SS', NULL, NULL);
INSERT INTO ot_req VALUES(801,'SSPR',800,'SSMR');
INSERT INTO ot_req VALUES(810,'SSMR',,);
INSERT INTO ot_req VALUES(811,'SSMR',,);
INSERT INTO ot_req VALUES(812,'SSMR',,);
INSERT INTO ot_req VALUES(813,'SSPR',812,'SSMR');
INSERT INTO ot_req VALUES(814,'SSMR',,);
INSERT INTO ot_req VALUES(815,'SSPR',814,'SSMR');


SELECT
rh_sysid
Of
ot_req
WHERE
rh_sysid
PO NO
(SELECT
rh_ref_sys_id
Of
ot_req
WHERE
rh_ref_sys_id IS NOT NULL)
AND
rh_txn_type! = "SŠPR";

Result

RH_SYSID
810
811

Looking forward to your support.

Thanks in advance :)

Unus wrote:
My problem is to lower the cost.

rh_ref_sys_id will never be sšpr. Only sšpr will reference number

SQL> exec dbms_stats.gather_table_stats(user,'ot_req')

PL/SQL-procedure is geslaagd.

SQL> set autotrace on
SQL> select rh_sysid
  2    from ot_req
  3   where rh_sysid not in
  4         ( select rh_ref_sys_id
  5             from ot_req
  6            where rh_ref_sys_id is not null
  7         )
  8     and rh_txn_type!='SSPR'
  9  /

  RH_SYSID
----------
       810
       811

2 rijen zijn geselecteerd.

Uitvoeringspan
----------------------------------------------------------
Plan hash value: 2746377339

-----------------------------------------------------------------------------
| Id  | Operation          | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
-----------------------------------------------------------------------------
|   0 | SELECT STATEMENT   |        |     5 |    60 |     7  (15)| 00:00:01 |
|*  1 |  HASH JOIN ANTI SNA|        |     5 |    60 |     7  (15)| 00:00:01 |
|*  2 |   TABLE ACCESS FULL| OT_REQ |     5 |    50 |     3   (0)| 00:00:01 |
|*  3 |   TABLE ACCESS FULL| OT_REQ |     3 |     6 |     3   (0)| 00:00:01 |
-----------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - access("RH_SYSID"="RH_REF_SYS_ID")
   2 - filter("RH_TXN_TYPE"<>'SSPR')
   3 - filter("RH_REF_SYS_ID" IS NOT NULL)

Statistics
----------------------------------------------------------
          1  recursive calls
          0  db block gets
         14  consistent gets
          0  physical reads
          0  redo size
        469  bytes sent via SQL*Net to client
        416  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          2  rows processed

SQL> select nvl(rh_ref_sys_id,rh_sysid) rh_sysid
  2    from ot_req
  3   group by nvl(rh_ref_sys_id,rh_sysid)
  4  having count(*) = 1
  5  /

  RH_SYSID
----------
       810
       811

2 rijen zijn geselecteerd.

Uitvoeringspan
----------------------------------------------------------
Plan hash value: 2435394825

------------------------------------------------------------------------------
| Id  | Operation           | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
------------------------------------------------------------------------------
|   0 | SELECT STATEMENT    |        |     1 |     6 |     4  (25)| 00:00:01 |
|*  1 |  FILTER             |        |       |       |            |          |
|   2 |   HASH GROUP BY     |        |     1 |     6 |     4  (25)| 00:00:01 |
|   3 |    TABLE ACCESS FULL| OT_REQ |     8 |    48 |     3   (0)| 00:00:01 |
------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter(COUNT(*)=1)

Statistics
----------------------------------------------------------
          1  recursive calls
          0  db block gets
          7  consistent gets
          0  physical reads
          0  redo size
        469  bytes sent via SQL*Net to client
        416  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          2  rows processed

Kind regards
Rob.

Tags: Database

Similar Questions

  • How to select all the records that have the difference of two dates of greater than a value

    Hi all

    I have a table as below:

    ID creation_date Modify_date

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

    1 10:11:07.243000000 JANUARY 7, 14 H 10:16:16.865000000 7 JANUARY 14 H

    2 13 JANUARY 14 12:07:27.603000000'M 12:08:09.955000000 13 JANUARY 14: 00

    I want to select all the IDs that is difference of Modify_date and creation_date is greater than 5 minutes.

    Please suggest how to achieve this goal, oracle database.

    TIA,

    Bob

    Select *.

    from table_name

    where (Modify_date - creation_date) * 1440 > = 5


    for timestamp:

    Select *.

    from table_name

    where extract (minute (Modify_date - creation_date)) > = 5



    -----

    Ramin Hashimzade

  • "An error in updating your system has occurred." Select 'OK' to undo the chnages that have been made.

    I install "WindowsXP-KB926139-v2 - x 86 - ENU"(power shell)
    at the end I have "an error in updating your system has occurred." Select 'OK' to undo the chnages that have been made. Windows XP 32-bit. Please help solve this problem. Thanks in advance.

    imran_iiui,
    When you look at your installed updates it appears as failed?  If Yes, what is the error code that you found?  Have you looked at the actual article for KB926139 and links for information PowerShell?  You can look through those.
    Mike - Engineer Support Microsoft Answers
    Visit our Microsoft answers feedback Forum and let us know what you think.

  • Service Pack 3 has not finished click OK to undo the changes that have been made

    Internet Exolorer 8, service Pack2 installed.  Tent to download and install service pack 3 again, Error Codes: several years ago

    Not enough free space.  Free storage, Total currently 6.06 GB GB 32.3.  HP pavilion 551w.

    Error codes: 11/10/09 OX80070641, same code on 29/09/12

    04/07/13 code OX8024600

    Remove Service pack 3 and reinstalled several days ago:

    "Preparing for download.

    Backup of files

    SP3 backup file. CAB

    Backup registry

    Creation of Restore Points

    Download Service Pack 3

    The initialization of the made installition

    Win SP3 installation

    SP3 Setup file. CAB

    Error installing service pack 3 Service pack 3 installation did not complete.

    Select 'OK' to undo the changes that have been made.

    Access denied»

    Firewall and anti virus disabled for installation.  Graphic bar showed about 75 to 80% installation complete.

    So far I have not checked to undo changes.  With the od SP3 download I show 5.82 GB of free space.

    As I have not checked to undo the changes, no error code appears for this latest attempt to download and install SP3.

    When you try to install Windows XP Service Pack, you receive the error message "Access denied" or "installing the Service Pack has not completed"
    http://support.Microsoft.com/kb/949377

    How to troubleshoot an installation fails on Windows XP Service Pack 3
    http://support.Microsoft.com/kb/950718

    Error message when you try to install Windows XP SP3: "you don't have enough disk space on % lecteur_systeme % to archive the uninstall files.
    http://support.Microsoft.com/kb/949375/

    Error messages when you try to install Windows XP Service Pack 3: "Service Pack 3 installation did not complete" and "an internal error has occurred."
    http://support.Microsoft.com/kb/949384/

  • Should I open the pages that have been delivered safely?

    Original title: CANCEL = Popup = I want TO OPEN the PAGES THAT HAVE BEEN DELIVERED safely, ABOUT

    CANCEL = POPUP = I WANT TO OPEN THE PAGES THAT HAVE BEEN DELIVERED SAFELY, ABOUT

    Hello


    1. which browser is installed on the computer?
    2. were there any changes (hardware or software) to the computer before the show?
    3. What is the exact error message?

    Perform the steps mentioned below, if you have Internet Explorer installed on the computer.
    a: Click on Tools > options Internet .
    b
    : click on the Security tab > custom level button
    c
    : Navigate to and Select the option to display mixed content.
    d:
    click apply , then ok.

    Hope this information helps.
  • Mix only the properties that have been changed

    Hi all

    Is it possible, form where we can identify the properties that have been changed in the source in the past 24 hours and use them only to the mix?

    You can mix changes, but there is no filter option to specify the specific date and time.

    Go to definition of Blender and select the difference as the value for the Mode property of propagation,

    If your Source is another manual entry of the user in DRM, you can think to filter the changes there and then deal with the DRM.

  • print all of the pages that have highlights

    My apologies if this isn't apparent. I've searched and searched. Acrobat X Pro running. At 1150 pages in pdf format. Want to search for and highlight several different words and phrases - then print ONLY the pages that have a word or phrase. Trying to figure out how to use bookmarks to do this - or something. Seems that this is a common need. Is it possible - without scripting something (that I have no time to learn how to make this project). Thank you.

    Hi swtrader2,

    I found this older article which may be just what you're looking for. You can use the tools of Protection of Document (drafting).

    The key is to not do the second part of the drafting process in two steps. The first step is just words; the second removes them from the document.

    The research and marking of multiple words in a PDF document

    You will notice that some option names are slightly different in your version of Acrobat (for example, you select text search & delete in the Protection component in the Toolbox). But I think you get the basic information you need of this clever workaround.

    Eager to learn how it works for you.

    Best,

    Sara

  • How to list all the tables that have no data

    Hi all


    I want to list all the tables that have no data. (registration number is 0)

    Someone help me.

    Thank you
    Thiensu2810

    Select owner, table_name from dba_tables where num_rows = 0;

    This assumes that the table statistics are COMMON.

  • Do I lose all the iMessages that have not been delivered to my iphone if I withdraw (from iMessage) my phone number? My current iphone is broken and I am planing to get a new one, with in a few months.

    Do I lose all the iMessages that have not been delivered to my iphone if I withdraw (from iMessage) my phone number? My current iphone is broken and I am planing to get a new one in a few months.

    You may lose everything.  iMessage, like most e-mail services, don't keep permanently undeliverable messages.  They only keep in the short period send queue (I don't know exactly how much time but some Apple tech sites indicate no more than 10 days to two weeks) until they are purged.  That's pretty standard as otherwise, large volume, messaging services would be sitting on tera-bytes of messages not delivered each month.

    You actually have to change my phone number?  If not, let alone sign and only in iMessage when you have the new phone with this set of numbers upward to the service.

  • When I opened the window "save the Page under", the drop-down box file name indicates the files that have been saved a long time ago. It is not cleared by a function 'clear history' that I can find. How can I erase this?

    1. Question

    When I opened the window "save the Page under", the drop-down box file name indicates the files that have been saved a long time ago. It is not cleared by a function 'clear history' that I can find. How can I erase this?

    Hello.

    I think this is a related issue of Windows, because it is the Manager to save the windows file that we are talking about here (right?). You should contact Microsoft for help with this one, I think. You expect to be able to delete entries simply by touching delete on your keyboard when they are concentrated (that is how it goes for the removal of the form entries specific autocomplete in Firefox), but I have not tried.

    I'm sorry I can't be more helpful.

  • When I try to type with the keys that have numbers on them, I have numbers instead of letters.

    The keyboard of my laptop does not work correctly.

    I have somehow turned the keys of the calculator and when I try to type with the keys that have numbers on them, I have numbers instead of letters.  Does anyone know how to disable this option?

    I use a laptop with a wireless keyboard to send this message, but want to use my laptop keyboard.
    Help!

    Hi newsgirl,.

    Somewhere at the top of the laptop keyboard is a key that says Num Lock (or Num Lk or something like that).  It can be accessed directly, or you may need to press a key to access (or some other keys).  In any case, you must click this to turn off the number lock because it is what causes the problem.  This key is usually used on laptops to create a section of a regular keyboard that can act as the normal keyboard calculator keypad (for those who need that, like accountants or persons who need to enter strings of numbers).  Once you turn it off, you will be fine as the keyboard returns to normal.

    I hlpe that aid.

    Good luck!

  • Error message, "not a win 32 application" when I try to open the programs that have always worked in the past, I get this message

    Original title: 'not a win 32 application '.

    When I try to open the programs that have always worked in the past, I get this message. How can I fix?

    Larry

    Take a look at the various reasons and solutions here http://en.kioskea.net/faq/1591-exe-is-not-a-valid-win32-application

  • error message received when downloading CC PS I needed to upgrade my display driver.  I've now updated - how can I get the improvements that have been disabled on initial installation?  I use Windows 7-64 bit.

    I received an error message telling me that my display driver was not at the height, & that some improvements would not be enabled.  I've since updated my display driver.  How can I get the improvements that have been initially disabled?

    Thank you...

    If you have all the features you need and there is no problem.  let alone ps.

  • I have Acrobat Pro on my computer and I work with the drawing that have been digitized in PDF format. The scanners are not aligned or place because of the poor scanning process. Anyway is to align the document even if it requires me to crop or lose

    I have Acrobat Pro on my computer and I work with the drawing that have been digitized in PDF format. The scanners are not aligned or place because of the poor scanning process. Is there anyway to align the document even if it requires me to crop or lose some on the edges?

    Hi brad.

    Yes. You can use the analysis tools to straighten and crop your document. Here is a link to a new tutorial. The key to activate the sliding options recovery is to choose the option of the camera Image in the drop to Enhance, and gives you tools to set the correct page for smoothing areas.

    fundamental https://helpx.adobe.com/Acrobat/How-to/scan-Paper-documents-Searchable-PDF.html?Set=Acroba--principes t - create a pdf file

    Donna.

  • Audit/etc for the files that have changed

    In a typical "NIX environment, if I wanted to find any file changed in the last 3 days, I would use:"

    find/etc - mtime 3

    Does anyone know if the search ESXi5.0 option supports this option 'find '?

    Thanks in advance.

    At least 5.1 ESXi, you could use

    find/etc - mtime-3

    to see the files that have changed in the last three days for example.

  • I'm looking for all the cards that have a VIEW as the target object.

    Environment:

    OWB Tahoe development Version 11.2.0.1 Client on Windows 7
    Repositories on Oracle EE 11.2 on AIX

    Is there a way via the repository tables or OMB (shudder!) to get a list of all the cards that have a VIEW that the target object?

    Thank you very much!!

    -gary

    Try this:

    Re: How metadata repository OWB mapping?

    **************
    (1) log under user OWBSYS
    (2) run a procedure owbsys.wb_workspace_management.set_workspace

    exec owbsys.wb_workspace_management.set_workspace ('', '');
    (3) now the public view contains rows
    (4) at the end of the work to perform the owbsys.wb_workspace_management.unset_workspace procedure

    exec owbsys.wb_workspace_management.unset_workspace ();

    *************

Maybe you are looking for