Forum .LRN Q&A: Response to Message View in Forums is very slow on Postgresql

I have replaced the subselect
(select fm2.subject
                    from forums_messages fm2
                    where fm2.message_id = forums_message__root_message_id(foru
ms_messages.message_id)) as root_subject
with
(select forums_message__get_subject(forums_message__root_message_id(forums_messages.message_id)) as root_subject
and created this function

create function forums_message__get_subject(integer) returns varchar
as '
declare
  p_message_id  alias for $1;
  v_subject     varchar;
begin

        select subject into v_subject from
        forums_messages where message_id=p_message_id;
return v_subject;
end;' language 'plpgsql';
which causes postgresql to use an index scan to get the subject. Response time is greatly improved.