Re: pgsql: Introduce hash_search_with_hash_value() function - Mailing list pgsql-committers

From Alexander Korotkov
Subject Re: pgsql: Introduce hash_search_with_hash_value() function
Date
Msg-id CAPpHfdvJf0pFJuvx4JPmdGjLOwxg4_9Q1up2JUYkuyar9GZu7g@mail.gmail.com
Whole thread Raw
In response to Re: pgsql: Introduce hash_search_with_hash_value() function  (Pavel Stehule <pavel.stehule@gmail.com>)
Responses Re: pgsql: Introduce hash_search_with_hash_value() function
List pgsql-committers
On Wed, Aug 7, 2024 at 1:03 PM Pavel Stehule <pavel.stehule@gmail.com> wrote:
>
> st 7. 8. 2024 v 10:52 odesílatel Alexander Korotkov <aekorotkov@gmail.com> napsal:
>>
>> Hi, Pavel!
>>
>> On Wed, Aug 7, 2024 at 9:35 AM Pavel Stehule <pavel.stehule@gmail.com> wrote:
>> > st 7. 8. 2024 v 6:08 odesílatel Alexander Korotkov <akorotkov@postgresql.org> napsal:
>> >>
>> >> Introduce hash_search_with_hash_value() function
>> >>
>> >> This new function iterates hash entries with given hash values.  This function
>> >> is designed to avoid full sequential hash search in the syscache invalidation
>> >> callbacks.
>> >>
>> >> Discussion: https://postgr.es/m/5812a6e5-68ae-4d84-9d85-b443176966a1%40sigaev.ru
>> >> Author: Teodor Sigaev
>> >> Reviewed-by: Aleksander Alekseev, Tom Lane, Michael Paquier, Roman Zharkov
>> >> Reviewed-by: Andrei Lepikhov
>> >
>> >
>> > I tried to use hash_seq_init_with_hash_value in session variables patch, but it doesn't work there.
>> >
>> > <-->if (!sessionvars)
>> > <--><-->return;
>> >
>> > elog(NOTICE, "%u", hashvalue);
>> >
>> >
>> > <-->hash_seq_init(&status, sessionvars);
>> >
>> > <-->while ((svar = (SVariable) hash_seq_search(&status)) != NULL)
>> > <-->{
>> > <--><-->if (hashvalue == 0 || svar->hashvalue == hashvalue)
>> > <--><-->{
>> > <--><--><-->elog(NOTICE, "FOUND OLD");
>> > <--><--><-->svar->is_valid = false;
>> > <--><-->}
>> > <-->}
>> >
>> >
>> >
>> > <-->/*
>> > <--> * If the hashvalue is not specified, we have to recheck all currently
>> > <--> * used session variables.  Since we can't tell the exact session variable
>> > <--> * from its hashvalue, we have to iterate over all items in the hash bucket.
>> > <--> */
>> > <-->if (hashvalue == 0)
>> > <--><-->hash_seq_init(&status, sessionvars);
>> > <-->else
>> > <--><-->hash_seq_init_with_hash_value(&status, sessionvars, hashvalue);
>> >
>> > <-->while ((svar = (SVariable) hash_seq_search(&status)) != NULL)
>> > <-->{
>> > <--><-->Assert(hashvalue == 0 || svar->hashvalue == hashvalue);
>> >
>> > elog(NOTICE, "found");
>> >
>> > <--><-->svar->is_valid = false;
>> > <--><-->needs_validation = true;
>> > <-->}
>> > }
>> >
>> > Old methods found an entry, but new not.
>> >
>> > What am I doing wrong?
>>
>> I'm trying to check this.  Applying this patch [1], but got conflicts.
>> Could you please, rebase the patch, so I can recheck the issue?
>
> I sent rebased patchset


Thank you.
Please see 40064a8ee1 takes special efforts to match HTAB hash
function to syscache hash function.  By default, their hash values
don't match and you can't simply use syscache hash value to search
HTAB.  This probably should be mentioned in the header comment of
hash_seq_init_with_hash_value().

------
Regards,
Alexander Korotkov
Supabase



pgsql-committers by date:

Previous
From: Pavel Stehule
Date:
Subject: Re: pgsql: Introduce hash_search_with_hash_value() function
Next
From: Pavel Stehule
Date:
Subject: Re: pgsql: Introduce hash_search_with_hash_value() function