OSSP CVS Repository

ossp - Check-in [5399]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 5399
Date: 2006-May-11 20:32:07 (local)
2006-May-11 18:32:07 (UTC)
User:rse
Branch:
Comment: - Add Hash indexing support UUID data type of PostgreSQL bindings. - Add comparison operators and B-Tree indexing support UUID data type of PostgreSQL bindings.

Submitted by: Roman Neuhauser <neuhauser@sigpipe.cz>

Tickets:
#93 PGSQL API: b-tree ops for use in Primary Keys
Inspections:
Files:
ossp-pkg/uuid/ChangeLog      1.117 -> 1.118     7 inserted, 0 deleted
ossp-pkg/uuid/pgsql/uuid.c      1.3 -> 1.4     75 inserted, 1 deleted
ossp-pkg/uuid/pgsql/uuid.sql.in      1.3 -> 1.4     115 inserted, 10 deleted

ossp-pkg/uuid/ChangeLog 1.117 -> 1.118

--- ChangeLog    2006/05/11 17:44:42     1.117
+++ ChangeLog    2006/05/11 18:32:07     1.118
@@ -13,6 +13,13 @@
 
   Changes between 1.4.2 and 1.5.0 (13-Mar-2006 to XX-May-2006)
 
+   o Add Hash indexing support UUID data type of PostgreSQL bindings.
+     [Ralf S. Engelschall]
+
+   o Add comparison operators and B-Tree indexing support UUID data
+     type of PostgreSQL bindings.
+     [Roman Neuhauser <neuhauser@sigpipe.cz>]
+
    o Fix PHP bindings: the wrong argument to uuid_create()
      was forced to a reference
      [Roman Neuhauser <neuhauser@sigpipe.cz>]


ossp-pkg/uuid/pgsql/uuid.c 1.3 -> 1.4

--- uuid.c       2006/02/07 08:19:15     1.3
+++ uuid.c       2006/05/11 18:32:07     1.4
@@ -39,10 +39,11 @@
 /*  PostgreSQL (part 2/2) headers */
 #include "fmgr.h"
 #include "lib/stringinfo.h"
+#include "access/hash.h"
 
 /* internal UUID datum data structure */
 typedef struct {
-    char uuid_bin[UUID_LEN_BIN];
+    unsigned char uuid_bin[UUID_LEN_BIN];
 } uuid_datum_t;
 
 /* forward declarations */
@@ -50,9 +51,15 @@
 Datum pg_uuid_out    (PG_FUNCTION_ARGS);
 Datum pg_uuid_recv   (PG_FUNCTION_ARGS);
 Datum pg_uuid_send   (PG_FUNCTION_ARGS);
+Datum pg_uuid_hash   (PG_FUNCTION_ARGS);
 Datum pg_uuid_make   (PG_FUNCTION_ARGS);
 Datum pg_uuid_eq     (PG_FUNCTION_ARGS);
 Datum pg_uuid_ne     (PG_FUNCTION_ARGS);
+Datum pg_uuid_lt     (PG_FUNCTION_ARGS);
+Datum pg_uuid_gt     (PG_FUNCTION_ARGS);
+Datum pg_uuid_le     (PG_FUNCTION_ARGS);
+Datum pg_uuid_ge     (PG_FUNCTION_ARGS);
+Datum pg_uuid_cmp    (PG_FUNCTION_ARGS);
 
 /* API function: uuid_in */
 PG_FUNCTION_INFO_V1(pg_uuid_in);
@@ -323,6 +330,23 @@
     PG_RETURN_POINTER(uuid_datum);
 }
 
+/* API function: uuid_hash */
+PG_FUNCTION_INFO_V1(pg_uuid_hash);
+Datum pg_uuid_hash(PG_FUNCTION_ARGS)
+{
+    uuid_datum_t *uuid_datum;
+
+    /* sanity check input argument */
+    if ((uuid_datum = (uuid_datum_t *)PG_GETARG_POINTER(0)) == NULL) {
+        ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION),
+                errmsg("invalid UUID datum argument")));
+        PG_RETURN_NULL();
+    }
+
+    /* return hash value of the UUID */
+    PG_RETURN_INT32(hash_any(uuid_datum->uuid_bin, sizeof(uuid_datum->uuid_bin)));
+}
+
 /* INTERNAL function: _uuid_cmp */
 static int _uuid_cmp(PG_FUNCTION_ARGS)
 {
@@ -407,3 +431,53 @@
     PG_RETURN_BOOL(rc != 0);
 }
 
+/* API function: uuid_lt */
+PG_FUNCTION_INFO_V1(pg_uuid_lt);
+Datum pg_uuid_lt(PG_FUNCTION_ARGS)
+{
+    int rc;
+
+    rc = _uuid_cmp(fcinfo);
+    PG_RETURN_BOOL(rc == -1);
+}
+
+/* API function: uuid_gt */
+PG_FUNCTION_INFO_V1(pg_uuid_gt);
+Datum pg_uuid_gt(PG_FUNCTION_ARGS)
+{
+    int rc;
+
+    rc = _uuid_cmp(fcinfo);
+    PG_RETURN_BOOL(rc == 1);
+}
+
+/* API function: uuid_le */
+PG_FUNCTION_INFO_V1(pg_uuid_le);
+Datum pg_uuid_le(PG_FUNCTION_ARGS)
+{
+    int rc;
+
+    rc = _uuid_cmp(fcinfo);
+    PG_RETURN_BOOL(rc < 1);
+}
+
+/* API function: uuid_ge */
+PG_FUNCTION_INFO_V1(pg_uuid_ge);
+Datum pg_uuid_ge(PG_FUNCTION_ARGS)
+{
+    int rc;
+
+    rc = _uuid_cmp(fcinfo);
+    PG_RETURN_BOOL(rc > -1);
+}
+
+/* API function: uuid_cmp */
+PG_FUNCTION_INFO_V1(pg_uuid_cmp);
+Datum pg_uuid_cmp(PG_FUNCTION_ARGS)
+{
+    int rc;
+
+    rc = _uuid_cmp(fcinfo);
+    PG_RETURN_INT32(rc);
+}
+


ossp-pkg/uuid/pgsql/uuid.sql.in 1.3 -> 1.4

--- uuid.sql.in  2006/01/13 06:44:34     1.3
+++ uuid.sql.in  2006/05/11 18:32:07     1.4
@@ -33,16 +33,35 @@
 
 SET search_path TO public;
 
-DROP FUNCTION uuid_in(CSTRING)    CASCADE;
-DROP FUNCTION uuid_out(uuid)      CASCADE;
-DROP FUNCTION uuid_recv(INTERNAL) CASCADE;
-DROP FUNCTION uuid_send(uuid)     CASCADE;
-DROP TYPE     uuid                CASCADE;
-DROP FUNCTION uuid(uuid)          CASCADE;
-DROP FUNCTION uuid_eq(uuid)       CASCADE;
-DROP FUNCTION uuid_ne(uuid)       CASCADE;
-DROP OPERATOR =(uuid,uuid)        CASCADE;
-DROP OPERATOR <>(uuid,uuid)       CASCADE;
+DROP FUNCTION uuid_in(CSTRING)                    CASCADE;
+DROP FUNCTION uuid_out(uuid)                      CASCADE;
+DROP FUNCTION uuid_recv(INTERNAL)                 CASCADE;
+DROP FUNCTION uuid_send(uuid)                     CASCADE;
+DROP TYPE     uuid                                CASCADE;
+DROP CAST     (CSTRING AS uuid)                   CASCADE;
+DROP CAST     (uuid AS CSTRING)                   CASCADE;
+
+DROP FUNCTION uuid(CSTRING)                       CASCADE;
+DROP FUNCTION uuid(INTEGER)                       CASCADE;
+DROP FUNCTION uuid(INTEGER, CSTRING, CSTRING)     CASCADE;
+
+DROP FUNCTION uuid_eq(uuid)                       CASCADE;
+DROP FUNCTION uuid_ne(uuid)                       CASCADE;
+DROP FUNCTION uuid_lt(uuid, uuid)                 CASCADE;
+DROP FUNCTION uuid_gt(uuid, uuid)                 CASCADE;
+DROP FUNCTION uuid_le(uuid, uuid)                 CASCADE;
+DROP FUNCTION uuid_ge(uuid, uuid)                 CASCADE;
+DROP OPERATOR =(uuid,uuid)                        CASCADE;
+DROP OPERATOR <>(uuid,uuid)                       CASCADE;
+DROP OPERATOR <(uuid,uuid)                        CASCADE;
+DROP OPERATOR >(uuid,uuid)                        CASCADE;
+DROP OPERATOR <=(uuid,uuid)                       CASCADE;
+DROP OPERATOR >=(uuid,uuid)                       CASCADE;
+
+DROP FUNCTION uuid_hash(uuid)                     CASCADE;
+DROP FUNCTION uuid_cmp(uuid, uuid)                CASCADE;
+DROP OPERATOR CLASS uuid_ops USING hash           CASCADE;
+DROP OPERATOR CLASS uuid_ops USING btree          CASCADE;
 
 BEGIN;
 
@@ -83,6 +102,12 @@
 COMMENT ON TYPE uuid
     IS 'UUID type';
 
+CREATE CAST (CSTRING AS uuid)
+    WITH FUNCTION uuid_in(CSTRING) AS ASSIGNMENT;
+
+CREATE CAST (uuid AS CSTRING)
+    WITH FUNCTION uuid_out(uuid)   AS ASSIGNMENT;
+
 --
 --  the UUID constructor function
 --
@@ -116,6 +141,26 @@
     IMMUTABLE STRICT
     LANGUAGE C AS '@MODULE_PATHNAME@', 'pg_uuid_ne';
 
+CREATE FUNCTION
+    uuid_lt(uuid, uuid) RETURNS BOOL
+    IMMUTABLE STRICT
+    LANGUAGE C AS '@MODULE_PATHNAME@', 'pg_uuid_lt';
+
+CREATE FUNCTION
+    uuid_gt(uuid, uuid) RETURNS BOOL
+    IMMUTABLE STRICT
+    LANGUAGE C AS '@MODULE_PATHNAME@', 'pg_uuid_gt';
+
+CREATE FUNCTION
+    uuid_le(uuid, uuid) RETURNS BOOL
+    IMMUTABLE STRICT
+    LANGUAGE C AS '@MODULE_PATHNAME@', 'pg_uuid_le';
+
+CREATE FUNCTION
+    uuid_ge(uuid, uuid) RETURNS BOOL
+    IMMUTABLE STRICT
+    LANGUAGE C AS '@MODULE_PATHNAME@', 'pg_uuid_ge';
+
 CREATE OPERATOR = (
     leftarg    = uuid,
     rightarg   = uuid,
@@ -130,6 +175,66 @@
     procedure  = uuid_ne
 );
 
+CREATE OPERATOR < (
+    leftarg    = uuid,
+    rightarg   = uuid,
+    commutator = >,
+    negator    = >=,
+    procedure  = uuid_lt
+);
+
+CREATE OPERATOR > (
+    leftarg    = uuid,
+    rightarg   = uuid,
+    commutator = <,
+    negator    = <=,
+    procedure  = uuid_gt
+);
+
+CREATE OPERATOR <= (
+    leftarg    = uuid,
+    rightarg   = uuid,
+    commutator = >=,
+    negator    = >,
+    procedure  = uuid_le
+);
+
+CREATE OPERATOR >= (
+    leftarg    = uuid,
+    rightarg   = uuid,
+    commutator = <=,
+    negator    = <,
+    procedure  = uuid_ge
+);
+
+--
+--  the UUID support for indexing
+--
+
+CREATE FUNCTION
+    uuid_hash(uuid) RETURNS INTEGER
+    IMMUTABLE STRICT
+    LANGUAGE C AS '@MODULE_PATHNAME@', 'pg_uuid_hash';
+
+CREATE FUNCTION
+    uuid_cmp(uuid, uuid) RETURNS INTEGER
+    IMMUTABLE STRICT
+    LANGUAGE C AS '@MODULE_PATHNAME@', 'pg_uuid_cmp';
+
+CREATE OPERATOR CLASS uuid_ops
+    DEFAULT FOR TYPE uuid USING hash AS
+    OPERATOR 1 =,   -- 1: equal
+    FUNCTION 1 uuid_hash(uuid);
+
+CREATE OPERATOR CLASS uuid_ops
+    DEFAULT FOR TYPE uuid USING btree AS
+    OPERATOR 1 <,   -- 1: less than
+    OPERATOR 2 <=,  -- 2: less than or equal
+    OPERATOR 3 =,   -- 3: equal
+    OPERATOR 4 >=,  -- 4: greater than or equal
+    OPERATOR 5 >,   -- 5: greater than
+    FUNCTION 1 uuid_cmp(uuid, uuid);
+
 --
 --  epilog
 --

CVSTrac 2.0.1