From 66c029c842629958b3ae0d389f24ea3407225723 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 5 Nov 2014 11:34:11 -0500 Subject: [PATCH] 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. --- contrib/chkpass/chkpass--1.0.sql | 7 +++++-- contrib/ltree/ltree--1.0.sql | 16 ++++++++-------- contrib/pg_trgm/pg_trgm--1.1.sql | 4 ++-- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/contrib/chkpass/chkpass--1.0.sql b/contrib/chkpass/chkpass--1.0.sql index d1fbedc446..406a61924c 100644 --- a/contrib/chkpass/chkpass--1.0.sql +++ b/contrib/chkpass/chkpass--1.0.sql @@ -10,12 +10,15 @@ CREATE FUNCTION chkpass_in(cstring) RETURNS chkpass AS 'MODULE_PATHNAME' - LANGUAGE C STRICT; + LANGUAGE C STRICT VOLATILE; +-- Note: chkpass_in actually is volatile, because of its use of random(). +-- In hindsight that was a bad idea, but there's no way to change it without +-- breaking some usage patterns. CREATE FUNCTION chkpass_out(chkpass) RETURNS cstring AS 'MODULE_PATHNAME' - LANGUAGE C STRICT; + LANGUAGE C STRICT IMMUTABLE; CREATE TYPE chkpass ( internallength = 16, diff --git a/contrib/ltree/ltree--1.0.sql b/contrib/ltree/ltree--1.0.sql index 5a2f375a4f..7d55fc603f 100644 --- a/contrib/ltree/ltree--1.0.sql +++ b/contrib/ltree/ltree--1.0.sql @@ -6,12 +6,12 @@ CREATE FUNCTION ltree_in(cstring) RETURNS ltree AS 'MODULE_PATHNAME' -LANGUAGE C STRICT; +LANGUAGE C STRICT IMMUTABLE; CREATE FUNCTION ltree_out(ltree) RETURNS cstring AS 'MODULE_PATHNAME' -LANGUAGE C STRICT; +LANGUAGE C STRICT IMMUTABLE; CREATE TYPE ltree ( INTERNALLENGTH = -1, @@ -303,12 +303,12 @@ CREATE OPERATOR CLASS ltree_ops CREATE FUNCTION lquery_in(cstring) RETURNS lquery AS 'MODULE_PATHNAME' -LANGUAGE C STRICT; +LANGUAGE C STRICT IMMUTABLE; CREATE FUNCTION lquery_out(lquery) RETURNS cstring AS 'MODULE_PATHNAME' -LANGUAGE C STRICT; +LANGUAGE C STRICT IMMUTABLE; CREATE TYPE lquery ( INTERNALLENGTH = -1, @@ -414,12 +414,12 @@ CREATE OPERATOR ^? ( CREATE FUNCTION ltxtq_in(cstring) RETURNS ltxtquery AS 'MODULE_PATHNAME' -LANGUAGE C STRICT; +LANGUAGE C STRICT IMMUTABLE; CREATE FUNCTION ltxtq_out(ltxtquery) RETURNS cstring AS 'MODULE_PATHNAME' -LANGUAGE C STRICT; +LANGUAGE C STRICT IMMUTABLE; CREATE TYPE ltxtquery ( INTERNALLENGTH = -1, @@ -481,12 +481,12 @@ CREATE OPERATOR ^@ ( CREATE FUNCTION ltree_gist_in(cstring) RETURNS ltree_gist AS 'MODULE_PATHNAME' -LANGUAGE C STRICT; +LANGUAGE C STRICT IMMUTABLE; CREATE FUNCTION ltree_gist_out(ltree_gist) RETURNS cstring AS 'MODULE_PATHNAME' -LANGUAGE C STRICT; +LANGUAGE C STRICT IMMUTABLE; CREATE TYPE ltree_gist ( internallength = -1, diff --git a/contrib/pg_trgm/pg_trgm--1.1.sql b/contrib/pg_trgm/pg_trgm--1.1.sql index 1fff7af2c4..34b37e4787 100644 --- a/contrib/pg_trgm/pg_trgm--1.1.sql +++ b/contrib/pg_trgm/pg_trgm--1.1.sql @@ -53,12 +53,12 @@ CREATE OPERATOR <-> ( CREATE FUNCTION gtrgm_in(cstring) RETURNS gtrgm AS 'MODULE_PATHNAME' -LANGUAGE C STRICT; +LANGUAGE C STRICT IMMUTABLE; CREATE FUNCTION gtrgm_out(gtrgm) RETURNS cstring AS 'MODULE_PATHNAME' -LANGUAGE C STRICT; +LANGUAGE C STRICT IMMUTABLE; CREATE TYPE gtrgm ( INTERNALLENGTH = -1,