Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 05CDA1337B3E for ; Fri, 14 Jan 2011 05:47:26 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 14793-06 for ; Fri, 14 Jan 2011 09:47:19 +0000 (UTC) X-Greylist: delayed 00:48:33.129737 by SQLgrey-1.7.6 Received: from smtpsvr.ivp.ne.jp (smtpsvr.ivp.ne.jp [59.159.236.17]) by mail.postgresql.org (Postfix) with ESMTP id 4DC711337B8A for ; Fri, 14 Jan 2011 05:47:17 -0400 (AST) Received: from IVPNAKAGAWAPC (ivpb.ivp.co.jp [219.96.232.34]) by smtpsvr.ivp.ne.jp (8.13.8/3.7W) with ESMTP id p0E8wg6a027577 for ; Fri, 14 Jan 2011 17:58:42 +0900 Message-ID: <49A94E2FF0F642B4ACBE09DB20CA5630@IVPNAKAGAWAPC> From: =?iso-2022-jp?B?GyRCQ2ZAbiEhQD81LhsoQg==?= To: Subject: why does seq scan instead of index scan Date: Fri, 14 Jan 2011 17:58:43 +0900 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-2022-jp"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal Importance: Normal X-Mailer: Microsoft Windows Live Mail 14.0.8117.416 X-MimeOLE: Produced By Microsoft MimeOLE V14.0.8117.416 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=2.195 tagged_above=-5 required=5 tests=BAYES_40=-0.001, STOX_REPLY_TYPE=0.439, STOX_REPLY_TYPE_WITHOUT_QUOTES=1.757 X-Spam-Level: ** X-Archive-Number: 201101/39 X-Sequence-Number: 34986 Hello everyone. I'm trying to use like 'xx%' search on Text[] column. Here is the SQL. Select * From table Where 'aa' <= ANY(keywords) and 'aa\uFFFD' > ANY(keywords) This looks like wooking as I intend. But partially not working. There is the explanation. Explain Select * From table Where 'aa' <= ANY(keywords) and 'aa\uFFFD' > ANY(keywords) --\uFFFD is max unicode -- keywords field is Text[] "Seq Scan on table (cost=10000000000.00..10000000081.98 rows=275 width=1870)" " Filter: (('aa'::text <= ANY (keywords)) AND ('aa\uFFFD'::text > ANY (keywords)))" I thought it uses index scan. But actually it uses seq scan. Why? I don't get it. When I seach with the following SQL on Text column, it uses index scan, and perfectlly working. Select * From table Where keyword >= 'aa' and keyword < 'aa\uFFFD' "Bitmap Heap Scan on table (cost=4.36..35.63 rows=11 width=1870)" " Recheck Cond: ((keyword >= 'aa'::text) AND (keyword < 'aa\uFFFD'::text))" " -> Bitmap Index Scan on table_keyword_idx (cost=0.00..4.36 rows=11 width=0)" " Index Cond: ((keyword >= 'aa'::text) AND (keyword < 'aa\uFFFD'::text))" INDEX table_keywords_idx ON table USING GIN (keywords); INDEX table_keyword_idx ON table USING btree (keyword); I changed the index, table_keywords_idx to btree, but also not working... Why index scan is not used on Text[], despite index scan used on Text field? Thank you in advance.