Skip to content

Commit 8c49086

Browse files
committed
[PGPRO-8894] Correction of expression calculation for case recheckPhrase=true
1 parent c40b86e commit 8c49086

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ REGRESS = security rum rum_validate rum_hash ruminv timestamp orderby orderby_ha
3030
int2 int4 int8 float4 float8 money oid \
3131
time timetz date interval \
3232
macaddr inet cidr text varchar char bytea bit varbit \
33-
numeric rum_weight
33+
numeric rum_weight expr
3434

3535
TAP_TESTS = 1
3636

expected/expr.out

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
CREATE TABLE documents (
2+
en text not null,
3+
score float not null,
4+
textsearch_index_en_col tsvector
5+
);
6+
INSERT INTO documents VALUES ('the pet cat is in the shed', 56, to_tsvector('english', 'the pet cat is in the shed'));
7+
CREATE INDEX textsearch_index_en ON documents
8+
USING rum (textsearch_index_en_col rum_tsvector_addon_ops, score)
9+
WITH (attach = 'score', to = 'textsearch_index_en_col');
10+
SET enable_seqscan=off;
11+
-- should be 1 row
12+
SELECT * FROM documents WHERE textsearch_index_en_col @@ ('pet'::tsquery <-> ('dog'::tsquery || 'cat'::tsquery));
13+
en | score | textsearch_index_en_col
14+
----------------------------+-------+--------------------------
15+
the pet cat is in the shed | 56 | 'cat':3 'pet':2 'shed':7
16+
(1 row)
17+
18+
SET enable_seqscan=on;
19+
-- 1 row
20+
SELECT * FROM documents WHERE textsearch_index_en_col @@ ('pet'::tsquery <-> ('dog'::tsquery || 'cat'::tsquery));
21+
en | score | textsearch_index_en_col
22+
----------------------------+-------+--------------------------
23+
the pet cat is in the shed | 56 | 'cat':3 'pet':2 'shed':7
24+
(1 row)
25+
26+
DROP TABLE documents;

sql/expr.sql

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
CREATE TABLE documents (
2+
en text not null,
3+
score float not null,
4+
textsearch_index_en_col tsvector
5+
);
6+
7+
INSERT INTO documents VALUES ('the pet cat is in the shed', 56, to_tsvector('english', 'the pet cat is in the shed'));
8+
9+
CREATE INDEX textsearch_index_en ON documents
10+
USING rum (textsearch_index_en_col rum_tsvector_addon_ops, score)
11+
WITH (attach = 'score', to = 'textsearch_index_en_col');
12+
13+
SET enable_seqscan=off;
14+
-- should be 1 row
15+
SELECT * FROM documents WHERE textsearch_index_en_col @@ ('pet'::tsquery <-> ('dog'::tsquery || 'cat'::tsquery));
16+
17+
SET enable_seqscan=on;
18+
-- 1 row
19+
SELECT * FROM documents WHERE textsearch_index_en_col @@ ('pet'::tsquery <-> ('dog'::tsquery || 'cat'::tsquery));
20+
21+
DROP TABLE documents;

src/rum_ts_utils.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,14 @@ checkcondition_rum(void *checkval, QueryOperand *val, ExecPhraseData *data)
284284
* addInfo
285285
*/
286286
if (gcv->recheckPhrase)
287-
return ((val->weight) ? TS_MAYBE : TS_YES);
287+
{
288+
/*
289+
* We cannot return TS_YES here (if "val->weight > 0"), because
290+
* data->npos = 0 and we have incorrect porocessing of this result
291+
* at the upper levels. So return TS_MAYBE.
292+
*/
293+
return TS_MAYBE;
294+
}
288295

289296
positions = DatumGetByteaP(gcv->addInfo[j]);
290297
ptrt = (char *) VARDATA_ANY(positions);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy