对我来说,以下查询的运行速度非常慢:
SELECT r.comp,b.comp,n.comp
FROM paths AS p
INNER JOIN comps AS r ON (p.root=r.id)
INNER JOIN comps AS b ON (p.base=b.id)
INNER JOIN comps AS n ON (p.name=n.id);
运行EXPLAIN(BUFFERS,ANALYZE)会得到以下结果: http://explain.depesz.com/s/iKG
是否(重新)为每个别名构建comps
表的哈希值?我可以做些什么来加快速度?注意:运行两个单独的查询以自己加入数据的速度更快。
Postgres版本:9.1.9 机器:Ubuntu 12.04 8 | 4核Xeon 2.5Ghz | 8GB内存
archiving=> \d+ comps
Table "public.comps"
Column | Type | Modifiers | Storage | Description
--------+--------+----------------------------------------------------+----------+-------------
id | bigint | not null default nextval('comps_id_seq'::regclass) | plain |
comp | text | not null | extended |
Indexes:
"comps_pkey" PRIMARY KEY, btree (id)
"comps_comp_key" UNIQUE CONSTRAINT, btree (comp)
"comps_comp_idx" btree (comp)
"comps_id_idx" btree (id)
Has OIDs: no
答案 0 :(得分:0)
PostgreSQL没有对seljoin进行任何特殊优化 - 因此它是预期的行为。