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 1pZi2x-00089u-6S for pgsql-general@arkaria.postgresql.org; Wed, 08 Mar 2023 00:52:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pZi2u-0000n6-Nn for pgsql-general@arkaria.postgresql.org; Wed, 08 Mar 2023 00:52:44 +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 1pZi2u-0000h7-BB for pgsql-general@lists.postgresql.org; Wed, 08 Mar 2023 00:52:44 +0000 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pZi2r-0002TQ-JT for pgsql-general@lists.postgresql.org; Wed, 08 Mar 2023 00:52:43 +0000 Received: by mail-pl1-x629.google.com with SMTP id i3so16135276plg.6 for ; Tue, 07 Mar 2023 16:52:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yugabyte.com; s=google; t=1678236760; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=xhl42w6YNx5YQau5t4sO5GhWXbjLj4nNgqjoAvM+z0Q=; b=SZkpPqbgJ+FbBNX98hS09EIFWr9+NRMMsXm3LLV09p9AI618BcoK4sl2pgOs0VuQuC vGNI4NTh/CQOZ9EN3bpZaNsi3FJdEkLILzKr8DYsfHLsBmh744HcsxINvB8oe2ROriSi w8cKEb4a09HGND6VhL0OmDsX0DNoK2tPD0ELM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678236760; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xhl42w6YNx5YQau5t4sO5GhWXbjLj4nNgqjoAvM+z0Q=; b=XD5sgDpDMZGidB4IZbPwbuSTlTcfHkAs3eEBzgrj+25wu4LV4qW0vr21A3Ka/CEseA Jbt7cw/68W2OkEeXe4Q12WfXSqEvKXy/XkU9/gEf6dYOuUSbVrFxhr/JIOzrWSUR6Ko5 sjjBlfa3DPu0GDJmk487Tg832p6oYlqPP2aFCKeXHnO3yAn0b3WWOcLHuX/EEI/mf6FS 7I8ksh6stPq2Nufn01cv9ioI+fiG9pNXHtzEfZO/s08vGAe5FueMzNSMGypJdNRUvZYa 8vLnCtba6ZN8VonrwINHtRZ1wVQFHFqg4ygevwElkVLpnNPmAtpNSGXqiDx315u78Zip jY7g== X-Gm-Message-State: AO0yUKVjD8MB2YOITsuHNAC3lHzMYjgbjqm1nnI2JDBltlZrXWC1PVFh l44MXypUWGvlzCz9t50HZhO2JQ== X-Google-Smtp-Source: AK7set/bqvlpKwz7Vhab703EimxzR1u4Xkwar+YHZsvbJ0O4//Vh7AAcj3AEqKvsQ1pLDE6zgFmwJw== X-Received: by 2002:a17:90a:1d5:b0:23a:6dd3:f3d4 with SMTP id 21-20020a17090a01d500b0023a6dd3f3d4mr17570965pjd.12.1678236760507; Tue, 07 Mar 2023 16:52:40 -0800 (PST) Received: from smtpclient.apple ([2601:646:101:7fda:480c:8dec:ea21:1d49]) by smtp.gmail.com with ESMTPSA id hx20-20020a17090b441400b002371e290565sm8006057pjb.12.2023.03.07.16.52.39 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Mar 2023 16:52:40 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.14\)) Subject: Re: Behavior of PL/pgSQL function following drop and re-create of a table that it uses From: Bryn Llewellyn In-Reply-To: Date: Tue, 7 Mar 2023 16:52:39 -0800 Cc: pgsql-general list Content-Transfer-Encoding: quoted-printable Message-Id: References: <46DE0CE7-7E90-480D-8395-74E5309F7D26@yugabyte.com> To: "David G. Johnston" X-Mailer: Apple Mail (2.3654.120.0.1.14) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > david.g.johnston@gmail.com wrote: >=20 >> bryn@yugabyte.com wrote: >>=20 >> create table s.t(k serial primary key, v text); >> create function s.f(k_in in int) >> select s.f(1); >=20 > text, function is now compiled with that type resolution fixed. > I think mostly attributable to: >=20 > > The mutable nature of record variables presents another problem in = this connection. When fields of a record variable are used in = expressions or statements, the data types of the fields must not change = from one call of the function to the next, since each expression will be = analyzed using the data type that is present when the expression is = first reached. >=20 > Though possibly=E2=80=A6 variable declarations [are] considered = structural: >=20 > > The instruction tree fully translates the PL/pgSQL statement = structure, >=20 >> drop table s.t cascade; >> create table s.t(k serial primary key, v varchar(10)); >> select s.f(1); >=20 > still text as the compiled artifact is re-executed > =20 >> \c d0 d0$u0 >> select s.f(1); >=20 > now varchar as the function is recompiled during its first use in this = session. >=20 > Restarting everything is an approach to dealing with uncertainty. This = particular use case, though, isn't one that I'd be overly worried about. = Actually making DDL changes of this nature should be rare if not = forbidden. Once live on-the-fly column type changes just shouldn't = happen so having a plan in place that accommodates them is adding cost = for no real benefit. Thanks. I believe that you and I agree on the proper practice, = paraphrased here slightly w.r.t. what I wrote in my point #6 in my email = that started this thread: Regard a DDL on any object that an application uses as unsafe while the = app is in use. You must terminate all client-sessions before doing such = a DDL and re-start them only when all such DDLs are done successfully.