Re: Allow simplehash to use already-calculated hash values

From: Andres Freund <andres(at)anarazel(dot)de>
To: Jeff Davis <pgsql(at)j-davis(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Allow simplehash to use already-calculated hash values
Date: 2019-07-17 18:59:40
Message-ID: 20190717185940.jlxe5ksci6g7ttl2@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On 2019-07-17 11:17:46 -0700, Jeff Davis wrote:
> From a6aba8e53f7a36a42922add68098682c2c96683e Mon Sep 17 00:00:00 2001
> From: Jeff Davis <jdavis(at)postgresql(dot)org>
> Date: Wed, 17 Jul 2019 10:52:15 -0700
> Subject: [PATCH] Allow simplehash to use already-calculated hash values.
>
> Add _lookup_hash and _insert_hash functions for callers that have
> already calculated the hash value of the key.

I've not tested it, but this looks reasonable to me. Do you actually
need the lookup variant, or is that more for completeness?

> This is intended for use with hash algorithms that write to disk in
> partitions. The hash value can be calculated once, used to perform a
> lookup, used to select the partition, then written to the partition
> along with the tuple. When the tuple is read back, the hash value does
> not need to be recalculated.

nitpick^3: I'd s/This is intended for use/The immediate use-case is/

> +static inline SH_ELEMENT_TYPE *
> +SH_INSERT_HASH_INTERNAL(SH_TYPE * tb, SH_KEY_TYPE key, uint32 hash, bool *found)

I'd perhaps add a comment here along the lines of:

/*
* This is a separate static inline function, so it can be reliably be inlined
* into its wrapper functions even if SH_SCOPE is extern.
*/

Greetings,

Andres Freund

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2019-07-17 19:01:29 Re: Change ereport level for QueuePartitionConstraintValidation
Previous Message Darafei Komяpa Praliaskouski 2019-07-17 18:54:21 Unwanted expression simplification in PG12b2