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 1w9zi7-001xxs-2s for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Apr 2026 06:14:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w9zi6-00Euoi-1C for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Apr 2026 06:14:50 +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.96) (envelope-from ) id 1w9zi5-00EuoZ-1y for pgsql-hackers@lists.postgresql.org; Tue, 07 Apr 2026 06:14:50 +0000 Received: from m16.mail.163.com ([117.135.210.4]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1w9zhz-00000000yzY-1jwv for pgsql-hackers@lists.postgresql.org; Tue, 07 Apr 2026 06:14:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version: Content-Type; bh=5ZupagaFBeX8YcYOsCJMP5ZSflqFL9gwJAcv65sjT5U=; b=DPAH/mItZDZPLRqk6mQYjY1Xo4hbpUtHDzSdVaUVp8dBczU7d7VjHiMRJuJNYv ZknFOm40jNtY/a0mvjKjEK/yIGRxbo+WEFje7XJzrlwgD9+xn7H3V78WK5/obpcY u1b2q0PVfZ8G0NCleT9r7x0brKvltfbDjCmL1jFJ06Ygg= Received: from andy-coding (unknown []) by gzga-smtp-mtada-g1-1 (Coremail) with SMTP id _____wCnVrWPoNRp9DlkDg--.2250S3; Tue, 07 Apr 2026 14:13:36 +0800 (CST) From: Andy Fan To: Haibo Yan Cc: Dmitry Dolgov <9erthalion6@gmail.com>, David Rowley , Peter Eisentraut , Amit Langote , Alvaro Herrera , jian he , Chapman Flack , pgsql-hackers@lists.postgresql.org Subject: Re: Extract numeric filed in JSONB more effectively In-Reply-To: <7487A577-7BDC-4B94-9FFA-741E95439BFC@gmail.com> (Haibo Yan's message of "Thu, 2 Apr 2026 21:46:22 -0700") 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> User-Agent: mu4e 1.14.0-pre2; emacs 30.2 Date: Tue, 07 Apr 2026 14:13:35 +0800 Message-ID: <873417fgc0.fsf@163.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wCnVrWPoNRp9DlkDg--.2250S3 X-Coremail-Antispam: 1Uf129KBjvJXoW7uF18Cr4fKw1fJr1DGFy3Arb_yoW8WF1kpr 43Gw13Cr18Jr1UAwnrXF18Jr15Wr95Jr17Jr1UJr18Kr15Ar1UJr18KFyrCa4UJry5Xr42 qr1jyry5Aa1jy3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UY_M-UUUUU= X-Originating-IP: [101.227.46.165] X-CM-SenderInfo: x2klx3xlid0iqsrtqiywtou0bp/xtbC-xLbL2nUoJL1VwAA30 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Haibo, > I=E2=80=99d like to continue pushing this patch forward. > Based on the earlier discussion, I reworked the patch into a smaller > stage-1 version with a narrower scope and a simpler rewrite > strategy. .. > and does not yet try to cover array/path extraction or integer/float > typed extractors. Thanks for working on this. I did a quick comparison between this version and my last patch v18 [1], here is the difference. My previous v18[1]: 542 insertions(+), 59 deletions(-) Your patch: 543 insertions(+), 5 deletions(-) However as what you have realized, your current patch still lack of many=20 optimizations, Not only the integer/float stuff, but also many functions, e.g. jsonb_array_element, jsonb_extract_path, jsonb_path_query and jsonb_path_query_first. After considering this, what patch will look like in your approach? I guess you can see many duplications. Less code doesn't always mean better, but I think this still be a key consideration to address/check.=20=20 > I also ran a small microbenchmark to isolate the cast-over-object-field p= ath. On my setup, the current patch shows the following gains: > Query Before After Spee= dup > -------------------------------------------------------------------------= ------- > SELECT sum((j->'n')::numeric) FROM t 118.028 ms 56.082 ms 2.10x > SELECT count(*) FROM t WHERE (j->'b')::bool 115.665 ms 51.945 ms 2.23x > -------------------------------------------------------------------------= ------- Thanks for running the test.=20 [1] https://www.postgresql.org/message-id/87ttk0lgcx.fsf%40163.com --=20 Best Regards Andy Fan