Re: DISTINCT MAX() results mismatch on 8.2 and 8.3

Lists: pgsql-bugs
From: Taiki Yamaguchi <yamaguchi(at)sraoss(dot)co(dot)jp>
To: pgsql-bugs(at)postgresql(dot)org
Subject: DISTINCT MAX() results mismatch on 8.2 and 8.3
Date: 2008-03-27 02:23:08
Message-ID: 20080327112308.b1e9a692.yamaguchi@sraoss.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

Hi,

I tried DISTINCT MAX() on the 8.2 and 8.3 as below.

8.2.6
==============================
yamaguti=# create table t1 (i int, j int primary key);
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index
"t1_pkey" for table "t1" CREATE TABLE
yamaguti=# insert into t1 select g, g from generate_series(1, 100) as g;
INSERT 0 100
yamaguti=# select distinct max(i) from t1;
max
-----
100
(1 row)

yamaguti=# select distinct max(j) from t1;
max
-----
100
(1 row)
==============================

8.3.0
==============================
yamaguti=# create table t1 (i int, j int primary key);
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index
"t1_pkey" for table "t1" CREATE TABLE
yamaguti=# insert into t1 select g, g from generate_series(1, 100) as g;
INSERT 0 100
yamaguti=# select distinct max(i) from t1;
max
-----
100
(1 row)

yamaguti=# select distinct max(j) from t1;
ERROR: could not find pathkey item to sort
==============================

If a column has a primary-key constraint, DISTINCT MAX() fails on 8.3.

I know that the DISTINCT in this query has no meanings, but I wasn't
certain that this was an intended behaviour or not (a bug). If it was a
bug, would it be fixed in the future?

Best regards,

--
Taiki Yamaguchi
<yamaguchi(at)sraoss(dot)co(dot)jp>


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Taiki Yamaguchi <yamaguchi(at)sraoss(dot)co(dot)jp>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: DISTINCT MAX() results mismatch on 8.2 and 8.3
Date: 2008-03-27 04:38:38
Message-ID: 1381.1206592718@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

Taiki Yamaguchi <yamaguchi(at)sraoss(dot)co(dot)jp> writes:
> If a column has a primary-key constraint, DISTINCT MAX() fails on 8.3.

> I know that the DISTINCT in this query has no meanings, but I wasn't
> certain that this was an intended behaviour or not (a bug). If it was a
> bug, would it be fixed in the future?

It's certainly a bug and should be fixed ... I'm too tired to look into
the cause right now, though.

regards, tom lane


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Taiki Yamaguchi <yamaguchi(at)sraoss(dot)co(dot)jp>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: DISTINCT MAX() results mismatch on 8.2 and 8.3
Date: 2008-03-27 19:26:43
Message-ID: 29352.1206646003@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

Taiki Yamaguchi <yamaguchi(at)sraoss(dot)co(dot)jp> writes:
> yamaguti=# select distinct max(j) from t1;
> ERROR: could not find pathkey item to sort

Fixed in HEAD and 8.3. Thanks for the report!

regards, tom lane


From: "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov>
To: <pgsql-bugs(at)postgresql(dot)org>, "Taiki Yamaguchi" <yamaguchi(at)sraoss(dot)co(dot)jp>
Subject: Re: DISTINCT MAX() results mismatch on 8.2 and 8.3
Date: 2008-04-22 15:52:34
Message-ID: 480DC384.EE98.0025.0@wicourts.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

>>> On Wed, Mar 26, 2008 at 9:23 PM, in message
<20080327112308(dot)b1e9a692(dot)yamaguchi(at)sraoss(dot)co(dot)jp>, Taiki Yamaguchi
<yamaguchi(at)sraoss(dot)co(dot)jp> wrote:

> 8.3.0
> ==============================
> yamaguti=# create table t1 (i int, j int primary key);
> NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index
> "t1_pkey" for table "t1" CREATE TABLE
> yamaguti=# insert into t1 select g, g from generate_series(1, 100) as
g;
> INSERT 0 100
> yamaguti=# select distinct max(i) from t1;
> max
> -----
> 100
> (1 row)
>
> yamaguti=# select distinct max(j) from t1;
> ERROR: could not find pathkey item to sort
> ==============================

For the benefit of anyone searching the archives for the problem we
just hit, this message also occurs in 8.3.1 and also occurs against
the above test table for this statement:

test=# select max(j) as "maxj" from t1 order by "maxj";
ERROR: could not find pathkey item to sort

Neither statement causes the error when run against a build from
REL8_3_STABLE from 35 minutes ago (2008-04-22 10:15 CDT).

-Kevin


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov>
Cc: pgsql-bugs(at)postgresql(dot)org, "Taiki Yamaguchi" <yamaguchi(at)sraoss(dot)co(dot)jp>
Subject: Re: DISTINCT MAX() results mismatch on 8.2 and 8.3
Date: 2008-04-22 16:09:35
Message-ID: 22416.1208880575@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

"Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov> writes:
>> yamaguti=# select distinct max(j) from t1;
>> ERROR: could not find pathkey item to sort

> For the benefit of anyone searching the archives for the problem we
> just hit, this message also occurs in 8.3.1 and also occurs against
> the above test table for this statement:

> test=# select max(j) as "maxj" from t1 order by "maxj";
> ERROR: could not find pathkey item to sort

> Neither statement causes the error when run against a build from
> REL8_3_STABLE from 35 minutes ago (2008-04-22 10:15 CDT).

Yeah, this was repaired here:
http://archives.postgresql.org/pgsql-committers/2008-03/msg00563.php

The fix will be in 8.3.2.

regards, tom lane