@@ -3,6 +3,8 @@ CREATE EXTENSION tsvector2 SCHEMA test;
33ERROR: extension "tsvector2" must be installed in schema "public"
44CREATE EXTENSION tsvector2;
55CREATE TABLE test.t1(a tsvector2);
6+ -- use only indexes if possible
7+ SET enable_seqscan = off;
68CREATE OR REPLACE FUNCTION test.insert_records()
79RETURNS VOID AS $$
810DECLARE
1214 SELECT i FROM generate_series(1, 1000) i
1315 LOOP
1416 INSERT INTO test.t1(a)
15- SELECT array_to_tsvector2(array_agg(repeat(letter, floor(random() * count + 1)::int )))
17+ SELECT array_to_tsvector2(array_agg(repeat(letter, letters_count )))
1618 FROM (
17- SELECT chr(i) AS letter, b AS count
19+ SELECT chr(i) AS letter, b AS letters_count
1820 FROM generate_series(ascii('a'), ascii('z')) i
1921 FULL OUTER JOIN
2022 (SELECT b FROM generate_series(3, 12) b) t2
@@ -29,8 +31,8 @@ SELECT test.insert_records();
2931
3032(1 row)
3133
34+ -- btree
3235CREATE INDEX i1 ON test.t1 USING btree(a);
33- SET enable_seqscan = off;
3436EXPLAIN (COSTS OFF) SELECT * FROM test.t1 WHERE a >= 'a:1 b:2'::tsvector2;
3537 QUERY PLAN
3638---------------------------------------------------------
@@ -40,6 +42,31 @@ EXPLAIN (COSTS OFF) SELECT * FROM test.t1 WHERE a >= 'a:1 b:2'::tsvector2;
4042 Index Cond: (a >= '''a'':1 ''b'':2'::tsvector2)
4143(4 rows)
4244
45+ SELECT sum(length(a)) FROM test.t1 WHERE a >= 'a:1 b:2'::tsvector2;
46+ sum
47+ --------
48+ 260000
49+ (1 row)
50+
51+ DROP INDEX test.i1;
52+ -- gin
53+ CREATE INDEX i2 ON test.t1 USING gin(a);
54+ EXPLAIN (COSTS OFF) SELECT * FROM test.t1 WHERE a @@ 'zzz';
55+ QUERY PLAN
56+ -----------------------------------------------
57+ Bitmap Heap Scan on t1
58+ Recheck Cond: (a @@ '''zzz'''::tsquery)
59+ -> Bitmap Index Scan on i2
60+ Index Cond: (a @@ '''zzz'''::tsquery)
61+ (4 rows)
62+
63+ SELECT sum(length(a)) FROM test.t1 WHERE a @@ 'zzz';
64+ sum
65+ --------
66+ 260000
67+ (1 row)
68+
69+ DROP INDEX test.i2;
4370DROP SCHEMA test CASCADE;
4471NOTICE: drop cascades to 2 other objects
4572DETAIL: drop cascades to table test.t1
0 commit comments