pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: rawi <only4com@web.de>
To: pgsql-sql@postgresql.org
Subject: Index Usage and Running Times by FullTextSearch with prefix matching
Date: Thu, 13 Jun 2013 04:39:16 -0700 (PDT)
Message-ID: <1371123556877-5759021.post@n5.nabble.com> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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-...
Sent from the PostgreSQL - sql mailing list archive at Nabble.com.


-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql



view thread (6+ messages)  latest in thread

Message-ID: <1371123556877-5759021.post@n5.nabble.com>
Permalink:  ../1371123556877-5759021.post@n5.nabble.com/
Also on:    postgresql.org/message-id/1371123556877-5759021.post@n5.nabble.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: only4com@web.de
  Subject: Re: Index Usage and Running Times by FullTextSearch with prefix matching
  In-Reply-To: <1371123556877-5759021.post@n5.nabble.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox