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 1qRXXY-0027b8-L4 for pgsql-hackers@arkaria.postgresql.org; Thu, 03 Aug 2023 12:34:53 +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 1qRXXW-00DC76-UT for pgsql-hackers@arkaria.postgresql.org; Thu, 03 Aug 2023 12:34:51 +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 1qRXXW-00DC6y-JS for pgsql-hackers@lists.postgresql.org; Thu, 03 Aug 2023 12:34:51 +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 1qRXXU-000Kb5-Dw for pgsql-hackers@postgresql.org; Thu, 03 Aug 2023 12:34:50 +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=E0zdvk/pT/aDYgIDyknk43bf8qcznsDjRVNMEaFp4cQ=; b=vsYlEDV55uCvQI4s+S89fGTVfb NceXrCOiv2IzC5gHe1E39wfeRUaQZfVGatYK8kOXoHPDrJWyCIMuEEQbHGHm5Zfh8+UVAaDVsHcRe 5mroJ1xXGF0NF6oD+NZ8WyQiE3GzRxqDwjjjss03QSmDJNa3XpQCAlLIUc/o2/e8RBLBRteS2BWye BKtK2AIwu84mvrScQTluogpkhTwOub89toQbZ5kRglrfIRp7t9T+0BErABBcMq13yvFcbW7sOKiCb Sx+Oy1vfDYXxBFmBBEheUW7C03kpBQMnCaEchY+yzTLU4LQk2G+toJE5SpHl+PcHUT+Cmc0UAhv+d fuKCfPQw==; Received: from [::1] (port=47650 helo=adam.ace-host.net) by adam.ace-host.net with esmtpa (Exim 4.96) (envelope-from ) id 1qRXXM-00FPBL-0O; Thu, 03 Aug 2023 08:34:45 -0400 MIME-Version: 1.0 Date: Thu, 03 Aug 2023 08:34:44 -0400 From: Chapman Flack To: Andy Fan Cc: Pavel Stehule , jian he , pgsql-hackers Subject: Re: Extract numeric filed in JSONB more effectively In-Reply-To: References: User-Agent: Roundcube Webmail/1.6.0 Message-ID: <3198e7c138fc0b5f80512785a87b7bb2@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-03 03:53, Andy Fan wrote: > I didn't realize timetime types are binary compatible with SQL, > so maybe we can have some similar optimization as well. > (It is a pity that timestamp(tz) are not binary, or else we may > just need one operator). Not to veer from the thread, but something about that paragraph has been hard for me to parse/follow. >> Maybe we can introduce some *internal operator* "extract to type", and >> in >> rewrite stage we can the pattern (x->'field')::type transform to OP(x, >> 'field', typid) > > Not sure what the OP should be? If it is a function, what is the > return value? It looks to me like it is hard to do in c language? Now I am wondering about the 'planner support function' available in CREATE FUNCTION since PG 12. I've never played with that yet. Would that make it possible to have some, rather generic, extract from JSON operator that can look at the surrounding expression and replace itself sometimes with something more efficient? Regards, -Chap