开发者

selecting some records from table containing 200 million records

I am new to sql so my terminologies might not be very co开发者_运维技巧rrect.

I have a table Alignment which has got 250 million records. It has two columns chain_id1 and chain_id2. Some of these chains are foreign keys for chain_id from another table Centroid which has 22000 records.

Basically I need all those records which are have both chains as centroids.

I tried using the following query:

insert into NewAlignment(...) 
select .... 
from Alignment as A
   , Centroid  as C1
   , Centroid  as C2 
where (A.chain_id1 = C1.chain_id) 
  and (A.chain_id2 = C2.chain_id)

But the above query just stalls which is understandable looking at the size of the tables.

So I tried writing a script to scan through the tables and check for values and then insert in new table. In that way for 1000000 records it took about 13 minutes.

Is there any way to speed this up.

Thanks a lot.


You'll likely want to add indexes to your tables, particularly on Alignment.Chain_id1, Alignment.Chain_id2, and Centroid.Chain_id. This should help a lot.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜