ISN extension - wrong volatility level for isn_weak() function

Viktor Holmberg <v@viktorh.net>

From: Viktor Holmberg <v@viktorh.net>
To: pgsql-bugs@lists.postgresql.org
Date: 2025-03-14T11:49:06Z
Lists: pgsql-bugs

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. contrib/isn: Make weak mode a GUC setting, and fix related functions.

  2. Update contrib/seg for new scalarlesel/scalargesel selectivity functions.

Hello. Apologies if this is not the right place to bug report extensions, but I couldn’t find a better place. An at the very least I’d like to save someone a day of debugging this issue.

The isn_weak function in the isn extension reports the wrong value if you look at it inside a transaction:

BEGIN;

-- Prepare a statement for isn_weak():
PREPARE s_1 AS
 SELECT isn_weak() AS prepared_check;

-- First check - locks in the isn_weak value
EXECUTE s_1; -- => FALSE

-- Set isn_weak(true):
SELECT isn_weak(true) AS setting_true;

-- Check using normal query:
SELECT isn_weak() AS direct_check; -- => TRUE

EXECUTE s_1; -- => FALSE (!!!!)

This is because by default, that function is marked as immutable:

d6kpcv43m9du6> \df+ isn_weak
List of functions
─[ RECORD 1 ]───────┬──────────────────
Schema │ public
Name │ isn_weak
Result data type │ boolean
Argument data types │
Type │ func
Volatility │ immutable <————— bad
Parallel │ restricted
Owner │ postgres
Security │ invoker
Access privileges │
Language │ c
Internal name │ weak_input_status

I can manually fix this by changing it to STABLE:

ALTER FUNCTION isn_weak() STABLE;

Am I missing something or isn’t this quite weird? Would it at least be possible to change the documentation to explain this?

/Viktor Holmberg