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 1uwBsi-007BYs-0v for pgsql-hackers@arkaria.postgresql.org; Wed, 10 Sep 2025 03:52:29 +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 1uwBsf-00GTUN-W2 for pgsql-hackers@arkaria.postgresql.org; Wed, 10 Sep 2025 03:52:26 +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 1uwBsf-00GTUF-C4 for pgsql-hackers@lists.postgresql.org; Wed, 10 Sep 2025 03:52:25 +0000 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uwBsd-001ad4-1w for pgsql-hackers@postgresql.org; Wed, 10 Sep 2025 03:52:24 +0000 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-77251d7cca6so5356706b3a.3 for ; Tue, 09 Sep 2025 20:52:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1757476342; x=1758081142; darn=postgresql.org; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=z84KniRSP89qnZj16YEaRtCvl25zC5nS7K6Y3gbRS8Y=; b=crtZwr0RgTutd7WRif1fjYiOrn0plkJfC4+vjD84sQYGQXAO5tiNFeGuy3p+KsQYkZ CLPhK2XjmLxLbIK4A9AQzoE0KE7zD1gjBiNHZ5JPN5g6egORHkXZJFRAGQPDIxTOhsyc qoPNKYwisS9hcRGfKzNRiuIIqK2mOeIV+EkuIzmorLdpUCoJaupqIwmXqXmk4q0MK9tP IIhKNCjUkQm0sdg24yD0lbww7SJZbK8FnoRH16B2G+QLxs1P8CPwwZ2ePkp2yTqBNojs GFEyVA/PZ8SqiDL2o5xdGzk6X7DT/KeG4zFNO/A9BYB0mhZh/gws31aHNWT7WZGgfZHI 2mNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757476342; x=1758081142; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=z84KniRSP89qnZj16YEaRtCvl25zC5nS7K6Y3gbRS8Y=; b=ZqRawelEcN4UE8rJjwfwetUmKAwBDZ2dF9ifAyOcXPuOX/8SzTGXxwJbTi1wvLYR+E 7p36LfZM/zIKVkD0Ka0lrTAW/lA1q+f3Kus4qDvADRwxf3iOtdObcaTyokB6yhvBWjlu IErMsnDcGAWpmvA6qg+ZSS0vfAzgDVqBBH+buPskW1tNk+xQHoDd5cnDnJBBvUw1J3O/ zFYc/ps7icc9wdegcC3+wqOxAzMjYF8KwiQDqbLUI2wo1s2oEn1+diL+kBc+bJCiYyAq NnwvbzGnlCkt7b0PXWgbSiQIVnJ2SQ1ClK0oxf/h/+2sqXXRy4ulQgc71w2lOOtKppDX d2oQ== X-Forwarded-Encrypted: i=1; AJvYcCUnIucRpkWSZX660iqyYAOIl25P5ZAb4UOCqpwFQGKASKglAPzbFeSYW+ctVX5KszMAqXFCMHV5Ex0dJnlv@postgresql.org X-Gm-Message-State: AOJu0YyJGIR/5sRPm/5Y1FxPFRNSYxJsmWhz2oD7mwc7tktFI8TbHHIl Iu2pjohHr7YHfdOnzevdW4UAfBzlmoQSMZ7gC4QqY+d8sTyBmFsWBdtT X-Gm-Gg: ASbGncunv3dSEqI1NVuGEGdBqzN5WG3SxHi5ivRDYSXWkbus3WPhwrGYAD/sYU2vNAk UfYGb+yKC2SdZJ1vTgQBLMIsSrMZ+1kYKpS2J/7wtxqDHebX8NMcQvFxaNM3q6VJMet/QnKgulp EK4xx++UNrHTaeDuddEeJAwJ5oSRkz0wgYRRPOTFa1wwfmDqwO5Tk5U3199uBhjPGN6UjLwMRs2 eBGLoheoLNloNqY51lwR1yJbzijfQ8lARa3/sOU9l1eQFQZbNTzrlF0J1NFBKzlveXnbuY1zXxX /6evSlbhXBZ/kSk3sAQm0THV2p0dd3zZ90uLN714phG9AL+aCcnuinKjHr/Z10/Gdj1hG17A/BM 3ano/BXWlxV40o57CQKcCTSnGviFkVBID X-Google-Smtp-Source: AGHT+IER4KupW3JQMtdDIuhWcZPkOyRltwK9uCcjFf6ZXWPmVdFLCrlU/BasmfEMty1QM0DAx8MX+Q== X-Received: by 2002:a05:6a00:181d:b0:772:5352:eb4a with SMTP id d2e1a72fcca58-7742ddf2069mr17200046b3a.21.1757476342386; Tue, 09 Sep 2025 20:52:22 -0700 (PDT) Received: from smtpclient.apple ([142.171.105.12]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-774662fea7fsm3504988b3a.103.2025.09.09.20.52.18 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Sep 2025 20:52:21 -0700 (PDT) From: Chao Li Message-Id: Content-Type: multipart/alternative; boundary="Apple-Mail=_DB8E0C5E-8D69-44D5-999A-89EF77ECBEA8" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81\)) Subject: Re: SQL:2023 JSON simplified accessor support Date: Wed, 10 Sep 2025 11:52:05 +0800 In-Reply-To: Cc: jian he , Nikita Malakhov , Vik Fearing , Mark Dilger , Matheus Alcantara , Peter Eisentraut , Andrew Dunstan , Nikita Glukhov , PostgreSQL Hackers , "David E. Wheeler" To: Alexandra Wang References: <21fa36b4-6d56-4556-b524-9e3955b922c8@eisentraut.org> <290418A2-3A9B-4304-AAAD-4A40CFF1CB93@gmail.com> <98C6F445-773B-4C82-8198-7F5CD56D5252@gmail.com> <0D687585-0C6D-4B6E-B0B7-BDE084699CF3@gmail.com> X-Mailer: Apple Mail (2.3826.700.81) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_DB8E0C5E-8D69-44D5-999A-89EF77ECBEA8 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > = A few more comment for v16. 1 - 0002 ``` --- a/contrib/hstore/hstore_subs.c +++ b/contrib/hstore/hstore_subs.c - if (isSlice || list_length(*indirection) !=3D 1) + if (ai->is_slice || list_length(*indirection) !=3D 1) ``` We should put list_length() check before ai->is_slace. Because when = indirection length is greater than 1, it take a single check; other it = may need to check the both conditions. 2 - 0002 - also in hstore_subs.c=20 ``` *indirection =3D NIL; ``` We should do =E2=80=9Clist_delete_first_n(indirection, 1)=E2=80=9D. 3 - 0003 ``` +Datum +jsonPathFromParseResult(JsonPathParseResult *jsonpath, int = estimated_len, + struct Node *escontext) +{ ``` `jsonpath` is not changed in this function, so it should be defined as a = const: =E2=80=9Cconst JsonPathParseResult *jsonpath=E2=80=9D.=20 4 - 0004 ``` + Oid targets[2] =3D {INT4OID, = TEXTOID}; + + /* + * Jsonb can handle multiple subscript types, but cases = when a + * subscript could be coerced to multiple target types = must be + * avoided, similar to overloaded functions. It could be = possibly + * extend with jsonpath in the future. + */ + for (int i =3D 0; i < 2; i++) ``` This is a nit optimization. We can do: Oid targets[] =3D {INT4OID, TEXTOID}; For (int I =3D 0; I < sizeof(targets) / sizeof(targets[0]); I ++)=20 This way lets the compiler to decide length of =E2=80=9Ctargets=E2=80=9D. = So that avoids hard code =E2=80=9C2=E2=80=9D in =E2=80=9Cfor=E2=80=9D. = If we need to add more elements to =E2=80=9Ctargets=E2=80=9D, we can = just add it without updating =E2=80=9Cfor=E2=80=9D. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/ --Apple-Mail=_DB8E0C5E-8D69-44D5-999A-89EF77ECBEA8 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

<v16-0007-Implement-jsonb-wildcard-member-access= or.patch><v16-0001-Allow-transformation-of-only-a-sublist= -of-subscr.patch><v16-0004-Extract-coerce_jsonpath_subscript.patc= h><v16-0006-Implement-Jsonb-subscripting-with-slic= ing.patch><v16-0005-Implement-read-only-dot-notation-for-j= sonb.patch><v16-0003-Export-jsonPathFromParseResult.patch&g= t;<v16-0002-Allow-Generic-Type-Subscripting-to-Acc= ept-Dot-No.patch>

A few = more comment for v16.

1 - = 0002
```
--- = a/contrib/hstore/hstore_subs.c
+++ = b/contrib/hstore/hstore_subs.c

- if = (isSlice || list_length(*indirection) !=3D 1)
+ if = (ai->is_slice || list_length(*indirection) !=3D = 1)
```

We should put = list_length() check before ai->is_slace. Because when indirection = length is greater than 1, it take a single check; other it may need to = check the both conditions.

2 - 0002 - also in = hstore_subs.c 
```
   *indirection =3D = NIL;
```

We should do = =E2=80=9Clist_delete_first_n(indirection, = 1)=E2=80=9D.

3 - = 0003
```
+Datum
+jsonPathFromParseResul= t(JsonPathParseResult *jsonpath, int estimated_len,
+ = struct Node = *escontext)
+{
```

`jso= npath` is not changed in this function, so it should be defined as a = const: =E2=80=9Cconst JsonPathParseResult = *jsonpath=E2=80=9D. 

4 - = 0004
```
+ Oid = targets[2] =3D {INT4OID, TEXTOID};
+
+ = /*
+ * Jsonb can handle = multiple subscript types, but cases when a
+ = * subscript could be coerced to multiple target types must = be
+ = * avoided, similar to overloaded functions. It could be = possibly
+ * extend with jsonpath = in the future.
+ */
+ = for (int i =3D 0; i < 2; = i++)
```

This is a nit = optimization. We can do:

Oid targets[] =3D = {INT4OID, TEXTOID};
For (int I =3D 0; I < sizeof(targets) / = sizeof(targets[0]); I ++) 

This way lets = the compiler to decide length of =E2=80=9Ctargets=E2=80=9D. So that = avoids hard code =E2=80=9C2=E2=80=9D in =E2=80=9Cfor=E2=80=9D. If we = need to add more elements to =E2=80=9Ctargets=E2=80=9D, we can just add = it without updating =E2=80=9Cfor=E2=80=9D.

Best = regards,
--
Chao Li (Evan)
HighGo Software = Co., Ltd.
https://www.highgo.com/




= --Apple-Mail=_DB8E0C5E-8D69-44D5-999A-89EF77ECBEA8--