【发布时间】:2015-10-08 14:28:58
【问题描述】:
让我们考虑以下查询:
EXPLAIN (ANALYZE, BUFFERS) SELECT * FROM foo JOIN bar ON foo.c1=bar.c1;
在哪里
CREATE TABLE foo
(
c1 integer,
c2 text
)
和
CREATE TABLE bar
(
c1 integer,
c2 boolean
)
正如article中所解释的那样
PostgreSQL 对表 bar 进行顺序扫描,并计算哈希 对于它的每一行。然后,它对 foo 进行顺序扫描,并为 每行,计算行的哈希值并将其与条形图进行比较 哈希表。 如果匹配,该行将被放入结果中 设置。如果不匹配,则跳过该行。
计划如下:
Hash Join (cost=13463.00..49297.00 rows=500000 width=42) (actual time=95.634..1001.306 rows=500000 loops=1)
Hash Cond: (foo.c1 = bar.c1)
Buffers: shared hit=3850 read=6697
-> Seq Scan on foo (cost=0.00..18334.00 rows=1000000 width=37) (actual time=0.026..135.609 rows=1000000 loops=1)
Buffers: shared hit=1637 read=6697
-> Hash (cost=7213.00..7213.00 rows=500000 width=5) (actual time=95.478..95.478 rows=500000 loops=1)
Buckets: 65536 Batches: 1 Memory Usage: 18067kB
Buffers: shared hit=2213
-> Seq Scan on bar (cost=0.00..7213.00 rows=500000 width=5) (actual time=0.004..37.040 rows=500000 loops=1)
Buffers: shared hit=2213
Total runtime: 1017.572 ms
我无法理解的是如何确定该行是否应该在结果集中。哈希相等的事实并不意味着行满足谓词foo.c1=bar.c1。
问题: 那么,在比较哈希之后,我们应该检查谓词是否满足?另外,每个桶是否必须包含具有相同哈希的行?
【问题讨论】:
标签: sql postgresql join hash