pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Gregory Stark <stark@enterprisedb.com>
To: Nis Jørgensen <nis@superlativ.dk>
Cc: pgsql-sql@postgresql.org
Subject: Re: The nested view from hell - Restricting a subquerry
Date: Mon, 23 Jul 2007 05:21:48 +0100
Message-ID: <87y7h74un7.fsf@oxford.xeocode.com> (raw)
In-Reply-To: <f80r63$8lo$1@sea.gmane.org>
References: <46A2CABF.3080108@obviously.com>
	<f7v6na$2gc$1@sea.gmane.org>
	<2385.1185127507@sss.pgh.pa.us>
	<f80r63$8lo$1@sea.gmane.org>

Nis Jørgensen <nis@superlativ.dk> writes:

> Well, the query can be satisfied by looking only at the rows with an
> order_id matching the invoice_id given. The condition that this is the
> largest invoice in the group then needs to be checked afterwards.
>
> I certainly did not expect the query planner to be able to deduce this,
> though.

No, that's not true. If you had two records in eg_order with the same order_id
but different invoice_ids then the query would need both records to satisfy
the query.

The query planner can't deduce that this can't happen because it simply does
not have that information.

The more I look at this view the more I think it's just seriously broken.
Why is it grouping by order_id at all if, I suspect, there will only be one
record per order_id in eg_orders??

-- 
  Gregory Stark
  EnterpriseDB          http://www.enterprisedb.com




view thread (11+ messages)  latest in thread

Message-ID: <87y7h74un7.fsf@oxford.xeocode.com>
Permalink:  ../87y7h74un7.fsf@oxford.xeocode.com/
Also on:    postgresql.org/message-id/87y7h74un7.fsf@oxford.xeocode.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-sql@postgresql.org
  Cc: stark@enterprisedb.com, nis@superlativ.dk
  Subject: Re: The nested view from hell - Restricting a subquerry
  In-Reply-To: <87y7h74un7.fsf@oxford.xeocode.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