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 1wXTpc-003HzI-1U for pgsql-bugs@arkaria.postgresql.org; Thu, 11 Jun 2026 01:03:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wXTpb-00Dj8I-0R for pgsql-bugs@arkaria.postgresql.org; Thu, 11 Jun 2026 01:03:39 +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 1wXTpa-00Dj8A-2r for pgsql-bugs@lists.postgresql.org; Thu, 11 Jun 2026 01:03:38 +0000 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wXTpY-000000026Ey-3zq2 for pgsql-bugs@lists.postgresql.org; Thu, 11 Jun 2026 01:03:37 +0000 Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-bec3ffb95dbso1243854566b.0 for ; Wed, 10 Jun 2026 18:03:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1781139815; cv=none; d=google.com; s=arc-20240605; b=PQdEcxJ+4/wKZzZgUfLillrHITcisEZG6fucdWwPrEbOkpWWF5Yoz0gBISSKgtpN6S MPgSnb1CJN74dyQJ3unfBYOP6yi8ieR8onesGHI6Y34MQ6htHCUpIYkKQK8KGWg8Nn7v O3eorhffiiTPdBv/pVW7VYAQTtbTu3reIoP57yTmb3pafDzo66u2fm6oJmFNkATi0ree DvzDupzUmSK+h/azvmNJXsCIL8ep5uF3bxA6LJznyjinfzfmf88StGfcYZ18Wht1hqQl i+Hn1ed3asE3ErI+Yas26rscGjWCMNzLmsEzIcmtSJRJkWVT4zOvN+hQqSvfDNVK6h8V kB2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=sgmnMmn10BQyeS6jyM+cws0wRHauEjMH0YBvf5+/cvk=; fh=WH8cNUJKs41ZRcIF7JG4+fUkwpRRu8cnD/bhI8x3MA0=; b=J3rjcy5tTfaCgooACyGB+bpQWHP3NGiKUQKMhExvS2kYVwzn0KAEy3V4nD/FP801Wi 3yDy8n30x5WdpgD8DtJWVRBew2XcrBVu2fhd90CQ1aO7Tl2NWursFVRBcfRw4JZSvmxe tJveM+FeHwx4Suf/1VUbfRdNzhv0IFo4n/uvExO7RdsDHVOxC02nt/xWwSdLD3p2i6qq UuKcRmC7LPDjb7sRdumhBk3Cf6tfcrDHfyR4AXJRu2+0kf2mQcR2fa0E4oSSmfDuG/Bh EoMNUyO3l2fg1KgfuTHzIXEvWDMg166dD3jy2KmL+s8P8VnS9OCww/WQdcFoO41DJnOc SFCA==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781139815; x=1781744615; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=sgmnMmn10BQyeS6jyM+cws0wRHauEjMH0YBvf5+/cvk=; b=l6ROdKBMEnbggbeOoW0qCJ32v7buE/bf8cGmzzFHIHAw0tqN15Z4fsdbhNh5GkOjAj M1ofUawPEhdadXm62HY3jS2l9Keey1wPX0WL+moMvoGViIgVK3qCjhs2PN2XHx+LNAkj LuFAOLzOAIxoCXAGoMb043kWAaSJNuKPq2x4EaEPVl7e2UHa0aVyLgGVy7JYBNN0QZIM gJ/ft7SzN27PD/l4teK/yGYeNrmI00FKHFRFrEl/nAYPe5ux2uFfwAsQVfTi12KRpnKr nLgcVDSWJIrgoegh0Tu9QtDteu3ozH8O81TJPpOYIpEynSyWCBAPQfagKfwrUW0pWsOd xV5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781139815; x=1781744615; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=sgmnMmn10BQyeS6jyM+cws0wRHauEjMH0YBvf5+/cvk=; b=szdZRFqR0Quw6+H3PlyUV11sexST0rAks7lVT2xmSsqd5tgBGjjw+Im8fGn5SO+o8c 3zlwUiwm/C/rZNpNpQJpqiU8MTrifaB+cbX/PVx6FNwiIE+KHiQRGPPcH3Y1rcsHioN/ LmqystCcMcVbV/y6q8odvDaBa2BQgN433XOsyEcc92EgTrVW6az6hSVcvrXXDuzsydVq Ei2RhtGM2g0YddhA7SrLlDLoQya66KB0fomrP1oeQFovoMbFkRTAwuIX4MZVj8fr1yYY A4jVlUcEs7L4S+28VFqyUi5aDlF92PzlYjcNWKhUMmDLlESEuHGxSCo0/HXgn6v/454L Ynpw== X-Gm-Message-State: AOJu0Yzx7A7fs124XIytvZBo0sEf4OpOn/iXTpu8APoXqQ2F/q+Ls5BL imAEOOn2wfgH+qELbZx0/QvGQ5Xl/qhgEyUAx508xT154gev4GAw+NJK2UL9SZ2uyDWDXmVqMCI jpPCZyoIWYVp54gIODMb22YawIRH9N7U= X-Gm-Gg: Acq92OGoXSMAp6S54JJ9Jae3BOc8aimoHfWObOJWB0wQ3Vm38xs0cJn1UW5X5cLOSsc uZBfhnPhDxz+3idOQgJuXmJMO6lLuv8oooDSg3KSzUcGGEXXEJ7qElJR7e71COIJmg4PzKvFB6m C0PaBcNDsAb1g599vdPkaQp3Igl6zXLWJffz8ylWDOfp80HOH9wqO6oUhbqeDJovuitQp4DWeEn WedzSxbUk8KT+bp8s2SkTyudOXB2vFwMbEWFp5TzTmiZDNpyTLGGYWvwr8KMTwlBwqJ4eqAs6ix v+uJWuIuAA2jYhxkXu5KMeDJudfP126Lpe5kV4LWs+DYyKcwmTB1rsrxQJ/knOQ= X-Received: by 2002:a17:907:d1b:b0:bd5:18e8:1ac1 with SMTP id a640c23a62f3a-bfc85745e41mr11634266b.5.1781139815297; Wed, 10 Jun 2026 18:03:35 -0700 (PDT) MIME-Version: 1.0 References: <19517-4c53dcdcef98d263@postgresql.org> In-Reply-To: From: Tender Wang Date: Thu, 11 Jun 2026 09:03:22 +0800 X-Gm-Features: AVVi8Cd-oOdldSWrgawjU_rlEOpWQw1Nxs2IodKrXwT6qx23K3N90fBLtZphK1c Message-ID: Subject: Re: BUG #19517: Eager Aggregation produces wrong count(*) when pushed into RHS of Hash Semi Join To: ihalatci@gmail.com Cc: pgsql-bugs@lists.postgresql.org, Matheus Alcantara Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi all Matheus Alcantara =E4=BA=8E2026=E5=B9=B46=E6=9C= =8811=E6=97=A5=E5=91=A8=E5=9B=9B 04:19=E5=86=99=E9=81=93=EF=BC=9A > > On Wed Jun 10, 2026 at 12:44 PM -03, PG Bug reporting form wrote: > > Likely cause > > ------------ > > Eager Aggregation appears to consider the RHS of a SEMI/ANTI join a leg= al > > site to push a partial aggregate, but for SEMI joins each outer row mat= ches > > at most one inner row by the join's own semantics, so partial counts ta= ken > > on the inner side cannot be combined into a correct outer-side count(*)= . > > Either eager aggregation must be disabled for the RHS of SEMI/ANTI join= s, > > or the partial state must be projected through the semi-join such that > > each surviving outer row contributes exactly one partial. > > > > Two follow-up commits to eager aggregation landed on 2026-04-06 > > ("Fix volatile function evaluation in eager aggregation" and > > "Fix collation handling for grouping keys in eager aggregation"), but > > neither addresses semi-join correctness. > > > > Wondering if commit ffeda04259b (Fix eager aggregation for semi/antijoin > inner rels) is about fixing this issue. Can you please check it? I think > that 19beta1 was created before the fix was applied on master. > Yes, this commit ffeda04259b has fixed this problem. But it wasn't included in the 19beta1. I tried on HEAD, and the result was correct. postgres=3D# SELECT u.user_id, count(*) FROM u WHERE u.value_2 =3D ANY (SELECT e.value_2 FROM e WHERE u.user_id > e.user_id) GROUP BY u.user_id; user_id | count ---------+------- 5 | 26 (1 row) postgres=3D# explain SELECT u.user_id, count(*) FROM u WHERE u.value_2 =3D ANY (SELECT e.value_2 FROM e WHERE u.user_id > e.user_id) GROUP BY u.user_id; QUERY PLAN --------------------------------------------------------------------- HashAggregate (cost=3D4.76..4.77 rows=3D1 width=3D12) Group Key: u.user_id -> Hash Semi Join (cost=3D3.25..4.71 rows=3D9 width=3D4) Hash Cond: (u.value_2 =3D e.value_2) Join Filter: (u.user_id > e.user_id) -> Seq Scan on u (cost=3D0.00..1.26 rows=3D26 width=3D8) -> Hash (cost=3D2.00..2.00 rows=3D100 width=3D8) -> Seq Scan on e (cost=3D0.00..2.00 rows=3D100 width=3D8) (8 rows) --=20 Thanks, Tender Wang