From: | rawi <only4com(at)web(dot)de> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Index Usage and Running Times by FullTextSearch with prefix matching |
Date: | 2013-06-13 11:39:16 |
Message-ID: | 1371123556877-5759021.post@n5.nabble.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Hi
I tested the following:
CREATE TABLE t1
(
id serial NOT NULL,
a character varying(125),
a_tsvector tsvector,
CONSTRAINT t1_pkey PRIMARY KEY (id)
);
INSERT INTO t1 (a, a_tsvector)
VALUES ('ooooo,ppppp,fffff,jjjjj,zzzzz,jjjjj',
to_tsvector('ooooo,ppppp,fffff,jjjjj,zzzzz,jjjjj');
CREATE INDEX a_tsvector_idx ON t1 USING gin (a_tsvector);
(I have generated 900000 records with random words like this)
Now querying: normal full text search
SELECT count(a)
FROM t1
WHERE a_tsvector @@ to_tsquery('aaaaa & bbbbb & ccccc & ddddd')
(RESULT: count: 619)
Total query runtime: 353 ms.
Query Plan:
"Aggregate (cost=6315.22..6315.23 rows=1 width=36)"
" -> Bitmap Heap Scan on t1 (cost=811.66..6311.46 rows=1504 width=36)"
" Recheck Cond: (a_tsvector @@ to_tsquery('aaaaa & bbbbb & ccccc &
ddddd'::text))"
" -> Bitmap Index Scan on a_tsvector_idx (cost=0.00..811.28
rows=1504 width=0)"
" Index Cond: (a_tsvector @@ to_tsquery('aaaaa & bbbbb & ccccc
& ddddd'::text))"
And querying: FTS with prefix matching:
SELECT count(a)
FROM t1
WHERE a_tsvector @@ to_tsquery('aaa:* & b:* & c:* & d:*')
(RESULT: count: 619)
Total query runtime: 21266 ms.
Query Plan:
"Aggregate (cost=804.02..804.03 rows=1 width=36)"
" -> Bitmap Heap Scan on t1 (cost=800.00..804.02 rows=1 width=36)"
" Recheck Cond: (a_tsvector @@ to_tsquery('aaa:* & b:* & c:* &
d:*'::text))"
" -> Bitmap Index Scan on a_tsvector_idx (cost=0.00..800.00 rows=1
width=0)"
" Index Cond: (a_tsvector @@ to_tsquery('aaa:* & b:* & c:* &
d:*'::text))"
I don't understand the big query time difference, despite the explainig
index usage.
NOnetheless I'd like to simulate LIKE 'aaa%' with full text search. Would I
have a better sollution?
Many thanks in advance!
Rawi
--
View this message in context: http://postgresql.1045698.n5.nabble.com/Index-Usage-and-Running-Times-by-FullTextSearch-with-prefix-matching-tp5759021.html
Sent from the PostgreSQL - sql mailing list archive at Nabble.com.
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2013-06-13 14:56:38 | Re: Index Usage and Running Times by FullTextSearch with prefix matching |
Previous Message | Thomas Kellerer | 2013-06-07 14:26:49 | Re: Advice with an insert query |