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 1o6RR5-0006i6-So for pgsql-general@arkaria.postgresql.org; Wed, 29 Jun 2022 06:44:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1o6RR3-0002eP-9J for pgsql-general@arkaria.postgresql.org; Wed, 29 Jun 2022 06:44:25 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o6RR2-0002eE-RX for pgsql-general@lists.postgresql.org; Wed, 29 Jun 2022 06:44:24 +0000 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1o6RQv-0007Ui-Gl for pgsql-general@lists.postgresql.org; Wed, 29 Jun 2022 06:44:24 +0000 Received: by mail-wr1-x42e.google.com with SMTP id i25so15355843wrc.13 for ; Tue, 28 Jun 2022 23:44:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20210112.gappssmtp.com; s=20210112; h=message-id:subject:from:to:cc:date:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=XrbN20zpZhM1mlvqyakxcfKwg9c/8sBql3osL6yzK0Y=; b=hv6U2yNCgrqupx/3w9iAivAceSxoxaa/XTHqltNX2hR8KTyYEqxBarsAZIcYZ3bjBZ JOMoixzzZvxb0fzwb9fgXMcQDVKvcO/Qsjj34Nf6WWrgZDlmIb63/EtYh20d1GPGWjwM hdNgfEjV/sIfZ/kqfsOVu+rs6vlmxJdhAl4xP3LmEIFdRaamtLaD/c01dhOG0WzSmf1K 1WQWTEHAB20IlnuuEFqd7oIW25wRKSpPON5knfNxqiUUj94MwA5KVje2vPgPrY1BGXD9 z6MlddSvigegDaZjyvVvL4vaEFsC3IpJZY1+aN6s9jaXIB+3rzRnOyGyuRme3UdyzgBX 3iYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=XrbN20zpZhM1mlvqyakxcfKwg9c/8sBql3osL6yzK0Y=; b=CTUuDc2Ua3f2650quC/rmwMT75aKKuBnuNK6jSSL8G2Zz0KGpoTLq9pu+lSEH5tB53 3nO4dQ0vfLTttcz2DJ1ewAKVlU6bYM+tIMDEYMTMRVSFQiiuFVJj6OVZS7i/IHE/yxIL olAmIfUKS5RGP5UMK0LLhtsZxgKthk7+QDzrg+2iWL1BC+6xq6rBJfHA4CJxaQp0WhGc Xesvw1MNwOA/iu9og9Bre5ccAiox2IroJ2xrFThBONypAkrk2CORkuQfrF5i//1Xm+My BeSwlVmrZjpI8DS6YwfrPphaqqooQFVOR4pIc3C6bL57uu4c/y1IWD8y6fhuD2Td795d zb8g== X-Gm-Message-State: AJIora9bhxudNHzxSxwr6eSXJkp62HJX+IGXKAZhlVWrS8ABtq4YG8al GOrU7PvxdA3MY2YTAerTcsxvtQ== X-Google-Smtp-Source: AGRyM1t/S6/2hjhEQ7GN63u/V5/Rh2F9EA6/uYRc51nsjFq5TJ9SCRUt9VTbjDF8N2W7IJqI0xFqUQ== X-Received: by 2002:a5d:6d8b:0:b0:21b:9814:793d with SMTP id l11-20020a5d6d8b000000b0021b9814793dmr1412326wrs.344.1656485055126; Tue, 28 Jun 2022 23:44:15 -0700 (PDT) Received: from localhost.localdomain (217-149-173-181.nat.highway.telekom.at. [217.149.173.181]) by smtp.gmail.com with ESMTPSA id l5-20020a05600c47c500b0039c693a54ecsm2276804wmo.23.2022.06.28.23.44.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jun 2022 23:44:14 -0700 (PDT) Message-ID: <29ca255d477eaf9fb600890a6212a4d913ef0d31.camel@cybertec.at> Subject: Re: User's responsibility when using a chain of "immutable" functions? From: Laurenz Albe To: Christophe Pettus , Bryn Llewellyn Cc: pgsql-general list Date: Wed, 29 Jun 2022 08:42:36 +0200 In-Reply-To: <80C40450-6C0C-46E2-AE82-E7D46120F7FF@thebuild.com> References: <38FB5DA3-5940-43A9-8B09-5C856E2B18C4@yugabyte.com> <80C40450-6C0C-46E2-AE82-E7D46120F7FF@thebuild.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.42.4 (3.42.4-2.fc35) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, 2022-06-28 at 19:02 -0700, Christophe Pettus wrote: > > On Jun 28, 2022, at 18:41, Bryn Llewellyn wrote: > > Should I simply understand that when I have such a dynamic dependency > > chain of "immutable" functions, and should I drop and re-create the > > function at the start of the chain, then all bets are off until I drop > > and re-create every function along the rest of the chain? > > Yes. That is not enough in the general case. You are not allowed to redefine an IMMUTABLE function in a way that changes its behavior: CREATE FUNCTION const(integer) RETURNS integer LANGUAGE plpgsql IMMUTABLE AS 'BEGIN RETURN $1; END;'; CREATE TABLE t (x integer); INSERT INTO t VALUES (1); CREATE INDEX ON t (const(x)); SET enable_seqscan = off; SELECT * FROM t WHERE const(x) = 1; -- returns a correct result x ═══ 1 (1 row) CREATE OR REPLACE FUNCTION const(integer) RETURNS integer LANGUAGE plpgsql IMMUTABLE AS 'BEGIN RETURN $1 + 1; END;'; SELECT * FROM t WHERE const(x) = 1; -- returns a bad result x ═══ 1 (1 row) Of course, you are allowed to cheat if you know what you are doing. But any problem you encounter that way is your own problem entirely. Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com