This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Query performance

 
Mahesh Bamane
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic