Tatsuo Ishii <t-ishii@sra.co.jp> writes:
> I have a plan to clean up the usage of putenv(), getenv() in libpq+MB
> configuration. This needs some interface changes with libpq in the
> frontend side. I'm not sure this is visible to end users or not, and I
> would like to hear from hackes.
I think it is a very good idea to remove getenv() from PQmblen().
getenv() is rather slow, at least on the machines I use, and having
to do it for each character processed is a huge performance hit.
PQmblen is exported by libpq (psql is an example of an application
that uses it). So very possibly, changing it would break a few client
applications. A possible answer is to leave PQmblen alone, and invent
a new routine with a different name that looks at PGconn. We could
deprecate PQmblen and delete it after a few releases. I'm not sure
if this is worth the trouble or not --- maybe it's OK to make a non-
compatible change to PQmblen.
> (1) While establishing a connection, if the environment variable
> PGCLIENTENCODING is not set, libpq asks the backend what the encoding
> for the database is.
> Above implementation has a design flaw since it is not multithread-safe.
You would still do one getenv() during connection setup, right, to see
if PGCLIENTENCODING is set? If you don't, that would be a significant
change in behavior that might make a lot of people unhappy.
regards, tom lane