• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Query performance

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Vashko
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Vashko
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic