how to get index scan at work?

Поиск
Список
Период
Сортировка
Искать

how to get index scan at work?

От:
Rajesh Kumar Mallah <mallah@trade-india.com>
Дата:
 Hi folks, 

can any one help me with this.

tradein_clients=> explain SELECT   email_id from email_bank where lower(email) = 'mallah@grex.org' ;
NOTICE:  QUERY PLAN:

Seq Scan on email_bank  (cost=0.00..25223.02 rows=9385 width=4)

EXPLAIN
tradein_clients=> explain SELECT   email_id from email_bank where email = 'mallah@grex.org' ;
NOTICE:  QUERY PLAN:

Index Scan using email_bank_email_key on email_bank  (cost=0.00..4.83 rows=1 width=4)

EXPLAIN

i want to query the data in case insensetive manner , but if i put lower(email)
index is not being used  any workarounds??
 

regds
Mallah.
 
 
 

Re: how to get index scan at work?

От:
Thomas Swan <tswan@olemiss.edu>
Дата:
 Rajesh Kumar Mallah wrote:
Hi folks,

can any one help me with this.

tradein_clients=> explain SELECT   email_id from email_bank where lower(email) = 'mallah@grex.org' ;
NOTICE:  QUERY PLAN:

Seq Scan on email_bank  (cost=0.00..25223.02 rows=9385 width=4)

EXPLAIN
tradein_clients=> explain SELECT   email_id from email_bank where email = 'mallah@grex.org' ;
NOTICE:  QUERY PLAN:

Index Scan using email_bank_email_key on email_bank  (cost=0.00..4.83 rows=1 width=4)

EXPLAIN

i want to query the data in case insensetive manner , but if i put lower(email)
index is not being used  any workarounds??
 

regds
Mallah.

ILIKE is the case insensitive comparison operator.  

SELECT   email_id from email_bank WHERE email ILIKE 'user@domain.org'

You might also want to create an using the lower function.

CREATE INDEX my_foo_index ON LOWER(email_bank(email));

Re: how to get index scan at work?

От:
Rajesh Kumar Mallah <mallah@trade-india.com>
Дата:
 Hi Thomas, 

it  did not  work  for me!

tradein_clients=> explain SELECT  email_id from email_bank where email ILIKE 'mallah@grex.org';
NOTICE:  QUERY PLAN:
Seq Scan on email_bank  (cost=0.00..22926.16 rows=1 width=4)
EXPLAIN
tradein_clients=> explain SELECT  email_id from email_bank where email = 'mallah@grex.org';
NOTICE:  QUERY PLAN:
Index Scan using email_bank_case_insen on email_bank  (cost=0.00..4.83 rows=1 width=4)
EXPLAIN
tradein_clients=>
 

btw i could not create the index the way you suggested

regds

tradein_clients=> CREATE UNIQUE  INDEX  email_bank_case_insen on LOWER(email_bank(email));
ERROR:  DefineIndex: relation "lower" not found
tradein_clients=>
 

Re: how to get index scan at work?

От:
Stephan Szabo <sszabo@megazone23.bigpanda.com>
Дата:

On Fri, 19 Apr 2002, Rajesh Kumar Mallah wrote:

> btw i could not create the index the way you suggested
>
> regds
>
> tradein_clients=> CREATE UNIQUE  INDEX  email_bank_case_insen on
> LOWER(email_bank(email));
> ERROR:  DefineIndex: relation "lower" not found
> tradein_clients=>

It actually should be:
create index email_bank_case_insen on email_bank(lower(email));

And that should allow
lower(email)=''
to be indexable.


FAQ