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 1qWjdq-004Cf3-U2 for pgsql-hackers@arkaria.postgresql.org; Thu, 17 Aug 2023 20:30:51 +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 1qWjdp-004HuU-50 for pgsql-hackers@arkaria.postgresql.org; Thu, 17 Aug 2023 20:30:49 +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 1qWjdo-004HuM-Oq for pgsql-hackers@lists.postgresql.org; Thu, 17 Aug 2023 20:30:48 +0000 Received: from anastigmatix.net ([68.171.216.17]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qWjdl-000j4p-Lg for pgsql-hackers@postgresql.org; Thu, 17 Aug 2023 20:30:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=anastigmatix.net; s=default; h=Content-Transfer-Encoding:Content-Type: Message-ID:References:In-Reply-To:Subject:Cc:To:From:Date:MIME-Version:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=iBTVO1qaq19Y1zKgv610DVwYbpPNPgyz61zQ1k8P2jg=; b=JYiVFPhNlJ0F/TnuG2ZJuDN3xb AMjjH1eyu9c0xryTMds/3bq8B363IcKbCNxB4tcpknaLjrXIgzG40OR6yQGtHCpz4rhusBASwUZDd sbBLAMxHeJczclnXLjgzjdxPK83S2qlKt5SlyiunKiUh/mtgyjmHcrNY/W3ECmGlFRsxPgTLi6tFB e4U+uk7gwikDsH+vuX9cT53wqdXdEobjzBcQpl6kwTEVVHoKbCW13k4MRtr+2EShSqoc+w9XGlqAd tdu7u9uDmoS8O/dImqG7ZS3dbC5qxOwAhZYh+PxDoCBviO0rI0nZnPBzr5mq/B8xcETKd1gAIzUa6 4Epp/Cow==; Received: from [::1] (port=34268 helo=adam.ace-host.net) by adam.ace-host.net with esmtpa (Exim 4.96) (envelope-from ) id 1qWjdi-003mLK-1v; Thu, 17 Aug 2023 16:30:42 -0400 MIME-Version: 1.0 Date: Thu, 17 Aug 2023 16:30:41 -0400 From: Chapman Flack To: Andy Fan Cc: jian he , Pavel Stehule , Tom Lane , pgsql-hackers Subject: Re: Extract numeric filed in JSONB more effectively In-Reply-To: References: <3507485.1691090027@sss.pgh.pa.us> <900892914fdc3f477b101d699efb40e0@anastigmatix.net> <903341.1692022214@sss.pgh.pa.us> User-Agent: Roundcube Webmail/1.6.0 Message-ID: <4b97f1a1dd9b6e45443d24870d3be698@anastigmatix.net> X-Sender: chap@anastigmatix.net Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - adam.ace-host.net X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - anastigmatix.net X-Get-Message-Sender-Via: adam.ace-host.net: authenticated_id: chap@anastigmatix.net X-Authenticated-Sender: adam.ace-host.net: chap@anastigmatix.net X-Source: X-Source-Args: X-Source-Dir: X-From-Rewrite: unmodified, already matched List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2023-08-17 05:07, Andy Fan wrote: > Thanks for the review, v9 attached! From the earliest iterations of this patch, I seem to recall a couple of designs being considered: In one, the type-specific cast function would only be internally usable, would take a type oid as an extra parameter (supplied in the SupportRequestSimplify rewriting), and would have to be declared with some nonspecific return type; 'internal' was mentioned. The idea of an 'internal' return type with no 'internal' parameter was quickly and rightly shot down. But it would have seemed to me enough to address that objection by using 'internal' also in its parameter list. I could imagine a function declared with two 'internal' parameters, one understood to be a JsonbValue and one understood to be a type oid, and an 'internal' result, treated in the rewritten expression tree as binary-coercible to the desired result. Admittedly, I have not tried to implement that myself to see what unexpected roadblocks might exist on that path. Perhaps there are parts of that rewriting that no existing node type can represent? Someone more familiar with those corners of PostgreSQL may immediately see other difficulties I do not. But I have the sense that that approach was abandoned early, in favor of the current approach using user-visible polymorphic types, and supplying typed dummy constants for use in the resolution of those types, with a new function introduced to create said dummy constants, including allocation and input conversion in the case of numeric, just so said dummy constants can be passed into functions that have no use for them other than to call get_fn_expr_argtype to recover the type oid, which was the only thing needed in the first place. Compared to the initial direction I thought this was going, none of that strikes me as better. Nothing makes my opinion authoritative here, and there may indeed be reasons it is better, known to others more familiar with that code than I am. But it bugs me. If the obstacles to the earlier approach came down to needing a new type of expression node, something like "assertion of 'internal'-to-foo binary coercibility, vouched by a prosupport function", would that be a bad thing? Regards, -Chap