Postgre database ignoring created index ?!

Posted by drasto on Stack Overflow See other posts from Stack Overflow or by drasto
Published on 2010-05-18T23:07:58Z Indexed on 2010/05/18 23:10 UTC
Read the original article Hit count: 284

I have an Postgre database and a table called my_table. There are 4 columns in that table (id, column1, column2, column3). The id column is primary key, there are no other constrains or indexes on columns. The table has about 200000 rows.

I want to print out all rows which has value of column column2 equal(case insensitive) to 'value12'. I use this:

SELECT * FROM my_table WHERE column2 = lower('value12')

here is the execution plan for this statement(result of set enable_seqscan=on; EXPLAIN SELECT * FROM my_table WHERE column2 = lower('value12')):

Seq Scan on my_table (cost=0.00..4676.00 rows=10000 width=55)
Filter: ((column2)::text = 'value12'::text)

I consider this to be to slow so I create an index on column column2 for better prerformance of searches:

CREATE INDEX my_index ON my_table (lower(column2))

Now I ran the same select:

SELECT * FROM my_table WHERE column2 = lower('value12')

and I expect it to be much faster because it can use index. However it is not faster, it is as slow as before. So I check the execution plan and it is the same as before(see above). So it still uses sequential scen and it ignores the index! Where is the problem ?

© Stack Overflow or respective owner

Related posts about postgresql

Related posts about database