Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b5z16-0003aB-Fu for pgsql-hackers@arkaria.postgresql.org; Thu, 26 May 2016 17:24:16 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1b5z15-0003jY-Jb for pgsql-hackers@arkaria.postgresql.org; Thu, 26 May 2016 17:24:15 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1b5yzk-0002Fh-Ri for pgsql-hackers@postgresql.org; Thu, 26 May 2016 17:22:52 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1b5yzh-0008A1-Q2 for pgsql-hackers@postgresql.org; Thu, 26 May 2016 17:22:52 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u4QHMkkU010434; Thu, 26 May 2016 13:22:46 -0400 From: Tom Lane To: Andres Freund cc: pgsql-hackers@postgresql.org Subject: Re: ORDER/GROUP BY expression not found in targetlist In-reply-to: <20160526021235.w4nq7k3gnheg7vit@alap3.anarazel.de> References: <20160526021235.w4nq7k3gnheg7vit@alap3.anarazel.de> Comments: In-reply-to Andres Freund message dated "Wed, 25 May 2016 19:12:35 -0700" Date: Thu, 26 May 2016 13:22:46 -0400 Message-ID: <10433.1464283366@sss.pgh.pa.us> X-Pg-Spam-Score: -3.3 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org Andres Freund writes: > trying to reproduce a performance problem I just found: > =# CREATE TABLE twocol(col01 int, col02 int); > =# SELECT DISTINCT col01, col02, col01 FROM twocol ; > ERROR: XX000: ORDER/GROUP BY expression not found in targetlist > LOCATION: get_sortgroupref_tle, tlist.c:341 > which appears to be a 9.6 regression, presumable fallout from the path > restructuring. Huh. The problem is that createplan.c is trying to apply the physical-tlist optimization to the seqscan underneath the aggregate node. That means that the output from the seqscan is just "col01, col02", which means that col01 can only be decorated with a single ressortgroupref ... but there are two ressortgrouprefs for it as far as the groupClause is concerned. Only one gets applied to the seqscan's tlist, and then later we fail because we don't find the other one there. Conclusions: * we need to back off the physical-tlist optimization in this case * the code that transfers sortgroupref labels onto a tlist probably ought to notice and complain if it's asked to put inconsistent labels onto the same column. I'm a little surprised that it's not discarding the third grouping item as redundant ... but that's probably not something to mess with right now. Prior versions don't appear to do that either. regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers