Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支持多表联合查询吗 #48

Closed
huapeng222 opened this issue Jun 19, 2017 · 5 comments
Closed

支持多表联合查询吗 #48

huapeng222 opened this issue Jun 19, 2017 · 5 comments
Labels

Comments

@huapeng222
Copy link

原有的左连右连数据库查询,如果用这个,是不是需要分开来查询

@RingoD
Copy link
Collaborator

RingoD commented Jun 19, 2017

@alexlee002
Copy link

alexlee002 commented Jun 20, 2017

sqlite连表查询性能不是特别好。

我的测试:

table1: fid, file_name, base_path, file_size, creation_date, modification_date; 20w+条数据
table2: fid, tag_id, tag_type; 400w+条数据

连表查询,耗时14秒左右。
如果分别从两个表中查出数据放到dictionary/set中, 然后在内存中对比, 耗时不到2秒。

所以一般在数据量比较大的时候, 不建议用连表操作。

@RingoD
Copy link
Collaborator

RingoD commented Jun 20, 2017

@alexlee002 那你计算过取出数据耗时吗,相加起来比较如何?
连表操作大部分时候还是能有性能提升的,但依赖于SQL写的如何。
可以贴一下你的sample和对应的联表SQL。

@RingoD
Copy link
Collaborator

RingoD commented Jun 21, 2017

no reply

@RingoD RingoD closed this as completed Jun 21, 2017
@alexlee002
Copy link

@RingoD

大概是这样的sql

select tag_id, count(*) as num from fileMetas as a, file_tags as b where a.fid=b.fid and a.basePath like '/my/path/to/search/%' and b.tag_type=1 group by tag_id order by num desc limit 10;

-- output: 
-- total: 12850.468040ms 

如果我分成两个SQL分别查询, 然后在内存里边计算:

select fid, tag_id from file_tags where tag_type=1;
select fid from fileMetas where basePath like '/my/path/to/search/%';

-- output:
--  total: 1628.209949ms 

相差一个数量级, 当然也并非所有连表查询都这样, 实际情况测试之后再选择连表还是自己手动计算。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants