postgreSQL-在vs任何 [英] postgreSQL - in vs any

查看:137
本文介绍了postgreSQL-在vs任何的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我都尝试过

1) smthng =任何(从exmplTable中选择ID)

1) smthng = any(select id from exmplTable)

2) smthng (从示例表中选择ID)

2) smthng in (select id from exmplTable)

并且我的数据也得到了相同的结果。

and I am getting the same results for my data.

这两个表达式有什么区别吗?

推荐答案

不,在这些变体中是相同的:

No, in these variants are same:

您可以看到-执行计划是相同的

You can see - the execution plans are same too:


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)

这篇关于postgreSQL-在vs任何的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆