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.96) (envelope-from ) id 1wzIcS-003vmz-14 for pgsql-hackers@arkaria.postgresql.org; Wed, 26 Aug 2026 18:45:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wzIcR-00FFYg-12 for pgsql-hackers@arkaria.postgresql.org; Wed, 26 Aug 2026 18:45:03 +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.96) (envelope-from ) id 1wzIcR-00FFYX-07 for pgsql-hackers@lists.postgresql.org; Wed, 26 Aug 2026 18:45:03 +0000 Received: from mail-ot1-x330.google.com ([2607:f8b0:4864:20::330]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wzIcP-00000002YaI-27T1 for pgsql-hackers@lists.postgresql.org; Wed, 26 Aug 2026 18:45:02 +0000 Received: by mail-ot1-x330.google.com with SMTP id 46e09a7af769-7e9ecd7216cso972339a34.3 for ; Wed, 26 Aug 2026 11:45:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787769899; x=1788374699; darn=lists.postgresql.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:to:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to:content-type; bh=Ryozz03JCiviyJfsjCgZHNIRotxoQt5a8rTtV1ffu1M=; b=j3RttxqqJsGgPyks9wb395G+nBqQ5kKC5AIJQa/aFFml4PLP7RKZqPxXfc48j4pz9f sptZx44odH+4f8Td3x4p+4BDQmJf0UVybZ39vxEYq6C+zYYVyzsSyMpCBjwfXCaLu0T+ sHze7ngB0gn6AGmLA/NKmUVx94rl8wLDXV8jkkgxXPOosuTXBnClLkgsqpDOj8dJbtOE O/Ci2u0J0a70Of/PEhn8jpbxZiRFLK7dk+UXrmxl9iABrNk/C9DVw1AM5HPvhXJLBJd+ mThdn1G2etdnXblaFgC7vOX7WmddeTsLqXTLUWKhgWuQsEnZ+h/p0IvmXVDR2NGlK+3N gzdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787769899; x=1788374699; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:to:subject:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Ryozz03JCiviyJfsjCgZHNIRotxoQt5a8rTtV1ffu1M=; b=T199NUm8ZiE3SvLGN0HNAYmJ0nFhHdxQtuGg7QgZp9v0Ks6TKNqcsZ0eFpcC8LnFpq i8j/vbxK/p9duOKTMU39jRg0AE9SxqN6iVgswQ8DSv4DdTcr78rOnombQ/Zoo0HPAbHo NXqHqK1tM9cQDUe5scJuRFKDalWCz4x2BJ43jsJPjZbPTykJSNDUn5uhmFc/BYPDZ5f1 ipg3Jnus5zxSQB1pXHfjwaB2f5f2l8LD2oWqlVqLi2ZQJhPG6953gW1afjyeo42whXTQ 5QF3W5s5xRom2C9/HoHvh5cZqsIKLQkAgMmJNhlR/1JSSbo+bRdMQKfFR/jU9EmLECBZ QLyw== X-Gm-Message-State: AFuF++nflD+K+I9nuNFrA5Jm8l8gsr6h/6l73nmjPy2I/6bmKt7UJh+V Fhu7kc+b4SelxCerYu6XRV7xwkJaqZWR/KVOvu3SWgKZixmZobrLh6vCxnnV72+2 X-Gm-Gg: AR+sD13ztkqn25i/YzUgu+6CkHzTXqgCOUQOXOlYlF73PoCO36DDRvVX754XnHzMd8H Pm0vVJzFPRMmv05mUVaQWtcm3lXaUThGz+RDuJXQwJlY+Cl7lpyUaAUC3r27jjj9Ln4SQPKL4wk bXx+Z0WhtXrBoAmCBqDh7u+n9HJaBu+tyQAHBFjoyNHY6zEC4OC/ndbbebMFf5GZnYbzNjbw3oY ngpoWHuP/vBcTlKvaPUXoxvziMUUPSe5Ms4VgluzU4CWa0no0ZVKUB8Kd/9+hi8Hb+RpCzZyX7l n5Bm/FieSKGNQeOqIvkxn3XcwosZhQdCcjAQlFL8qYjlLxoyuj2lgUdQigD0+ljrhoBLgkAuKrr B6jnPW54zXLFLcYbb2Y+WDm/s2SewGe+iSwZEXfvOJVl7MRW4T9uutUAtAPfKGNs7Q5IbD9fkWi PT5Tm96gVn4sYHS35jnlrJmMQ0aQQl51wRsOqIa0iCJey47ZnDKxCyGQ/XlaChtcXIMmj17MxYp zR0Jd+Dcq/sWrjS8N6Inhow/j1TMdH2W2oYioysxbLHaQ== X-Received: by 2002:a05:6830:25c1:b0:7d7:ed69:81b2 with SMTP id 46e09a7af769-7f4c4e7322emr8518665a34.5.1787769899617; Wed, 26 Aug 2026 11:44:59 -0700 (PDT) Received: from [192.168.1.132] ([163.116.253.147]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7f4c81d7c76sm2207874a34.4.2026.08.26.11.44.58 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 26 Aug 2026 11:44:59 -0700 (PDT) Message-ID: <13bcb1c8-96c7-4e66-877d-2ed5143efa24@gmail.com> Date: Wed, 26 Aug 2026 13:44:58 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Fire create_upper_paths_hook for UPPERREL_PARTIAL_GROUP_AGG To: pgsql-hackers@lists.postgresql.org References: <6fc72a7d-9f52-4a72-9adf-1912da255605@dunslane.net> Content-Language: en-US From: Bryan Green In-Reply-To: <6fc72a7d-9f52-4a72-9adf-1912da255605@dunslane.net> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 8/12/26 17:32, Andrew Dunstan wrote: > > Greetings > > create_partial_grouping_paths() builds the UPPERREL_PARTIAL_GROUP_AGG > upper relation.  It already calls the FDW callback GetForeignUpperPaths > there, but never calls create_upper_paths_hook, the general-purpose > hook that non-FDW extensions use to add paths. UPPERREL_PARTIAL_DISTINCT > doesn't have this gap: create_partial_distinct_paths() calls both > GetForeignUpperPaths and create_upper_paths_hook for it. > > This patch adds the missing create_upper_paths_hook call right next to > the existing GetForeignUpperPaths call, so a non-FDW extension can add > partial aggregation paths at the same point an FDW already can, before > those paths are gathered and a Finalize Aggregate is built on top. > > It's a small, self-contained planner change with no effect on existing > plans unless an extension registers create_upper_paths_hook and adds > paths at this new call site. > > cheers > > > andrew > > -- > Andrew Dunstan > EDB: https://www.enterprisedb.com Andrew, If you use enable_partitionwise_aggregate then create_partial_grouping_paths will run once for the parent and then again for each child. This leads to the upper_targets[UPPERREL_PARTIAL_GROUP_AGG] assignment being overwritten per child, resulting in upper_targets holding the last child's reltarget. This happens whenever partitionwise aggregation is considered-- it doesn't have to win. So any extension reading the slot after the grouping stage gets the wrong target. I reproduced this with a test hook. The hook already gets the target as output_rel->reltarget, so I think we could just drop the assignment? bg -- Bryan Green EDB: https://www.enterprisedb.com