X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 2FC669DC841 for ; Tue, 17 Jan 2006 16:14:21 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 80349-05 for ; Tue, 17 Jan 2006 16:14:21 -0400 (AST) X-Greylist: delayed 00:13:10.243888 by SQLgrey- Received: from l0isi08.larcb.ecs.nasa.gov (l0isi08u.ecs.nasa.gov [129.165.226.2]) by postgresql.org (Postfix) with ESMTP id E650D9DC993 for ; Tue, 17 Jan 2006 16:14:14 -0400 (AST) Received: (from hermes@localhost) by l0isi08.larcb.ecs.nasa.gov (AIX5.1/8.11.6p2/8.11.0) id k0HK1jd2187466 for ; Tue, 17 Jan 2006 15:01:45 -0500 X-Authentication-Warning: l0isi08.larcb.ecs.nasa.gov: hermes set sender to using -f Received: by larcb.ecs.nasa.gov via smwrap Version 5.1.5 id smwrapPGapMa; Tue Jan 17 15:01:23 2006 Message-ID: <43CD4CE5.3020506@larcb.ecs.nasa.gov> Date: Tue, 17 Jan 2006 15:00:37 -0500 From: Yantao Shi User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) MIME-Version: 1.0 To: Subject: wildcard search performance with "like" Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/259 X-Sequence-Number: 16737 Hi, I have a postges 8.1.1 table with over 29 million rows in it. The colunm (file_name) that I need to search on has entries like the following: MOD04_L2.A2005311.1400.004.2005312013848.hdf MYD04_L2.A2005311.0700.004.2005312013437.hdf I have an index on this column. But an index search is performance only when I give the full file_name for search: testdbspc=# explain select file_name from catalog where file_name = 'MOD04_L2.A2005311.1400.004.2005312013848.hdf'; QUERY PLAN Index Scan using catalog_pk_idx on catalog (cost=0.00..6.01 rows=1 width=404) Index Cond: (file_name = 'MOD04_L2.A2005311.1400.004.2005312013848.hdf'::bpchar) (2 rows) What I really need to do most of the time is a multi-wildcard search on this column, which is now doing a whole table scan without using the index at all: testdbspc=# explain select file_name from catalog where file_name like 'MOD04_L2.A2005311.%.004.2005312013%.hdf'; QUERY PLAN Seq Scan on catalog (cost=0.00..429.00 rows=1 width=404) Filter: (file_name ~~ 'MOD04_L2.A2005311.%.004.2005312013%.hdf'::text) (2 rows) Obviously, the performance of the table scan on such a large table is not acceptable. I tried full-text indexing and searching. It did NOT work on this column because all the letters and numbers are linked together with "." and considered one big single word by to_tsvector. Any solutions for this column to use an index search with multiple wild cards? Thanks a lot, Yantao Shi