Re: pg_trgm Memory Allocation logic

Поиск
Список
Период
Сортировка
От Heikki Linnakangas
Тема Re: pg_trgm Memory Allocation logic
Дата
Msg-id 54FDA007.1060303@iki.fi
обсуждение исходный текст
Ответ на Re: pg_trgm Memory Allocation logic  (Alvaro Herrera <alvherre@2ndquadrant.com>)
Список pgsql-hackers
On 03/09/2015 02:54 PM, Alvaro Herrera wrote:
> Beena Emerson wrote:
>> In the pg_trgm module, within function generate_trgm, the memory for trigrams
>> is allocated as follows:
>>
>> trg = (TRGM *) palloc(TRGMHDRSIZE + sizeof(trgm) * (slen / 2 + 1) *3);
>>
>> I have been trying to understand why this is so because it seems to be
>> allocating more space than that is required.
>
> Maybe it's considering a worst-case for multibyte characteres?  I don't
> really know if trgm supports multibyte, but I assume it does.  If it
> does, then probably the trigrams consist of chars, not bytes.

Nope. Trigrams are always three bytes, even ones containing multibyte 
characters. If there are any multibyte characters in the trigram, we 
store a 3-byte checksum of the three characters instead. That loses some 
information, you can have a collision where one multibyte trigram 
incorrectly matches another one, but the trigram algorithms are 
generally not too concerned about exact results.

- Heikki




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

Предыдущее
От: Alvaro Herrera
Дата:
Сообщение: Re: Object files generated by ecpg test suite not ignored on Windows
Следующее
От: Tom Lane
Дата:
Сообщение: Re: pg_trgm Memory Allocation logic