Hello
>
> (1) Are there any good guidelines for what operations in pl/pgsql are
> optimized for which data structures? For example, it turns out that a great
> deal of time is being spent in the substring() function, which surprised me.
> I thought that by switching to an array, it might be faster, but that
> wasn't the case, at least in my tests. Having a sense of what I should and
> shouldn't be trying, and which built-in functions are particularly fast or
> slow, would be useful to know.
>
PL/pgSQL is perfect like glue for SQL. For all other isn't good
http://okbob.blogspot.com/2010/04/frequent-mistakes-in-plpgsql-design.html
http://www.pgsql.cz/index.php/PL/pgSQL_%28en%29#When_PL.2FpgSQL_is_not_applicable
>
> (2) Is there any configuration setting that would (perhaps) speed things up
> a bit? I thought that maybe work_mem would help, but the documentation
> didn't indicate this at all, and sure enough, nothing really changed when I
> increased it.
>
>
probably not
Just PL/pgSQL is not C, and you cannot do some heavy string or array operations.
Regards
Pavel Stehule