Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: How can i tune this sql query ?

Re: How can i tune this sql query ?

From: Robert Klemme <bob.news_at_gmx.net>
Date: Wed, 18 Jan 2006 18:26:41 +0100
Message-ID: <437c2mF1lj9d5U1@individual.net>


Pankaj wrote:
> Hi there,
>
> Can u pls tell me how can i tune this query ?
>
> at any time records in UnitIDTbl and INFOTBL is not more then 50000.
>
> INSERT INTO UnitIDTbl
> SELECT DISTINCT ID,INUMBER,'E-NOTFOUND'
> FROM IMPORTTBL
> WHERE LTRIM(RTRIM(ID)) || LTRIM(RTRIM(TO_CHAR(INUMBER)))
> NOT IN
> (SELECT DISTINCT LTRIM(RTRIM(ID)) || LTRIM(RTRIM(TO_CHAR(INUMBER)))
> FROM INFOTBL )
> AND (IMODE = 'N' OR IMODE = 'I' )
> AND ATYPE != 'R'
Replace RTRIM(LTRIM()) by TRIM(). Even better, make sure your data is stored trimmed. Then you can do

INSERT INTO UnitIDTbl
SELECT DISTINCT ID,INUMBER,'E-NOTFOUND'
FROM IMPORTTBL impo
WHERE NOT EXISTS ( SELECT *
FROM INFOTBL it

WHERE it.id = impo.id AND it.inumber = impo.inumber )
AND impo.IMODE IN ('N','I')
AND impo.ATYPE != 'R'

And index on (IMODE) and and index on (ID, INUMBER) may help, too. But note that due to the exclusion criterion the database is unlikely to use index on atype.

HTH     robert Received on Wed Jan 18 2006 - 11:26:41 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US