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 1uuWFR-00BZ7r-OT for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Sep 2025 13:13:02 +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 1uuWFQ-007ZKs-Oz for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Sep 2025 13:13:01 +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 1uuWFQ-007ZKe-Fb for pgsql-hackers@lists.postgresql.org; Fri, 05 Sep 2025 13:13:00 +0000 Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uuWFO-000gQy-2m for pgsql-hackers@postgresql.org; Fri, 05 Sep 2025 13:13:00 +0000 Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-b0472bd218bso378417466b.1 for ; Fri, 05 Sep 2025 06:12:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1757077977; x=1757682777; 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=Go6BFgtdE77UiYYgVnqWG2qUHlahXbQbM6UddYBO4ak=; b=BTn5lKRS280lrK2fBIgB8wzAcOaHP6BKCQKe0It8UcyXS7tkJ/VZQAJmx3vxFKKJZ8 2AOjX3qW9LNbT8A3ZmWhWwt+TP9SorJdupLQ3PkSr+tJ1qCkFMnsbJ1VNUti0ISXLdq/ ijtOAPNstw8ZxDKJJ0UOaEzshXoukyDH/PfqMPi5/y4sxMInqkMfinvzuOe9uRr7epyg UiHKpyIfSYLu/ZV4/lXwRMckjyVcAn11ULCZlZBpYBFQXgqXlxH101DdWNm81SFK2P+F Rx/ewxau8/k3YAym/k5vzYb5DQcFkqEBeDbgC33QNKYZA5Vxsbgra6xhztBajMov7jjE rFSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757077977; x=1757682777; h=content-transfer-encoding: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=Go6BFgtdE77UiYYgVnqWG2qUHlahXbQbM6UddYBO4ak=; b=RFugyZxfI9vKBwb4zT1pq74e96qZx2GsiwOugFgXoWQsf1rCDLMEOs/iczsVTQYmtj 2wcxckvCQFzSZwQric4fQ5nM9gl6PQiE22N0SGL8YOQmRS5tvYLNCLcJJcojRXpA65kh UNjvphaWXT2BozjB1EKcGPjnBIBYVjRRCdWg8uht6qtUzotFg1QpyfCqnu7/26dPrAsW s1vHY80l4PP2MIH9gG6yjbKQ8tKIElwmE6dgT5UCDzbSIR03PqGEiZcM7t41IbNblMs5 IfDLfYkR1+HthUKZlJoNnnyVa41YoK/zuHLcSPBduvTpqeMe5E5Q6FYg6bqmM8YjFzUo t1/g== X-Forwarded-Encrypted: i=1; AJvYcCWkNtiFZtkM6VVYtgUfk+MR3VT8feI7ZZJrhjW/aRY8rjk6fURXMPdrDBFSZSXiSsSSV1QDYjwudqvqdIT/@postgresql.org X-Gm-Message-State: AOJu0Yzq8ZlF5XEEde2ZXCSfxodx0OQ3oLQ93GF8l4uzdUYJtSN2YdPF r5WcIVIjuYFMwCAG7lc+FoQYWQR7x+uVq7iorKLWKwK0YEo17N+eXCHfVftiVTvrKFWDici5fI2 p5dAdKMmNCMySXfvEh+XvwJneP76nLSA= X-Gm-Gg: ASbGncs8XCBSbdu/mSqvttgt2CNLxdtw4qegnywk9YKvwROzp09taU1ZhmuaAj/saxG xg7JrJ8f6WXixkSjhcFXapjJcIRtFUqrtVrj4+QrU//jJ2mAEozF6DhIpO24CworTPJyXQy5PU0 Yv8My29L/2CbZGXeHXaT/F5xwxw+V3Uv6llbp6JECAiDl2PO3mIiMnRDl5hcyFQd4z8lYq0Q2qI hri5aLjR8Mi2pUlPQ== X-Google-Smtp-Source: AGHT+IH782BnN/zYwnXv3m56M4sFop5Ff6ObBSpc11BgVunyoL3E5sXHkN5cojoOHEalA4AVn29D1PcVqG+DNyj4LFY= X-Received: by 2002:a17:907:8693:b0:b04:83ba:9b84 with SMTP id a640c23a62f3a-b0483bab566mr562099766b.50.1757077977101; Fri, 05 Sep 2025 06:12:57 -0700 (PDT) MIME-Version: 1.0 References: <87il22cj51.fsf@163.com> In-Reply-To: From: Robert Haas Date: Fri, 5 Sep 2025 09:12:44 -0400 X-Gm-Features: Ac12FXxBunsz1AiClTFZFKjouMs5EZgTTPQCj3Fuo3Jt2dAPLZDANI6Eu6WAfCQ Message-ID: Subject: Re: Eager aggregation, take 3 To: Richard Guo Cc: Tom Lane , Tender Wang , Paul George , Andy Fan , PostgreSQL-development , pgsql-hackers@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 On Wed, Aug 6, 2025 at 3:52=E2=80=AFAM Richard Guo = wrote: > To avoid potential memory blowout risks from large partial aggregation > values, v18 avoids applying eager aggregation if any aggregate uses an > INTERNAL transition type, as this typically indicates a large internal > data structure (as in string_agg or array_agg). However, this also > excludes aggregates like avg(numeric) and sum(numeric), which are > actually safe to use with eager aggregation. > > What we really want to exclude are aggregate functions that can > produce large transition values by accumulating or concatenating input > rows. So I'm wondering if we could instead check the transfn_oid > directly and explicitly exclude only F_ARRAY_AGG_TRANSFN and > F_STRING_AGG_TRANSFN. We don't need to worry about json_agg, > jsonb_agg, or xmlagg, since they don't support partial aggregation > anyway. This strategy seems fairly unfriendly towards out-of-core code. Can you come up with something that allows the author of a SQL-callable function to include or exclude the function by a choice that is under their control, rather than hard-coding something in PostgreSQL itself? --=20 Robert Haas EDB: http://www.enterprisedb.com