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 1wh6fH-0000U3-1S for pgsql-bugs@arkaria.postgresql.org; Tue, 07 Jul 2026 14:20:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wh6fF-000yVo-35 for pgsql-bugs@arkaria.postgresql.org; Tue, 07 Jul 2026 14:20:46 +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 1wh6fF-000yVg-2H for pgsql-bugs@lists.postgresql.org; Tue, 07 Jul 2026 14:20:46 +0000 Received: from mail-wr1-f53.google.com ([209.85.221.53]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wh6fD-000000002yD-2pUv for pgsql-bugs@postgresql.org; Tue, 07 Jul 2026 14:20:46 +0000 Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-4798bea72f9so2575608f8f.1 for ; Tue, 07 Jul 2026 07:20:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1783434043; cv=none; d=google.com; s=arc-20260327; b=HY2tKtJa1iPF+5/IdYVGDyp4Me7J67hwWf0wuNx2ONA28VItoTZysr8rdKE/A82bz8 2LhoLRrCnf14EQ9+PIYvpUS4i9c/bpPG5COBZXyIIY0WCCwpLG4fhF3W+Ny6QNInEGgl seWzYWKvCwPud8pF0BdoMWH/pybCaLuKBkCWiXRVBWXTHuDyNLE4/1fpuqHuWhKd/WPQ UX9EuPN36THoKzwEMCndqYa7KQJlrz36y+eAvWoNGzeCcAmH/cuvXSRUNiKpZCQj3k+J bV7fsaNzccp/gOdB8nd7i8R6BCzxQwD4iA5q6AkNqCYDCEUnIgFk6asi0KAE178LKza6 fnuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=DQMq35w6s3/LqJ4MjB/oqlWUMIBCO6z5Wthvl25dFnU=; fh=I3eq9JLue6E0avFHTsCcomGp3fA3Ma3e1aqZSlFoqdo=; b=PnFzuefY0XbaQg84XaHTfdxz0ECGqFsbjd6YRYvHtATJIAT/0I8h//4dskox73jyXP kikNf+9r9mPDPXxer44pnvVXiNJbcXFaPH8rqelmae40BHvzRZQzfiE8Oc5gzfkeBUmL heZ23mOH9NRNyDbNyoJDqPgZepV4Eyu0llUJFd4pFKT+mmUvFiIpgY3mIrZjayRrB1At 4c6C1uw4QWVDgfVF/Vo6iE1y2x2msvQGHTkG0mwcR8QxWvWYIAxtxZ3jHRLggqnkFNkl qbqXFVV4myvcUSe140x11TFdiAmiJqRW5cydBuUTW78WkRXxhqxL7kVtot1otFM5OoFz HOXQ==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783434043; x=1784038843; 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=DQMq35w6s3/LqJ4MjB/oqlWUMIBCO6z5Wthvl25dFnU=; b=NEyKeR7BtuQvCygzISbPIYVMByxVThVxLVTY+Rh2Q6+qgUEPz853CmhNNmJiroZwZh heh/21jp4Qjh0i8aPSYapTCeSM6DHMUR3lzGNy+fm0ZrIWFVN92j4sR53uiTX1Rqki2Q royZCvwy/CWTDROL4UUnc1LYLLnsL/0DAfpJF+t7GWEHSZph5/HKIE5B2Ey3+e42/B8o BQzazcTFBBIQTec+6KfqZdFIEJaYQuT4rmsH3B/96rV4ICfY6Xj3v81UOaUaP+pQqBaI Y3PXRR2NfsTIUlGcvwkw16QHSe2VAKuHVkyinss83MtDN9fDK8m3ogedBYQOPN/ydFd8 ehLg== X-Gm-Message-State: AOJu0YzsNp0DE3slW9Swjfb99NzJYOCiaw1vrcrhxA/N/CyeOaiOQAG6 gtCx30PgvndeqLuAmA2A9H1i2UWfL1EwkngrBo49P552BCjpmQzPNlDXK/rpHzR3yzYMcN5XwKr YChA6begoXlvpZSlZigx07fOkoJYAcmM= X-Gm-Gg: AfdE7cmnKd/eVkdWqZk8ZYUkfl2WEy4vBD4OQSqZUYeCI9pO/Nm/lXJyXVyPfxcOKzx PB6Bp2tgeBWhDgh69yXQMGhJKbrVDVU2qum84935EjH+vjPPyYQiMAhQ1rogMVJ+HwSUI3/iAjP J3golunBOjzfauIlMggLU0Qgojx8ts9iEIdHP7a7evtLelOiD1SCG8uIpq0bPV3XRovi57PwxXa y9aVzG7OcOb4HgO2Mw5lwuornrrQtTZJVMJ+ac3//uIvmMt786vrOFwfvkmVKepAFvVeasp X-Received: by 2002:a05:6000:4699:b0:46e:8f0e:2f02 with SMTP id ffacd0b85a97d-47de66c3d09mr4556493f8f.33.1783434042650; Tue, 07 Jul 2026 07:20:42 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Thom Brown Date: Tue, 7 Jul 2026 15:20:14 +0100 X-Gm-Features: AVVi8CfNn37o78xQ7U-PjuUinp7OkymazgySL8mVZ22MkB3IONvYw2On8lCPwlM Message-ID: Subject: Re: EXPLAIN (VERBOSE) fails with for JSON_ARRAYAGG/JSON_OBJECTAGG + window function To: Richard Guo Cc: pgsql-bugs 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 Tue, 7 Jul 2026 at 14:49, Thom Brown wrote: > > On Mon, 6 Jul 2026 at 03:17, Richard Guo wrote: > > > > On Fri, Jul 3, 2026 at 5:36=E2=80=AFPM Thom Brown wrot= e: > > > Thanks for taking a look at this. It's unfortunate that reconstructin= g > > > the syntax is problematic, because in the case of the original query > > > that tripped on this bug, I lose the following from my original query= : > > > ... > > > I guess the relevant information can be gleaned from this, but not fo= r > > > JSON_ARRAYAGG(i RETURNING text) because we get the same output whethe= r > > > we're returning text or json. > > > > Yeah, the v1 patch is lossy, and the lost information cannot be > > recovered from the plan at all. > > > > So I'm switching back to the resolve_special_varno() reconstruction I > > had tried and set aside. My earlier objection was that it makes the > > WindowAgg look like it computes a JSON aggregate when it only passes > > through a value computed below. But the lower node still prints > > jsonb_agg_strict(name), so the plan does show where the aggregate is > > computed, and I think that is a smaller cost than losing the > > information outright. Also, partial aggregation already deparses this > > way. The combining aggregate's argument is a Var referencing the > > partial aggregate's output, and get_agg_expr() resolves it back with > > resolve_special_varno() to reprint the aggregate at the finalizing > > node. > > > > I still don't want to hack the planner to keep the JsonConstructorExpr > > with its Aggref in make_window_input_target(), because I still think > > that that is too invasive and changes which node evaluates the > > wrapper. > > > > Hence, I end up with the attached v2 patch. > > I've tested it against the output from the 1st patch. > > Patch 1: > ((jsonb_agg_strict(e.emp_name ORDER BY e.emp_name))) > > Patch 2: > (JSON_ARRAYAGG(e.emp_name ORDER BY e.emp_name RETURNING jsonb)) > > 1: > ((jsonb_object_agg_strict(e.emp_name, e.salary))) > > 2: > (JSON_OBJECTAGG(e.emp_name : e.salary ABSENT ON NULL RETURNING jsonb)) > > With that last one, why is that colon there? Actually, I don't know what I was thinking. This is clearly a key:value pairing, so ignore that remark. But we do get more info with this line in the 2nd patch. So all looks good to me. Thanks Thom