Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 048be0e

Browse files
author
Zakirov Artur
committed
RUM commited
0 parents  commit 048be0e

23 files changed

+15209
-0
lines changed

Makefile

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# contrib/rum/Makefile
2+
3+
MODULE_big = rum
4+
OBJS = rumsort.o rum_ts_utils.o \
5+
rumbtree.o rumbulk.o rumdatapage.o \
6+
rumentrypage.o rumfast.o rumget.o ruminsert.o \
7+
rumscan.o rumutil.o rumvacuum.o rumvalidate.o $(WIN32RES)
8+
9+
EXTENSION = rum
10+
DATA = rum--1.0.sql
11+
PGFILEDESC = "RUM index access method"
12+
13+
REGRESS = rum
14+
15+
ifdef USE_PGXS
16+
PG_CONFIG = pg_config
17+
PGXS := $(shell $(PG_CONFIG) --pgxs)
18+
include $(PGXS)
19+
else
20+
subdir = contrib/rum
21+
top_builddir = ../..
22+
include $(top_builddir)/src/Makefile.global
23+
include $(top_srcdir)/contrib/contrib-global.mk
24+
endif
25+
26+
wal-check: temp-install
27+
$(prove_check)

README.md

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# RUM - RUM access methods
2+
3+
## Introduction
4+
5+
The **rum** module provides access methods to work with RUM index. It is based
6+
on the GIN access methods code.
7+
8+
## License
9+
10+
This module available under the same license as
11+
[PostgreSQL](http://www.postgresql.org/about/licence/).
12+
13+
## Installation
14+
15+
Before build and install **rum** you should ensure following:
16+
17+
* PostgreSQL version is 9.6.
18+
19+
Typical installation procedure may look like this:
20+
21+
$ git clone https://github.com/postgrespro/rum
22+
$ cd rum
23+
$ make USE_PGXS=1
24+
$ sudo make USE_PGXS=1 install
25+
$ make USE_PGXS=1 installcheck
26+
$ psql DB -c "CREATE EXTENSION rum;"
27+
28+
## New access method and operator class
29+
30+
The **rum** module provides the access method **rum** and the operator class
31+
**rum_tsvector_ops**.
32+
33+
The module provides new operators.
34+
35+
| Operator | Returns | Description
36+
| ------------------- | ------- | ----------------------------------------------
37+
| tsvector >< tsquery | float4 | Returns distance between tsvector and tsquery.
38+
39+
## Examples
40+
41+
Let us assume we have the table:
42+
43+
```sql
44+
CREATE TABLE test_rum(t text, a tsvector);
45+
46+
CREATE TRIGGER tsvectorupdate
47+
BEFORE UPDATE OR INSERT ON test_rum
48+
FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger('a', 'pg_catalog.english', 't');
49+
50+
INSERT INTO test_rum(t) VALUES ('The situation is most beautiful');
51+
INSERT INTO test_rum(t) VALUES ('It is a beautiful');
52+
INSERT INTO test_rum(t) VALUES ('It looks like a beautiful place');
53+
```
54+
55+
To create the **rum** index we need create an extension:
56+
57+
```sql
58+
CREATE EXTENSION rum;
59+
```
60+
61+
Then we can create new index:
62+
63+
```sql
64+
CREATE INDEX rumidx ON test_rum USING rum (a rum_tsvector_ops);
65+
```
66+
67+
And we can execute the following queries:
68+
69+
```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');
71+
t | rank
72+
---------------------------------+-----------
73+
The situation is most beautiful | 0.0303964
74+
It is a beautiful | 0.0303964
75+
It looks like a beautiful place | 0.0607927
76+
(3 rows)
77+
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');
79+
t | rank
80+
---------------------------------+-----------
81+
The situation is most beautiful | 0.0303964
82+
It looks like a beautiful place | 0.0303964
83+
(2 rows)
84+
```
85+
86+
## Authors
87+
88+
Alexander Korotkov <[email protected]> Postgres Professional Ltd., Russia
89+
90+
Oleg Bartunov <[email protected]> Postgres Professional Ltd., Russia
91+
92+
Teodor Sigaev <[email protected]> Postgres Professional Ltd., Russia

data/rum.data

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
As a reward for your reformation I write to you on this precious sheet.
2+
You see I have come to be wonderfully attached to Heidelberg, the
3+
beautiful, the quaint, the historically poetic, learned and picturesque
4+
old town on the Neckar. It seems like another home. So I could not show
5+
my appreciation of you in a more complimentary way than by sending this
6+
little series of pictures. Have you ever been here, I wonder? You did
7+
not say, but you wrote as if you knew it by sight as well as by heart.
8+
As I cannot know, I will venture an explanation. The panorama speaks for
9+
itself. Put on your “specs” and look at the castle, half way up the
10+
_berg_, “the Jettenhuhl, a wooded spur of the Konigestuhl.” Look at it
11+
from the “Terrasse.” Thus you’ll get something of an idea of it. The
12+
Gesprente Thurm is the one that was blown up by the French. The
13+
thickness of the walls, twenty-one feet, and the solid masonry, held it
14+
so well that only a fragment, as it were, gave way. It still hangs as if
15+
ready to be replaced. “Das Grosse Fass Gebaude,” too, you will have no
16+
difficulty in making out. If you only had it with its 49,000 gallons of
17+
wine, but wouldn’t you divide with your neighbors! The columns in the
18+
portico that shows in the Schlosshof are the four brought from
19+
Charlemagne’s palace at Ingelheim by the Count Palatine Ludwig, some
20+
time between 1508-44. The Zum Ritter has nothing to do with the castle,
21+
but is an ancient structure (1592) in the Renaissance style, and one of
22+
the few that escaped destruction in 1693. It is a beautiful, highly
23+
ornamental building, and I wish you could see it, if you have not seen
24+
it.
25+
26+
All the above information, I beg you to believe, I do not intend you
27+
to think was evolved from my inner consciousness, but gathered from
28+
the--nearest guide-book!
29+
30+
I am so much obliged to you for mapping out Switzerland to me. I have
31+
been trying my best to get all those “passes” into my brain. Now, thanks
32+
to your letter, I have them all in the handiest kind of a bunch. Ariel
33+
like, “I’ll do my bidding gently,” and as surely, if I get there. But
34+
there are dreadful reports of floods and roads caved in and bridges
35+
swept away and snows and--enough of such exciting items as sets one
36+
thinking--“to go or not to go?” We are this far on the way. Reached
37+
here this afternoon. Have spent the evening sauntering in the gardens,
38+
the Conversationhaus, the bazaar, mingling with the throng, listening to
39+
the band, and comparing what it is with what it was. It was a gay and
40+
curious spectacle, but on the whole had “the banquet-hall deserted”
41+
look. The situation is most beautiful. It lies, you know, at the
42+
entrance of the Black Forest, among picturesque, thickly-wooded hills,
43+
in the valley of the Oos, and extends up the slope of some of the hills.
44+
The Oos is a most turbid, turbulent stream; dashes through part of the
45+
town with angry, headlong speed. There is an avenue along its bank of
46+
oaks, limes and maples, bordered with flower-beds and shrubberies, and
47+
adorned with fountains and handsome villas. We shall devote to-morrow to
48+
seeing all there is to be seen, and go to Strassburg to-morrow evening
49+
for two or three days. From there to Constance, and then hold _our_
50+
“Council” as to further movements.
51+
def fgr
52+
def xxx fgr

expected/rum.out

+173
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
CREATE EXTENSION rum;
2+
CREATE TABLE test_rum( t text, a tsvector );
3+
CREATE TRIGGER tsvectorupdate
4+
BEFORE UPDATE OR INSERT ON test_rum
5+
FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger('a', 'pg_catalog.english', 't');
6+
CREATE INDEX rumidx ON test_rum USING rum (a rum_tsvector_ops);
7+
\copy test_rum(t) from 'data/rum.data';
8+
SET enable_seqscan=off;
9+
explain (costs off)
10+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'ever|wrote');
11+
QUERY PLAN
12+
------------------------------------------------------------------
13+
Aggregate
14+
-> Bitmap Heap Scan on test_rum
15+
Recheck Cond: (a @@ '''ever'' | ''wrote'''::tsquery)
16+
-> Bitmap Index Scan on rumidx
17+
Index Cond: (a @@ '''ever'' | ''wrote'''::tsquery)
18+
(5 rows)
19+
20+
explain (costs off)
21+
SELECT * FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'ever|wrote')
22+
ORDER BY a >< to_tsquery('pg_catalog.english', 'ever|wrote');
23+
QUERY PLAN
24+
------------------------------------------------------------------
25+
Sort
26+
Sort Key: ((a >< '''ever'' | ''wrote'''::tsquery))
27+
-> Bitmap Heap Scan on test_rum
28+
Recheck Cond: (a @@ '''ever'' | ''wrote'''::tsquery)
29+
-> Bitmap Index Scan on rumidx
30+
Index Cond: (a @@ '''ever'' | ''wrote'''::tsquery)
31+
(6 rows)
32+
33+
explain (costs off)
34+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english',
35+
'def <-> fgr');
36+
QUERY PLAN
37+
-----------------------------------------------------------
38+
Aggregate
39+
-> Index Scan using rumidx on test_rum
40+
Index Cond: (a @@ '''def'' <-> ''fgr'''::tsquery)
41+
(3 rows)
42+
43+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'ever|wrote');
44+
count
45+
-------
46+
2
47+
(1 row)
48+
49+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'have&wish');
50+
count
51+
-------
52+
1
53+
(1 row)
54+
55+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'knew&brain');
56+
count
57+
-------
58+
0
59+
(1 row)
60+
61+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'among');
62+
count
63+
-------
64+
1
65+
(1 row)
66+
67+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'structure&ancient');
68+
count
69+
-------
70+
1
71+
(1 row)
72+
73+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', '(complimentary|sight)&(sending|heart)');
74+
count
75+
-------
76+
2
77+
(1 row)
78+
79+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english',
80+
'def <-> fgr');
81+
count
82+
-------
83+
1
84+
(1 row)
85+
86+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english',
87+
'def <2> fgr');
88+
count
89+
-------
90+
2
91+
(1 row)
92+
93+
SELECT rum_ts_distance(a, to_tsquery('pg_catalog.english', 'way')), *
94+
FROM test_rum
95+
WHERE a @@ to_tsquery('pg_catalog.english', 'way')
96+
ORDER BY a >< to_tsquery('pg_catalog.english', 'way');
97+
rum_ts_distance | t | a
98+
-----------------+--------------------------------------------------------------------------+---------------------------------------------------------------
99+
0.0607927 | my appreciation of you in a more complimentary way than by sending this | 'appreci':2 'complimentari':8 'send':12 'way':9
100+
0.0607927 | itself. Put on your “specs” and look at the castle, half way up the | 'castl':10 'half':11 'look':7 'put':2 'spec':5 'way':12
101+
0.0607927 | so well that only a fragment, as it were, gave way. It still hangs as if | 'fragment':6 'gave':10 'hang':14 'still':13 'way':11 'well':2
102+
0.0607927 | 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
103+
(4 rows)
104+
105+
SELECT rum_ts_distance(a, to_tsquery('pg_catalog.english', 'way & (go | half)')), *
106+
FROM test_rum
107+
WHERE a @@ to_tsquery('pg_catalog.english', 'way & (go | half)')
108+
ORDER BY a >< to_tsquery('pg_catalog.english', 'way & (go | half)');
109+
rum_ts_distance | t | a
110+
-----------------+---------------------------------------------------------------------+---------------------------------------------------------
111+
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
112+
0.0991032 | itself. Put on your “specs” and look at the castle, half way up the | 'castl':10 'half':11 'look':7 'put':2 'spec':5 'way':12
113+
(2 rows)
114+
115+
INSERT INTO test_rum (t) VALUES ('foo bar foo the over foo qq bar');
116+
INSERT INTO test_rum (t) VALUES ('345 qwerty copyright');
117+
INSERT INTO test_rum (t) VALUES ('345 qwerty');
118+
INSERT INTO test_rum (t) VALUES ('A fat cat has just eaten a rat.');
119+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'bar');
120+
count
121+
-------
122+
1
123+
(1 row)
124+
125+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'qwerty&345');
126+
count
127+
-------
128+
2
129+
(1 row)
130+
131+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', '345');
132+
count
133+
-------
134+
2
135+
(1 row)
136+
137+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'rat');
138+
count
139+
-------
140+
1
141+
(1 row)
142+
143+
SELECT a FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'bar') ORDER BY a;
144+
a
145+
------------------------------
146+
'bar':2,8 'foo':1,3,6 'qq':7
147+
(1 row)
148+
149+
DELETE FROM test_rum;
150+
SELECT count(*) from test_rum;
151+
count
152+
-------
153+
0
154+
(1 row)
155+
156+
CREATE TABLE tst (i int4, t tsvector);
157+
INSERT INTO tst SELECT i%10, to_tsvector('simple', substr(md5(i::text), 1, 1)) FROM generate_series(1,100000) i;
158+
CREATE INDEX tstidx ON tst USING rum (t rum_tsvector_ops);
159+
DELETE FROM tst WHERE i = 1;
160+
VACUUM tst;
161+
INSERT INTO tst SELECT i%10, to_tsvector('simple', substr(md5(i::text), 1, 1)) FROM generate_series(10001,11000) i;
162+
DELETE FROM tst WHERE i = 2;
163+
VACUUM tst;
164+
INSERT INTO tst SELECT i%10, to_tsvector('simple', substr(md5(i::text), 1, 1)) FROM generate_series(11001,12000) i;
165+
DELETE FROM tst WHERE i = 3;
166+
VACUUM tst;
167+
INSERT INTO tst SELECT i%10, to_tsvector('simple', substr(md5(i::text), 1, 1)) FROM generate_series(12001,13000) i;
168+
DELETE FROM tst WHERE i = 4;
169+
VACUUM tst;
170+
INSERT INTO tst SELECT i%10, to_tsvector('simple', substr(md5(i::text), 1, 1)) FROM generate_series(13001,14000) i;
171+
DELETE FROM tst WHERE i = 5;
172+
VACUUM tst;
173+
INSERT INTO tst SELECT i%10, to_tsvector('simple', substr(md5(i::text), 1, 1)) FROM generate_series(14001,15000) i;

0 commit comments

Comments
 (0)