开发过程中遇到一个问题,查询远程数据库中存在,而本地库不存在的数据,远程数据库不在物理局域网内,通过虚拟网络组成局域网,并建立dblink;
procedure中的sql语句:
1、select * from test_remote@db_link a where a.id not in (select b.id from test_local b);2、select * from test_remote@db_link a where not exists (select 1 from test_local b where b.id = a.id);我想问,在这种网络情况中,上面两条sql那个语句执行效率高一点、占用资源相对少一点?因为这两sql语句执行比较频繁!求帮助!
procedure中的sql语句:
1、select * from test_remote@db_link a where a.id not in (select b.id from test_local b);2、select * from test_remote@db_link a where not exists (select 1 from test_local b where b.id = a.id);我想问,在这种网络情况中,上面两条sql那个语句执行效率高一点、占用资源相对少一点?因为这两sql语句执行比较频繁!求帮助!
第二种要高些
exists要比in效率高些如果子查询的数据大就是exists高些 小的话in跟exists差不多
这个问题没有什么不平常的地方,sql的解析和执行是不管你是否是远程数据库的,这个执行时间跟你网络情况完全无关,如果网络慢,你用哪种方式也快不了。