[SQL] why does seq scan instead of index scan

2011-01-14 Thread 中川 誠貴

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=100.00..181.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.



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


Re: [SQL] why does seq scan instead of index scan

2011-01-14 Thread Tom Lane
=?iso-2022-jp?B?GyRCQ2ZAbiEhQD81LhsoQg==?=  writes:
> I'm trying to use like 'xx%' search on Text[] column.
> I thought it uses index scan. But actually it uses seq scan.

> Why?

Those ANY expressions are not indexable.

regards, tom lane

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


Re: [SQL] why does seq scan instead of index scan

2011-01-14 Thread 中川 誠貴

Thank you for your response.

Are there any technique to index that query for like search on Text[] 
Columns?



Thanks.


Nakagawa Maskai


--
From: "Tom Lane" 
Sent: Saturday, January 15, 2011 2:56 AM
To: "中川 誠貴" 
Cc: 
Subject: Re: [SQL] why does seq scan instead of index scan


=?iso-2022-jp?B?GyRCQ2ZAbiEhQD81LhsoQg==?=  writes:

I'm trying to use like 'xx%' search on Text[] column.
I thought it uses index scan. But actually it uses seq scan.



Why?


Those ANY expressions are not indexable.

regards, tom lane

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



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