3

以下查询对我来说运行非常缓慢:

    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核至强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
4

1 回答 1

0

PostgreSQL 对 seljoin 没有任何特殊优化 - 所以这是预期的行为。

于 2013-08-05T19:08:21.287 回答