Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1d7a399

Browse files
committed
Add split-up between rum opclass based on lexeme text and based on hash of lexeme
1 parent8fc7c02 commit1d7a399

File tree

8 files changed

+689
-40
lines changed

8 files changed

+689
-40
lines changed

‎Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ EXTENSION = rum
1111
DATA = rum--1.0.sql
1212
PGFILEDESC = "RUM index access method"
1313

14-
REGRESS = rum ruminv timestamp orderby altorder
14+
REGRESS = rumrum_hashruminv timestamp orderby altorder
1515

1616
LDFLAGS_SL +=$(filter -lm,$(LIBS))
1717

‎expected/rum.out

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,4 +304,51 @@ SELECT a <=> to_tsquery('pg_catalog.english', 'w:*'), *
304304
FROM test_rum
305305
WHERE a @@ to_tsquery('pg_catalog.english', 'w:*')
306306
ORDER BY a <=> to_tsquery('pg_catalog.english', 'w:*');
307-
ERROR: Compare with prefix expressions isn't supported
307+
?column? | t | a
308+
----------+--------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------
309+
8.22467 | 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
310+
8.22467 | wine, but wouldn't you divide with your neighbors! The columns in the | 'column':11 'divid':6 'neighbor':9 'wine':1 'wouldn':3
311+
8.22467 | not say, but you wrote as if you knew it by sight as well as by heart. | 'heart':17 'knew':9 'say':2 'sight':12 'well':14 'wrote':5
312+
16.4493 | little series of pictures. Have you ever been here, I wonder? You did | 'ever':7 'littl':1 'pictur':4 'seri':2 'wonder':11
313+
16.4493 | 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
314+
16.4493 | _berg_, "the Jettenhuhl, a wooded spur of the Konigestuhl." Look at it | 'berg':1 'jettenhuhl':3 'konigestuhl':9 'look':10 'spur':6 'wood':5
315+
16.4493 | thickness of the walls, twenty-one feet, and the solid masonry, held it | 'feet':8 'held':13 'masonri':12 'one':7 'solid':11 'thick':1 'twenti':6 'twenty-on':5 'wall':4
316+
16.4493 | ornamental building, and I wish you could see it, if you have not seen | 'build':2 'could':7 'ornament':1 'see':8 'seen':14 'wish':5
317+
16.4493 | 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
318+
16.4493 | curious spectacle, but on the whole had "the banquet-hall deserted" | 'banquet':10 'banquet-hal':9 'curious':1 'desert':12 'hall':11 'spectacl':2 'whole':6
319+
16.4493 | As a reward for your reformation I write to you on this precious sheet. | 'precious':13 'reform':6 'reward':3 'sheet':14 'write':8
320+
16.4493 | entrance of the Black Forest, among picturesque, thickly-wooded hills, | 'among':6 'black':4 'entranc':1 'forest':5 'hill':11 'picturesqu':7 'thick':9 'thickly-wood':8 'wood':10
321+
16.4493 | You see I have come to be wonderfully attached to Heidelberg, the | 'attach':9 'come':5 'heidelberg':11 'see':2 'wonder':8
322+
16.4493 | my appreciation of you in a more complimentary way than by sending this | 'appreci':2 'complimentari':8 'send':12 'way':9
323+
(14 rows)
324+
325+
SELECT a <=> to_tsquery('pg_catalog.english', 'b:*'), *
326+
FROM test_rum
327+
WHERE a @@ to_tsquery('pg_catalog.english', 'b:*')
328+
ORDER BY a <=> to_tsquery('pg_catalog.english', 'b:*');
329+
?column? | t | a
330+
----------+--------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------
331+
8.22467 | been trying my best to get all those "passes" into my brain. Now, thanks | 'best':4 'brain':12 'get':6 'pass':9 'thank':14 'tri':2
332+
8.22467 | All the above information, I beg you to believe, I do not intend you | 'beg':6 'believ':9 'inform':4 'intend':13
333+
8.22467 | curious spectacle, but on the whole had "the banquet-hall deserted" | 'banquet':10 'banquet-hal':9 'curious':1 'desert':12 'hall':11 'spectacl':2 'whole':6
334+
8.22467 | oaks, limes and maples, bordered with flower-beds and shrubberies, and | 'bed':9 'border':5 'flower':8 'flower-b':7 'lime':2 'mapl':4 'oak':1 'shrubberi':11
335+
13.1595 | foo bar foo the over foo qq bar | 'bar':2,8 'foo':1,3,6 'qq':7
336+
16.4493 | ornamental building, and I wish you could see it, if you have not seen | 'build':2 'could':7 'ornament':1 'see':8 'seen':14 'wish':5
337+
16.4493 | the--nearest guide-book! | 'book':5 'guid':4 'guide-book':3 'nearest':2
338+
16.4493 | to your letter, I have them all in the handiest kind of a bunch. Ariel | 'ariel':15 'bunch':14 'handiest':10 'kind':11 'letter':3
339+
16.4493 | beautiful, the quaint, the historically poetic, learned and picturesque | 'beauti':1 'histor':5 'learn':7 'picturesqu':9 'poetic':6 'quaint':3
340+
16.4493 | there are dreadful reports of floods and roads caved in and bridges | 'bridg':12 'cave':9 'dread':3 'flood':6 'report':4 'road':8
341+
16.4493 | the Conversationhaus, the bazaar, mingling with the throng, listening to | 'bazaar':4 'conversationhaus':2 'listen':9 'mingl':5 'throng':8
342+
16.4493 | the band, and comparing what it is with what it was. It was a gay and | 'band':2 'compar':4 'gay':15
343+
16.4493 | look. The situation is most beautiful. It lies, you know, at the | 'beauti':6 'know':10 'lie':8 'look':1 'situat':3
344+
16.4493 | entrance of the Black Forest, among picturesque, thickly-wooded hills, | 'among':6 'black':4 'entranc':1 'forest':5 'hill':11 'picturesqu':7 'thick':9 'thickly-wood':8 'wood':10
345+
16.4493 | town with angry, headlong speed. There is an avenue along its bank of | 'along':10 'angri':3 'avenu':9 'bank':12 'headlong':4 'speed':5 'town':1
346+
16.4493 | like, "I'll do my bidding gently," and as surely, if I get there. But | 'bid':6 'gentl':7 'get':13 'like':1 'll':3 'sure':10
347+
16.4493 | _berg_, "the Jettenhuhl, a wooded spur of the Konigestuhl." Look at it | 'berg':1 'jettenhuhl':3 'konigestuhl':9 'look':10 'spur':6 'wood':5
348+
16.4493 | Gesprente Thurm is the one that was blown up by the French. The | 'blown':8 'french':12 'gesprent':1 'one':5 'thurm':2
349+
16.4493 | portico that shows in the Schlosshof are the four brought from | 'brought':10 'four':9 'portico':1 'schlosshof':6 'show':3
350+
16.4493 | the few that escaped destruction in 1693. It is a beautiful, highly | '1693':7 'beauti':11 'destruct':5 'escap':4 'high':12
351+
(20 rows)
352+
353+
DROP TABLE test_rum CASCADE;
354+
DROP TABLE tst CASCADE;

‎expected/rum_hash.out

Lines changed: 308 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,308 @@
1+
CREATE TABLE test_rum( t text, a tsvector );
2+
CREATE TRIGGER tsvectorupdate
3+
BEFORE UPDATE OR INSERT ON test_rum
4+
FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger('a', 'pg_catalog.english', 't');
5+
CREATE INDEX rumidx ON test_rum USING rum (a rum_tsvector_hash_ops);
6+
\copy test_rum(t) from 'data/rum.data';
7+
CREATE INDEX failed_rumidx ON test_rum USING rum (a rum_tsvector_timestamp_ops);
8+
ERROR: additional information attribute "a" is not found in index
9+
SET enable_seqscan=off;
10+
explain (costs off)
11+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'ever|wrote');
12+
QUERY PLAN
13+
------------------------------------------------------------------
14+
Aggregate
15+
-> Bitmap Heap Scan on test_rum
16+
Recheck Cond: (a @@ '''ever'' | ''wrote'''::tsquery)
17+
-> Bitmap Index Scan on rumidx
18+
Index Cond: (a @@ '''ever'' | ''wrote'''::tsquery)
19+
(5 rows)
20+
21+
explain (costs off)
22+
SELECT * FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'ever|wrote')
23+
ORDER BY a <=> to_tsquery('pg_catalog.english', 'ever|wrote');
24+
QUERY PLAN
25+
------------------------------------------------------------------
26+
Sort
27+
Sort Key: ((a <=> '''ever'' | ''wrote'''::tsquery))
28+
-> Bitmap Heap Scan on test_rum
29+
Recheck Cond: (a @@ '''ever'' | ''wrote'''::tsquery)
30+
-> Bitmap Index Scan on rumidx
31+
Index Cond: (a @@ '''ever'' | ''wrote'''::tsquery)
32+
(6 rows)
33+
34+
explain (costs off)
35+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english',
36+
'def <-> fgr');
37+
QUERY PLAN
38+
-----------------------------------------------------------
39+
Aggregate
40+
-> Index Scan using rumidx on test_rum
41+
Index Cond: (a @@ '''def'' <-> ''fgr'''::tsquery)
42+
(3 rows)
43+
44+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'ever|wrote');
45+
count
46+
-------
47+
2
48+
(1 row)
49+
50+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'have&wish');
51+
count
52+
-------
53+
1
54+
(1 row)
55+
56+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'knew&brain');
57+
count
58+
-------
59+
0
60+
(1 row)
61+
62+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'among');
63+
count
64+
-------
65+
1
66+
(1 row)
67+
68+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'structure&ancient');
69+
count
70+
-------
71+
1
72+
(1 row)
73+
74+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', '(complimentary|sight)&(sending|heart)');
75+
count
76+
-------
77+
2
78+
(1 row)
79+
80+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', '(gave | half) <-> way');
81+
count
82+
-------
83+
2
84+
(1 row)
85+
86+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', '(gave | !half) <-> way');
87+
count
88+
-------
89+
3
90+
(1 row)
91+
92+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', '!gave & way');
93+
count
94+
-------
95+
3
96+
(1 row)
97+
98+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', '!gave & wooded & !look');
99+
count
100+
-------
101+
1
102+
(1 row)
103+
104+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english',
105+
'def <-> fgr');
106+
count
107+
-------
108+
1
109+
(1 row)
110+
111+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english',
112+
'def <2> fgr');
113+
count
114+
-------
115+
1
116+
(1 row)
117+
118+
SELECT rum_ts_distance(a, to_tsquery('pg_catalog.english', 'way')), *
119+
FROM test_rum
120+
WHERE a @@ to_tsquery('pg_catalog.english', 'way')
121+
ORDER BY a <=> to_tsquery('pg_catalog.english', 'way');
122+
rum_ts_distance | t | a
123+
-----------------+--------------------------------------------------------------------------+---------------------------------------------------------------
124+
16.4493 | my appreciation of you in a more complimentary way than by sending this | 'appreci':2 'complimentari':8 'send':12 'way':9
125+
16.4493 | 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
126+
16.4493 | 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
127+
16.4493 | 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
128+
(4 rows)
129+
130+
SELECT rum_ts_distance(a, to_tsquery('pg_catalog.english', 'way & (go | half)')), *
131+
FROM test_rum
132+
WHERE a @@ to_tsquery('pg_catalog.english', 'way & (go | half)')
133+
ORDER BY a <=> to_tsquery('pg_catalog.english', 'way & (go | half)');
134+
rum_ts_distance | t | a
135+
-----------------+---------------------------------------------------------------------+---------------------------------------------------------
136+
8.22467 | 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
137+
57.5727 | 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
138+
(2 rows)
139+
140+
SELECT
141+
a <=> to_tsquery('pg_catalog.english', 'way & (go | half)'),
142+
rum_ts_distance(a, to_tsquery('pg_catalog.english', 'way & (go | half)')),
143+
*
144+
FROM test_rum
145+
ORDER BY a <=> to_tsquery('pg_catalog.english', 'way & (go | half)') limit 2;
146+
?column? | rum_ts_distance | t | a
147+
----------+-----------------+---------------------------------------------------------------------+---------------------------------------------------------
148+
8.22467 | 8.22467 | 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
149+
57.5727 | 57.5727 | 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
150+
(2 rows)
151+
152+
-- Check ranking normalization
153+
SELECT rum_ts_distance(a, to_tsquery('pg_catalog.english', 'way'), 0), *
154+
FROM test_rum
155+
WHERE a @@ to_tsquery('pg_catalog.english', 'way')
156+
ORDER BY a <=> to_tsquery('pg_catalog.english', 'way');
157+
rum_ts_distance | t | a
158+
-----------------+--------------------------------------------------------------------------+---------------------------------------------------------------
159+
16.4493 | my appreciation of you in a more complimentary way than by sending this | 'appreci':2 'complimentari':8 'send':12 'way':9
160+
16.4493 | 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
161+
16.4493 | 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
162+
16.4493 | 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
163+
(4 rows)
164+
165+
SELECT rum_ts_distance(a, row(to_tsquery('pg_catalog.english', 'way & (go | half)'), 0)::rum_distance_query), *
166+
FROM test_rum
167+
WHERE a @@ to_tsquery('pg_catalog.english', 'way & (go | half)')
168+
ORDER BY a <=> to_tsquery('pg_catalog.english', 'way & (go | half)');
169+
rum_ts_distance | t | a
170+
-----------------+---------------------------------------------------------------------+---------------------------------------------------------
171+
8.22467 | 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
172+
57.5727 | 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
173+
(2 rows)
174+
175+
INSERT INTO test_rum (t) VALUES ('foo bar foo the over foo qq bar');
176+
INSERT INTO test_rum (t) VALUES ('345 qwerty copyright');
177+
INSERT INTO test_rum (t) VALUES ('345 qwerty');
178+
INSERT INTO test_rum (t) VALUES ('A fat cat has just eaten a rat.');
179+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'bar');
180+
count
181+
-------
182+
1
183+
(1 row)
184+
185+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'qwerty&345');
186+
count
187+
-------
188+
2
189+
(1 row)
190+
191+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', '345');
192+
count
193+
-------
194+
2
195+
(1 row)
196+
197+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'rat');
198+
count
199+
-------
200+
1
201+
(1 row)
202+
203+
SELECT a FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'bar') ORDER BY a;
204+
a
205+
------------------------------
206+
'bar':2,8 'foo':1,3,6 'qq':7
207+
(1 row)
208+
209+
-- Check full-index scan with order by
210+
SELECT a <=> to_tsquery('pg_catalog.english', 'ever|wrote') FROM test_rum ORDER BY a <=> to_tsquery('pg_catalog.english', 'ever|wrote');
211+
?column?
212+
----------
213+
16.4493
214+
16.4493
215+
Infinity
216+
Infinity
217+
Infinity
218+
Infinity
219+
Infinity
220+
Infinity
221+
Infinity
222+
Infinity
223+
Infinity
224+
Infinity
225+
Infinity
226+
Infinity
227+
Infinity
228+
Infinity
229+
Infinity
230+
Infinity
231+
Infinity
232+
Infinity
233+
Infinity
234+
Infinity
235+
Infinity
236+
Infinity
237+
Infinity
238+
Infinity
239+
Infinity
240+
Infinity
241+
Infinity
242+
Infinity
243+
Infinity
244+
Infinity
245+
Infinity
246+
Infinity
247+
Infinity
248+
Infinity
249+
Infinity
250+
Infinity
251+
Infinity
252+
Infinity
253+
Infinity
254+
Infinity
255+
Infinity
256+
Infinity
257+
Infinity
258+
Infinity
259+
Infinity
260+
Infinity
261+
Infinity
262+
Infinity
263+
Infinity
264+
Infinity
265+
Infinity
266+
Infinity
267+
Infinity
268+
Infinity
269+
(56 rows)
270+
271+
CREATE TABLE tst (i int4, t tsvector);
272+
INSERT INTO tst SELECT i%10, to_tsvector('simple', substr(md5(i::text), 1, 1)) FROM generate_series(1,100000) i;
273+
CREATE INDEX tstidx ON tst USING rum (t rum_tsvector_ops);
274+
DELETE FROM tst WHERE i = 1;
275+
VACUUM tst;
276+
INSERT INTO tst SELECT i%10, to_tsvector('simple', substr(md5(i::text), 1, 1)) FROM generate_series(10001,11000) i;
277+
DELETE FROM tst WHERE i = 2;
278+
VACUUM tst;
279+
INSERT INTO tst SELECT i%10, to_tsvector('simple', substr(md5(i::text), 1, 1)) FROM generate_series(11001,12000) i;
280+
DELETE FROM tst WHERE i = 3;
281+
VACUUM tst;
282+
INSERT INTO tst SELECT i%10, to_tsvector('simple', substr(md5(i::text), 1, 1)) FROM generate_series(12001,13000) i;
283+
DELETE FROM tst WHERE i = 4;
284+
VACUUM tst;
285+
INSERT INTO tst SELECT i%10, to_tsvector('simple', substr(md5(i::text), 1, 1)) FROM generate_series(13001,14000) i;
286+
DELETE FROM tst WHERE i = 5;
287+
VACUUM tst;
288+
INSERT INTO tst SELECT i%10, to_tsvector('simple', substr(md5(i::text), 1, 1)) FROM generate_series(14001,15000) i;
289+
set enable_bitmapscan=off;
290+
explain (costs off)
291+
SELECT a <=> to_tsquery('pg_catalog.english', 'w:*'), *
292+
FROM test_rum
293+
WHERE a @@ to_tsquery('pg_catalog.english', 'w:*')
294+
ORDER BY a <=> to_tsquery('pg_catalog.english', 'w:*');
295+
QUERY PLAN
296+
-----------------------------------------
297+
Index Scan using rumidx on test_rum
298+
Index Cond: (a @@ '''w'':*'::tsquery)
299+
Order By: (a <=> '''w'':*'::tsquery)
300+
(3 rows)
301+
302+
SELECT a <=> to_tsquery('pg_catalog.english', 'w:*'), *
303+
FROM test_rum
304+
WHERE a @@ to_tsquery('pg_catalog.english', 'w:*')
305+
ORDER BY a <=> to_tsquery('pg_catalog.english', 'w:*');
306+
ERROR: Compare with prefix expressions isn't supported
307+
DROP TABLE test_rum CASCADE;
308+
DROP TABLE tst CASCADE;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp