Changeset: 33fd055514de for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/33fd055514de
Modified Files:
        gdk/gdk_hash.c
        gdk/gdk_private.h
        gdk/gdk_utils.c
Branch: Jan2022
Log Message:

If the hash chain of the to-be-deleted value is longer than 1000, remove hash.
This fixes bug #7253.


diffs (62 lines):

diff --git a/gdk/gdk_hash.c b/gdk/gdk_hash.c
--- a/gdk/gdk_hash.c
+++ b/gdk/gdk_hash.c
@@ -1309,6 +1309,7 @@ HASHdelete_locked(BAT *b, BUN p, const v
                return;
        }
        bool seen = false;
+       BUN links = 0;
        for (;;) {
                if (!seen)
                        seen = atomcmp(v, BUNtail(bi, hb)) == 0;
@@ -1323,6 +1324,12 @@ HASHdelete_locked(BAT *b, BUN p, const v
                        break;
                }
                hb = hb2;
+               if (++links > HASH_DESTROY_CHAIN_LENGTH) {
+                       b->thash = NULL;
+                       doHASHdestroy(b, h);
+                       GDKclrerr();
+                       return;
+               }
        }
        h->heaplink.dirty = true;
        HASHputlink(h, hb, HASHgetlink(h, p));
diff --git a/gdk/gdk_private.h b/gdk/gdk_private.h
--- a/gdk/gdk_private.h
+++ b/gdk/gdk_private.h
@@ -476,6 +476,9 @@ extern BUN HASH_DESTROY_UNIQUES_FRACTION
 /* if the estimated number of unique values is less than 1 in this
  * number, don't build a hash table to do a hashselect */
 extern dbl NO_HASH_SELECT_FRACTION;           /* same here */
+/* if the hash chain is longer than this number, we delete the hash
+ * rather than maintaining it in HASHdelete */
+extern BUN HASH_DESTROY_CHAIN_LENGTH;
 
 #if !defined(NDEBUG) && !defined(__COVERITY__)
 /* see comment in gdk.h */
diff --git a/gdk/gdk_utils.c b/gdk/gdk_utils.c
--- a/gdk/gdk_utils.c
+++ b/gdk/gdk_utils.c
@@ -66,6 +66,9 @@ BUN HASH_DESTROY_UNIQUES_FRACTION = 1000
 /* if the estimated number of unique values is less than 1 in this
  * number, don't build a hash table to do a hashselect */
 dbl NO_HASH_SELECT_FRACTION = 1000;           /* same here */
+/* if the hash chain is longer than this number, we delete the hash
+ * rather than maintaining it in HASHdelete */
+BUN HASH_DESTROY_CHAIN_LENGTH = 1000;
 
 /*
  * @+ Monet configuration file
@@ -1169,6 +1172,11 @@ GDKinit(opt *set, int setlen, bool embed
                NO_HASH_SELECT_FRACTION = (dbl) strtoll(p, NULL, 10);
        if (NO_HASH_SELECT_FRACTION == 0)
                NO_HASH_SELECT_FRACTION = (dbl) 
GDK_UNIQUE_ESTIMATE_KEEP_FRACTION;
+       HASH_DESTROY_CHAIN_LENGTH = 0;
+       if ((p = GDKgetenv("hash_destroy_chain_length")) != NULL)
+               HASH_DESTROY_CHAIN_LENGTH = (BUN) strtoll(p, NULL, 10);
+       if (HASH_DESTROY_CHAIN_LENGTH == 0)
+               HASH_DESTROY_CHAIN_LENGTH = 1000;
 
        return GDK_SUCCEED;
 }
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to