Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Un5sB-0007p3-4p for pgsql-sql@arkaria.postgresql.org; Thu, 13 Jun 2013 11:39:23 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1Un5sA-0000Zm-8G for pgsql-sql@arkaria.postgresql.org; Thu, 13 Jun 2013 11:39:22 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Un5s9-0000Zg-5d for pgsql-sql@postgresql.org; Thu, 13 Jun 2013 11:39:21 +0000 Received: from sam.nabble.com ([216.139.236.26]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Un5s6-0004PA-1U for pgsql-sql@postgresql.org; Thu, 13 Jun 2013 11:39:20 +0000 Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1Un5s4-0001d8-Uu for pgsql-sql@postgresql.org; Thu, 13 Jun 2013 04:39:16 -0700 Date: Thu, 13 Jun 2013 04:39:16 -0700 (PDT) From: rawi To: pgsql-sql@postgresql.org Message-ID: <1371123556877-5759021.post@n5.nabble.com> Subject: Index Usage and Running Times by FullTextSearch with prefix matching MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: 1.9 (+) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org 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. -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql