Re: tsvector concatenation - backend crash

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: tsvector concatenation - backend crash
Дата
Msg-id 5397.1314392555@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: tsvector concatenation - backend crash  (jesper@krogh.cc)
Ответы Re: tsvector concatenation - backend crash  (Jesper Krogh <jesper@krogh.cc>)
Список pgsql-hackers
jesper@krogh.cc writes:
>> Attached SQL files gives (at least in my hands) a reliable backend crash
>> with this stacktrace .. reproduced on both 9.0.4 and HEAD. I'm sorry
>> I cannot provide a more trimmed down set of vectors the reproduces the
>> bug, thus
>> the "obsfucated" dataset. But even deleting single terms in the vectors
>> make the bug go away.

I found it.  tsvector_concat does this to compute the worst-case output
size needed:
/* conservative estimate of space needed */out = (TSVector) palloc0(VARSIZE(in1) + VARSIZE(in2));

Unfortunately, that's not really worst case: it could be that the output
will require more alignment padding bytes than the inputs did, if there
is a mix of lexemes with and without position data.  For example, if in1
contains one lexeme of odd length without position data, and in2
contains one lexeme of even length with position data (and no pad byte),
and in1's lexeme sorts before in2's, then we will need a pad byte in the
second lexeme where there was none before.

The core of the fix is to suppose that we might need a newly-added pad
byte for each lexeme:
out = (TSVector) palloc0(VARSIZE(in1) + VARSIZE(in2) + i1 + i2);

which really is an overestimate but I don't feel a need to be tenser
about it.  What I actually committed is a bit longer because I added
some comments and some Asserts ...

> Ok, I found 8.3.0 to be "good" so i ran a git bisect on it.. it gave
> me this commit:
> 
> e6dbcb72fafa4031c73cc914e829a6dec96ab6b6 is the first bad commit
> commit e6dbcb72fafa4031c73cc914e829a6dec96ab6b6
> Author: Tom Lane <tgl@sss.pgh.pa.us>
> Date:   Fri May 16 16:31:02 2008 +0000
> 
>     Extend GIN to support partial-match searches, and extend tsquery to
> support
>     prefix matching using this facility.

AFAICT this is a red herring: the bug exists all the way back to where
tsvector_concat was added, in 8.3.  I think the reason that your test
case happens to not crash before this commit is that it changed the sort
ordering rules for lexemes.  As you can see from my minimal example
above, we might need different numbers of pad bytes depending on how the
lexemes sort relative to each other.

Anyway, patch is committed; thanks for the report!
        regards, tom lane


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

Предыдущее
От: Daniel Farina
Дата:
Сообщение: Cryptic error message in low-memory conditions
Следующее
От: Tom Lane
Дата:
Сообщение: Re: pg_restore --no-post-data and --post-data-only