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 1tBsmQ-006iiM-0m for pgsql-hackers@arkaria.postgresql.org; Fri, 15 Nov 2024 09:38:17 +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 1tBsmM-008gjF-W9 for pgsql-hackers@arkaria.postgresql.org; Fri, 15 Nov 2024 09:38:15 +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 1tBsmM-008gj6-JA for pgsql-hackers@lists.postgresql.org; Fri, 15 Nov 2024 09:38:15 +0000 Received: from meesny.iki.fi ([2001:67c:2b0:1c1::201]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tBsmI-00232I-UP for pgsql-hackers@lists.postgresql.org; Fri, 15 Nov 2024 09:38:14 +0000 Received: from [192.168.1.110] (dsl-hkibng22-50ddb7-241.dhcp.inet.fi [80.221.183.241]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by meesny.iki.fi (Postfix) with ESMTPSA id 4XqX4x38GRzySZ; Fri, 15 Nov 2024 11:38:09 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1731663489; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vdV1Yp4oDim+CBptUGckWpNRxmkGrSKuVQHClWl9FPA=; b=EIhaqmi+t14lYfUXNWS6CnkJ20N2mAfaDBkgzC8xp4Iu/MRz2AoKRlgcV6qA5SaoPUWUzm Aw49Kf1+GLiLC3xGIV9PU6Nn0/uVciTjIMzLp3FmqJz1j3ae1qqM+LjPoOPGHOVH31m7N2 59tgEbFNjbFlEjSo2msxcArER+S5IKA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1731663489; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vdV1Yp4oDim+CBptUGckWpNRxmkGrSKuVQHClWl9FPA=; b=v7Jb2RNJakNwoe0LA4CNbMt1/HtV7JLzuAHQ2eLjm5MhKjB7eMgQy5Q9DTv6CmH2H4eSqE 5OUentLWTj/aDZ/PM1AzBxLGoXouQHHAkKd0pLbIfGJPMNfC8DU5aw/vpK2YvMHOYAuW3X Euf0swxvXWNFnJowJqcUJdAJu6XoqN4= ARC-Seal: i=1; s=meesny; d=iki.fi; t=1731663489; a=rsa-sha256; cv=none; b=mPrsk0gsl39B0S5CjsjF8/9aIRw5O3zM/tQmL1Wdb62o003b4JO0rjvdFe8QS6rtPk93ot 1XYAUFbfPL44pHBukBgh6em30Aj3XNctTb0oX4sWd8BHbyaomPzJCtK83KZAHedl53a49L IsT5EvQwP2lRHg4EGxiC/Y4yLS5dOUc= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi Message-ID: <1c767ec4-709e-45b1-bc0e-add024326e77@iki.fi> Date: Fri, 15 Nov 2024 11:38:08 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: JIT: The nullness of casetest.value can be determined at the JIT compile time. To: Xing Guo , Andreas Karlsson Cc: pgsql-hackers@lists.postgresql.org References: Content-Language: en-US From: Heikki Linnakangas In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 03/09/2024 18:18, Xing Guo wrote: > On Tue, Sep 3, 2024 at 8:09 PM Andreas Karlsson wrote: >> >> On 8/31/24 10:04 AM, Xing Guo wrote: >>> The nullness of casetest.value can be determined at the JIT compile >>> time. We can emit fewer codes by utilizing this property. The attached >>> patch is trying to fix it. >> >> I have not reviewed the code yet but the idea seems good. >> >> But I wonder if we shouldn't instead simplify the code a bit by >> specializing these steps when generating them instead of doing the work >> runtime/while generating machine code. Yes, I doubt the performance >> benefits matter but I personally think the code is cleaner before my >> patch than after it. > > +1 to the idea. > >> Long term it would be nice to get rid off >> caseValue_datum/domainValue_datum as mentioned by Andres[1] but that is >> a bigger job so think that either your patch or my patch would make >> sense to apply before that. > > I think your patch makes more sense than mine! Thanks! Huge +1 for cleaning up this abuse of caseValue_datum/domainValue_datum. While correct and sensible if we continue the abuse, these patches feel like putting lipstick on a pig. I think the most straightforward way to clean that up is to replace caseValue and domainValue in ExprContext with a generic array of "expression params", and a new Expr node type to refer to them. Basically, the same as we have now, but with explicit names to indicate that the values are supplied externally. In https://www.postgresql.org/message-id/20230302200549.l2ikytmnqzvy5a7a%40alap3.anarazel.de, Andres hinted at using ParamExecData for these. That'd be nice, but seems harder. Those params are reserved at planning time, so we'd need to somehow allocate more of them in ExecInitExpr, or move the bookkeeping to the planner. But just basically renaming "caseValue" to "externalValue" seems straightforward. PARAM_EXECs are also a slightly more expensive to evaluate, because they support lazy evaluation of the subplan. This goes off-topic, but I wonder if there are cases where we could know at ExecInitExpr() time that the parameter must be already evaluated when it's referred, and skip the lazy checks? -- Heikki Linnakangas Neon (https://neon.tech)