Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1krkFd-0003sL-Ec for pgsql-general@arkaria.postgresql.org; Tue, 22 Dec 2020 16:11:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1krkFc-0002wH-EL for pgsql-general@arkaria.postgresql.org; Tue, 22 Dec 2020 16:11:04 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1krkFa-0002wA-FL for pgsql-general@lists.postgresql.org; Tue, 22 Dec 2020 16:11:04 +0000 Received: from wout1-smtp.messagingengine.com ([64.147.123.24]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1krkFX-0004Kz-94 for pgsql-general@postgresql.org; Tue, 22 Dec 2020 16:11:01 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id F242F764; Tue, 22 Dec 2020 11:10:56 -0500 (EST) Received: from imap2 ([10.202.2.52]) by compute5.internal (MEProxy); Tue, 22 Dec 2020 11:10:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=compiler.org; h= mime-version:message-id:in-reply-to:references:date:from:to:cc :subject:content-type; s=fm3; bh=HdJLKuqlv0bUurIFLuLmNJoWzu3sZUg TiwbfVp0QMpU=; b=KniDSWB92d0V7D0vh0lLhqFepjIM6t1wKAEC4VnZPV+Gfsp cRaj5D7TmPHghMM/Jb6wy2EMmMj1pWkVWQuntId9F1Ao98p7xpLiIPXR3XTViW6K QRscEEG2ZZ5938bbVy28vSNdOdI6XkwJqMwp9pv2q4h4+S28Gkr4b/LYOHD6FEWT xp3s2YL7jQOFSw1wpA3Co6jDiR22Kge2ERsjuDA6+NwKbv4sklmIplfDyuklZnZ0 +hNT+TbzXQDUYhVvJyyj8qZrEZGWIrRr2sJMWep8XEwNUwVOGnzpx0BMwdUxNL0K QERSK+nCfxrWX0csO5pGBbT9cVNCPJJwxoyzz7w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=HdJLKu qlv0bUurIFLuLmNJoWzu3sZUgTiwbfVp0QMpU=; b=h2vbZTOyhi8JlLdVBiV6Pj kPVCqdsghrr3Al/5jFUfe+U/8srXiGHK1CaqySYo4SZGsTXJqyajI7gAx9VWFk1J x3ZqAdomePDsM1I4hpYcw+6ShEDtclASxUUxLbn64lZ6p9NSiiTIYmhsywZKaieZ yHMg4yYeAGI8SwpcM5EsBGLtj2Wt3TA7QojWzmEDMu9PgGnRXFCJcEFUagbCipr7 wUpHE4Zi0kTT+Uodciud+1yI7onhW+tgEflC6PiLnG0YBYYY2t7PHXssKa1Ingar YVVy+WXnQB7uK03kqD2/VDLleadrQmLvatnOiJ7fVbi2iM1/512w/DhZkdFQ/SWA == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrvddtgedgkeeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesrgdtreerreertdenucfhrhhomhepfdflohgv lhculfgrtghosghsohhnfdcuoehjohgvlhestghomhhpihhlvghrrdhorhhgqeenucggtf frrghtthgvrhhnpedtueduffdtfeffjedutdethfdvteehjeehjeeitefgudeifffffefg gfegvdehfeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpehjohgvlhestghomhhpihhlvghrrdhorhhg X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 19692E00A9; Tue, 22 Dec 2020 11:10:54 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.3.1-61-gb52c239-fm-20201210.001-gb52c2396 Mime-Version: 1.0 Message-Id: In-Reply-To: References: Date: Tue, 22 Dec 2020 17:10:35 +0100 From: "Joel Jacobson" To: "Laurenz Albe" , "Philip Semanchuk" Cc: pgsql-general Subject: Re: Avoid excessive inlining? Content-Type: multipart/alternative; boundary=5af0f73d2c624e2b9409da129542f495 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --5af0f73d2c624e2b9409da129542f495 Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On Tue, Dec 22, 2020, at 14:40, Laurenz Albe wrote: >I would say that the simplest way to prevent a function from being inli= ned >is to set a parameter on it: > ALTER FUNCTION f() SET enable_seqscan =3D on; Thanks, very useful, didn't know about that trick. I think I was a bit unclear about my problem, and might have used the wr= ong terminology. In my LATERAL query, there are calculations in a certain order. For each step, "columns" are computed named e.g. "g", "c", "h", "i", etc= . However, when looking at the query plan, these steps are gone, and inste= ad there is just one huge fully expanded expression, which doesn't look = very efficient. Ideas? PREPARE q_lateral AS SELECT make_date($1, easter_month, easter_day) FROM (VALUES ($1 % 19, $1 / 100)) AS Q1(g,c) JOIN LATERAL (VALUES ((c - c/4 - (8*c + 13)/25 + 19*g + 15) % 30)) AS Q2(h) ON TRUE JOIN LATERAL (VALUES (h - (h/28)*(1 - (h/28)*(29/(h + 1))*((21 - g)/11)))) AS Q3(i) ON TRUE JOIN LATERAL (VALUES (($1 + $1/4 + i + 2 - c + c/4) % 7)) AS Q4(j) ON TR= UE JOIN LATERAL (VALUES (i - j)) AS Q5(p) ON TRUE JOIN LATERAL (VALUES (3 + (p + 26)/30, 1 + (p + 27 + (p + 6)/40) % 31)) AS Q6(easter_month, easter_day) ON TRUE; SET plan_cache_mode =3D 'force_generic_plan'; EXPLAIN (ANALYZE, VERBOSE) EXECUTE q_lateral(2020); Result (cost=3D0.00..1.14 rows=3D1 width=3D4) (actual time=3D0.038..0.0= 38 rows=3D1 loops=3D1) Output: make_date($1, (3 + (((((((((($1 / 100) - (($1 / 100) / 4)) - (= ((8 * ($1 / 100)) + 13) / 25)) + (19 * ($1 % 19))) + 15) % 30) - (((((((= ($1 / 100) - (($1 / 100) / 4)) - (((8 * ($1 / 100)) + 13) / 25)) + (19 *= ($1 % 19))) + 15) % 30) / 28) * (1 - ((((((((($1 / 100) - (($1 / 100) /= 4)) - (((8 * ($1 / 100)) + 13) / 25)) + (19 * ($1 % 19))) + 15) % 30) /= 28) * (29 / ((((((($1 / 100) - (($1 / 100) / 4)) - (((8 * ($1 / 100)) += 13) / 25)) + (19 * ($1 % 19))) + 15) % 30) + 1))) * ((21 - ($1 % 19)) /= 11))))) - (((((($1 + ($1 / 4)) + ((((((($1 / 100) - (($1 / 100) / 4)) -= (((8 * ($1 / 100)) + 13) / 25)) + (19 * ($1 % 19))) + 15) % 30) - (((((= ((($1 / 100) - (($1 / 100) / 4)) - (((8 * ($1 / 100)) + 13) / 25)) + (19= * ($1 % 19))) + 15) % 30) / 28) * (1 - ((((((((($1 / 100) - (($1 / 100)= / 4)) - (((8 * ($1 / 100)) + 13) / 25)) + (19 * ($1 % 19))) + 15) % 30)= / 28) * (29 / ((((((($1 / 100) - (($1 / 100) / 4)) - (((8 * ($1 / 100))= + 13) / 25)) + (19 * ($1 % 19))) + 15) % 30) + 1))) * ((21 - ($1 % 19))= / 11)))))) + 2) - ($1 / 100)) + (($1 / 100) / 4)) % 7)) + 26) / 30)), (= 1 + ((((((((((($1 / 100) - (($1 / 100) / 4)) - (((8 * ($1 / 100)) + 13) = / 25)) + (19 * ($1 % 19))) + 15) % 30) - (((((((($1 / 100) - (($1 / 100)= / 4)) - (((8 * ($1 / 100)) + 13) / 25)) + (19 * ($1 % 19))) + 15) % 30)= / 28) * (1 - ((((((((($1 / 100) - (($1 / 100) / 4)) - (((8 * ($1 / 100)= ) + 13) / 25)) + (19 * ($1 % 19))) + 15) % 30) / 28) * (29 / ((((((($1 /= 100) - (($1 / 100) / 4)) - (((8 * ($1 / 100)) + 13) / 25)) + (19 * ($1 = % 19))) + 15) % 30) + 1))) * ((21 - ($1 % 19)) / 11))))) - (((((($1 + ($= 1 / 4)) + ((((((($1 / 100) - (($1 / 100) / 4)) - (((8 * ($1 / 100)) + 13= ) / 25)) + (19 * ($1 % 19))) + 15) % 30) - (((((((($1 / 100) - (($1 / 10= 0) / 4)) - (((8 * ($1 / 100)) + 13) / 25)) + (19 * ($1 % 19))) + 15) % 3= 0) / 28) * (1 - ((((((((($1 / 100) - (($1 / 100) / 4)) - (((8 * ($1 / 10= 0)) + 13) / 25)) + (19 * ($1 % 19))) + 15) % 30) / 28) * (29 / ((((((($1= / 100) - (($1 / 100) / 4)) - (((8 * ($1 / 100)) + 13) / 25)) + (19 * ($= 1 % 19))) + 15) % 30) + 1))) * ((21 - ($1 % 19)) / 11)))))) + 2) - ($1 /= 100)) + (($1 / 100) / 4)) % 7)) + 27) + (((((((((($1 / 100) - (($1 / 10= 0) / 4)) - (((8 * ($1 / 100)) + 13) / 25)) + (19 * ($1 % 19))) + 15) % 3= 0) - (((((((($1 / 100) - (($1 / 100) / 4)) - (((8 * ($1 / 100)) + 13) / = 25)) + (19 * ($1 % 19))) + 15) % 30) / 28) * (1 - ((((((((($1 / 100) - (= ($1 / 100) / 4)) - (((8 * ($1 / 100)) + 13) / 25)) + (19 * ($1 % 19))) += 15) % 30) / 28) * (29 / ((((((($1 / 100) - (($1 / 100) / 4)) - (((8 * (= $1 / 100)) + 13) / 25)) + (19 * ($1 % 19))) + 15) % 30) + 1))) * ((21 - = ($1 % 19)) / 11))))) - (((((($1 + ($1 / 4)) + ((((((($1 / 100) - (($1 / = 100) / 4)) - (((8 * ($1 / 100)) + 13) / 25)) + (19 * ($1 % 19))) + 15) %= 30) - (((((((($1 / 100) - (($1 / 100) / 4)) - (((8 * ($1 / 100)) + 13) = / 25)) + (19 * ($1 % 19))) + 15) % 30) / 28) * (1 - ((((((((($1 / 100) -= (($1 / 100) / 4)) - (((8 * ($1 / 100)) + 13) / 25)) + (19 * ($1 % 19)))= + 15) % 30) / 28) * (29 / ((((((($1 / 100) - (($1 / 100) / 4)) - (((8 *= ($1 / 100)) + 13) / 25)) + (19 * ($1 % 19))) + 15) % 30) + 1))) * ((21 = - ($1 % 19)) / 11)))))) + 2) - ($1 / 100)) + (($1 / 100) / 4)) % 7)) + 6= ) / 40)) % 31))) Planning Time: 4.144 ms Execution Time: 0.220 ms --5af0f73d2c624e2b9409da129542f495 Content-Type: text/html Content-Transfer-Encoding: quoted-printable
On Tue, De= c 22, 2020, at 14:40, Laurenz Albe wrote:
>I would say = that the simplest way to prevent a function from being inlined
=
>is to set a parameter on it:
>  ALTER FUN= CTION f() SET enable_seqscan =3D on;

Thanks= , very useful, didn't know about that trick.

I think I was a bit unclear about my problem, and might have used the = wrong terminology.

In my LATERAL query, the= re are calculations in a certain order.
For each step, "co= lumns" are computed named e.g. "g", "c", "h", "i", etc.
Ho= wever, when looking at the query plan, these steps are gone, and instead= there is just one huge fully expanded expression, which doesn't look ve= ry efficient.

Ideas?

P= REPARE q_lateral AS SELECT make_date($1, easter_month, easter_day)
FROM (VALUES ($1 % 19, $1 / 100)) AS Q1(g,c)
JOIN= LATERAL (VALUES ((c - c/4 - (8*c + 13)/25 + 19*g + 15) % 30)) AS
Q2(h) ON TRUE
JOIN LATERAL (VALUES (h - (h/28)*(1 = - (h/28)*(29/(h + 1))*((21 -
g)/11)))) AS Q3(i) ON TRUE
JOIN LATERAL (VALUES (($1 + $1/4 + i + 2 - c + c/4) % 7)) AS= Q4(j) ON TRUE
JOIN LATERAL (VALUES (i - j)) AS Q5(p) ON T= RUE
JOIN LATERAL (VALUES (3 + (p + 26)/30, 1 + (p + 27 + (= p + 6)/40) % 31))
AS Q6(easter_month, easter_day) ON TRUE;=

SET plan_cache_mode =3D 'force_generic_pla= n';

EXPLAIN (ANALYZE, VERBOSE) EXECUTE q_la= teral(2020);

Result  (cost=3D0.00..1.1= 4 rows=3D1 width=3D4) (actual time=3D0.038..0.038 rows=3D1 loops=3D1)
  Output: make_date($1, (3 + (((((((((($1 / 100) - (($1= / 100) / 4)) - (((8 * ($1 / 100)) + 13) / 25)) + (19 * ($1 % 19))) + 15= ) % 30) - (((((((($1 / 100) - (($1 / 100) / 4)) - (((8 * ($1 / 100)) + 1= 3) / 25)) + (19 * ($1 % 19))) + 15) % 30) / 28) * (1 - ((((((((($1 / 100= ) - (($1 / 100) / 4)) - (((8 * ($1 / 100)) + 13) / 25)) + (19 * ($1 % 19= ))) + 15) % 30) / 28) * (29 / ((((((($1 / 100) - (($1 / 100) / 4)) - (((= 8 * ($1 / 100)) + 13) / 25)) + (19 * ($1 % 19))) + 15) % 30) + 1))) * ((= 21 - ($1 % 19)) / 11))))) - (((((($1 + ($1 / 4)) + ((((((($1 / 100) - ((= $1 / 100) / 4)) - (((8 * ($1 / 100)) + 13) / 25)) + (19 * ($1 % 19))) + = 15) % 30) - (((((((($1 / 100) - (($1 / 100) / 4)) - (((8 * ($1 / 100)) += 13) / 25)) + (19 * ($1 % 19))) + 15) % 30) / 28) * (1 - ((((((((($1 / 1= 00) - (($1 / 100) / 4)) - (((8 * ($1 / 100)) + 13) / 25)) + (19 * ($1 % = 19))) + 15) % 30) / 28) * (29 / ((((((($1 / 100) - (($1 / 100) / 4)) - (= ((8 * ($1 / 100)) + 13) / 25)) + (19 * ($1 % 19))) + 15) % 30) + 1))) * = ((21 - ($1 % 19)) / 11)))))) + 2) - ($1 / 100)) + (($1 / 100) / 4)) % 7)= ) + 26) / 30)), (1 + ((((((((((($1 / 100) - (($1 / 100) / 4)) - (((8 * (= $1 / 100)) + 13) / 25)) + (19 * ($1 % 19))) + 15) % 30) - (((((((($1 / 1= 00) - (($1 / 100) / 4)) - (((8 * ($1 / 100)) + 13) / 25)) + (19 * ($1 % = 19))) + 15) % 30) / 28) * (1 - ((((((((($1 / 100) - (($1 / 100) / 4)) - = (((8 * ($1 / 100)) + 13) / 25)) + (19 * ($1 % 19))) + 15) % 30) / 28) * = (29 / ((((((($1 / 100) - (($1 / 100) / 4)) - (((8 * ($1 / 100)) + 13) / = 25)) + (19 * ($1 % 19))) + 15) % 30) + 1))) * ((21 - ($1 % 19)) / 11))))= ) - (((((($1 + ($1 / 4)) + ((((((($1 / 100) - (($1 / 100) / 4)) - (((8 *= ($1 / 100)) + 13) / 25)) + (19 * ($1 % 19))) + 15) % 30) - (((((((($1 /= 100) - (($1 / 100) / 4)) - (((8 * ($1 / 100)) + 13) / 25)) + (19 * ($1 = % 19))) + 15) % 30) / 28) * (1 - ((((((((($1 / 100) - (($1 / 100) / 4)) = - (((8 * ($1 / 100)) + 13) / 25)) + (19 * ($1 % 19))) + 15) % 30) / 28) = * (29 / ((((((($1 / 100) - (($1 / 100) / 4)) - (((8 * ($1 / 100)) + 13) = / 25)) + (19 * ($1 % 19))) + 15) % 30) + 1))) * ((21 - ($1 % 19)) / 11))= )))) + 2) - ($1 / 100)) + (($1 / 100) / 4)) % 7)) + 27) + (((((((((($1 /= 100) - (($1 / 100) / 4)) - (((8 * ($1 / 100)) + 13) / 25)) + (19 * ($1 = % 19))) + 15) % 30) - (((((((($1 / 100) - (($1 / 100) / 4)) - (((8 * ($1= / 100)) + 13) / 25)) + (19 * ($1 % 19))) + 15) % 30) / 28) * (1 - (((((= (((($1 / 100) - (($1 / 100) / 4)) - (((8 * ($1 / 100)) + 13) / 25)) + (1= 9 * ($1 % 19))) + 15) % 30) / 28) * (29 / ((((((($1 / 100) - (($1 / 100)= / 4)) - (((8 * ($1 / 100)) + 13) / 25)) + (19 * ($1 % 19))) + 15) % 30)= + 1))) * ((21 - ($1 % 19)) / 11))))) - (((((($1 + ($1 / 4)) + ((((((($1= / 100) - (($1 / 100) / 4)) - (((8 * ($1 / 100)) + 13) / 25)) + (19 * ($= 1 % 19))) + 15) % 30) - (((((((($1 / 100) - (($1 / 100) / 4)) - (((8 * (= $1 / 100)) + 13) / 25)) + (19 * ($1 % 19))) + 15) % 30) / 28) * (1 - (((= (((((($1 / 100) - (($1 / 100) / 4)) - (((8 * ($1 / 100)) + 13) / 25)) + = (19 * ($1 % 19))) + 15) % 30) / 28) * (29 / ((((((($1 / 100) - (($1 / 10= 0) / 4)) - (((8 * ($1 / 100)) + 13) / 25)) + (19 * ($1 % 19))) + 15) % 3= 0) + 1))) * ((21 - ($1 % 19)) / 11)))))) + 2) - ($1 / 100)) + (($1 / 100= ) / 4)) % 7)) + 6) / 40)) % 31)))
Planning Time: 4.144 ms<= br>
Execution Time: 0.220 ms


=
--5af0f73d2c624e2b9409da129542f495--