Skip to content

Commit 66c029c

Browse files
committed
Fix volatility markings of some contrib I/O functions.
In general, datatype I/O functions are supposed to be immutable or at worst stable. Some contrib I/O functions were, through oversight, not marked with any volatility property at all, which made them VOLATILE. Since (most of) these functions actually behave immutably, the erroneous marking isn't terribly harmful; but it can be user-visible in certain circumstances, as per a recent bug report from Joe Van Dyk in which a cast to text was disallowed in an expression index definition. To fix, just adjust the declarations in the extension SQL scripts. If we were being very fussy about this, we'd bump the extension version numbers, but that seems like more trouble (for both developers and users) than the problem is worth. A fly in the ointment is that chkpass_in actually is volatile, because of its use of random() to generate a fresh salt when presented with a not-yet-encrypted password. This is bad because of the general assumption that I/O functions aren't volatile: the consequence is that records or arrays containing chkpass elements may have input behavior a bit different from a bare chkpass column. But there seems no way to fix this without breaking existing usage patterns for chkpass, and the consequences of the inconsistency don't seem bad enough to justify that. So for the moment, just document it in a comment. Since we're not bumping version numbers, there seems no harm in back-patching these fixes; at least future installations will get the functions marked correctly.
1 parent e809fa2 commit 66c029c

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

contrib/chkpass/chkpass--1.0.sql

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@
1010
CREATE FUNCTION chkpass_in(cstring)
1111
RETURNS chkpass
1212
AS 'MODULE_PATHNAME'
13-
LANGUAGE C STRICT;
13+
LANGUAGE C STRICT VOLATILE;
14+
-- Note: chkpass_in actually is volatile, because of its use of random().
15+
-- In hindsight that was a bad idea, but there's no way to change it without
16+
-- breaking some usage patterns.
1417

1518
CREATE FUNCTION chkpass_out(chkpass)
1619
RETURNS cstring
1720
AS 'MODULE_PATHNAME'
18-
LANGUAGE C STRICT;
21+
LANGUAGE C STRICT IMMUTABLE;
1922

2023
CREATE TYPE chkpass (
2124
internallength = 16,

contrib/ltree/ltree--1.0.sql

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
CREATE FUNCTION ltree_in(cstring)
77
RETURNS ltree
88
AS 'MODULE_PATHNAME'
9-
LANGUAGE C STRICT;
9+
LANGUAGE C STRICT IMMUTABLE;
1010

1111
CREATE FUNCTION ltree_out(ltree)
1212
RETURNS cstring
1313
AS 'MODULE_PATHNAME'
14-
LANGUAGE C STRICT;
14+
LANGUAGE C STRICT IMMUTABLE;
1515

1616
CREATE TYPE ltree (
1717
INTERNALLENGTH = -1,
@@ -303,12 +303,12 @@ CREATE OPERATOR CLASS ltree_ops
303303
CREATE FUNCTION lquery_in(cstring)
304304
RETURNS lquery
305305
AS 'MODULE_PATHNAME'
306-
LANGUAGE C STRICT;
306+
LANGUAGE C STRICT IMMUTABLE;
307307

308308
CREATE FUNCTION lquery_out(lquery)
309309
RETURNS cstring
310310
AS 'MODULE_PATHNAME'
311-
LANGUAGE C STRICT;
311+
LANGUAGE C STRICT IMMUTABLE;
312312

313313
CREATE TYPE lquery (
314314
INTERNALLENGTH = -1,
@@ -414,12 +414,12 @@ CREATE OPERATOR ^? (
414414
CREATE FUNCTION ltxtq_in(cstring)
415415
RETURNS ltxtquery
416416
AS 'MODULE_PATHNAME'
417-
LANGUAGE C STRICT;
417+
LANGUAGE C STRICT IMMUTABLE;
418418

419419
CREATE FUNCTION ltxtq_out(ltxtquery)
420420
RETURNS cstring
421421
AS 'MODULE_PATHNAME'
422-
LANGUAGE C STRICT;
422+
LANGUAGE C STRICT IMMUTABLE;
423423

424424
CREATE TYPE ltxtquery (
425425
INTERNALLENGTH = -1,
@@ -481,12 +481,12 @@ CREATE OPERATOR ^@ (
481481
CREATE FUNCTION ltree_gist_in(cstring)
482482
RETURNS ltree_gist
483483
AS 'MODULE_PATHNAME'
484-
LANGUAGE C STRICT;
484+
LANGUAGE C STRICT IMMUTABLE;
485485

486486
CREATE FUNCTION ltree_gist_out(ltree_gist)
487487
RETURNS cstring
488488
AS 'MODULE_PATHNAME'
489-
LANGUAGE C STRICT;
489+
LANGUAGE C STRICT IMMUTABLE;
490490

491491
CREATE TYPE ltree_gist (
492492
internallength = -1,

contrib/pg_trgm/pg_trgm--1.1.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ CREATE OPERATOR <-> (
5353
CREATE FUNCTION gtrgm_in(cstring)
5454
RETURNS gtrgm
5555
AS 'MODULE_PATHNAME'
56-
LANGUAGE C STRICT;
56+
LANGUAGE C STRICT IMMUTABLE;
5757

5858
CREATE FUNCTION gtrgm_out(gtrgm)
5959
RETURNS cstring
6060
AS 'MODULE_PATHNAME'
61-
LANGUAGE C STRICT;
61+
LANGUAGE C STRICT IMMUTABLE;
6262

6363
CREATE TYPE gtrgm (
6464
INTERNALLENGTH = -1,

0 commit comments

Comments
 (0)