Re: [HACKERS] ERROR: pull_var_clause: Cannot handle node type 108

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: José Soares <jose(at)sferacarta(dot)com>
Cc: hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] ERROR: pull_var_clause: Cannot handle node type 108
Date: 1999-08-27 13:58:08
Message-ID: 6515.935762288@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

=?iso-8859-1?Q?Jos=E9?= Soares <jose(at)sferacarta(dot)com> writes:
> Tom Lane ha scritto:
>> I take it you are using 6.4, because 6.5 generates different failure
>> messages. But it's not any less broken :-(. The rewriter seems to have
>> a bunch of bugs associated with aggregate functions in HAVING clauses of
>> sub-selects.

> You are right Tom. I installed v6.5.1 and now the message is different, but I
> can't understand it again:

> hygea=> select oid,nome from prova where nome in (select nome from prova
> group by nome having 1<count(*));
> ERROR: SELECT/HAVING requires aggregates to be valid

Well, like I said, it's broken. What's actually going on is that the
rewriter is mistakenly deciding that the count(*) needs to be pushed
down into another level of subselect:

select oid,nome from prova where nome in
(select nome from prova group by nome having 1 <
(select count(*) from prova));

whereupon the optimizer quite rightly complains that there is no
aggregate function visible in the mid-level HAVING clause.

This pushing-down is probably the right thing for some scenarios
involving aggregate functions introduced by views, but it's surely
dead wrong in the example as given. I don't currently understand
the rewriter well enough to know when it should happen or not happen.
I might take a swipe at fixing it though if Jan doesn't step up to bat
soon --- this class of bugs has been generating complaints for a good
while.

regards, tom lane

Browse pgsql-hackers by date

  From Date Subject
Next Message Gene Sokolov 1999-08-27 14:45:47 Performance of MIN() and MAX()
Previous Message José Soares 1999-08-27 12:35:32 Re: [HACKERS] ERROR: pull_var_clause: Cannot handle node type 108