diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2020-05-07 15:59:52 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2020-05-07 15:59:52 -0400 |
commit | 7c9d9aa5ca2dd9b7661b2a2de75a3b963f3bc17c (patch) | |
tree | 82988cadb6b738aadc810026c3482750d077f0b8 /src/backend/utils/adt/tsvector_op.c | |
parent | 2bf56f50ebb0c9ce2416b27a640cf61488b5ed89 (diff) | |
download | postgresql-7c9d9aa5ca2dd9b7661b2a2de75a3b963f3bc17c.tar.gz postgresql-7c9d9aa5ca2dd9b7661b2a2de75a3b963f3bc17c.zip |
Fix YA text phrase search bug.
checkcondition_str() failed to report multiple matches for a prefix
pattern correctly: it would dutifully merge the match positions, but
then after exiting that loop, if the last prefix-matching word had
had no suitable positions, it would report there were no matches.
The upshot would be failing to recognize a match that the query
should match.
It looks like you need all of these conditions to see the bug:
* a phrase search (else we don't ask for match position details)
* a prefix search item (else we don't get to this code)
* a weight restriction (else checkclass_str won't fail)
Noted while investigating a problem report from Pavel Borisov,
though this is distinct from the issue he was on about.
Back-patch to 9.6 where phrase search was added.
Diffstat (limited to 'src/backend/utils/adt/tsvector_op.c')
-rw-r--r-- | src/backend/utils/adt/tsvector_op.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/backend/utils/adt/tsvector_op.c b/src/backend/utils/adt/tsvector_op.c index d571b93ddb8..5dc988f139b 100644 --- a/src/backend/utils/adt/tsvector_op.c +++ b/src/backend/utils/adt/tsvector_op.c @@ -1326,12 +1326,13 @@ checkcondition_str(void *checkval, QueryOperand *val, ExecPhraseData *data) WordEntry *StopLow = chkval->arrb; WordEntry *StopHigh = chkval->arre; WordEntry *StopMiddle = StopHigh; - int difference = -1; bool res = false; /* Loop invariant: StopLow <= val < StopHigh */ while (StopLow < StopHigh) { + int difference; + StopMiddle = StopLow + (StopHigh - StopLow) / 2; difference = tsCompareString(chkval->operand + val->distance, val->length, @@ -1397,6 +1398,11 @@ checkcondition_str(void *checkval, QueryOperand *val, ExecPhraseData *data) memcpy(allpos + npos, data->pos, sizeof(WordEntryPos) * data->npos); npos += data->npos; } + else + { + /* at loop exit, res must be true if we found matches */ + res = (npos > 0); + } } else { |