Question

The following query is running very slowly for me:

    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);

Running EXPLAIN (BUFFERS,ANALYZE) gives the following result: http://explain.depesz.com/s/iKG

Is it (re)building a hash for the comps table for each alias? Anything I can do to make this faster? Note: running two separate queries to join the data myself is faster.

Postgres version: 9.1.9 Machine: Ubuntu 12.04 8 | 4-core Xeon 2.5Ghz | 8GB of RAM

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
Était-ce utile?

La solution

PostgreSQL does not have any special optimizations for seljoin - so it is expected behavior.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top