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

Commit27ec961

Browse files
committed
add actual support for several types as addinfo for tsvector
1 parent34b2b70 commit27ec961

15 files changed

+144
-38
lines changed

‎expected/altorder.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CREATE TABLE atsts (id int, t tsvector, d timestamp);
22
\copy atsts from 'data/tsts.data'
3-
CREATE INDEX atsts_idx ON atsts USING rum (trum_tsvector_timestamp_ops, d)
3+
CREATE INDEX atsts_idx ON atsts USING rum (trum_tsvector_addon_ops, d)
44
WITH (attach = 'd', to = 't', order_by_attach='t');
55
INSERT INTO atsts VALUES (-1, 't1 t2', '2016-05-02 02:24:22.326724');
66
INSERT INTO atsts VALUES (-2, 't1 t2 t3', '2016-05-02 02:26:22.326724');

‎expected/altorder_hash.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CREATE TABLE atsts (id int, t tsvector, d timestamp);
22
\copy atsts from 'data/tsts.data'
3-
CREATE INDEX atsts_idx ON atsts USING rum (trum_tsvector_hash_timestamp_ops, d)
3+
CREATE INDEX atsts_idx ON atsts USING rum (trum_tsvector_hash_addon_ops, d)
44
WITH (attach = 'd', to = 't', order_by_attach='t');
55
INSERT INTO atsts VALUES (-1, 't1 t2', '2016-05-02 02:24:22.326724');
66
INSERT INTO atsts VALUES (-2, 't1 t2 t3', '2016-05-02 02:26:22.326724');

‎expected/orderby.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CREATE TABLE tsts (id int, t tsvector, d timestamp);
22
\copy tsts from 'data/tsts.data'
3-
CREATE INDEX tsts_idx ON tsts USING rum (trum_tsvector_timestamp_ops, d)
3+
CREATE INDEX tsts_idx ON tsts USING rum (trum_tsvector_addon_ops, d)
44
WITH (attach = 'd', to = 't');
55
INSERT INTO tsts VALUES (-1, 't1 t2', '2016-05-02 02:24:22.326724');
66
INSERT INTO tsts VALUES (-2, 't1 t2 t3', '2016-05-02 02:26:22.326724');

‎expected/orderby_hash.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CREATE TABLE tsts (id int, t tsvector, d timestamp);
22
\copy tsts from 'data/tsts.data'
3-
CREATE INDEX tsts_idx ON tsts USING rum (trum_tsvector_hash_timestamp_ops, d)
3+
CREATE INDEX tsts_idx ON tsts USING rum (trum_tsvector_hash_addon_ops, d)
44
WITH (attach = 'd', to = 't');
55
INSERT INTO tsts VALUES (-1, 't1 t2', '2016-05-02 02:24:22.326724');
66
INSERT INTO tsts VALUES (-2, 't1 t2 t3', '2016-05-02 02:26:22.326724');

‎expected/rum.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ 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 (arum_tsvector_timestamp_ops);
8+
CREATE INDEX failed_rumidx ON test_rum USING rum (arum_tsvector_addon_ops);
99
ERROR: additional information attribute "a" is not found in index
1010
SET enable_seqscan=off;
1111
explain (costs off)

‎expected/rum_hash.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ BEFORE UPDATE OR INSERT ON test_rum
44
FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger('a', 'pg_catalog.english', 't');
55
CREATE INDEX rumidx ON test_rum USING rum (a rum_tsvector_hash_ops);
66
\copy test_rum(t) from 'data/rum.data';
7-
CREATE INDEX failed_rumidx ON test_rum USING rum (arum_tsvector_timestamp_ops);
7+
CREATE INDEX failed_rumidx ON test_rum USING rum (arum_tsvector_addon_ops);
88
ERROR: additional information attribute "a" is not found in index
99
SET enable_seqscan=off;
1010
explain (costs off)

‎gen_rum_sql--1.0--1.1.pl

Lines changed: 125 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,52 @@
1919
2020
EOT
2121

22+
my$func_distance_template=<<EOT;
23+
$func_base_template
24+
25+
CREATE FUNCTION rum_TYPEIDENT_distance(TYPENAME, TYPENAME)
26+
RETURNS float8
27+
AS 'MODULE_PATHNAME'
28+
LANGUAGE C IMMUTABLE STRICT;
29+
30+
CREATE OPERATOR <=> (
31+
PROCEDURE = rum_TYPEIDENT_distance,
32+
LEFTARG = TYPENAME,
33+
RIGHTARG = TYPENAME,
34+
COMMUTATOR = <=>
35+
);
36+
37+
CREATE FUNCTION rum_TYPEIDENT_left_distance(TYPENAME, TYPENAME)
38+
RETURNS float8
39+
AS 'MODULE_PATHNAME'
40+
LANGUAGE C IMMUTABLE STRICT;
41+
42+
CREATE OPERATOR <=| (
43+
PROCEDURE = rum_TYPEIDENT_left_distance,
44+
LEFTARG = TYPENAME,
45+
RIGHTARG = TYPENAME,
46+
COMMUTATOR = |=>
47+
);
48+
49+
CREATE FUNCTION rum_TYPEIDENT_right_distance(TYPENAME, TYPENAME)
50+
RETURNS float8
51+
AS 'MODULE_PATHNAME'
52+
LANGUAGE C IMMUTABLE STRICT;
53+
54+
CREATE OPERATOR |=> (
55+
PROCEDURE = rum_TYPEIDENT_right_distance,
56+
LEFTARG = TYPENAME,
57+
RIGHTARG = TYPENAME,
58+
COMMUTATOR = <=|
59+
);
60+
61+
CREATE FUNCTION rum_TYPEIDENT_outer_distance(TYPENAME, TYPENAME, smallint)
62+
RETURNS float8
63+
AS 'MODULE_PATHNAME'
64+
LANGUAGE C STRICT IMMUTABLE;
65+
66+
EOT
67+
2268
my$opclass_base_template=<<EOT;
2369
2470
CREATE OPERATOR CLASS rum_TYPEIDENT_ops
@@ -38,54 +84,80 @@
3884
3985
EOT
4086

87+
my$opclass_distance_template=<<EOT;
88+
89+
CREATE OPERATOR CLASS rum_TYPEIDENT_ops
90+
DEFAULT FOR TYPE TYPENAME USING rum
91+
AS
92+
OPERATOR1<(TYPECMPTYPE, TYPECMPTYPE),
93+
OPERATOR2<=(TYPECMPTYPE, TYPECMPTYPE),
94+
OPERATOR3=(TYPECMPTYPE, TYPECMPTYPE),
95+
OPERATOR4>=(TYPECMPTYPE, TYPECMPTYPE),
96+
OPERATOR5>(TYPECMPTYPE, TYPECMPTYPE),
97+
OPERATOR20<=> (TYPENAME,TYPENAME) FOR ORDER BY pg_catalog.float_ops,
98+
OPERATOR21<=| (TYPENAME,TYPENAME) FOR ORDER BY pg_catalog.float_ops,
99+
OPERATOR22|=> (TYPENAME,TYPENAME) FOR ORDER BY pg_catalog.float_ops,
100+
FUNCTION1TYPECMPFUNC(TYPECMPTYPE,TYPECMPTYPE),
101+
FUNCTION2rum_TYPESUBIDENT_extract_value(TYPESUBNAME, internal),
102+
FUNCTION3rum_TYPESUBIDENT_extract_query(TYPESUBNAME, internal, int2, internal, internal),
103+
FUNCTION4rum_btree_consistent(internal,smallint,internal,int,internal,internal,internal,internal),
104+
FUNCTION5rum_TYPESUBIDENT_compare_prefix(TYPESUBNAME,TYPESUBNAME,int2, internal),
105+
-- support to TYPEIDENT distance in rum_tsvector_addon_ops
106+
FUNCTION9rum_TYPEIDENT_outer_distance(TYPENAME, TYPENAME, smallint),
107+
STORAGE TYPENAME;
108+
109+
EOT
110+
41111
my@opinfo =map {
42112
$_->{TYPEIDENT} =$_->{TYPENAME}if !exists$_->{TYPEIDENT};
43113
$_->{TYPECMPTYPE} =$_->{TYPENAME}if !exists$_->{TYPECMPTYPE};
44114
$_->{TYPESUBNAME} =$_->{TYPENAME}if !exists$_->{TYPESUBNAME};
45115
$_->{TYPESUBIDENT}=$_->{TYPEIDENT}if !exists$_->{TYPESUBIDENT};
46116
$_
47117
} (
118+
# timestamp/tz aren't here: they are in rum--1.0.sql
119+
48120
{
49121
TYPENAME=>'int2',
50122
TYPECMPFUNC=>'btint2cmp',
51-
func_tmpl=>\$func_base_template,
52-
opclass_tmpl=>\$opclass_base_template,
123+
func_tmpl=>\$func_distance_template,
124+
opclass_tmpl=>\$opclass_distance_template,
53125
},
54126
{
55127
TYPENAME=>'int4',
56128
TYPECMPFUNC=>'btint4cmp',
57-
func_tmpl=>\$func_base_template,
58-
opclass_tmpl=>\$opclass_base_template,
129+
func_tmpl=>\$func_distance_template,
130+
opclass_tmpl=>\$opclass_distance_template,
59131
},
60132
{
61133
TYPENAME=>'int8',
62134
TYPECMPFUNC=>'btint8cmp',
63-
func_tmpl=>\$func_base_template,
64-
opclass_tmpl=>\$opclass_base_template,
135+
func_tmpl=>\$func_distance_template,
136+
opclass_tmpl=>\$opclass_distance_template,
65137
},
66138
{
67139
TYPENAME=>'float4',
68140
TYPECMPFUNC=>'btfloat4cmp',
69-
func_tmpl=>\$func_base_template,
70-
opclass_tmpl=>\$opclass_base_template,
141+
func_tmpl=>\$func_distance_template,
142+
opclass_tmpl=>\$opclass_distance_template,
71143
},
72144
{
73145
TYPENAME=>'float8',
74146
TYPECMPFUNC=>'btfloat8cmp',
75-
func_tmpl=>\$func_base_template,
76-
opclass_tmpl=>\$opclass_base_template,
147+
func_tmpl=>\$func_distance_template,
148+
opclass_tmpl=>\$opclass_distance_template,
77149
},
78150
{
79151
TYPENAME=>'money',
80152
TYPECMPFUNC=>'cash_cmp',
81-
func_tmpl=>\$func_base_template,
82-
opclass_tmpl=>\$opclass_base_template,
153+
func_tmpl=>\$func_distance_template,
154+
opclass_tmpl=>\$opclass_distance_template,
83155
},
84156
{
85157
TYPENAME=>'oid',
86158
TYPECMPFUNC=>'btoidcmp',
87-
func_tmpl=>\$func_base_template,
88-
opclass_tmpl=>\$opclass_base_template,
159+
func_tmpl=>\$func_distance_template,
160+
opclass_tmpl=>\$opclass_distance_template,
89161
},
90162
{
91163
TYPENAME=>'time',
@@ -174,13 +246,6 @@
174246
TYPECMPFUNC=>'rum_numeric_cmp',
175247
func_tmpl=>\$func_base_template,
176248
opclass_tmpl=>\$opclass_base_template,
177-
preamble=><<EOT
178-
CREATE FUNCTION rum_numeric_cmp(numeric, numeric)
179-
RETURNS int4
180-
AS 'MODULE_PATHNAME'
181-
LANGUAGE C STRICT IMMUTABLE;
182-
183-
EOT
184249
},
185250
);
186251

@@ -191,14 +256,51 @@
191256
RETURNS bool
192257
AS 'MODULE_PATHNAME'
193258
LANGUAGE C STRICT IMMUTABLE;
259+
260+
ALTER FUNCTION
261+
rum_tsquery_timestamp_consistent (internal,smallint,tsvector,int,internal,internal,internal,internal)
262+
RENAME TO rum_tsquery_addon_consistent;
263+
264+
CREATE FUNCTION rum_numeric_cmp(numeric, numeric)
265+
RETURNS int4
266+
AS 'MODULE_PATHNAME'
267+
LANGUAGE C STRICT IMMUTABLE;
268+
269+
CREATE OPERATOR CLASS rum_tsvector_addon_ops
270+
FOR TYPE tsvector USING rum
271+
AS
272+
OPERATOR1@@ (tsvector, tsquery),
273+
--support function
274+
FUNCTION1gin_cmp_tslexeme(text, text),
275+
FUNCTION2rum_extract_tsvector(tsvector,internal,internal,internal,internal),
276+
FUNCTION3rum_extract_tsquery(tsquery,internal,smallint,internal,internal,internal,internal),
277+
FUNCTION4rum_tsquery_addon_consistent(internal,smallint,tsvector,int,internal,internal,internal,internal),
278+
FUNCTION5gin_cmp_prefix(text,text,smallint,internal),
279+
FUNCTION7rum_tsquery_pre_consistent(internal,smallint,tsvector,int,internal,internal,internal,internal),
280+
STORAGE text;
281+
282+
/*
283+
* rum_tsvector_hash_timestamp_ops operator class
284+
*/
285+
286+
CREATE OPERATOR CLASS rum_tsvector_hash_addon_ops
287+
FOR TYPE tsvector USING rum
288+
AS
289+
OPERATOR1@@ (tsvector, tsquery),
290+
--support function
291+
FUNCTION1btint4cmp(integer, integer),
292+
FUNCTION2rum_extract_tsvector_hash(tsvector,internal,internal,internal,internal),
293+
FUNCTION3rum_extract_tsquery_hash(tsquery,internal,smallint,internal,internal,internal,internal),
294+
FUNCTION4rum_tsquery_addon_consistent(internal,smallint,tsvector,int,internal,internal,internal,internal),
295+
FUNCTION7rum_tsquery_pre_consistent(internal,smallint,tsvector,int,internal,internal,internal,internal),
296+
STORAGE integer;
297+
194298
EOT
195299

196300
foreachmy$t (@opinfo)
197301
{
198302
print"/*--------------------$t->{TYPENAME}-----------------------*/\n\n";
199303

200-
print$t->{preamble}ifexists$t->{preamble};
201-
202304
formy$v (qw(func_tmpl opclass_tmpl))
203305
{
204306
nextif !exists$t->{$v};

‎rum--1.0.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,9 @@ RETURNS bool
243243
AS'MODULE_PATHNAME'
244244
LANGUAGE C IMMUTABLE STRICT;
245245

246+
/*
247+
*!!!deprecated, use rum_tsvector_hash_addon_ops!!!
248+
*/
246249
CREATEOPERATOR CLASSrum_tsvector_timestamp_ops
247250
FOR TYPE tsvector USING rum
248251
AS
@@ -258,6 +261,7 @@ AS
258261

259262
/*
260263
* rum_tsvector_hash_timestamp_ops operator class
264+
*!!!deprecated, use rum_tsvector_hash_addon_ops!!!
261265
*/
262266

263267
CREATEOPERATOR CLASSrum_tsvector_hash_timestamp_ops

‎sql/altorder.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ CREATE TABLE atsts (id int, t tsvector, d timestamp);
22

33
\copy atstsfrom'data/tsts.data'
44

5-
CREATEINDEXatsts_idxON atsts USING rum (trum_tsvector_timestamp_ops, d)
5+
CREATEINDEXatsts_idxON atsts USING rum (trum_tsvector_addon_ops, d)
66
WITH (attach='d', to='t', order_by_attach='t');
77

88

‎sql/altorder_hash.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ CREATE TABLE atsts (id int, t tsvector, d timestamp);
22

33
\copy atstsfrom'data/tsts.data'
44

5-
CREATEINDEXatsts_idxON atsts USING rum (trum_tsvector_hash_timestamp_ops, d)
5+
CREATEINDEXatsts_idxON atsts USING rum (trum_tsvector_hash_addon_ops, d)
66
WITH (attach='d', to='t', order_by_attach='t');
77

88

‎sql/orderby.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ CREATE TABLE tsts (id int, t tsvector, d timestamp);
22

33
\copy tstsfrom'data/tsts.data'
44

5-
CREATEINDEXtsts_idxON tsts USING rum (trum_tsvector_timestamp_ops, d)
5+
CREATEINDEXtsts_idxON tsts USING rum (trum_tsvector_addon_ops, d)
66
WITH (attach='d', to='t');
77

88

‎sql/orderby_hash.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ CREATE TABLE tsts (id int, t tsvector, d timestamp);
22

33
\copy tstsfrom'data/tsts.data'
44

5-
CREATEINDEXtsts_idxON tsts USING rum (trum_tsvector_hash_timestamp_ops, d)
5+
CREATEINDEXtsts_idxON tsts USING rum (trum_tsvector_hash_addon_ops, d)
66
WITH (attach='d', to='t');
77

88

‎sql/rum.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ CREATE INDEX rumidx ON test_rum USING rum (a rum_tsvector_ops);
99

1010
\copy test_rum(t)from'data/rum.data';
1111

12-
CREATEINDEXfailed_rumidxON test_rum USING rum (arum_tsvector_timestamp_ops);
12+
CREATEINDEXfailed_rumidxON test_rum USING rum (arum_tsvector_addon_ops);
1313

1414
SET enable_seqscan=off;
1515

‎sql/rum_hash.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ CREATE INDEX rumidx ON test_rum USING rum (a rum_tsvector_hash_ops);
77

88
\copy test_rum(t)from'data/rum.data';
99

10-
CREATEINDEXfailed_rumidxON test_rum USING rum (arum_tsvector_timestamp_ops);
10+
CREATEINDEXfailed_rumidxON test_rum USING rum (arum_tsvector_addon_ops);
1111

1212
SET enable_seqscan=off;
1313

‎src/rum_ts_utils.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ typedef Datum (*TSVectorEntryBuilder)(TSVector vector, WordEntry *we);
5858
typedefDatum (*TSQueryEntryBuilder)(TSQueryquery,QueryOperand*operand);
5959

6060
staticDatum*rum_extract_tsvector_internal(TSVectorvector,int32*nentries,
61-
Datum**addInfo,
61+
Datum**addInfo,
6262
bool**addInfoIsNull,
63-
TSVectorEntryBuilderbuild_tsvector_entry);
63+
TSVectorEntryBuilderbuild_tsvector_entry);
6464
staticDatum*rum_extract_tsquery_internal(TSQueryquery,int32*nentries,
65-
bool**ptr_partialmatch,
65+
bool**ptr_partialmatch,
6666
Pointer**extra_data,
6767
int32*searchMode,
6868
TSQueryEntryBuilderbuild_tsquery_entry);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp