Dan Libby <dan(at)libby(dot)com> writes:
> Or failing that, I'd at least like to understand why the planner
> is deciding not to use the category_lang index when the result
> set is coming from a function instead of a "regular" table.
The planner defaults to assuming that set-returning functions return
1000 rows (as you can see in the EXPLAIN output). A plan that would
win for a single returned row would lose badly at 1000 rows ...
and vice versa. See the archives for various debates about how to
get a better estimate; it's not an easy problem.
regards, tom lane