[GENERAL] Index not used when using a function

2010-01-13 Thread Nick
SELECT * FROM locations WHERE id = 12345 LIMIT 1 uses the primary key (id) index, but... SELECT * FROM locations WHERE id = get_location_id_from_ip(641923892) LIMIT 1 does not and is verrry slow. Any ideas why? Whats weird is that it works (uses index) on a previous db, but when I copied

Re: [GENERAL] Index not used when using a function

2010-01-13 Thread Tom Lane
Nick nboutel...@gmail.com writes: SELECT * FROM locations WHERE id = 12345 LIMIT 1 uses the primary key (id) index, but... SELECT * FROM locations WHERE id = get_location_id_from_ip(641923892) LIMIT 1 does not and is verrry slow. Any ideas why? You didn't mark the function stable or

Re: [GENERAL] Index not used when using a function

2010-01-13 Thread Nick
On Jan 13, 4:21 pm, t...@sss.pgh.pa.us (Tom Lane) wrote: Nick nboutel...@gmail.com writes: SELECT * FROM locations WHERE id = 12345 LIMIT 1 uses the primary key (id) index, but... SELECT * FROM locations WHERE id = get_location_id_from_ip(641923892) LIMIT 1 does not and is verrry slow.