Skip to content

Commit 376610b

Browse files
author
Artur Zakirov
committed
A lot of fixes from Teodor Sigaev and Alexander Korotkov
1 parent 8b0dbc0 commit 376610b

26 files changed

+2869
-126
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.deps
2+
*.o
3+
*.so
4+
results

Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
# contrib/rum/Makefile
22

33
MODULE_big = rum
4-
OBJS = rumsort.o rum_ts_utils.o \
4+
OBJS = rumsort.o rum_ts_utils.o rumtsquery.o \
55
rumbtree.o rumbulk.o rumdatapage.o \
66
rumentrypage.o rumfast.o rumget.o ruminsert.o \
7-
rumscan.o rumutil.o rumvacuum.o rumvalidate.o $(WIN32RES)
7+
rumscan.o rumutil.o rumvacuum.o rumvalidate.o \
8+
rum_timestamp.o $(WIN32RES)
89

910
EXTENSION = rum
1011
DATA = rum--1.0.sql
1112
PGFILEDESC = "RUM index access method"
1213

13-
REGRESS = rum
14+
REGRESS = rum ruminv timestamp orderby
1415

1516
ifdef USE_PGXS
1617
PG_CONFIG = pg_config

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ CREATE INDEX rumidx ON test_rum USING rum (a rum_tsvector_ops);
6767
And we can execute the following queries:
6868

6969
```sql
70-
=> SELECT t, a >< to_tsquery('english', 'beautiful | place') AS rank FROM test_rum WHERE a @@ to_tsquery('english', 'beautiful | place') order by a >< to_tsquery('english', 'beautiful | place');
70+
=# SELECT t, a >< to_tsquery('english', 'beautiful | place') AS rank FROM test_rum WHERE a @@ to_tsquery('english', 'beautiful | place') order by a >< to_tsquery('english', 'beautiful | place');
7171
t | rank
7272
---------------------------------+-----------
7373
The situation is most beautiful | 0.0303964
7474
It is a beautiful | 0.0303964
7575
It looks like a beautiful place | 0.0607927
7676
(3 rows)
7777

78-
=> SELECT t, a >< to_tsquery('english', 'place | situation') AS rank FROM test_rum WHERE a @@ to_tsquery('english', 'place | situation') order by a >< to_tsquery('english', 'place | situation');
78+
=# SELECT t, a >< to_tsquery('english', 'place | situation') AS rank FROM test_rum WHERE a @@ to_tsquery('english', 'place | situation') order by a >< to_tsquery('english', 'place | situation');
7979
t | rank
8080
---------------------------------+-----------
8181
The situation is most beautiful | 0.0303964

data/tsts.data

Lines changed: 508 additions & 0 deletions
Large diffs are not rendered by default.

expected/orderby.out

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
CREATE TABLE tsts (id int, t tsvector, d timestamp);
2+
\copy tsts from 'data/tsts.data'
3+
CREATE INDEX tsts_idx ON tsts USING rum (t rum_tsvector_timestamp_ops, d)
4+
WITH (orderby = 'd', addto = 't');
5+
INSERT INTO tsts VALUES (-1, 't1 t2', '2016-05-02 02:24:22.326724');
6+
INSERT INTO tsts VALUES (-2, 't1 t2 t3', '2016-05-02 02:26:22.326724');
7+
SELECT count(*) FROM tsts WHERE t @@ 'wr|qh';
8+
count
9+
-------
10+
158
11+
(1 row)
12+
13+
SELECT count(*) FROM tsts WHERE t @@ 'wr&qh';
14+
count
15+
-------
16+
17
17+
(1 row)
18+
19+
SELECT count(*) FROM tsts WHERE t @@ 'eq&yt';
20+
count
21+
-------
22+
6
23+
(1 row)
24+
25+
SELECT count(*) FROM tsts WHERE t @@ 'eq|yt';
26+
count
27+
-------
28+
98
29+
(1 row)
30+
31+
SELECT count(*) FROM tsts WHERE t @@ '(eq&yt)|(wr&qh)';
32+
count
33+
-------
34+
23
35+
(1 row)
36+
37+
SELECT count(*) FROM tsts WHERE t @@ '(eq|yt)&(wr|qh)';
38+
count
39+
-------
40+
39
41+
(1 row)
42+
43+
SET enable_indexscan=OFF;
44+
SET enable_indexonlyscan=OFF;
45+
SET enable_bitmapscan=OFF;
46+
SELECT id, d, d <-> '2016-05-16 14:21:25' FROM tsts WHERE t @@ 'wr&qh' ORDER BY d <-> '2016-05-16 14:21:25' LIMIT 5;
47+
id | d | ?column?
48+
-----+---------------------------------+---------------
49+
355 | Mon May 16 14:21:22.326724 2016 | 2.673276
50+
354 | Mon May 16 13:21:22.326724 2016 | 3602.673276
51+
371 | Tue May 17 06:21:22.326724 2016 | 57597.326724
52+
406 | Wed May 18 17:21:22.326724 2016 | 183597.326724
53+
415 | Thu May 19 02:21:22.326724 2016 | 215997.326724
54+
(5 rows)
55+
56+
SELECT id, d, d <-| '2016-05-16 14:21:25' FROM tsts WHERE t @@ 'wr&qh' ORDER BY d <-| '2016-05-16 14:21:25' LIMIT 5;
57+
id | d | ?column?
58+
-----+---------------------------------+---------------
59+
355 | Mon May 16 14:21:22.326724 2016 | 2.673276
60+
354 | Mon May 16 13:21:22.326724 2016 | 3602.673276
61+
252 | Thu May 12 07:21:22.326724 2016 | 370802.673276
62+
232 | Wed May 11 11:21:22.326724 2016 | 442802.673276
63+
168 | Sun May 08 19:21:22.326724 2016 | 673202.673276
64+
(5 rows)
65+
66+
SELECT id, d, d |-> '2016-05-16 14:21:25' FROM tsts WHERE t @@ 'wr&qh' ORDER BY d |-> '2016-05-16 14:21:25' LIMIT 5;
67+
id | d | ?column?
68+
-----+---------------------------------+---------------
69+
371 | Tue May 17 06:21:22.326724 2016 | 57597.326724
70+
406 | Wed May 18 17:21:22.326724 2016 | 183597.326724
71+
415 | Thu May 19 02:21:22.326724 2016 | 215997.326724
72+
428 | Thu May 19 15:21:22.326724 2016 | 262797.326724
73+
457 | Fri May 20 20:21:22.326724 2016 | 367197.326724
74+
(5 rows)
75+
76+
RESET enable_indexscan;
77+
RESET enable_indexonlyscan;
78+
RESET enable_bitmapscan;
79+
SET enable_seqscan = off;
80+
EXPLAIN (costs off)
81+
SELECT count(*) FROM tsts WHERE t @@ 'wr|qh';
82+
QUERY PLAN
83+
-------------------------------------------------------------
84+
Aggregate
85+
-> Bitmap Heap Scan on tsts
86+
Recheck Cond: (t @@ '''wr'' | ''qh'''::tsquery)
87+
-> Bitmap Index Scan on tsts_idx
88+
Index Cond: (t @@ '''wr'' | ''qh'''::tsquery)
89+
(5 rows)
90+
91+
SELECT count(*) FROM tsts WHERE t @@ 'wr|qh';
92+
count
93+
-------
94+
158
95+
(1 row)
96+
97+
SELECT count(*) FROM tsts WHERE t @@ 'wr&qh';
98+
count
99+
-------
100+
17
101+
(1 row)
102+
103+
SELECT count(*) FROM tsts WHERE t @@ 'eq&yt';
104+
count
105+
-------
106+
6
107+
(1 row)
108+
109+
SELECT count(*) FROM tsts WHERE t @@ 'eq|yt';
110+
count
111+
-------
112+
98
113+
(1 row)
114+
115+
SELECT count(*) FROM tsts WHERE t @@ '(eq&yt)|(wr&qh)';
116+
count
117+
-------
118+
23
119+
(1 row)
120+
121+
SELECT count(*) FROM tsts WHERE t @@ '(eq|yt)&(wr|qh)';
122+
count
123+
-------
124+
39
125+
(1 row)
126+
127+
EXPLAIN (costs off)
128+
SELECT id, d, d <-> '2016-05-16 14:21:25' FROM tsts WHERE t @@ 'wr&qh' ORDER BY d <-> '2016-05-16 14:21:25' LIMIT 5;
129+
QUERY PLAN
130+
-----------------------------------------------------------------------------------
131+
Limit
132+
-> Index Scan using tsts_idx on tsts
133+
Index Cond: (t @@ '''wr'' & ''qh'''::tsquery)
134+
Order By: (d <-> 'Mon May 16 14:21:25 2016'::timestamp without time zone)
135+
(4 rows)
136+
137+
SELECT id, d, d <-> '2016-05-16 14:21:25' FROM tsts WHERE t @@ 'wr&qh' ORDER BY d <-> '2016-05-16 14:21:25' LIMIT 5;
138+
id | d | ?column?
139+
-----+---------------------------------+---------------
140+
355 | Mon May 16 14:21:22.326724 2016 | 2.673276
141+
354 | Mon May 16 13:21:22.326724 2016 | 3602.673276
142+
371 | Tue May 17 06:21:22.326724 2016 | 57597.326724
143+
406 | Wed May 18 17:21:22.326724 2016 | 183597.326724
144+
415 | Thu May 19 02:21:22.326724 2016 | 215997.326724
145+
(5 rows)
146+
147+
EXPLAIN (costs off)
148+
SELECT id, d, d <-| '2016-05-16 14:21:25' FROM tsts WHERE t @@ 'wr&qh' ORDER BY d <-| '2016-05-16 14:21:25' LIMIT 5;
149+
QUERY PLAN
150+
-----------------------------------------------------------------------------------
151+
Limit
152+
-> Index Scan using tsts_idx on tsts
153+
Index Cond: (t @@ '''wr'' & ''qh'''::tsquery)
154+
Order By: (d <-| 'Mon May 16 14:21:25 2016'::timestamp without time zone)
155+
(4 rows)
156+
157+
SELECT id, d, d <-| '2016-05-16 14:21:25' FROM tsts WHERE t @@ 'wr&qh' ORDER BY d <-| '2016-05-16 14:21:25' LIMIT 5;
158+
id | d | ?column?
159+
-----+---------------------------------+---------------
160+
355 | Mon May 16 14:21:22.326724 2016 | 2.673276
161+
354 | Mon May 16 13:21:22.326724 2016 | 3602.673276
162+
252 | Thu May 12 07:21:22.326724 2016 | 370802.673276
163+
232 | Wed May 11 11:21:22.326724 2016 | 442802.673276
164+
168 | Sun May 08 19:21:22.326724 2016 | 673202.673276
165+
(5 rows)
166+
167+
EXPLAIN (costs off)
168+
SELECT id, d, d |-> '2016-05-16 14:21:25' FROM tsts WHERE t @@ 'wr&qh' ORDER BY d |-> '2016-05-16 14:21:25' LIMIT 5;
169+
QUERY PLAN
170+
-----------------------------------------------------------------------------------
171+
Limit
172+
-> Index Scan using tsts_idx on tsts
173+
Index Cond: (t @@ '''wr'' & ''qh'''::tsquery)
174+
Order By: (d |-> 'Mon May 16 14:21:25 2016'::timestamp without time zone)
175+
(4 rows)
176+
177+
SELECT id, d, d |-> '2016-05-16 14:21:25' FROM tsts WHERE t @@ 'wr&qh' ORDER BY d |-> '2016-05-16 14:21:25' LIMIT 5;
178+
id | d | ?column?
179+
-----+---------------------------------+---------------
180+
371 | Tue May 17 06:21:22.326724 2016 | 57597.326724
181+
406 | Wed May 18 17:21:22.326724 2016 | 183597.326724
182+
415 | Thu May 19 02:21:22.326724 2016 | 215997.326724
183+
428 | Thu May 19 15:21:22.326724 2016 | 262797.326724
184+
457 | Fri May 20 20:21:22.326724 2016 | 367197.326724
185+
(5 rows)
186+
187+
--to be fixed
188+
--EXPLAIN (costs off)
189+
--SELECT id, d, d <-> '2016-05-16 14:21:25' FROM tsts ORDER BY d <-> '2016-05-16 14:21:25' LIMIT 5;
190+
--SELECT id, d, d <-> '2016-05-16 14:21:25' FROM tsts ORDER BY d <-> '2016-05-16 14:21:25' LIMIT 5;

expected/rum.out

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'ever|
1919

2020
explain (costs off)
2121
SELECT * FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'ever|wrote')
22-
ORDER BY a >< to_tsquery('pg_catalog.english', 'ever|wrote');
22+
ORDER BY a <-> to_tsquery('pg_catalog.english', 'ever|wrote');
2323
QUERY PLAN
2424
------------------------------------------------------------------
2525
Sort
26-
Sort Key: ((a >< '''ever'' | ''wrote'''::tsquery))
26+
Sort Key: ((a <-> '''ever'' | ''wrote'''::tsquery))
2727
-> Bitmap Heap Scan on test_rum
2828
Recheck Cond: (a @@ '''ever'' | ''wrote'''::tsquery)
2929
-> Bitmap Index Scan on rumidx
@@ -93,7 +93,7 @@ SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english',
9393
SELECT rum_ts_distance(a, to_tsquery('pg_catalog.english', 'way')), *
9494
FROM test_rum
9595
WHERE a @@ to_tsquery('pg_catalog.english', 'way')
96-
ORDER BY a >< to_tsquery('pg_catalog.english', 'way');
96+
ORDER BY a <-> to_tsquery('pg_catalog.english', 'way');
9797
rum_ts_distance | t | a
9898
-----------------+--------------------------------------------------------------------------+---------------------------------------------------------------
9999
0.0607927 | my appreciation of you in a more complimentary way than by sending this | 'appreci':2 'complimentari':8 'send':12 'way':9
@@ -105,7 +105,7 @@ SELECT rum_ts_distance(a, to_tsquery('pg_catalog.english', 'way')), *
105105
SELECT rum_ts_distance(a, to_tsquery('pg_catalog.english', 'way & (go | half)')), *
106106
FROM test_rum
107107
WHERE a @@ to_tsquery('pg_catalog.english', 'way & (go | half)')
108-
ORDER BY a >< to_tsquery('pg_catalog.english', 'way & (go | half)');
108+
ORDER BY a <-> to_tsquery('pg_catalog.english', 'way & (go | half)');
109109
rum_ts_distance | t | a
110110
-----------------+---------------------------------------------------------------------+---------------------------------------------------------
111111
0.103556 | thinking--“to go or not to go?” We are this far on the way. Reached | 'far':11 'go':3,7 'reach':15 'think':1 'way':14

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