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 1wAHcI-002EbD-2P for pgsql-hackers@arkaria.postgresql.org; Wed, 08 Apr 2026 01:22:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wAHcH-003fCw-0Q for pgsql-hackers@arkaria.postgresql.org; Wed, 08 Apr 2026 01:22:01 +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 1wAHcG-003fCo-2Q for pgsql-hackers@lists.postgresql.org; Wed, 08 Apr 2026 01:22:01 +0000 Received: from mail-yx1-xb136.google.com ([2607:f8b0:4864:20::b136]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wAHcE-00000001DSH-1R0t for pgsql-hackers@lists.postgresql.org; Wed, 08 Apr 2026 01:22:00 +0000 Received: by mail-yx1-xb136.google.com with SMTP id 956f58d0204a3-6501547d7edso5961143d50.0 for ; Tue, 07 Apr 2026 18:21:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1775611316; cv=none; d=google.com; s=arc-20240605; b=ZnGhHVWQ6qjncS5RTWn7YXZe13NWQRJIjhqtf/8WKJCgn/N8gVMY4/ynGimFhFtwUM GNUBc9D+ED+adNiJrt5He0Klz71oPsfkrTA2vUdd2uHfUg3C9ZqdF27nck2cmdF2aBVp rfjkwzmOAspsWKlu+w6hajEOP1AMdeZCbBzMUnqEPKTYjnpyveZZUwN8VbsPh3Do3hJd H4WUiCfteBCPCKD8pxLdWrRAHLMXh0dzxn/YfLHD2X0zzr5kvwSzrLWmF6R1IUaR6Qgn tOdkR1pYcDgdHdqyQRczj+9bRKSQwaC0YZiDd6iCv5G4Vucwpu/tvgLvU78ctu+1NHuP aUMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=q9Cm1HC3doOvu/fciC5dKtFtpCe2esKm2ZB7AKswIe0=; fh=9Im1Tyd5ng0xX9yn14gXlGLYkffgQFWwFEIL474xHuA=; b=fGXScbi4poC3Q2Q8MVICrEC0YO8eOZUItF39c6BvucdC0nbDLtWMSG+KVqicDtVLXe qqwbs/ucOZIQw+0ytERctRT8myyvpVjm0qV9dXPDRfqwxCEBnpEanI0So/eqow4XFKXl AQ9nFucWUzqsKrN2yTKu45k9dzD/m9vVOvaHv4AUnBGMA+12T7zcFqf6QwoVNHXc8e2d OBDXarWuyhgad+HtXjKv8H6l0WV8wAXGX5p0udDes9FAo7b/+u+d23w+6snw9aNuKECx a6bbh3Mlie6wBEJpQ/+h/J1CQSxWoS+5+l73cro/v9ttf2dbp570XAsZt1go3R1dk5Dh cONA==; darn=lists.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=1775611316; x=1776216116; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=q9Cm1HC3doOvu/fciC5dKtFtpCe2esKm2ZB7AKswIe0=; b=LdHA7ttm95dtnmIJLb+y9hTXHX6RQvSdBX4NbXNsVh1D+p9yVL7U2RTlMZHWfGXyhc ZhAqWFtez2+qz3WY2to+p7fVhZ4UV2Yvrg2hkiQC7PqaE4NXTpOjGz4MSjethn3XVVoM BOvxWxH6z9BToBU5f9eFmQ06VfsprM8+ZS5+8qQSPtxc/e1qMBStwbZWpNnNZdSMBg+d Z1QeXpeSd6ooGj1Z0cx0jkp4zmAGa50i0vr6ohlhcPO7HXWanXnB55aaEyV220QF1Hvt L41UX4Qg8OXqlgYSBy2gjkbA8RJGl/gJaWwij8wCF0t0blW9eyiJfuYS7RPsvjHM9QQj Dgyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775611316; x=1776216116; h=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=q9Cm1HC3doOvu/fciC5dKtFtpCe2esKm2ZB7AKswIe0=; b=LaPggROgpOAnBYSrwcOnwQXAOTIoUtK0oQx5g7PpdIRexEUAlTCnfLRDWamh6iTO0a R+XLJViuO0JQWN33ORn1aAOeL3AnJpTLKUQT7Q0RYYzBuSnFSDVPLKLPr+dwbSFDkTv7 TWh6R63gxT/DvuvS3QKZbL8nNUpdAwZHwE3ibI6gtwx0txpfq2AaShw29PCtj55zy7Av RxMxR1Yxoh/bgsVCVwfg/l7fGvcvRL/WYeP35/m6lI3xgtWr7mG8CvzoDJVRgxUZPx07 1bwjD2wiqho70D/hmDa5BdNlC5Hk7esxeS6BxvQFZV3jAZpUhlau5Y6e/zOwui5M1bOz rr1A== X-Forwarded-Encrypted: i=1; AJvYcCW0jA38+LQV+CX6S+EL5ph4teiBM6oxH7OhXiBZ4rgWkeFkHb3ac69nslKp+Nt31QbKdy3HmeJ1ANp3W8qT@lists.postgresql.org X-Gm-Message-State: AOJu0YwXk6aE0jhmlKMf7EI4nGWoUXYxCDO3rRUO/x0YXkTvpWcCmx5G UhaoZSnJOop68kKqnc0Vpn14zEdGiUuR/qdspNJCCo0u9V+qMiyuMmMjE6AaNp59Momuae41Z2e Q7ErplpqK+R3Ml4l/s5SnQ/ktQyVwHIQ= X-Gm-Gg: AeBDieteWwaaEyVXVwjWIsKdV05yDRB4zU7fIKuqyFpe13mb0Jh7wV58s4Zk0uG6to9 OLrjcImF72ZQ1SFkFISoYCYjAzDmxiUOp1Sn/eoZISD2h9XU6ldLspFm7M1LMd1S7ZDlWBtGoK/ CVp+1euILaZ2VF2xVTP0Mdz8QrWd3x9bKKgEhs4g2qt5EvlIZY8Z31EuQZRtTLHXV/NUBcMAs3s wPIvmaEzH8Dmj+olKCmx2larLlldP4tQvtZOIBGwmJAChG+hE+rY4nToOzAAb8a8sAnZLHeFRoI Ey7EW55Im2rK2/H27XyrBvxbn1zKoYRcOUMAxlo= X-Received: by 2002:a05:690e:4849:b0:650:3064:4d19 with SMTP id 956f58d0204a3-650486bf384mr14596354d50.6.1775611316569; Tue, 07 Apr 2026 18:21:56 -0700 (PDT) MIME-Version: 1.0 References: <87r0hmvuvr.fsf@163.com> <8102ff5b-b156-409e-a48f-e53e63a39b36@eisentraut.org> <8734t6c5rh.fsf@163.com> <87o7bn7z56.fsf@163.com> <875xx197bp.fsf@163.com> <87ttk0lgcx.fsf@163.com> <8734m5fua1.fsf@163.com> <87a5dx4cfb.fsf@163.com> <7487A577-7BDC-4B94-9FFA-741E95439BFC@gmail.com> <873417fgc0.fsf@163.com> <87eckqz5i9.fsf@163.com> In-Reply-To: <87eckqz5i9.fsf@163.com> From: Haibo Yan Date: Tue, 7 Apr 2026 18:21:45 -0700 X-Gm-Features: AQROBzAEKHtpu8D_huqtDpzzRa08pIGNz6iVKv2yECJPgPdiQrqLv8THJEcymNk Message-ID: Subject: Re: Extract numeric filed in JSONB more effectively To: Andy Fan Cc: Dmitry Dolgov <9erthalion6@gmail.com>, David Rowley , Peter Eisentraut , Amit Langote , Alvaro Herrera , jian he , Chapman Flack , pgsql-hackers@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000c88b2e064ee8b9f7" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000c88b2e064ee8b9f7 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Apr 7, 2026 at 5:00=E2=80=AFPM Andy Fan wro= te: > Haibo Yan writes: > > Hi Haibo, > > > I agree that if this approach is extended to the full matrix naively, > > duplication will become a real issue. > > Could you summary how it would be? I think it would be helpful for > others to review. Otherwise every reviewer needs to count them many > times. > > -- > Best Regards > Andy Fan > Hi Andy, Sure. My current thought is to extend it in stages, rather than trying to solve the full matrix in a single patch. A rough plan would be: 1. Keep the current stage-1 patch small and validate the basic approach first - jsonb_object_field / -> / equivalent subscripting form - casts to numeric and bool - support-function rewrite directly to explicit typed extractor functions 2. Extend target types before extending extractor families - add int4 / int8 / float8 for the same object-field family first - keep the SQL-visible rewrite targets explicit, e.g. - jsonb_object_field_int4 - jsonb_object_field_int8 - jsonb_object_field_float8 - avoid the previous numeric-intermediate rewrite shape 3. Then extend to other extractor families with the same overall pattern - likely starting with jsonb_array_element and jsonb_extract_path - and possibly jsonb_path_query_first later - each family would still rewrite to explicit typed extractor entry points, e.g. - jsonb_array_element_numeric - jsonb_extract_path_bool - jsonb_path_query_first_int4 4. Keep duplication manageable by sharing the implementation underneath - keep the SQL/catalog-level rewrite targets explicit for readability and reviewability - but factor the C implementation into: - extractor-family lookup helpers - target-type conversion helpers - thin wrappers, possibly generated with small macros So the idea would be: explicit rewrite targets at the SQL/catalog level, but shared lookup/conversion code underneath, instead of going back to the earlier start/finish/internal pipeline. I agree that if this is extended naively across the full matrix, duplication will become a real issue. My reason for keeping the current patch narrow is that I wanted to first validate this simpler rewrite shape on a small subset before deciding how best to scale it further. Regards, Haibo --000000000000c88b2e064ee8b9f7 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Tue, Apr 7, 2026 at 5:00=E2=80=AFPM An= dy Fan <zhihuifan1213@163.com> wrote:
Haibo Yan <tristan.yim@gmail.com> writ= es:

Hi Haibo,

> I agree that if this approach is extended to the full matrix naively,<= br> > duplication will become a real issue.

Could you summary how it would be? I think it would be helpful for
others to review.=C2=A0 Otherwise every reviewer needs to count them many times.

--
Best Regards
Andy Fan
Hi Andy,
Sure.

My current thought is to extend it in stages, rather = than trying to solve the full matrix in a single patch.

A rough plan would be:

1. Keep the curre= nt stage-1 patch small and validate the basic approach first

  • jsonb_object_field / = -> / equivalent subscripting form

  • casts to numeric and = bool

  • support-function rewrite directly to explicit typed e= xtractor functions

2. Extend target types before extending ext= ractor families

  • add int4 / int8 / float8 for the= same object-field family first

  • keep the SQL-visible rewrite targets explicit, e.g.

    • jsonb_object_field_int4

    • jsonb_object_field_int8

    • jsonb_object_field_float8

  • avoid the previous numeric-intermediate rewrite shape=

  • 3. Then extend to other extractor families with the same over= all pattern

      likely starting with = jsonb_array_element and jsonb_extract_path<= /p>

    • and possibly jsonb_pa= th_query_first later

    • each family would still rewrite to explicit typed ext= ractor entry points, e.g.

      • jsonb_array_element_numeric

      • jsonb_extract_path_bool

      • jsonb_path_query_first_int4

    4. Keep duplication manageable by sharing the implementati= on underneath

      =
    • keep the SQL/catalog-level rewrite targets explicit f= or readability and reviewability

    • but factor the C implementation into:

      • extractor-family lookup helpers

      • target-type conversion helpers

      • thin wrappers, possibly generated with small macros

    So the idea would be: explicit rewrite targets at the= SQL/catalog level, but shared lookup/conversion code underneath, instead o= f going back to the earlier start/finish/internal pipeline.

    I agree that if this is extended naively across the f= ull matrix, duplication will become a real issue. My reason for keeping the= current patch narrow is that I wanted to first validate this simpler rewri= te shape on a small subset before deciding how best to scale it further.

    Regards,

    Haibo


    --000000000000c88b2e064ee8b9f7--