pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Josh Berkus <josh@agliodbs.com>
To: Hannes Dorbath <light@theendofthetunnel.de>
Cc: pgsql-performance@postgresql.org
Subject: Re: Query Optimizer Failure / Possible Bug
Date: Mon, 28 Mar 2005 11:51:17 -0800
Message-ID: <200503281151.17344.josh@agliodbs.com> (raw)
In-Reply-To: <d1u4m3$1qm2$1@news.hub.org>
References: <d1u4m3$1qm2$1@news.hub.org>

Hannes,

> The query and the corresponding EXPLAIN is at
>
> http://hannes.imos.net/query.txt

The problem is that you're using a complex corellated sub-select in the SELECT 
clause:

    SELECT
      d.delivery_id,
      da.article_no,
      da.amount,
      (
          SELECT
            COUNT(*)
          FROM
            serials s
            INNER JOIN rma_ticket_serials rts ON (
                s.serial_id = rts.serial_id
            )
          WHERE
            s.article_no  = da.article_no AND
            s.delivery_id = d.delivery_id AND
            rts.replace   = FALSE
      ) AS replaced_serials

This means that the planner pretty much has to iterate over the subquery, 
running it once for each row in the result set.   If you want the optimizer 
to use a JOIN structure instead, put the subselect in the FROM clause.

-- 
--Josh

Josh Berkus
Aglio Database Solutions
San Francisco



view thread (7+ messages)  latest in thread

Message-ID: <200503281151.17344.josh@agliodbs.com>
Permalink:  ../200503281151.17344.josh@agliodbs.com/
Also on:    postgresql.org/message-id/200503281151.17344.josh@agliodbs.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: josh@agliodbs.com, light@theendofthetunnel.de
  Subject: Re: Query Optimizer Failure / Possible Bug
  In-Reply-To: <200503281151.17344.josh@agliodbs.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox