Nick <nboutelier(at)gmail(dot)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 immutable.
http://www.postgresql.org/docs/8.4/static/xfunc-volatility.html
regards, tom lane