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.96) (envelope-from ) id 1vInbq-00EoMP-2z for pgsql-bugs@arkaria.postgresql.org; Tue, 11 Nov 2025 12:36:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vInap-0063b1-1J for pgsql-bugs@arkaria.postgresql.org; Tue, 11 Nov 2025 12:35:27 +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.96) (envelope-from ) id 1vInap-0063ar-0F for pgsql-bugs@lists.postgresql.org; Tue, 11 Nov 2025 12:35:27 +0000 Received: from lana.depesz.com ([88.198.49.178] helo=depesz.com) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vInam-006Y23-2q for pgsql-bugs@lists.postgresql.org; Tue, 11 Nov 2025 12:35:26 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=depesz.com; s=20170201; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Reply-To: Message-ID:Subject:To:Sender:From:Date:Cc:Content-ID:Content-Description: In-Reply-To:References; bh=5EpyYe9tSGhznBqO7yNof8SPuFifuIo4IDiplf5N2d0=; b=aA h7+cVyhpvQDidVAh6XODebMsiHCPRM0NXqOmi5uNUGC2y7EJokkbKgKFgUnSNWsUjuxkSd692hJ1U Ij2VFsk3PZcu5X4wiGk/uJTpcqeIkfF15pdpPO5vgrAxsP6wxYwnvl1rP0lEo5YfTiz3Q8G8zclOF aGbkn8BBOJLMLSg=; Received: from depesz by depesz.com with local (Exim 4.96) (envelope-from ) id 1vInak-00Fqvs-0B for pgsql-bugs@lists.postgresql.org; Tue, 11 Nov 2025 13:35:22 +0100 Date: Tue, 11 Nov 2025 13:35:22 +0100 From: hubert depesz lubaczewski Sender: depesz@depesz.com To: PostgreSQL mailing lists Subject: Functions used by index don't need to be immutable? Message-ID: Reply-To: depesz@depesz.com MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, while researching some blogpost I found that we can make index on volatile functions. Tested this code: CREATE TABLE wiki_docs ( id INT8 generated always as identity PRIMARY KEY, title TEXT, body TEXT ); create function get_tsvector( IN the_row wiki_docs ) returns tsvector as $$ select setweight( to_tsvector('english', the_row.title), 'A') || setweight( to_tsvector('english', the_row.body), 'B'); $$ language sql; create index the_magic_gist on wiki_docs using gist( get_tsvector(wiki_docs) ); create index the_magic_gin on wiki_docs using gin( get_tsvector(wiki_docs) ); Ran it in in every Pg from 10 to 19, and it worked. postgres=# select provolatile from pg_proc where proname = 'get_tsvector'; provolatile ------------- v (1 row) Which seems to contradict part of https://www.postgresql.org/docs/18/sql-createindex.html which says: > All functions and operators used in an index definition must be > “immutable”, What am I misunderstanding and/or doing wrong? Best regards, depesz