|
| 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