Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Selecting in sorted order and joining
Hi,
I have a question to the performance people..
I have two tables that i join. Table A contains unhandled transactions, theoretically millions, and table B contains customer records, hundred of thousands.
I want to read table A in ascending order, records with oldest timestamp first.
A fast implementation would be select a.date, a.somedata, b.customerid from a, b where a.date < sysdate and b.primarykey = a.somefield order by date.
This takes up way too many resources during sorting. Sometimes it takes so long that i get a 'snapshot too old' error.
What i would like to accomplish is to avoid the "order by". I can to it when not joining, by doing this:
select /*+ INDEX_ASC(t logoff_transaction_datetype) */ t.date_created,
t.logon_id, t.ispvn, t.ip_address
t.date_created < sysdate
This gives a beautiful explain plan:
operation options name
---------------- ---------------- ------------------------------
SELECT STATEMENT
TABLE ACCESS BY ROWID LOGOFF_TRANSACTION INDEX RANGE SCAN LOGOFF_TRANSACTION_DATETYPE
However... When i join it won't use my unique key index, even though i try to select from the second table using a unique column. Have a look:
select /*+ INDEX_ASC(t logoff_transaction_datetype) */ t.date_created,
t.logon_id, t.ispvn, t.ip_address, u.public_id from transaction t, user u where t.type=1 and t.date_created < sysdate and u.logon_id = t.logon_id operation options nameSELECT STATEMENT
---------------- ---------------- ------------------------------
TABLE ACCESS FULL BCCUSER TABLE ACCESS BY ROWID LOGOFF_TRANSACTION INDEX RANGE SCAN LOGOFF_TRANSACTION_DATETYPE
I'm using PRO*C and could live with splittning this up in more than one statement, but i don't think it will help me. The first (fine) select will return the transactions, but i cannot select the rest from the user table as SELECT xxx from user where logon_id = :my_hostarray.
What can i do? I _do_ want to avoid sorting all the transactions...
Any indexes needed can be created.
Any help greatly appreciated.
Sincerely,
Brian
Brian Rasmusson, Software engineer & analyst e-mail: br_at_belle.dk Belle Systems A/S web : www.belle.dk Network, Internet and communication specialists phone : +45 59442500 ------------------------------------------------------------------------Received on Wed May 20 1998 - 07:05:00 CDT
![]() |
![]() |