Better debugging code, another bug fix.
authorRobert Haas <rhaas@postgresql.org>
Wed, 25 Jul 2012 14:12:06 +0000 (10:12 -0400)
committerRobert Haas <rhaas@postgresql.org>
Wed, 25 Jul 2012 14:12:06 +0000 (10:12 -0400)
contrib/hashtest/hashtest.c
src/backend/utils/hash/chash.c

index baa60493d3ff1004106153142d983af2051d839d..825f65e0cfceb8dd1d0b828e0a719274d2732b05 100644 (file)
@@ -67,48 +67,31 @@ test_dynahash(PG_FUNCTION_ARGS)
 Datum
 test_chash(PG_FUNCTION_ARGS)
 {
+       uint32  i;
        hentry  e;
-       bool    ok;
-
-       e.key = 1;
-       e.val = 0;
-       ok = CHashSearch(chash, &e);
-       if (ok)
-               elog(LOG, "search 1: found (value = %d)", e.val);
-       else
-               elog(LOG, "search 1: not found");
-
-       e.key = 1;
-       e.val = 2;
-       ok = CHashInsert(chash, &e);
-       if (ok)
-               elog(LOG, "insert 1: done");
-       else
-               elog(LOG, "insert 1: collision (value = %d)", e.val);
-
-       e.key = 1;
-       e.val = 0;
-       ok = CHashSearch(chash, &e);
-       if (ok)
-               elog(LOG, "search 1: found (value = %d)", e.val);
-       else
-               elog(LOG, "search 1: not found");
-
-       e.key = 1;
-       e.val = 3;
-       ok = CHashInsert(chash, &e);
-       if (ok)
-               elog(LOG, "insert 1: done");
-       else
-               elog(LOG, "insert 1: collision (value = %d)", e.val);
-
-       e.key = 1;
-       e.val = 0;
-       ok = CHashSearch(chash, &e);
-       if (ok)
-               elog(LOG, "search 1: found (value = %d)", e.val);
-       else
-               elog(LOG, "search 1: not found");
+
+       for (i = 0; i < 1000000; ++i)
+       {
+               bool ok;
+
+               e.key = i;
+               e.val = i * 31;
+               ok = CHashInsert(chash, &e);
+               if (!ok)
+                       elog(LOG, "insert %u: failed", i);
+       }
+
+       for (i = 0; i < 1000000; ++i)
+       {
+               bool ok;
+
+               e.key = i;
+               ok = CHashSearch(chash, &e);
+               if (!ok)
+                       elog(LOG, "search %u: not found", i);
+               else if (e.val != e.key * 31)
+                       elog(LOG, "search %u: found %u", i, e.val);
+       }
 
        PG_RETURN_VOID();
 }
index 2c003c72257035fef7915ddf11d5b797a3552e51..9053f4453905649fe25390d67477817db9407d4c 100644 (file)
@@ -694,6 +694,9 @@ CHashAllocate(CHashTable table)
                                return new;
                        }
                }
+
+               /* Advance to next freelist. */
+               f_current = (f_current + 1) % table->nfreelists;
        }
 }