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 1wTxX4-000rDh-09 for pgsql-hackers@arkaria.postgresql.org; Mon, 01 Jun 2026 07:57: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 1wTxX1-009T6k-2c for pgsql-hackers@arkaria.postgresql.org; Mon, 01 Jun 2026 07:57:56 +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 1wTxX1-009T6c-1i for pgsql-hackers@lists.postgresql.org; Mon, 01 Jun 2026 07:57:55 +0000 Received: from mail-ej1-x62e.google.com ([2a00:1450:4864:20::62e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wTxWz-00000000Xjk-2hvi for pgsql-hackers@postgresql.org; Mon, 01 Jun 2026 07:57:55 +0000 Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-bdb3fd39045so1501717066b.3 for ; Mon, 01 Jun 2026 00:57:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1780300671; cv=none; d=google.com; s=arc-20240605; b=SRHdo5UYX2zFz8vxXOF6Y0Qbra3ywSJxs1BZbUQzKgIi74XolWj5jHy5wRb9T2Cgnx k74QmrS4vhkQ5kQpnH3DHRtDVA2Ds95pceGpJTtCaQu/cmB9zzFg57B3gXi5PbUEPnKe jtWpX+iNy0OE6uCUYDCIxUhST8NOnfuQcyRIkGaFSy1rFg7BwflpNLF84vd9We6JRWI/ 4cwUhQeho1sz5KS5DOF6J5tQ7I63mFI2PROlO+7qRGOVs9Rh9JVZXfeGv/Zk77miyXcR lKTd7h+P8q0hRFf4ZhD+G0dwiZLqHi72Dw/Tb050u5pO1yx8o01e03Qih9T5lBlx2N7L 2VJg== 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=laWQ3LBVbCPN/sdMCblT6wdTk2APqWYF51L5m5ABWck=; fh=rwyijEanxOX4X4tB9HXX/ipYqZNo5o61zESEi9CnbgE=; b=ZH6usNMQipVvwCIfYT95GUq+JWv2lewKHOW865n1RYZGtl/vfMcg297ag8qSjv0Zwr J2ILPJ4KOlSi/QaNnr7Gb5iZj8kUJjRKm9o+I0NwaYgW+w8P66eo2RYFg45W+zJfSiD2 GRPUS1dJlYy/YeM2mgDi0h9hmVRHaz5aZLpdzG+menY42topRKHcpgl9fV8igzJhSav1 Wwa0bC8TPG/qexG8DeGua8+8fzjSj4h6MlZMhguZ7+ZISYNfjAV//BVW+il/euquRDYb JBHsEBX50DUTmDa7T8FmFVNgrpmabekkwWvLJuNXfPDOljkd0E+UGw/NiM7r3Tng9b5w siBg==; darn=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=1780300671; x=1780905471; darn=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=laWQ3LBVbCPN/sdMCblT6wdTk2APqWYF51L5m5ABWck=; b=juj5EfQi76ITRWKRAjFKz9ExUwFN9doc1tJoR7Kw9gL+nnkdyH4t9L43T7IZvUjv5O xHnUDoVqqTUjV0fYghfz2SWLb9tzjWUTaeAMyHCFP9L2HmO00y2WcbzrC1e8mWhChQ0t hR13vWt1JJw4VAyq0XWz141kHtbTKyqVrRXovJtQwalg1uIBqxjPsx4Rn2xkSuBBc9QR AQxsFlCgTD3uAyqfcn6/sdBcaBciavh/1wdHJZJV8H8Io//Q0Ne2dfRF7kcaNsZAGPh5 H4i254itP1a4Whksm4vlTMVNsyPUdLrXuQ7hLE8ELLm6PlzfvIx4lB2V2wIcxpOzhZpB 3jCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780300671; x=1780905471; 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=laWQ3LBVbCPN/sdMCblT6wdTk2APqWYF51L5m5ABWck=; b=P3IT35qtXQt37Cn5UBNMUWoCP+tRSJJg3EUW4+NtMo2J0ZtlZrWjvprvN2e78fUA1T eiRwRT2j72cqZ40PedHk6jrG6JNuU+teijBaqFOwA4WyYyibC9Go398lNM8Vv5DylVeb hq/O60QjGWucrfOXlUK7cjkxhYMltg8h52UyyiGZKKekQeIw9oJDt7GCX+7zfeubiGIL H+azN7eYVW0StdvkF5F0nP/ZwyaeQExfUae92Tez70oHIXbsygwbIrBChFu8fI5qfwYw v2RGgOtibJtKocK+jt8nI5CE5GWNh6j/wogx7YTHtbAmeIEn8DrbNrsTrOlFQG5uhEre znZw== X-Forwarded-Encrypted: i=1; AFNElJ8anict8y1oBbEPqZrUU1N7/IjbIOVwYiGnblA4lN96OsJWsC/nOjatQRZZUO+GjVzCxTQ8+zPjpNtXeX+X@postgresql.org X-Gm-Message-State: AOJu0YwWsSJAGR1obf9VopttmSkC1+W0x/dJKwv5CJkRtSnBphCuX2DG ymgbAlP2yy+Ke40UIEtM0FAtrE7Dq9lutiDeYl6F/j7Q8jX4OeecJE0H8HPYcV893u+Irt8oQAH 1ox6B7o3rifb+zZ5RXxaLfA1LjJFI/HM= X-Gm-Gg: Acq92OGmuciJDW0K7jQa++dOcVyWvdSR6EUHpaNy9shGbxWtZeSmdmTCDG7PMlr904D KbTPUppDtwQ/j7G6hfB3+DSbi7MDPwwvWMnrEuuXBvDxWpPwf4SZnKS9LloyDBP2c1VUnHvcHur HtizopMUD2kc/XuHh8Ac/4m2SXg8JT7PwzTj1HS1PCSY0Hh9VIn8K0tlQRUiy2w7jSoM+nL8UQ6 Xc0sFVEUTmRNTBIOQzE7UI17KHt32cNZht8YcYPMQHC54W8jvoBcldqlvUUgObhvWIadHgayWbn A4JkvzJZS62aT6+QLuSF/B9kPYZcGs+NevwSftnwx7qQkcWcgHgkpFxz/ZWhrQ== X-Received: by 2002:a17:907:e143:b0:beb:7b50:3a7b with SMTP id a640c23a62f3a-beb7b505c83mr193564966b.6.1780300670492; Mon, 01 Jun 2026 00:57:50 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Tender Wang Date: Mon, 1 Jun 2026 15:57:39 +0800 X-Gm-Features: AVHnY4JT8G_FeuVkr3sU45ReO1FAKLlw2IVWIpm5milTSNyE2u5kkT9Hdve2Gcc Message-ID: Subject: Re: Eager aggregation, take 3 To: Richard Guo Cc: Radim Marek , PostgreSQL-development 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 Richard Guo =E4=BA=8E2026=E5=B9=B46=E6=9C=881=E6= =97=A5=E5=91=A8=E4=B8=80 15:19=E5=86=99=E9=81=93=EF=BC=9A > > Thanks for the report. This is a bug. We should never push a partial > aggregation down to a relation on the inner (RHS) side of a semi/anti > join. A semi/anti join does not preserve its inner rows in the join > output, so a partial aggregate computed on the inner side would not > survive the join and could not be combined by the final aggregation. > > > I haven't thought about it too deeply yet. Maybe we can do something > > in the make_grouped_join_rel(). > > ... > > if (sjinfo->jointype =3D=3D JOIN_ANTI || sjinfo->jointype =3D=3D JOIN_S= EMI) > > return; > > ... > > That does fix the reported case, but I think it's too broad: it also > disables pushing a partial aggregate to the outer side of a semi/anti > join, which is valid. And by the time we reach make_grouped_join_rel > the grouped relation for the inner-side relation has already been > built, so it would just go unused. Yes, checking only the jointype and concluding that partial agg is not allo= wed will cause us to miss some optimization opportunities for the outer side of the semi or anti-join. > So I'd rather fix it in eager_aggregation_possible_for_relation, right > next to the existing outer-join check, by rejecting a relation that > lies on the inner side of a semijoin/antijoin. See attached. The attached LGTM. --=20 Thanks, Tender Wang