Re: [pgsql-bugs] Daily digest v1.1387 (8 messages)

From: Josh Berkus <josh(at)agliodbs(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: Re: [pgsql-bugs] Daily digest v1.1387 (8 messages)
Date: 2005-03-09 17:49:30
Message-ID: 200503090949.30909.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Tom,

> the issue is clearly that the known-false HAVING clause is pushed down
> inside the aggregation, as though it were WHERE.  The existing code
> pushes down HAVING to WHERE if the clause contains no aggregates, but
> evidently this is too simplistic.  What are the correct conditions for
> pushing down HAVING clauses to WHERE?

When the HAVING clause refers to a unaltered GROUP BY column; that is, one
whose contents are not aggregated, calculated, or aliased. I can't think of
any other condition which would be permissable. I would guess that the
reason why that test case bombs is that the planner detects that "2" is not
aggregates, calculated, or aliased and assumes that it's a GROUP BY column.

The real problem with this query is that we have a constant column which is
always in existance, thus producing a single row when run without the HAVING
clause. Personally, I've always felt that the SQL committee made a mistake
in having aggregates of no rows produce a single null output row; it leads to
wierdness like this here.

Hopefully someone can back that up with an ANSI-SQL reference ...

--
Josh Berkus
Aglio Database Solutions
San Francisco

Browse pgsql-bugs by date

  From Date Subject
Next Message Sergio Lob 2005-03-09 18:21:18 Re: [BUGS] BUG #1523: precision column value returned from
Previous Message Neil Conway 2005-03-09 11:56:20 Re: Fault when return strings over 256 characters in PLpgSQL