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 1wLeIs-001vb9-1b for pgsql-general@arkaria.postgresql.org; Sat, 09 May 2026 09:48:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wLeIo-00CyZh-31 for pgsql-general@arkaria.postgresql.org; Sat, 09 May 2026 09:48:54 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wLeIo-00CyZZ-1R for pgsql-general@lists.postgresql.org; Sat, 09 May 2026 09:48:54 +0000 Received: from mx1.polytechnique.org ([129.104.30.34]) by magus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wLeIl-00000001NYF-3HBJ for pgsql-general@lists.postgresql.org; Sat, 09 May 2026 09:48:53 +0000 Received: from mail-qt1-f171.google.com (mail-qt1-f171.google.com [209.85.160.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ssl.polytechnique.org (Postfix) with ESMTPSA id 15A2F1A4EC for ; Sat, 9 May 2026 11:48:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=melix.org; s=svoboda; t=1778320130; bh=GTnbPOPvQxkggmgrza1OvJ3Lgdnrj/96cltvxTb7hSE=; h=From:Date:Message-ID:Subject:To:From; b=cQM34d3p5G1DFNjOns9fj+Vb/v8DAdfL6GxiuZC02GA787NnVnglVGncquUb3A7a0 QcfQF/fgEjpBKsAUOI9KI4gD5e0MX3Q6ucd++gEa+lp6fCgFIfIWEoN/tig2BQ144D /QSataLkSRxEBWHEFsssA12tPEOcPHJes6V5rqzGu2ok/SVLrYck9sSgm0ry3mrfn5 8cB3QnaN5uffDGdoZjqNSYBWLMzAAIsI3n6FMUheN+Ptqh2X8FDT5q+MWltvCJB/Ig Nrq/aOsXbB41vBsMQFiV36eu/jegrmgxz6lXVdkyP+zx4TYaukfXdPG1KyinqxpmwH 36ZGDXzOi4UxVulJvOMSjYOst55EI6Cli0ZtjO7ROTneYlNWe3XdRrGu4j6d/oI/I+ p01okBFbKtDDf8giJWqmSdeUuXspF1erJDcG7RKWCAeq+bBMbodTPAu2090+sYsLXi /U0KoqtKeCNNo1vbjtZZpJDNGjsC6ZRoiHb2vkzvXpj/6S7cEfB6KIQDNJK8YkoBbi H0C+8nN56stAu1XHmNW8VSLCZ53ZmpAhtMCMJWEobbcw10g0m5FTA4rghOJ3eVWvXi rwHO8CWcv+vu/FEwbdTmuj0LjX+lhay56wJCQgNJ9uwx4QwXDBssut2Hm8NqtOVAYl 4axAEGXpDoCXzuVbGGd23twU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=melix.org; s=svoboda; t=1778320130; bh=GTnbPOPvQxkggmgrza1OvJ3Lgdnrj/96cltvxTb7hSE=; h=From:Date:Message-ID:Subject:To:From; b=cQM34d3p5G1DFNjOns9fj+Vb/v8DAdfL6GxiuZC02GA787NnVnglVGncquUb3A7a0 QcfQF/fgEjpBKsAUOI9KI4gD5e0MX3Q6ucd++gEa+lp6fCgFIfIWEoN/tig2BQ144D /QSataLkSRxEBWHEFsssA12tPEOcPHJes6V5rqzGu2ok/SVLrYck9sSgm0ry3mrfn5 8cB3QnaN5uffDGdoZjqNSYBWLMzAAIsI3n6FMUheN+Ptqh2X8FDT5q+MWltvCJB/Ig Nrq/aOsXbB41vBsMQFiV36eu/jegrmgxz6lXVdkyP+zx4TYaukfXdPG1KyinqxpmwH 36ZGDXzOi4UxVulJvOMSjYOst55EI6Cli0ZtjO7ROTneYlNWe3XdRrGu4j6d/oI/I+ p01okBFbKtDDf8giJWqmSdeUuXspF1erJDcG7RKWCAeq+bBMbodTPAu2090+sYsLXi /U0KoqtKeCNNo1vbjtZZpJDNGjsC6ZRoiHb2vkzvXpj/6S7cEfB6KIQDNJK8YkoBbi H0C+8nN56stAu1XHmNW8VSLCZ53ZmpAhtMCMJWEobbcw10g0m5FTA4rghOJ3eVWvXi rwHO8CWcv+vu/FEwbdTmuj0LjX+lhay56wJCQgNJ9uwx4QwXDBssut2Hm8NqtOVAYl 4axAEGXpDoCXzuVbGGd23twU= Received: by mail-qt1-f171.google.com with SMTP id d75a77b69052e-5102582e23eso20541421cf.1 for ; Sat, 09 May 2026 02:48:50 -0700 (PDT) X-Gm-Message-State: AOJu0YwfcgrjSDvzhPDTOWKTy3dxe4xCrt/Z22nCuvOAe3CWFoWzVRHC sH9qjXnbE8oSEvxPbEWzlM2jybSvMtEJCoPMgpdH9jTTW3GMEiP8V0gneC2rvBWTnXVgvlWB807 1VcuzGnxLbxARKfmP4LZBBR2e3Khp1KHixYpZezdn X-Received: by 2002:a05:622a:1789:b0:50d:82db:773e with SMTP id d75a77b69052e-514a0b821bbmr25885901cf.47.1778320129205; Sat, 09 May 2026 02:48:49 -0700 (PDT) MIME-Version: 1.0 From: =?UTF-8?B?SsOpcsOpbXkgTGFs?= Date: Sat, 9 May 2026 11:48:13 +0200 X-Gmail-Original-Message-ID: X-Gm-Features: AVHnY4IC7HnoJCtm0mR9A6eUTwkDVODgW2JMi6Vlb5QKOVVgBx6D5XKez7Rr8i4 Message-ID: Subject: fdw: foreign partition and aggregate function To: pgsql-general@lists.postgresql.org Content-Type: multipart/alternative; boundary="0000000000009939c006515f6b27" X-AV-Checked: ClamAV using ClamSMTP at svoboda.polytechnique.org (Sat May 9 11:48:50 2026 +0200 (CEST)) X-Spam-Flag: No, tests=bogofilter, spamicity=0.010983, queueID=552F11A4F7 X-Org-Mail: jeremy.lal.1997@polytechnique.org List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000009939c006515f6b27 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, Using PostgreSQL on Debian 18.3-1.pgdg13+1 I've setup a partitioned table, with local and foreign partitions like this Cl=C3=A9 de partition : LIST (part_id) Partitions: foreign_parts_s1.mytable_1 FOR VALUES IN (1), FOREIGN, parts_s10.mytable_10 FOR VALUES IN (10), PARTITIONED, and ran ANALYZE mytable; Now when I query directly the foreign table, the plan is what I expect SELECT count(*) FROM foreign_parts_s1.mytable_1 WHERE part_id =3D 1; Foreign Scan Output: (count(*)) Relations: Aggregate on (foreign_parts_s1.mytable_1) Remote SQL: SELECT count(*) FROM parts_s1.mytable_1 and is somewhat as fast as the same query on the remote server. However, when I query the parent table, the aggregate is not pushed down: SELECT count(*) FROM mytable WHERE part_id =3D 1; Aggregate Output: count(*) -> Foreign Scan on foreign_parts_s1.mytable_1 mytable Remote SQL: SELECT NULL FROM parts_s1.mytable_1 WHERE ((part_id =3D 1)) and it reads all the rows, so it's not a viable query. I tried with various parameters like enable_partitionwise_aggregate enable_partitionwise_join also use_remote_estimate on the server options. Is it the expected behavior ? Did I miss something ? J=C3=A9r=C3=A9my --0000000000009939c006515f6b27 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,

Using PostgreSQL o= n Debian 18.3-1.pgdg13+1

I've setup a partitio= ned table, with local and foreign partitions like this
Cl=C3=A9 de par= tition : LIST (part_id)
Partitions: foreign_parts_s1.mytable_1 FOR VALUE= S IN (1), FOREIGN,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 parts_= s10.mytable_10 FOR VALUES IN (10), PARTITIONED,=C2=A0

<= div>and ran ANALYZE mytable;

Now when I query dire= ctly the foreign table, the plan is what I expect
SELECT count(*)= FROM foreign_parts_s1.mytable_1 WHERE part_id =3D 1;
=C2=A0Foreign Scan=
=C2=A0 =C2=A0Output: (count(*))
=C2=A0 =C2=A0Relations: Aggregate on= (foreign_parts_s1.mytable_1)
=C2=A0 =C2=A0Remote SQL: SELECT count(*) F= ROM parts_s1.mytable_1

and is somewhat as fast as the sam= e query on the remote server.

However, when I query the= parent table, the aggregate is not pushed down:
SELECT count(*) FROM my= table WHERE part_id =3D 1;
Aggregate
Output: count(*)
-> Foreig= n Scan on foreign_parts_s1.mytable_1 mytable
Remote SQL: SELECT NULL FRO= M parts_s1.mytable_1 WHERE ((part_id =3D 1))

and it reads all the rows, so it's not a viable query.

I tried with various parameters like
enable_partitionwis= e_aggregate
enable_partitionwise_join
also use_remote_e= stimate on the server options.

Is it the expected behavior ? Did I m= iss something ?

J=C3=A9r=C3=A9my
--0000000000009939c006515f6b27--