Re: ntile() throws ERROR when hashagg is false

From: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
To: Rajkumar Raghuwanshi <rajkumar(dot)raghuwanshi(at)enterprisedb(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: ntile() throws ERROR when hashagg is false
Date: 2018-06-14 06:57:42
Message-ID: 87efh9svy2.fsf@news-spur.riddles.org.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

>>>>> "Rajkumar" == Rajkumar Raghuwanshi <rajkumar(dot)raghuwanshi(at)enterprisedb(dot)com> writes:

Rajkumar> Hi

Rajkumar> ntile() throws ERROR when hashagg is false, test case given
Rajkumar> below.

Rajkumar> postgres=# create table foo (a int, b int, c text);
Rajkumar> CREATE TABLE
Rajkumar> postgres=# insert into foo select i%20, i%30, to_char(i%12, 'FM0000') from
Rajkumar> generate_series(0, 36) i;
Rajkumar> INSERT 0 37
Rajkumar> postgres=# explain select ntile(a) OVER () from foo GROUP BY a;

This query isn't actually legal per the spec; the argument of ntile is
restricted to being a constant or parameter, so it can't change from row
to row. PG is more flexible, but that doesn't make the query any more
meaningful.

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).

--
Andrew (irc:RhodiumToad)

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Konstantin Knizhnik 2018-06-14 07:13:44 Re: WAL prefetch
Previous Message Thomas Munro 2018-06-14 06:52:51 Re: WAL prefetch