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 1vFuma-003OxA-8c for pgsql-hackers@arkaria.postgresql.org; Mon, 03 Nov 2025 13:39:39 +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 1vFumX-003kPk-Vo for pgsql-hackers@arkaria.postgresql.org; Mon, 03 Nov 2025 13:39:37 +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.94.2) (envelope-from ) id 1vFumX-003kPc-MC for pgsql-hackers@lists.postgresql.org; Mon, 03 Nov 2025 13:39:36 +0000 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vFumT-005kfh-2z for pgsql-hackers@lists.postgresql.org; Mon, 03 Nov 2025 13:39:36 +0000 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-294fc62d7f4so39897335ad.2 for ; Mon, 03 Nov 2025 05:39:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762177171; x=1762781971; darn=lists.postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=b+d5jcYULcL1X+5hwG10XcTGbVZ8lVDr5jiH/8FlSrk=; b=aD+SCQ0UdjMLhSyUdoyZZC/f4wRGe9yf/qJAhD0OJeyoBBCOH2KJRK0NIoPEhnSUeX cpLrNzjyQD8IsRGxqGv09Er1aR2laqgUrObR7zkIuf8QcewK9ownY4SYK0KxQsk+o+Lw Ahizd2oOVcIi12yCvVotFfBCkpl5clAfuXPiAEinmqipbuw177UMZ5tRhuVHaYC+y+Jt p9eMZw2ZuFFfagqbmXMx1HQLnvS2ovxhjDQs9ZZSquurcHi7Ku4ubACoA+ZVKt9isxjZ 4Hjg48Na58xwGwoYlK1clGDpi5JHqRe39jZj3xgdkPb/YPYOhjjePfFWceeOs9BLna0y uGzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762177171; x=1762781971; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=b+d5jcYULcL1X+5hwG10XcTGbVZ8lVDr5jiH/8FlSrk=; b=LLFoJ0iiR2M+HMPkveL3xIDKGPFV/JWHI2mOQovjWWon4XS++1XmLHUnVb9nqYzSBg 6P0dingNbRAGLgWOjwxWRJteToGp6exQPhk2hnN0A3k3BetKF9z/htKMCJcD42aMduZ1 RWoRHjh5UG8V2J1RaI8MS3x7ZM6mWXh1bLtEu9Nm6U+8bKewI/AFWfufeVTj2gd+81NY mtX2NXS9w+h7kPgqprQ0wtZe5IaIxQz/u+Di5b/qC02nukZJP0lbd/AX+1ozbAEfabA3 ZKh65imn6qz70oKnvb3+tQrEkNr3smCBuW88/u9FUdyUMvDTfLwJt1XmkIquo6vlwHK5 m8+g== X-Forwarded-Encrypted: i=1; AJvYcCVBP8wCY6ev3fHD7ATLfc6OqvZnnrOkzE43/EEHFUY2OOAxvE9UDF6GjYle1JCEpSqGlfsxLK0JR3W+PX5m@lists.postgresql.org X-Gm-Message-State: AOJu0YzjSXnMuXI7GUJ0Q3uHaQVt7TGP7lLTcfBI5cb785kdhMdw129S sBc0Ja316/FioBBl4EYziyQdN41pNDSByttQOz8mkXlhgtWj4wF9ZucB X-Gm-Gg: ASbGncv/W9DUce9zcrYz/fhPwla7jYtVH+X2LqEMnAR0Lu5MVjw3gHPsUwNYItHJLui isONyC673GJuEc7MYSnSfU0MPXUPYcxTezNi3kkgo5tl9HP2b4CgDmYGW5vurkZ7hVXl8krc8if wpFbFD4uv/OSi7HcAlyv3bGiBjHZ+lOoUSGy1TMb/4vHkZKsjNMt/P3mJwnKgPhn69hEi84IDRD PjrG1fPjJpT2xmdlaYUD43sRcTu3tCykFjdcB2utBynwGQdputze3iu2Wd0CkkoDEMKo/3nZpzk luWL7G9sGqDpabgS79hr+YrrOTvEwNAmA+Vmb9irW8pCJQh3s27PKTOyGqk9eaZD1UO1a0cNuzZ LA74DvC13WaB98qf6sDuFHbcjlTdxjnPdHUXKGbBBUqVgDzfML/oM1h4EcJfl9VVIg7M8IT476G v/VR7vl+vb57frL6WTm+B3Jw== X-Google-Smtp-Source: AGHT+IHRIRboEJrNFuvZUSz5tDHXqyNuDbn2Un1phlMiEgzJng6ttkzuVH9w0A6y662o/Ddqyh0ahw== X-Received: by 2002:a17:902:f68b:b0:274:3db8:e755 with SMTP id d9443c01a7336-2951a4936a6mr162137335ad.30.1762177171141; Mon, 03 Nov 2025 05:39:31 -0800 (PST) Received: from smtpclient.apple ([170.178.170.211]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-295688c68f0sm76275395ad.41.2025.11.03.05.39.29 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Nov 2025 05:39:30 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81\)) Subject: Re: Making jsonb_agg() faster From: Chao Li In-Reply-To: <163563.1762117009@sss.pgh.pa.us> Date: Mon, 3 Nov 2025 21:38:46 +0800 Cc: jian he , pgsql-hackers@lists.postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: References: <1060917.1753202222@sss.pgh.pa.us> <617666.1755277022@sss.pgh.pa.us> <654628.1755297629@sss.pgh.pa.us> <2129790.1755889894@sss.pgh.pa.us> <68A1061C-81A5-46AA-AFA9-48294908254C@gmail.com> <2613D418-67E0-4DD8-BDA6-AB1BB04DB1A2@gmail.com> <2466173.1756498180@sss.pgh.pa.us> <163563.1762117009@sss.pgh.pa.us> To: Tom Lane X-Mailer: Apple Mail (2.3826.700.81) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Nov 3, 2025, at 04:56, Tom Lane wrote: >=20 > PFA v3, rebased over 8a27d418f, no substantive changes whatever. >=20 > regards, tom lane >=20 I am on vacation this week, I only find a hour in the evening and did an = eyeball review without actually tracing and testing this patch set. = Overall, the changes are solid and look good to me. Only a few small = comments on 0001: 1 - jsonpath_exec.c ``` @@ -2874,8 +2874,7 @@ executeKeyValueMethod(JsonPathExecContext *cxt, = JsonPathItem *jsp, { JsonBaseObjectInfo baseObject; JsonbValue obj; - JsonbParseState *ps; - JsonbValue *keyval; + JsonbInState ps; Jsonb *jsonb; =20 if (tok !=3D WJB_KEY) @@ -2889,7 +2888,8 @@ executeKeyValueMethod(JsonPathExecContext *cxt, = JsonPathItem *jsp, tok =3D JsonbIteratorNext(&it, &val, true); Assert(tok =3D=3D WJB_VALUE); =20 - ps =3D NULL; + memset(&ps, 0, sizeof(ps)); + ``` In elsewhere of the patch, you all use =E2=80=9CJsonbInState ps =3D = {0}=E2=80=9D to do the initialization, only this place uses memset(). = Can we keep consistent and use {0} here also. I see there is a = =E2=80=9Ccontinue=E2=80=9D and a =E2=80=9Cbreak=E2=80=9D before the = memset(), maybe you want to avoid unnecessary initialization. I guess = that is a tiny saving, but if you think that saving is worthwhile, I=E2=80= =99m fine with keeping the current code. 2 - jsonb_util.c ``` + case TIMETZOID: + /* pass-by-reference */ + oldcontext =3D = MemoryContextSwitchTo(outcontext); + v->val.datetime.value =3D = datumCopy(v->val.datetime.value, + = false, 12); ``` Instead of hard-coding 12, can we use "sizeof(TimeTzADT)=E2=80=9D for = better readability? 3 - jsonb_plperl.c ``` + { + /* XXX Ugly hack */ + jsonb_state->result =3D palloc(sizeof(JsonbValue)); + memcpy(jsonb_state->result, &out, sizeof(JsonbValue)); + } ``` And ``` + else + { + /* XXX Ugly hack */ + jsonb_state->result =3D out; + } ``` You left two =E2=80=9Cugly hack=E2=80=9D comments. Maybe add a short = description for why they are hack and what can be improved in the = future. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/