aspose file tools*
The moose likes JDBC and the fly likes Query performance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Query performance" Watch "Query performance" New topic
Author

Query performance

Mahesh Bamane
Ranch Hand

Joined: Mar 12, 2008
Posts: 66
I've 2 tables Table A and Table B, I want to find out the uncommon records from table A for column say 'abc'.

I'm using following query for the same:

select A.abc from A left join B on A.abc = B.abc where A.abc is null;

Table A has say some ~5 million records, the query is taking lot of time to execute. I'm doing this in shell script.

Is there any other way though which I can improve the performance and make the process faster.


There is nothing like trying, either you do it or you don't.
SCJP 1.5
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3436
    
  47

Some tricks might be available depending on our database, and on the number of records in the B table. This kind of query is called "anti-join", you might be able to google for some tricks available for your database.
Mahesh Bamane
Ranch Hand

Joined: Mar 12, 2008
Posts: 66
I'm using Sybase DB, also Table A has less records than Table B. Say Table A has 5000 records and Table B has 200000 records.
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3436
    
  47

You said table A has 5 million records earlier. If it actually has less records than B, and you're only interested to see records from A that do not have corresponding records in B, I'd use:
Make sure B.abc column is indexed.
Mahesh Bamane
Ranch Hand

Joined: Mar 12, 2008
Posts: 66
Sorry for the confusion, Even I'm planning to use NOT IN. But again the other doubt was LEFT JOIN is faster or using NOT IN would be faster?
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3436
    
  47

That's easy - try it!

I don't have any experience with Sybase, but I'd say the NOT IN might be faster - if you don't forget about the index on B.abc.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Query performance
 
Similar Threads
Limiting the Fetch Size
Parallel Hint! Very cool!
Slow performance-Full text search
Netbeans - Persistence Add Record To Child Table
Inverse this where condition