[英]Is there a way to get data from table #2 if it has a foreign key with table #1 and I do query for table #1
[英]It is too slow to excute query that get data from another table which has foreign key and not exists in
我的選擇查詢太慢。
大約2,000,000行。
Field Type
no bigint(20) primary key, auto_increment
title text
body text
tags text
url varchar(200)
date datetime
Field Type
no int primary key, auto_increment
blogId bigint(20)
term varchar(200)
frequency bigint(20)
TF float
IDF float
weight float
Ns int(11)
primary key(no),
unique key(blogid, term),
foreign key(blogId) references blog_data(no)
我想獲取不在ngram_relation表中的blog_data.no。 因此,我在下面執行查詢。
select no, title, body, tags, url
from blog_data where not exists (
select blogid as gg
from ngram_relation
group by blogid
having blog_data.no=gg
) limit 0, 10000
然后,第一次執行就很好。 第一次執行后, ngram_relation表大約有260,000行。
但是第二次執行不起作用。 剛鎖。
如何修改查詢?
使用左外部聯接可以過濾blog_data中存在的記錄,而不是ngram_relation中存在的記錄。 這應該更快。
像這樣的東西(可能不是確切的代碼):
select top 10000 from blog_data b left outer join ngram_relation n on b.no = n.no where n.no is null
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.