Skip to content

Commit e704e3c

Browse files
author
Mikhail Kharitonov
committed
[PGPRO-11480] Fix RUM tsquery evaluation with negated subtrees
Tags: rum
1 parent cbf80ab commit e704e3c

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

expected/ruminv.out

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ INSERT INTO test_invrum VALUES ('(a|b)&c'::tsquery);
99
INSERT INTO test_invrum VALUES ('(!(a|b))&c'::tsquery);
1010
INSERT INTO test_invrum VALUES ('(a|b)&(c|d)'::tsquery);
1111
INSERT INTO test_invrum VALUES ('!a'::tsquery);
12+
INSERT INTO test_invrum VALUES ('a&!(b&c)'::tsquery);
1213
INSERT INTO test_invrum VALUES ('(a|a1|a2|a3|a4|a5)&(b|b1|b2|b3|b4|b5|b6)&!(c|c1|c2|c3)'::tsquery);
1314
SELECT * FROM test_invrum WHERE q @@ ''::tsvector;
1415
q
@@ -20,12 +21,13 @@ SELECT * FROM test_invrum WHERE q @@ ''::tsvector;
2021
(4 rows)
2122

2223
SELECT * FROM test_invrum WHERE q @@ 'a'::tsvector;
23-
q
24-
----------------
24+
q
25+
----------------------
2526
'a' | 'b'
2627
!( 'a' & 'b' )
2728
'a' & !'b'
28-
(3 rows)
29+
'a' & !( 'b' & 'c' )
30+
(4 rows)
2931

3032
SELECT * FROM test_invrum WHERE q @@ 'b'::tsvector;
3133
q
@@ -42,8 +44,9 @@ SELECT * FROM test_invrum WHERE q @@ 'a b'::tsvector;
4244
'a' | 'b'
4345
'a' & 'b'
4446
!'a' | 'b'
47+
'a' & !( 'b' & 'c' )
4548
( 'a' | 'a1' | 'a2' | 'a3' | 'a4' | 'a5' ) & ( 'b' | 'b1' | 'b2' | 'b3' | 'b4' | 'b5' | 'b6' ) & !( 'c' | 'c1' | 'c2' | 'c3' )
46-
(4 rows)
49+
(5 rows)
4750

4851
SELECT * FROM test_invrum WHERE q @@ 'c'::tsvector;
4952
q
@@ -63,7 +66,8 @@ SELECT * FROM test_invrum WHERE q @@ 'a c'::tsvector;
6366
'a' & !'b'
6467
( 'a' | 'b' ) & 'c'
6568
( 'a' | 'b' ) & ( 'c' | 'd' )
66-
(5 rows)
69+
'a' & !( 'b' & 'c' )
70+
(6 rows)
6771

6872
SELECT * FROM test_invrum WHERE q @@ 'b c'::tsvector;
6973
q
@@ -102,7 +106,8 @@ SELECT * FROM test_invrum WHERE q @@ 'a d'::tsvector;
102106
!( 'a' & 'b' )
103107
'a' & !'b'
104108
( 'a' | 'b' ) & ( 'c' | 'd' )
105-
(4 rows)
109+
'a' & !( 'b' & 'c' )
110+
(5 rows)
106111

107112
SELECT * FROM test_invrum WHERE q @@ 'b d'::tsvector;
108113
q
@@ -121,8 +126,9 @@ SELECT * FROM test_invrum WHERE q @@ 'a b d'::tsvector;
121126
'a' & 'b'
122127
!'a' | 'b'
123128
( 'a' | 'b' ) & ( 'c' | 'd' )
129+
'a' & !( 'b' & 'c' )
124130
( 'a' | 'a1' | 'a2' | 'a3' | 'a4' | 'a5' ) & ( 'b' | 'b1' | 'b2' | 'b3' | 'b4' | 'b5' | 'b6' ) & !( 'c' | 'c1' | 'c2' | 'c3' )
125-
(5 rows)
131+
(6 rows)
126132

127133
SELECT * FROM test_invrum WHERE q @@ 'c d'::tsvector;
128134
q
@@ -142,7 +148,8 @@ SELECT * FROM test_invrum WHERE q @@ 'a c d'::tsvector;
142148
'a' & !'b'
143149
( 'a' | 'b' ) & 'c'
144150
( 'a' | 'b' ) & ( 'c' | 'd' )
145-
(5 rows)
151+
'a' & !( 'b' & 'c' )
152+
(6 rows)
146153

147154
CREATE INDEX test_invrum_idx ON test_invrum USING rum(q);
148155
SET enable_seqscan = OFF;
@@ -152,12 +159,13 @@ SELECT * FROM test_invrum WHERE q @@ ''::tsvector;
152159
(0 rows)
153160

154161
SELECT * FROM test_invrum WHERE q @@ 'a'::tsvector;
155-
q
156-
----------------
162+
q
163+
----------------------
157164
'a' | 'b'
158165
!( 'a' & 'b' )
159166
'a' & !'b'
160-
(3 rows)
167+
'a' & !( 'b' & 'c' )
168+
(4 rows)
161169

162170
SELECT * FROM test_invrum WHERE q @@ 'b'::tsvector;
163171
q
@@ -216,7 +224,8 @@ SELECT * FROM test_invrum WHERE q @@ 'a b c'::tsvector;
216224
!'a' | 'b'
217225
( 'a' | 'b' ) & 'c'
218226
( 'a' | 'b' ) & ( 'c' | 'd' )
219-
(5 rows)
227+
'a' & !( 'b' & 'c' )
228+
(6 rows)
220229

221230
SELECT * FROM test_invrum WHERE q @@ 'd'::tsvector;
222231
q
@@ -234,7 +243,8 @@ SELECT * FROM test_invrum WHERE q @@ 'a d'::tsvector;
234243
!( 'a' & 'b' )
235244
'a' & !'b'
236245
( 'a' | 'b' ) & ( 'c' | 'd' )
237-
(4 rows)
246+
'a' & !( 'b' & 'c' )
247+
(5 rows)
238248

239249
SELECT * FROM test_invrum WHERE q @@ 'b d'::tsvector;
240250
q

sql/ruminv.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ INSERT INTO test_invrum VALUES ('(a|b)&c'::tsquery);
1010
INSERT INTO test_invrum VALUES ('(!(a|b))&c'::tsquery);
1111
INSERT INTO test_invrum VALUES ('(a|b)&(c|d)'::tsquery);
1212
INSERT INTO test_invrum VALUES ('!a'::tsquery);
13+
INSERT INTO test_invrum VALUES ('a&!(b&c)'::tsquery);
1314
INSERT INTO test_invrum VALUES ('(a|a1|a2|a3|a4|a5)&(b|b1|b2|b3|b4|b5|b6)&!(c|c1|c2|c3)'::tsquery);
1415

1516
SELECT * FROM test_invrum WHERE q @@ ''::tsvector;

src/rumtsquery.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ make_query_item_wrap(QueryItem *item, QueryItemWrap *parent, bool not)
9494

9595
wrap->type = QI_OPR;
9696
wrap->oper = oper;
97+
wrap->not = not;
9798

9899
make_query_item_wrap(item + item->qoperator.left, wrap, not);
99100
make_query_item_wrap(item + 1, wrap, not);

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