PRO*_*ima 26 postgresql operation any sql-in
我试过了两个
1)smthng = any(从exmplTable中选择id)
2)smthng in(从exmplTable中选择id)
我的数据得到了相同的结果.
这两个表达有什么不同吗?
Pav*_*ule 24
不,在这些变体中是相同的:
你可以看到 - 执行计划也是一样的:
postgres=# explain select * from foo1 where id in (select id from foo2); ???????????????????????????????????????????????????????????????????? ? QUERY PLAN ? ???????????????????????????????????????????????????????????????????? ? Hash Semi Join (cost=3.25..21.99 rows=100 width=4) ? ? Hash Cond: (foo1.id = foo2.id) ? ? -> Seq Scan on foo1 (cost=0.00..15.00 rows=1000 width=4) ? ? -> Hash (cost=2.00..2.00 rows=100 width=4) ? ? -> Seq Scan on foo2 (cost=0.00..2.00 rows=100 width=4) ? ???????????????????????????????????????????????????????????????????? (5 rows) postgres=# explain select * from foo1 where id = any (select id from foo2); ???????????????????????????????????????????????????????????????????? ? QUERY PLAN ? ???????????????????????????????????????????????????????????????????? ? Hash Semi Join (cost=3.25..21.99 rows=100 width=4) ? ? Hash Cond: (foo1.id = foo2.id) ? ? -> Seq Scan on foo1 (cost=0.00..15.00 rows=1000 width=4) ? ? -> Hash (cost=2.00..2.00 rows=100 width=4) ? ? -> Seq Scan on foo2 (cost=0.00..2.00 rows=100 width=4) ? ???????????????????????????????????????????????????????????????????? (5 rows)
Wig*_*rld 11
这可能是一个极端情况,但:
select * from myTable where id IN ()
Run Code Online (Sandbox Code Playgroud)
将产生:错误:“)”或附近的语法错误
但
select * from myTable where id = ANY('{}');
Run Code Online (Sandbox Code Playgroud)
将返回一个空结果集
| 归档时间: |
|
| 查看次数: |
17116 次 |
| 最近记录: |