Documentation Home
MySQL NDB Cluster API Developer Guide
Download this Manual Ndb::computeHash()

Description.  This method can be used to compute a distribution hash value, given a table and its keys.


computeHash() can be used only for tables that use native NDB partitioning.


static int computeHash
      Uint32*                     hashvalueptr,
      const NdbDictionary::Table* table,
      const struct Key_part_ptr*  keyData,
      void*                       xfrmbuf = 0,
      Uint32                      xfrmbuflen = 0

Parameters.  This method takes the following parameters:

  • If the method call is successful, hashvalueptr is set to the computed hash value.

  • A pointer to a table (see Section 2.3.37, “The Table Class”).

  • keyData is a null-terminated array of pointers to the key parts that are part of the table's distribution key. The length of each key part is read from metadata and checked against the passed value (see Section 2.3.15, “The Key_part_ptr Structure”).

  • xfrmbuf is a pointer to temporary buffer used to calculate the hash value.

  • xfrmbuflen is the length of this buffer.


    If xfrmbuf is NULL (the default), then a call to malloc() or free() is made automatically, as appropriate. computeHash() fails if xfrmbuf is not NULL and xfrmbuflen is too small.

    Previously, it was assumed that the memory returned by the malloc() call would always be suitably aligned, which is not always the case. Beginning with NDB 7.3.2, when malloc() provides a buffer to this method, the buffer is explicitly aligned after it is allocated, and before it is actually used. (Bug #16484617)

Return value.  0 on success, an error code on failure. (If the method call succeeds, the computed hash value is made available via hashvalueptr.)