Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rmkkd-009eKK-TQ for pgsql-hackers@arkaria.postgresql.org; Wed, 20 Mar 2024 01:28:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rmkkc-001TMl-DP for pgsql-hackers@arkaria.postgresql.org; Wed, 20 Mar 2024 01:28:18 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rmkkc-001TMc-4M for pgsql-hackers@lists.postgresql.org; Wed, 20 Mar 2024 01:28:18 +0000 Received: from mail-lf1-x132.google.com ([2a00:1450:4864:20::132]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rmkkZ-005Pz3-1e for pgsql-hackers@lists.postgresql.org; Wed, 20 Mar 2024 01:28:17 +0000 Received: by mail-lf1-x132.google.com with SMTP id 2adb3069b0e04-513e4dd6ca4so385317e87.0 for ; Tue, 19 Mar 2024 18:28:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710898094; x=1711502894; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=kW5zLWJOBpybogtFePbldqHzEF06L1iwfu+izM5GMCs=; b=gqQz9a8zeqstzxNG273GNmrUCog1Kubt1/NANq0WXqknELlZeA558kUCV8K131EHSp +v4ncT1nH1FXpA9eT9u4rReVqSzRyVzgIPUthDhyBim26tN+WJ16UZ3dJHXvYWTuikgV ZQFyPVy5xBJBr9J08wK89g5kWIwSuYHhoMIjlinpl3/z1PMAlgWueRv7+1MEsFZfYren OHGAPEgGjr/4ldDULDoXnDRsWhdF+ywCR0VGlDF9Bz/F3Rf1YMlMU+jDheIRJ0mklzUS FSVYiVurcLO/7xxl+wHAN93RRCNqUtAmr3qNXrAXrbfkSrHuwp8f7m3Q2zRzfm30kID9 wakQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710898094; x=1711502894; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=kW5zLWJOBpybogtFePbldqHzEF06L1iwfu+izM5GMCs=; b=hTOM8f2pIh/O0YTGHyOBSmek7eIObvUgdk4L7UD07JUmwOD1NjLkbvD0TI3ePbECNK ugBIbQH59tNgqEmfCR7/cw6um6YSTAmCYikZQ91xc+pKpP/P8YMw+tgpn1WbJp7gHxqo BQDZcBHIYoaFpgBrdJaUcZXqSSRLKgabIlYnpUlstTsfEwi0gFntsLZk002vZzIRYtTt t37D9u+mKnWpjQES0j+naTGktCbQiU58pzUSbqnoVI5pMVIEcVJR4wEBy51eXFXWUh5j 0hgGXSnMUg8fAqo1ioTxjg3eS0iOf9Mm7h59PaNJFAkRHjn2891n2PFzP9GT417FwrE1 vy4A== X-Forwarded-Encrypted: i=1; AJvYcCWhe1m1fIOjnERJBiSyqAMl/Nf6WjdNxe4DwDtPnFkaHYo7m1nN1EDw4x0ZURE2nudQMhCAIhkcjWqRfrbad5x8K2EnViEkc6u/JB54UL1QtpAO X-Gm-Message-State: AOJu0YxSoT1SF+tKUTQlCIQAJ9TsyCSO/qcKMe9G6mtQ9SJIy/WAj9AR of2Gw86VdtaHmbEeqDCFsN+8A2Ky11ve2zYs14N/zRztD3s6D3OC8PWWY80fF7OByiK5yVAcpVV 8CEw96Wd2oCbFkHXA74T9ksjKLhAh24kb5P8= X-Google-Smtp-Source: AGHT+IGzm12DXFTSl3g19EDXFNTjLMFv6TJ3RBnVmr8u5Mijg9K/xI9zy59bZS634ZCuEpJatN2jpm52UtZbT/BVwlU= X-Received: by 2002:a05:6512:558:b0:513:d1d9:9eda with SMTP id h24-20020a056512055800b00513d1d99edamr301476lfl.27.1710898094295; Tue, 19 Mar 2024 18:28:14 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: David Rowley Date: Wed, 20 Mar 2024 14:28:02 +1300 Message-ID: Subject: Re: pg16: XX000: could not find pathkey item to sort To: Ashutosh Bapat Cc: Alexander Lakhin , Robert Haas , Richard Guo , Justin Pryzby , pgsql-hackers@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, 18 Mar 2024 at 18:50, Ashutosh Bapat wrote: > If the problem you speculate is different from this one, I am not able to see it. It might help give an example query or explain more. I looked at this again and I might have been wrong about there being a problem. I set a breakpoint in create_gather_merge_path() and adjusted the startup and total cost to 1 when I saw the pathkeys containing {a,b}. It turns out this is the non-partitionwise aggregate path, and of course, the targetlist there does contain the "b" column, so it's fine in that case that the pathkeys are {a,b}. I had previously thought that this was for the partition-wise aggregate plan, in which case the targetlist would contain a, sum(b order by b), of which there's no single value of "b" that we can legally sort by. Here's the full plan. postgres=# explain verbose SELECT a, sum(b order by b) FROM t GROUP BY a ORDER BY a; QUERY PLAN --------------------------------------------------------------------------------------------------- GroupAggregate (cost=1.00..25.60 rows=200 width=12) Output: t.a, sum(t.b ORDER BY t.b) Group Key: t.a -> Gather Merge (cost=1.00..1.00 rows=4520 width=8) Output: t.a, t.b Workers Planned: 2 -> Sort (cost=158.36..163.07 rows=1882 width=8) Output: t.a, t.b Sort Key: t.a, t.b -> Parallel Append (cost=0.00..56.00 rows=1882 width=8) -> Parallel Seq Scan on public.tp1 t_1 (cost=0.00..23.29 rows=1329 width=8) Output: t_1.a, t_1.b -> Parallel Seq Scan on public.td t_2 (cost=0.00..23.29 rows=1329 width=8) Output: t_2.a, t_2.b (14 rows) David