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 1tEYAs-0087Nf-HL for pgsql-hackers@arkaria.postgresql.org; Fri, 22 Nov 2024 18:14:34 +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 1tEYAq-00B8Lj-O7 for pgsql-hackers@arkaria.postgresql.org; Fri, 22 Nov 2024 18:14:32 +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 1tEYAq-00B8La-By for pgsql-hackers@lists.postgresql.org; Fri, 22 Nov 2024 18:14:32 +0000 Received: from mail-lj1-x22e.google.com ([2a00:1450:4864:20::22e]) 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 1tEYAn-003K0f-Nu for pgsql-hackers@lists.postgresql.org; Fri, 22 Nov 2024 18:14:31 +0000 Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-2fb6110c8faso26739891fa.1 for ; Fri, 22 Nov 2024 10:14:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732299269; x=1732904069; 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=lBpv5bqWuTWutryfU3K/p+Wncrdz4Tnh4cU+ywtKlxE=; b=LFGiBCSmuk5gAqShlX3A4ktiBKXUqh6utA1/nV2zF1Mn/6MFostpLN21b7yGU+fj6S s6+tvl/+BWzh6cN4L+5ceLNLi0N2Ia7CvCXVLsLJqL/qp80jyzBU/2dM1zlrbbDeL3Om nMrrLpCZc6Js31Qrne/BxnCwKWFt6TF24OoFEZl978TiQjmPL83GD9hFjYuk1Ul1WAHT iU1jNY5BrSMOXCup1ij1Zz5nh70uQX1sUZUYbOqZfk5wm9xvWnLJDAAvGpuTdpVFQIvq 15N+UXBK/VKEX1rN8WyHcmuHyoWzRWzfNEg0enrWNbhLFUgc9F7xCaZvNOYKhnYdBYE3 YK3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732299269; x=1732904069; 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=lBpv5bqWuTWutryfU3K/p+Wncrdz4Tnh4cU+ywtKlxE=; b=BDVLIpkNZ/2DCaWyV0dw8seQtCpz2MuG4rTiOnpZ/+NRdHP+SxJb5J+k2Hvcg2Ijln z6319WqD1xGZ+zLFMvy1qYYh/o+djQtGfCW2kW+2aunt5wxNos/84h5yFIuofRSN3l1p sbrfhp6ufzkL1nJAUAIyT6eFi55dMY+MjIO7ANiiFMaNYN++8OpBvV837v75DcFlMnf9 tuM16cxmgS6bQ4I1c+Vfj1YJ6/2uRraUM3EyjtlAlGxWadx3autEG5Rb2pthd5xeik/K FnpVcky8QEvt+yqh3xvRyR38AzzamImG0GpKeWPJX46j9b4icONF7tNYqG0HxFQ3clBE tsOA== X-Forwarded-Encrypted: i=1; AJvYcCXTD2zkb9spzZx5z2o+V2UOqxDSyrfW9OcxpcfR9sWq40P5mKzYCkj9NOr+mo+v42rFouiI298v3lecD77a@lists.postgresql.org X-Gm-Message-State: AOJu0YxxbGFK5hBwF4gv1/CzB3KwjM9/SJ1DElkAT1R7SYc5cUCQTqr0 YuFHMsB40z1buJ7gyJ6l6g8+9K5pk5fHtY66ylFqKtl37EiHs5Fy X-Gm-Gg: ASbGncs0U7XeG7J/mFs0BwF2uM9Zq8yIBlYfmJabHkavTVzrg9BOxiagpCx8gQ68xSO JW6L8a4cuHPaHuXiAWMBfZTRnk04emRCreDNLFobgDyj9WCRcWopUtfVAkPhnTluIBWntFTCRce +Qh0qVcBUJAUQuz3b2lVoYDfacUBCQ5UTMikWekRKW1riVs4aDfJ8mSg8cmfe8KRZSmmHxqC6Jz a+P0MBtLioGGAEQcBOY3Q8Ulk9LkOFd5COJzNcyfBSFVwgqe46NiiETHS8yBbB/Omm+Hly68Yis ltmU6ou32QLv1wrJMhHr2PqykPqduY1rDdotBQ4VgWrIHNe8GnC2XAjpeDSg1VU= X-Google-Smtp-Source: AGHT+IEsTKjAam3r7AWW08cg59wokF6VipQOmTW8dp2FOV63LVP1EIQrxkGaw4KwTFGnyBcHN9Qk/A== X-Received: by 2002:a2e:bd17:0:b0:2ff:a380:1473 with SMTP id 38308e7fff4ca-2ffa71f8870mr26750991fa.37.1732299268435; Fri, 22 Nov 2024 10:14:28 -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-5d01d3b035bsm1149729a12.21.2024.11.22.10.14.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Nov 2024 10:14:27 -0800 (PST) Date: Fri, 22 Nov 2024 19:14:25 +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: <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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87a5dx4cfb.fsf@163.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Mon, Nov 18, 2024 at 08:23:52AM 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. > >> > >> [...] > >> > >> 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. > > Another reason is for reducing code duplication, writting too many > similar function looks not good to me. Chapman expressed this idea > first at [1]. Search "it would make me happy to further reduce some > of the code" in the message. > > Acutally this doesn't make the patch complexer too much. > > [1] > https://www.postgresql.org/message-id/5138c6b5fd239e7ce4e1a4e63826ac27%40anastigmatix.net It might not make everything too much complex, but e.g. relabeling of the first argument for a "finish" function into an internal one sounds strange to me. Maybe there is a way to avoid duplication of the code, but keep all needed functions in pg_proc? Btw, sorry to complain about small details, but I find start / finish naming pattern not quite fitting here. Their main purpose is to extract / convert a value, the order in which they are happening is less relevant.