From: Nathan Wagner Date: Tue, 23 Sep 2014 03:44:28 +0000 (+0000) Subject: mark functions as immutable X-Git-Url: https://pd.if.org/git/?p=uuid;a=commitdiff_plain;h=5394807cb2d9c07c8689d3f48c9b05d20c44beb4 mark functions as immutable Indexing on the result of a function doesn't work for volatile functions. This was preventing effective use of GIN indexes on uuid types in some circumstances. --- diff --git a/postgres/Makefile b/postgres/Makefile index 9c5b5d8..f18fad1 100644 --- a/postgres/Makefile +++ b/postgres/Makefile @@ -3,8 +3,7 @@ EXTENSION=pduuid MODULES= pduuid -DATA= pduuid--1.0.sql -#DOCS= README.uuid_ossp +DATA= pduuid--1.0.1.sql pduuid--1.0.sql pduuid--1.0--1.0.1.sql #SHLIB_LINK= -Lpduuid -lpduuid MODULE_big= pduuid OBJS= uuid.o ../internal.o ../rng.o ../md5.o ../sha1.o diff --git a/postgres/pduuid--1.0--1.0.1.sql b/postgres/pduuid--1.0--1.0.1.sql new file mode 100644 index 0000000..26057b0 --- /dev/null +++ b/postgres/pduuid--1.0--1.0.1.sql @@ -0,0 +1,9 @@ +alter function uuid_nil() immutable; +alter function uuid_ns_dns() immutable; +alter function uuid_ns_oid() immutable; +alter function uuid_ns_url() immutable; +alter function uuid_ns_x500() immutable; +alter function uuid_url(text) immutable; +alter function uuid_dns(text) immutable; +alter function uuid_oid(text) immutable; +alter function uuid_x500(text) immutable; diff --git a/postgres/pduuid--1.0.1.sql b/postgres/pduuid--1.0.1.sql new file mode 100644 index 0000000..beddb12 --- /dev/null +++ b/postgres/pduuid--1.0.1.sql @@ -0,0 +1,130 @@ +-- uuid support function install script +-- written by nathan wagner and placed in the public domain + +create function uuid_v1() returns uuid as 'pduuid', 'uuid_gen_v1' +language C strict; + +create function uuid_v1mc() returns uuid as 'pduuid', 'uuid_gen_v1_mc' +language C strict; + +create function uuid_v3(uuid, text) returns uuid +as 'pduuid', 'uuid_gen_v3' +language C strict; + +create function uuid_v4() returns uuid as 'pduuid', 'uuid_gen_v4' +language C strict; + +create function uuid_v5(uuid, text) returns uuid +as 'pduuid', 'uuid_gen_v5' +language C strict; + +create function uuid_recent() returns uuid as 'pduuid', 'uuid_recent' +language C strict; + +create function uuid_nil() returns uuid as 'pduuid', 'uuid_nil' +language C immutable strict; + +create function uuid_ns_dns() returns uuid as 'pduuid', 'uuid_dns' +language C immutable strict; + +create function uuid_ns_oid() returns uuid as 'pduuid', 'uuid_oid' +language C immutable strict; + +create function uuid_ns_url() returns uuid as 'pduuid', 'uuid_url' +language C immutable strict; + +create function uuid_ns_x500() returns uuid as 'pduuid', 'uuid_x500' +language C immutable strict; + +create function uuid_url(text) returns uuid as $$ +select uuid_v5(uuid_ns_url(), $1); +$$ +language 'sql' immutable strict; + +create function uuid_dns(text) returns uuid as $$ +select uuid_v5(uuid_ns_dns(), $1); +$$ +language 'sql' immutable strict; + +create function uuid_oid(text) returns uuid as $$ +select uuid_v5(uuid_ns_oid(), $1); +$$ +language 'sql' immutable strict; + +create function uuid_x500(text) returns uuid as $$ +select uuid_v5(uuid_ns_x500(), $1); +$$ +language 'sql' immutable strict; + +-- Casts + +-- Bytea + +create function uuid_bytea_cast(uuid) returns bytea as +'pduuid', 'uuid_cast_bytea' +language C strict; + +create function uuid_bytea_uncast(bytea) returns uuid as +'pduuid', 'uuid_cast_from_bytea' +language C strict; + +create cast (uuid as bytea) with function uuid_bytea_cast(uuid); + +create cast (bytea as uuid) with function uuid_bytea_uncast(bytea); + +-- Numeric + +create function uuid_numeric_cast(uuid) returns numeric as +'pduuid', 'uuid_cast_numeric' +language C strict; + +create function uuid_numeric_uncast(numeric) returns uuid as +'pduuid', 'uuid_cast_from_numeric' +language C strict; + +create cast (uuid as numeric) with function uuid_numeric_cast(uuid); + +create cast (numeric as uuid) with function uuid_numeric_uncast(numeric); + +-- Bit and bit varying + +create function uuid_bit_cast(uuid) returns bit(128) as +'pduuid', 'uuid_cast_bit' +language C strict; + +create function uuid_bit_uncast(bit(128)) returns uuid as +'pduuid', 'uuid_cast_from_bit' +language C strict; + +create cast (uuid as bit(128)) with function uuid_bit_cast(uuid); + +create cast (uuid as bit varying) with function uuid_bit_cast(uuid); + +create cast (bit(128) as uuid) with function uuid_bit_uncast(bit(128)); + +create cast (bit varying as uuid) with function uuid_bit_uncast(bit(128)); + +-- Field extraction functions + +create function uuid_version(uuid) returns integer as +'pduuid', 'uuid_extract_version' +language C strict; + +create function uuid_macaddr(uuid) returns macaddr as +'pduuid', 'uuid_extract_macaddr' +language C strict; + +create function uuid_timestamp(uuid) returns timestamp as +'pduuid', 'uuid_extract_timestamp' +language C strict; + +create function uuid_timestamptz(uuid) +returns timestamp with time zone as +'pduuid', 'uuid_extract_timestamp' +language C strict; + +-- TODO +-- cast to timestamp / extract timestamp +-- cast to macaddr / extract macaddr +-- extract variant +-- extract clock sequence diff --git a/postgres/pduuid.control b/postgres/pduuid.control index b49e728..65c37fc 100644 --- a/postgres/pduuid.control +++ b/postgres/pduuid.control @@ -1,4 +1,3 @@ relocatable = true comment = 'Public Domain uuid support functions' -default_version = '1.0' - +default_version = '1.0.1'