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 1qX6cY-00599d-Qm for pgsql-hackers@arkaria.postgresql.org; Fri, 18 Aug 2023 21:03:02 +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 1qX6cW-00Daek-Gm for pgsql-hackers@arkaria.postgresql.org; Fri, 18 Aug 2023 21:03:00 +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 1qX6cW-00Daec-6R for pgsql-hackers@lists.postgresql.org; Fri, 18 Aug 2023 21:03:00 +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 1qX6cR-000vJZ-Lz for pgsql-hackers@postgresql.org; Fri, 18 Aug 2023 21:02:59 +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=3jqxjJ43cLNumOXKXjm/Q+vlI2aHG0fg6iB7iSskTeQ=; b=AgX5reXBtYXI1A/9UXdpOjKkUp emzuPQ2i6s4SnDjnXr00G4Xjf8UJ0JPUYrJPT5R4eEnoAFpgqDUIwfOKEVuUxTBe2KpYJJAe/pEzM diInTwTqSlHbaP9Jj8ZzWbuaBSqaQLlUUb6EuMCucDyZE9gLRZdgXMxKcs5mQmXC8b7mgsWzepwyl 6kTbEpvKZNQYLGcnYeUck8En4UqlIwfCimY+YbxWHT9fo5KmBnO+ohc9L1MuTjk1AjVLcATa6KDlF 4kUYRwqAJuUah/s/xBRjAW5Ptq55q1hocmgwp2mgrZkx1LvjZAWZkMhqyzvRKAX//KBUUQW7CbcCk GoTcqKLw==; Received: from [::1] (port=45556 helo=adam.ace-host.net) by adam.ace-host.net with esmtpa (Exim 4.96) (envelope-from ) id 1qX6cN-002LAz-3C; Fri, 18 Aug 2023 17:02:52 -0400 MIME-Version: 1.0 Date: Fri, 18 Aug 2023 17:02:52 -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> <4b97f1a1dd9b6e45443d24870d3be698@anastigmatix.net> <111272f2dc112c7becdd35ad89f6b935@anastigmatix.net> User-Agent: Roundcube Webmail/1.6.0 Message-ID: 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-18 15:08, Chapman Flack wrote: > But I don't know that adding relabel nodes wouldn't still be > the civilized thing to do. Interestingly, when I relabel both places, like this: Oid targetOid = fexpr->funcresulttype; Const *target = makeConst( OIDOID, -1, InvalidOid, sizeof(Oid), ObjectIdGetDatum(targetOid), false, true); RelabelType *rTarget = makeRelabelType((Expr *)target, INTERNALOID, -1, InvalidOid, COERCE_IMPLICIT_CAST); fexpr->funcid = new_func_id; fexpr->args = opexpr->args; fexpr->args = list_insert_nth(fexpr->args, 0, rTarget); expr = (Expr *)makeRelabelType((Expr *)fexpr, targetOid, -1, InvalidOid, COERCE_IMPLICIT_CAST); } PG_RETURN_POINTER(expr); EXPLAIN looks like this: Seq Scan on pg_temp.test_jsonb Output: jsonb_array_element_type(('23'::oid)::internal, test_json, 0), (test_json -> 0) Filter: (test_jsonb.json_type = 'scalarint'::text) With COERCE_IMPLICIT_CAST both places, the relabeling of the function result is invisible, but the relabeling of the argument is visible. With the second one changed to COERCE_EXPLICIT_CAST: Seq Scan on pg_temp.test_jsonb Output: (jsonb_array_element_type(('23'::oid)::internal, test_json, 0))::integer, (test_json -> 0) Filter: (test_jsonb.json_type = 'scalarint'::text) then both relabelings are visible. I'm not sure whether one way is better than the other, or whether it is even important to add the relabel nodes at all, as nothing raises an error without them. As a matter of taste, it seems like a good idea though. Regards, -Chap