Re: Avoid overflow with simplehash

Поиск
Список
Период
Сортировка
От Ranier Vilela
Тема Re: Avoid overflow with simplehash
Дата
Msg-id CAEudQApjsFoXMVONZjpiW5ZxVwg+uNg2vNV-w8F0cEHnRBUm5w@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Avoid overflow with simplehash  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: Avoid overflow with simplehash  (Andres Freund <andres@anarazel.de>)
Список pgsql-hackers
Em qui., 6 de jul. de 2023 às 12:16, Tom Lane <tgl@sss.pgh.pa.us> escreveu:
Ranier Vilela <ranier.vf@gmail.com> writes:
> See the comments:
> "Search for the first empty element."
> If the empty element is not found, startelem has PG_UINT64_MAX value,
> which do not fit in uint32.

Hi Tom,
I think the point of that assertion is exactly that we're required to
have an empty element (because max fillfactor is less than 1),
so the search should have succeeded.

It does seem like we could do

        uint64          startelem = SH_MAX_SIZE;

        ...

        Assert(startelem < SH_MAX_SIZE);

which'd make it a little clearer that the expectation is for
startelem to have changed value.
I still have doubts about this.

see:
#include <iostream>
#include <string>
#include <limits.h>

#define SH_MAX_SIZE1 (((unsigned long long) 0xFFFFFFFFU) + 1)
#define SH_MAX_SIZE2 (((unsigned long long) 0xFFFFFFFFU) - 1)

int main()
{
    unsigned long long max_size1 = SH_MAX_SIZE1;
    unsigned long long max_size2 = SH_MAX_SIZE2;
    unsigned int cur1 = SH_MAX_SIZE1;
    unsigned int cur2 = SH_MAX_SIZE2;

    printf("SH_MAX_SIZE1=%llu\n", max_size1);
    printf("SH_MAX_SIZE2=%llu\n", max_size2);
    printf("cur1=%u\n", cur1);
    printf("cur2=%u\n", cur2);
}
warning: implicit conversion from 'unsigned long long' to 'unsigned int' changes value from 4294967296 to 0 [-Wconstant-conversion]

outputs:
SH_MAX_SIZE1=4294967296
SH_MAX_SIZE2=4294967294
cur1=0
cur2=4294967294

And in the comments we have:
"Iterate backwards, that allows the current element to be deleted, even
* if there are backward shifts"

So if an empty element is not found and the *cur* field is set to 0 (SH_MAX_SIZE -> uint32),
then will it iterate forwards?

  And I agree that declaring "i"
as int is wrong.
Thanks for the confirmation.

regards,
Ranier Vilela

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: Re: UUID v7
Следующее
От: Peter Eisentraut
Дата:
Сообщение: Re: Add more sanity checks around callers of changeDependencyFor()