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

Commitf48c31f

Browse files
committed
Merge branch 'CORE-241-rum' of gitlab.postgrespro.ru:pgpro-dev/postgrespro into CORE-241-rum
2 parents0a80645 +00ceebc commitf48c31f

File tree

12 files changed

+402
-35
lines changed

12 files changed

+402
-35
lines changed

‎expected/rum.out

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ BEFORE UPDATE OR INSERT ON test_rum
55
FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger('a', 'pg_catalog.english', 't');
66
CREATE INDEX rumidx ON test_rum USING rum (a rum_tsvector_ops);
77
\copy test_rum(t) from 'data/rum.data';
8+
CREATE INDEX failed_rumidx ON test_rum USING rum (a rum_tsvector_timestamp_ops);
9+
ERROR: additional information attribute "a" is not found in index
810
SET enable_seqscan=off;
911
explain (costs off)
1012
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'ever|wrote');
@@ -76,6 +78,30 @@ SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', '(comp
7678
2
7779
(1 row)
7880

81+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', '(gave | half) <-> way');
82+
count
83+
-------
84+
2
85+
(1 row)
86+
87+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', '(gave | !half) <-> way');
88+
count
89+
-------
90+
3
91+
(1 row)
92+
93+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', '!gave & way');
94+
count
95+
-------
96+
3
97+
(1 row)
98+
99+
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', '!gave & wooded & !look');
100+
count
101+
-------
102+
1
103+
(1 row)
104+
79105
SELECT count(*) FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english',
80106
'def <-> fgr');
81107
count
@@ -124,6 +150,29 @@ SELECT
124150
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
125151
(2 rows)
126152

153+
-- Check ranking normalization
154+
SELECT rum_ts_distance(a, to_tsquery('pg_catalog.english', 'way'), 0), *
155+
FROM test_rum
156+
WHERE a @@ to_tsquery('pg_catalog.english', 'way')
157+
ORDER BY a <=> to_tsquery('pg_catalog.english', 'way');
158+
rum_ts_distance | t | a
159+
-----------------+--------------------------------------------------------------------------+---------------------------------------------------------------
160+
16.4493 | my appreciation of you in a more complimentary way than by sending this | 'appreci':2 'complimentari':8 'send':12 'way':9
161+
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
162+
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
163+
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
164+
(4 rows)
165+
166+
SELECT rum_ts_distance(a, row(to_tsquery('pg_catalog.english', 'way & (go | half)'), 0)::rum_distance_query), *
167+
FROM test_rum
168+
WHERE a @@ to_tsquery('pg_catalog.english', 'way & (go | half)')
169+
ORDER BY a <=> to_tsquery('pg_catalog.english', 'way & (go | half)');
170+
rum_ts_distance | t | a
171+
-----------------+---------------------------------------------------------------------+---------------------------------------------------------
172+
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
173+
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
174+
(2 rows)
175+
127176
INSERT INTO test_rum (t) VALUES ('foo bar foo the over foo qq bar');
128177
INSERT INTO test_rum (t) VALUES ('345 qwerty copyright');
129178
INSERT INTO test_rum (t) VALUES ('345 qwerty');
@@ -158,6 +207,68 @@ SELECT a FROM test_rum WHERE a @@ to_tsquery('pg_catalog.english', 'bar') ORDER
158207
'bar':2,8 'foo':1,3,6 'qq':7
159208
(1 row)
160209

210+
-- Check full-index scan with order by
211+
SELECT a <=> to_tsquery('pg_catalog.english', 'ever|wrote') FROM test_rum ORDER BY a <=> to_tsquery('pg_catalog.english', 'ever|wrote');
212+
?column?
213+
----------
214+
16.4493
215+
16.4493
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+
Infinity
270+
(56 rows)
271+
161272
CREATE TABLE tst (i int4, t tsvector);
162273
INSERT INTO tst SELECT i%10, to_tsvector('simple', substr(md5(i::text), 1, 1)) FROM generate_series(1,100000) i;
163274
CREATE INDEX tstidx ON tst USING rum (t rum_tsvector_ops);

‎rum--1.0.sql

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,31 @@ LANGUAGE C;
66
-- Access method
77
CREATE ACCESS METHOD rum TYPE INDEX HANDLER rumhandler;
88

9-
-- Opclasses
9+
-- tsvector opclasses
10+
11+
CREATETYPErum_distance_queryAS (query tsquery, methodint);
12+
13+
CREATEFUNCTIONtsquery_to_distance_query(tsquery)
14+
RETURNS rum_distance_query
15+
AS'MODULE_PATHNAME','tsquery_to_distance_query'
16+
LANGUAGE C IMMUTABLE STRICT;
17+
18+
CREATE CAST (tsqueryAS rum_distance_query)
19+
WITH FUNCTION tsquery_to_distance_query(tsquery)AS IMPLICIT;
20+
1021
CREATEFUNCTIONrum_ts_distance(tsvector,tsquery)
1122
RETURNS float4
12-
AS'MODULE_PATHNAME'
23+
AS'MODULE_PATHNAME','rum_ts_distance_tt'
24+
LANGUAGE C IMMUTABLE STRICT;
25+
26+
CREATEFUNCTIONrum_ts_distance(tsvector,tsquery,int)
27+
RETURNS float4
28+
AS'MODULE_PATHNAME','rum_ts_distance_ttf'
29+
LANGUAGE C IMMUTABLE STRICT;
30+
31+
CREATEFUNCTIONrum_ts_distance(tsvector,rum_distance_query)
32+
RETURNS float4
33+
AS'MODULE_PATHNAME','rum_ts_distance_td'
1334
LANGUAGE C IMMUTABLE STRICT;
1435

1536
CREATE OPERATOR<=> (
@@ -18,6 +39,12 @@ CREATE OPERATOR <=> (
1839
PROCEDURE= rum_ts_distance
1940
);
2041

42+
CREATE OPERATOR<=> (
43+
LEFTARG= tsvector,
44+
RIGHTARG= rum_distance_query,
45+
PROCEDURE= rum_ts_distance
46+
);
47+
2148
CREATEFUNCTIONrum_extract_tsvector(tsvector,internal,internal,internal,internal)
2249
RETURNS internal
2350
AS'MODULE_PATHNAME'

‎rum.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,13 @@ typedef struct
663663
boolrecheck;
664664
}RumOrderingItem;
665665

666+
typedefenum
667+
{
668+
RumFastScan,
669+
RumRegularScan,
670+
RumFullScan
671+
}RumScanType;
672+
666673
typedefstructRumScanOpaqueData
667674
{
668675
MemoryContexttempCtx;
@@ -684,7 +691,7 @@ typedef struct RumScanOpaqueData
684691
RumKeykey;
685692
boolfirstCall;
686693
boolisVoidRes;/* true if query is unsatisfiable */
687-
booluseFastScan;
694+
RumScanTypescanType;
688695
TIDBitmap*tbm;
689696

690697
ScanDirectionnaturalOrder;
@@ -760,7 +767,12 @@ extern Datum rum_extract_tsquery(PG_FUNCTION_ARGS);
760767
externDatumrum_tsvector_config(PG_FUNCTION_ARGS);
761768
externDatumrum_tsquery_pre_consistent(PG_FUNCTION_ARGS);
762769
externDatumrum_tsquery_distance(PG_FUNCTION_ARGS);
763-
externDatumrum_ts_distance(PG_FUNCTION_ARGS);
770+
externDatumrum_ts_distance_tt(PG_FUNCTION_ARGS);
771+
externDatumrum_ts_distance_ttf(PG_FUNCTION_ARGS);
772+
externDatumrum_ts_distance_td(PG_FUNCTION_ARGS);
773+
774+
externDatumtsquery_to_distance_query(PG_FUNCTION_ARGS);
775+
764776

765777
/* GUC parameters */
766778
externPGDLLIMPORTintRumFuzzySearchLimit;
@@ -870,6 +882,8 @@ rumDataPageLeafRead(Pointer ptr, OffsetNumber attnum, RumKey * item,
870882
{
871883
attr=rumstate->addAttrs[attnum-1];
872884

885+
Assert(attr);
886+
873887
if (attr->attbyval)
874888
{
875889
/* do not use aligment for pass-by-value types */
@@ -949,6 +963,8 @@ rumDataPageLeafReadPointer(Pointer ptr, OffsetNumber attnum, RumKey * item,
949963
{
950964
attr=rumstate->addAttrs[attnum-1];
951965

966+
Assert(attr);
967+
952968
if (!attr->attbyval)
953969
ptr= (Pointer)att_align_pointer(ptr,attr->attalign,attr->attlen,
954970
ptr);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp