简体   繁体   English

从包含2亿条记录的表中选择一些记录

[英]selecting some records from table containing 200 million records

I am new to sql so my terminologies might not be very correct. 我是sql的新手,所以我的术语可能不太正确。

I have a table Alignment which has got 250 million records. 我有一张表Alignment,其中有2.5亿条记录。 It has two columns chain_id1 and chain_id2. 它具有两列chain_id1和chain_id2。 Some of these chains are foreign keys for chain_id from another table Centroid which has 22000 records. 其中一些链是来自另一个具有22000条记录的表Centroid的chain_id的外键。

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. 以这种方式,一百万条记录大约花费了13分钟。

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 . 您可能希望向表中添加索引,尤其是在Alignment.Chain_id1Alignment.Chain_id2Centroid.Chain_id This should help a lot. 这应该有很大帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM