Re: Hashes from composite keys?

From: robur.6 6 <robur.6_at_gmail.com>
Date: Mon, 26 Jul 2010 04:09:22 -0700 (PDT)
Message-ID: <a14ffd86-9d70-434d-aa5d-067dab3f9ec3_at_w12g2000yqj.googlegroups.com>


On Jul 23, 11:14 pm, Karsten Wutzke <kwut..._at_web.de> wrote:
> Hello,
>
> what are the best practices for generating hash codes from composite
> keys? I need to mimic something like what a composite index does. In
> fact, it's for mapping between relational keys and object IDs.
>
> Can anyone point me into the right direction please?
>
> Karsten

Actually Bob gave you a great answer (in fact several of them). In short, what you want to achieve is mathematically impossible (well, not really impossible but pretty useless). Use any textbook to find the differences between a key (one-to-one) and a hash function. Even if you will eventually find an implementation on the net (or hints about) better stay away from it.

I will give you an example about how trying to be smart and ignoring the theory can ruin a project. Trying to fix an application that randomly failed to insert data, I discovered that a smart guy used a hash of several columns instead of a composite key. The motivation was the fact that different "records" have different key "fields" (yes, instances of different classes). This "smart" and "flexible" (agile?) solution "saved" a lot of developing time and database space, allowing a great boost of the department's KPI's. The only reasonable fix (such a terrible design could be corrected only by rewriting) was to replace the hash column with some concatenation of several columns.

PS: If you are curious about what happened to the smart developer, well, you can be sure he is not writing code anymore. Now he is the manager of the developing department... Received on Mon Jul 26 2010 - 13:09:22 CEST

Original text of this message