Commit cc988fbb authored by Tom Lane's avatar Tom Lane

Improve ResourceOwners' behavior for large numbers of owned objects.

The original coding was quite fast so long as objects were always
released in reverse order of addition; otherwise, it degenerated into
O(N^2) behavior due to searching for the array element to delete.
Improve matters by switching to hashed storage when the number of
objects of a given type exceeds 64.  (The cutover point is open to
discussion, of course, but some simple performance testing suggests
that hashing has enough overhead to be a loser below there.)

Also, refactor resowner.c so that we don't need N copies of the array
management code.  Since all the resource IDs the code currently needs
to deal with are either pointers or integers, it seems sufficient to
create a one-size-fits-all infrastructure in which everything is
converted to a Datum for storage.

Aleksander Alekseev, reviewed by Stas Kelvich, further fixes by me
parent 879d7139
...@@ -297,6 +297,9 @@ hashvarlena(PG_FUNCTION_ARGS) ...@@ -297,6 +297,9 @@ hashvarlena(PG_FUNCTION_ARGS)
* of 2. There is no need to do mod a prime (mod is sooo slow!). * of 2. There is no need to do mod a prime (mod is sooo slow!).
* If you need less than 32 bits, use a bitmask. * If you need less than 32 bits, use a bitmask.
* *
* This procedure must never throw elog(ERROR); the ResourceOwner code
* relies on this not to fail.
*
* Note: we could easily change this function to return a 64-bit hash value * Note: we could easily change this function to return a 64-bit hash value
* by using the final values of both b and c. b is perhaps a little less * by using the final values of both b and c. b is perhaps a little less
* well mixed than c, however. * well mixed than c, however.
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment