Re: ntile() throws ERROR when hashagg is false - Mailing list pgsql-hackers

From David Rowley
Subject Re: ntile() throws ERROR when hashagg is false
Date
Msg-id CAKJS1f8gORmofJM1jPqgvZb0khT+QxUgAWCYis5JQ72D-H8Nzw@mail.gmail.com
Whole thread Raw
In response to Re: ntile() throws ERROR when hashagg is false  (Andrew Gierth <andrew@tao11.riddles.org.uk>)
Responses Re: ntile() throws ERROR when hashagg is false
List pgsql-hackers
On 14 June 2018 at 18:57, Andrew Gierth <andrew@tao11.riddles.org.uk> wrote:
> What I think pg is actually doing is taking the value of the ntile()
> argument from the first row and using that for the whole partition.
> In your example, enabling or disabling hashagg changes the order of the
> input rows for the window function (since you've specified no ordering
> in the window definition), and with hashagg off, you get the smallest
> value of a first (which is 0 and thus an error).

Seems that's the case. I'd guess it was written that way so we could
allow PARAM_EXTERN Params rather than requiring the arg to be a Const.

I wonder if it would be worth adding a run-time check in
window_ntile() that causes an ERROR on first call if there are any
Vars or PARAM_EXEC Params in the function argument. An ERROR might be
better than doing something that the user does not expect.

Ideally, something would alert the user much sooner than the executor,
but I think doing it that way would be quite a bit more work.

-- 
 David Rowley                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services


pgsql-hackers by date:

Previous
From: David Rowley
Date:
Subject: Re: why partition pruning doesn't work?
Next
From: Surafel Temesgen
Date:
Subject: Re: ON CONFLICT DO NOTHING on pg_dump