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 1u2cdI-003NWY-D7 for pgsql-general@arkaria.postgresql.org; Wed, 09 Apr 2025 21:06:52 +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 1u2cdG-007Lgo-Rv for pgsql-general@arkaria.postgresql.org; Wed, 09 Apr 2025 21:06:51 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u2cdG-007LgZ-GR for pgsql-general@lists.postgresql.org; Wed, 09 Apr 2025 21:06:50 +0000 Received: from mail-oa1-x31.google.com ([2001:4860:4864:20::31]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1u2cdF-003wRM-0O for pgsql-general@lists.postgresql.org; Wed, 09 Apr 2025 21:06:49 +0000 Received: by mail-oa1-x31.google.com with SMTP id 586e51a60fabf-2cc36b39545so71113fac.1 for ; Wed, 09 Apr 2025 14:06:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1744232808; x=1744837608; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=HVyunyyMmSHGV7SVkRyjAtqc1JfZcEXU5Q9accrN2Fk=; b=Lvh1JWkVTvtWaWSA/ctNvKPjzP8nwihGX5y1T6ZxFG0Nv2PdusXbm4y6+kCZhzXyMj 5M2UZcMD+WAQ2v8RwZmjeWzOLolb6iYH9p5Dix6hlTAgaI7CIL9a0sWFXlsZINOKIURP 3a7wPIAqxBPyRfa1v+gPNkGIAi0BXbtNgWR82pF7vcREy6Z9WGmBDYlFPbAmlOAADskm HVU3d9L3P4Gy1CTRJzSeFYpZ5xk7LiC/okudQH5z2DxQXCCI4fxZF8+A3zZ9Y8UqZ/a8 FDCmxJtkf7bN/xo7nT9a+GwIiA1fgh6J72xDcRLwldS7FbPbbftfFhpLIXETquyiCSRM nEPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744232808; x=1744837608; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=HVyunyyMmSHGV7SVkRyjAtqc1JfZcEXU5Q9accrN2Fk=; b=uLH0pvm9nn47HD5uq8ARI7Y+GudX02kHPvEG7KOXU6Vx8Pu2fiDFh2jyK4y4raziv5 RuTATd/t0bFieB4V0HCHaMnjy3/v6/By7kNtoVKGrlC9X++qWvC8x1UNfnaXwmOWw46J vmkgBmkOjH/i+r4I6rtxGFET2XyMwUAKi2x87angJ29PaVn2EAxSHBlqdriXLrTVLOGH NOC7KZ+Uy1JIYoqo1hMAcYZGfhHLR4w3Wg6M1MowGMpuCwRNE6Z1rh4bO1r/hLRy4iry fHxvVM9bpYYz7K07ONGu9rnH9AF8ja/hTNpSv+BXj+s5CChJEDti/uw/kudfqsDHAvhb vaGw== X-Forwarded-Encrypted: i=1; AJvYcCXZ/gKZ6S8UFHUXUNVCRkweg+9P5AXd9po1FcHZAoyd8LqTILUZ4Fd/M+EOs9P5U7Yi9lvkAYIttRP+8kaV@lists.postgresql.org X-Gm-Message-State: AOJu0YyQFJQOo/VphYFgPIBupMWIflFu2QelkCpaQrXrP0O2Y7Gun+Em 0z5bwGog8KNq7BJlLLw/Uw1DDq1N1sEofs60Hgrk7SrQlF52iF+r2X4RtuldVRzms9ffWKuBRYo pzQAgpp3GXTZvkLgqLcDTue4U4qG00A== X-Gm-Gg: ASbGnctLpnZ3+saVHEcGvmZss8VDWIO8JRPta7fDDBxOGoY9bYY7JGKi8vEk92UaZMe a79/BdDMAH1KcqYL93TxEFemOui6T/w/oV8odsin2a8a7CbhObgd9bcTgK8tVibbNWs/Nyz0o/+ paoFmBErcpCXSEbgz1i2GxXpk2x1NAFuA= X-Google-Smtp-Source: AGHT+IHVj65azV/OVRO5e5VmhL0rB20TIVzKmOhgAD3nQaU6c/yKvEnn6N4hcWoKLA4LcWKla5PeC/jFGQtFKVvJpxI= X-Received: by 2002:a05:6870:ce94:b0:2c1:4d18:383a with SMTP id 586e51a60fabf-2d0b30df778mr164844fac.3.1744232808536; Wed, 09 Apr 2025 14:06:48 -0700 (PDT) MIME-Version: 1.0 References: <662101e2-5ca5-4bf5-9307-2519efde8690@ya.ru> <8687df7d49bc4b28b41c7cf4e9ad1e15d383b2fa.camel@cybertec.at> In-Reply-To: <8687df7d49bc4b28b41c7cf4e9ad1e15d383b2fa.camel@cybertec.at> From: "David G. Johnston" Date: Wed, 9 Apr 2025 14:06:12 -0700 X-Gm-Features: ATxdqUFRou1IqNei1k6dfMjyy-bMqy_1gpgGYBfXQwrR9lGDo_Pvh5vv4B3jayA Message-ID: Subject: Re: Interesting case of IMMUTABLE significantly hurting performance To: Laurenz Albe Cc: Olleg Samoylov , "pgsql-generallists.postgresql.org" Content-Type: multipart/alternative; boundary="000000000000f5668306325ed839" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000f5668306325ed839 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Apr 9, 2025 at 1:50=E2=80=AFPM Laurenz Albe wrote: > If you use EXPLAIN (VERBOSE), you will see that the function gets inlined > in the fast case. > > That saves the overhead of a function call. > > The IMMUTABLE function cannot be inlined because to_char() is not > IMMUTABLE. > So, the punishment for lying about the volatility of one's function is to prohibit it from being inlined even in a case where had you been truthful about the volatility it would have been inlined. David J. --000000000000f5668306325ed839 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Wed, Apr 9, 2025 at 1:50=E2=80=AFPM Laurenz Albe <laurenz.albe@cybertec.at> = wrote:
<= blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-l= eft:1px solid rgb(204,204,204);padding-left:1ex">If you use EXPLAIN (VERBOS= E), you will see that the function gets inlined in the fast case.

That saves the overhead of a function call.

The IMMUTABLE function cannot be inlined because to_char() is not IMMUTABLE= .

So, the punishment for lying about the volat= ility of one's function is to prohibit it from being inlined even in a = case where had you been truthful about the volatility it would have been in= lined.

David J.

--000000000000f5668306325ed839--