| From: | hubert depesz lubaczewski <depesz(at)depesz(dot)com> |
|---|---|
| To: | PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org> |
| Subject: | Functions used by index don't need to be immutable? |
| Date: | 2025-11-11 12:35:22 |
| Message-ID: | aRMtismOfO86U9gS@depesz.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Heikki Linnakangas | 2025-11-11 12:43:18 | Re: Functions used by index don't need to be immutable? |
| Previous Message | Thomas Munro | 2025-11-11 03:39:17 | Re: [EXTERNAL]Re: BUG #19094: select statement on postgres 17 vs postgres 18 is returning different/duplicate results |