Re: How does Index Scan get used
От | Frank Bax |
---|---|
Тема | Re: How does Index Scan get used |
Дата | |
Msg-id | 3.0.6.32.20020222151337.0079ac40@pop6.sympatico.ca обсуждение исходный текст |
Ответ на | How does Index Scan get used ("Samuel J. Sutjiono" <ssutjiono@wc-group.com>) |
Список | pgsql-sql |
LIKE works fine on my system (see regex notes below): fbax=# create table test (test_col text); CREATE fbax=# create index test_index on test (test_col); CREATE fbax=# insert into test values ('abc.xyz'); INSERT 6189442 1 fbax=# insert into test values ('abcxyz'); INSERT 6189443 1 fbax=# insert into test values ('abc/xyz'); INSERT 6189444 1 fbax=# explain select * from test where test_col like 'abc/%'; NOTICE: QUERY PLAN: Index Scan using test_index on test (cost=0.00..8.14 rows=10 width=12) EXPLAIN fbax=# select version(); version -------------------------------------------------------------------PostgreSQL 7.1 on i386-unknown-openbsd2.9, compiled byGCC 2.95.3 (1 row) fbax=# create index test_lower_index on test (lower(test_col)); CREATE fbax=# explain select * from test where lower(test_col) ~ '^abc'; NOTICE: QUERY PLAN: Seq Scan on test (cost=0.00..1.04 rows=1 width=12) EXPLAIN fbax=# insert into test ( select surname from chl_name ); INSERT 0 419 fbax=# vacuum analyse test; VACUUM fbax=# explain select * from test where lower(test_col) ~ '^abc'; NOTICE: QUERY PLAN: Index Scan using test_lower_index on test (cost=0.00..4.07 rows=4 width=12) EXPLAIN ===== ===== ===== ===== ===== regex ~* won't use index, because of the case-insensitive stuff. The above example only works when you anchor search to beginning of field using '^'. Frank At 09:46 AM 2/22/02 -0500, Samuel J. Sutjiono wrote: >I tried an Index Scan but I kept on getting Seq Scan. >Do you know why ? What do I need to do to get my query >to use index scan (I tried to turn it on by doing >SET ENABLE_indexscan = on; but it didn't work) > by doing SET ENABLE_indexscan = on; but it didn't work) >create table test (test_col text); >create index test_index on test (test_col); >insert into test values ('abc.xyz'); >insert into test values ('abcxyz'); >insert into test values ('abc/xyz'); > explain select * from test where test_col like 'abc/%'; >QUERY PLAN: >Seq Scan (cost=0.00..22.50 rows=10 width=12) >Another question: Does >Regex (~*) or like use table scan ? Thanks, Sam >_________________________________________________ > Expand your wireless world with Arkdom PLUS > http://www.arkdom.com/ >
В списке pgsql-sql по дате отправления: