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 1tBzDA-00867a-4J for pgsql-hackers@arkaria.postgresql.org; Fri, 15 Nov 2024 16:30:19 +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 1tBzD7-00Aplm-Gq for pgsql-hackers@arkaria.postgresql.org; Fri, 15 Nov 2024 16:30:18 +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 <9erthalion6@gmail.com>) id 1tBzD7-00Aple-6w for pgsql-hackers@lists.postgresql.org; Fri, 15 Nov 2024 16:30:17 +0000 Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from <9erthalion6@gmail.com>) id 1tBzD4-0026LR-5j for pgsql-hackers@lists.postgresql.org; Fri, 15 Nov 2024 16:30:17 +0000 Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-5cedf5fe237so2399736a12.3 for ; Fri, 15 Nov 2024 08:30:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731688213; x=1732293013; darn=lists.postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=Lu8X7Nkjszst3QjQCyPlY/Qxi/wCGwYFOg4nbW9RcVw=; b=KlTTtByfA9ei5Ev4cf9xAEeMSD5K8KcB1Anq6SnyyrdObEXHkFkrQiBirjfJpQH5zO 0JC1zpf9C04F8V4Xk2q+f+QzwwlA7Hpz743FRdo7ry9mwk/oA8/7LKkWkj7kDIvttXy/ kjQl9H83Nh3gUxcWXr2r+WfkhuT59U6N/vElhhIeHaYgxcyXwdLjYjyHnUo1jXEwIugG H3y5zTuV4EC9ZMxnX+Uzxn7/Bz+BMxhR8Qim+Zt/U8iJdd1BeC0Y6EINOJbnmZPtreeD cB71eSujA+7pRZ2ZszTip8mFoa/EmP8zHt1kDlje5LOYU+SYv8077J3Ca0lyK8yx1Rh2 EChQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731688213; x=1732293013; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Lu8X7Nkjszst3QjQCyPlY/Qxi/wCGwYFOg4nbW9RcVw=; b=C0TKasmv0zA9Y0oiyV3MrPfnrm98Rlldc3jLjHWshE9YuP1sIBycVQzE9XDfSnpJgP XJEALsZvr6OfT7+lkvi9Ml7t1M4q4WZTuXfXlWnhmOmHZ/e7W7r8kW47mupKhFJDnXQY lR7HL8I6d2d5KO+AlpTcF/Yl4At889uUj8s0SHl54kJxGlnndk0SytLN90CK8H7qYBWA gRMi/BRkQh66CYP2UUB4cO/Ns8dlhBjMpxDuOlcLSiclxcY1cKvoChBJFaS3y2irore2 agLGts/5RpCBnuKKhAuhdRO39coGiFqTZDDfqzbUYvb3HKnPzhI396ZEue8WmKjAOX13 HCYg== X-Forwarded-Encrypted: i=1; AJvYcCVn1G4p322FqCJrqcBfng24VpHIo53H/ymlXb433o4jBXMMnSKLymrTo0g5p6r7FfTOkOtokkLWNrQExfvO@lists.postgresql.org X-Gm-Message-State: AOJu0Yyvs7gqRH/M/EFcb6SlsU7LoNvThshLEv4lVvZogKPJ+8W4PnTx ccFbFZ9fTpe+cYfas3oDa8xsT5qZZ5k0rzJxBMw8L+hNUQy5u67S X-Google-Smtp-Source: AGHT+IFoCrTF+ymtCm+YCd1aGtG0OhFUitOwWFDKmvqZ30kznZWcu9NDuogwZofu8BdeC5m7T24pxg== X-Received: by 2002:a05:6402:35c3:b0:5ce:d4ec:caef with SMTP id 4fb4d7f45d1cf-5cf8fc58a8amr2606156a12.15.1731688212392; Fri, 15 Nov 2024 08:30:12 -0800 (PST) Received: from ddolgov-thinkpadt14sgen1.rmtde.csb (dslb-178-005-232-220.178.005.pools.vodafone-ip.de. [178.5.232.220]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5cf79b9e46bsm1701702a12.20.2024.11.15.08.30.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 08:30:11 -0800 (PST) Date: Fri, 15 Nov 2024 17:30:09 +0100 From: Dmitry Dolgov <9erthalion6@gmail.com> To: Andy Fan Cc: 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 Message-ID: References: <87h6jpob9x.fsf@163.com> <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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8734m5fua1.fsf@163.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Thu, Sep 12, 2024 at 03:03:18AM GMT, Andy Fan wrote: > > > I imagined you'd the patch should create a SupportRequestSimplify > > support function for jsonb_numeric() that checks if the input > > expression is an OpExpr with funcid of jsonb_object_field(). All you > > do then is ditch the cast and change the OpExpr to call a new function > > named jsonb_object_field_numeric() which returns the val.numeric > > directly. Likely the same support function could handle jsonb casts > > to other types too, in which case you'd just call some other function, > > e.g jsonb_object_field_timestamp() or jsonb_object_field_boolean(). > > Basically yes. The reason complexity comes when we many operators we > want to optimize AND my patch I want to reduce the number of function > created. > > The optimized functions and operators includes: > 1. jsonb_object_field / -> > 2. jsonb_array_element / -> > 3. jsonb_extract_path / #> > 4. jsonb_path_query > 5. jsonb_path_query_first > > > > ..., in which case you'd just call some other function, > > e.g jsonb_object_field_timestamp() or jsonb_object_field_boolean(). > > This works, but We need to create 2 functions for each operator. In the > patched case, we have 5 operators, so we need to create 10 functions. > > op[1,2,3,4,5]_bool > op[1,2,3,4,5]_numeric. > > Within the start / finish function, we need to create *7* functions. Any particular reason you want to keep number of functions minimal? Is it just to make the patch smaller? I might be missing something without looking at the implementation in details, but the difference between 10 and 7 functions doesn't seem to be significant.