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