]> pd.if.org Git - uuid/commitdiff
mark functions as immutable
authorNathan Wagner <nw@hydaspes.if.org>
Tue, 23 Sep 2014 03:44:28 +0000 (03:44 +0000)
committerNathan Wagner <nw@hydaspes.if.org>
Tue, 23 Sep 2014 03:49:26 +0000 (03:49 +0000)
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.

postgres/Makefile
postgres/pduuid--1.0--1.0.1.sql [new file with mode: 0644]
postgres/pduuid--1.0.1.sql [new file with mode: 0644]
postgres/pduuid.control

index 9c5b5d8350c7d010e6c3ef066fac8030b770b9cd..f18fad167e5a851637a2e5d55d9eb47e0d4d9be1 100644 (file)
@@ -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 (file)
index 0000000..26057b0
--- /dev/null
@@ -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 (file)
index 0000000..beddb12
--- /dev/null
@@ -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
index b49e72844be24ada2ec4daca4d508003d16996d7..65c37fc7c3fb3e37dff68442fb40f95559414cc6 100644 (file)
@@ -1,4 +1,3 @@
 relocatable = true
 comment = 'Public Domain uuid support functions'
-default_version = '1.0'
-
+default_version = '1.0.1'