Changeset: 7a4e53e8a05d for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=7a4e53e8a05d
Modified Files:
        gdk/gdk_hash.c
        monetdb5/modules/atoms/uuid.c
Branch: Jun2020
Log Message:

Don't make UUIDs go through a 32 bit bottleneck when calculating a hash.


diffs (73 lines):

diff --git a/gdk/gdk_hash.c b/gdk/gdk_hash.c
--- a/gdk/gdk_hash.c
+++ b/gdk/gdk_hash.c
@@ -97,7 +97,11 @@ HASHclear(Hash *h)
        memset(h->Bckt, 0xFF, h->nbucket * h->width);
 }
 
-#define HASH_VERSION           3
+#define HASH_VERSION           4
+/* this is only for the change of hash function of the UUID type; if
+ * HASH_VERSION is increased again from 4, the code associated with
+ * HASH_VERSION_NOUUID must be deleted */
+#define HASH_VERSION_NOUUID    3
 #define HASH_HEADER_SIZE       7       /* nr of size_t fields in header */
 
 static void
@@ -442,11 +446,21 @@ BATcheckhash(BAT *b)
                                        struct stat st;
 
                                        if (read(fd, hdata, sizeof(hdata)) == 
sizeof(hdata) &&
-                                           hdata[0] == (
+                                           (hdata[0] == (
 #ifdef PERSISTENTHASH
                                                    ((size_t) 1 << 24) |
 #endif
-                                                   HASH_VERSION) &&
+                                                   HASH_VERSION)
+#ifdef HASH_VERSION_NOUUID
+                                            /* if not uuid, also allow 
previous version */
+                                            || (hdata[0] == (
+#ifdef PERSISTENTHASH
+                                                        ((size_t) 1 << 24) |
+#endif
+                                                        HASH_VERSION_NOUUID) &&
+                                                strcmp(ATOMname(b->ttype), 
"uuid") != 0)
+#endif
+                                                   ) &&
                                            hdata[1] > 0 &&
                                            hdata[4] == (size_t) BATcount(b) &&
                                            fstat(fd, &st) == 0 &&
diff --git a/monetdb5/modules/atoms/uuid.c b/monetdb5/modules/atoms/uuid.c
--- a/monetdb5/modules/atoms/uuid.c
+++ b/monetdb5/modules/atoms/uuid.c
@@ -319,17 +319,19 @@ BUN
 UUIDhash(const void *v)
 {
        const uuid *u = (const uuid *) v;
-       unsigned int u1, u2, u3, u4;
+       ulng u1, u2;
 
-       u1 = (unsigned int) u->u[0] << 24 | (unsigned int) u->u[1] << 16 |
-               (unsigned int) u->u[2] << 8 | (unsigned int) u->u[3];
-       u2 = (unsigned int) u->u[4] << 24 | (unsigned int) u->u[5] << 16 |
-               (unsigned int) u->u[6] << 8 | (unsigned int) u->u[7];
-       u3 = (unsigned int) u->u[8] << 24 | (unsigned int) u->u[9] << 16 |
-               (unsigned int) u->u[10] << 8 | (unsigned int) u->u[11];
-       u4 = (unsigned int) u->u[12] << 24 | (unsigned int) u->u[13] << 16 |
-               (unsigned int) u->u[14] << 8 | (unsigned int) u->u[15];
-       return (BUN) mix_int(u1 ^ u2 ^ u3 ^ u4);
+       u1 = (ulng) u->u[0] << 56 | (ulng) u->u[1] << 48 |
+               (ulng) u->u[2] << 40 | (ulng) u->u[3] << 32 |
+               (ulng) u->u[4] << 24 | (ulng) u->u[5] << 16 |
+               (ulng) u->u[6] << 8 | (ulng) u->u[7];
+       u2 = (ulng) u->u[8] << 56 | (ulng) u->u[9] << 48 |
+               (ulng) u->u[10] << 40 | (ulng) u->u[11] << 32 |
+               (ulng) u->u[12] << 24 | (ulng) u->u[13] << 16 |
+               (ulng) u->u[14] << 8 | (ulng) u->u[15];
+       /* we're not using mix_hge since this we way get the same result
+        * on systems with and without 128 bit integer support */
+       return (BUN) (mix_lng(u1) ^ mix_lng(u2));
 }
 
 const uuid *
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to