Fix performance regression in dblink connection speed.

Previous commit e5de601267 modified dblink
to ensure client encoding matched the server. However the added
PQsetClientEncoding() call added significant overhead. Restore original
performance in the common case where client encoding already matches
server encoding by doing nothing in that case. Applies to all active
branches.

Issue reported and work sponsored by Zonar Systems.
This commit is contained in:
Joe Conway 2013-12-07 17:00:26 -08:00
parent 54aa5ef7f2
commit d6ca510d9d
1 changed files with 5 additions and 3 deletions

View File

@ -209,7 +209,8 @@ typedef struct remoteConnHashEnt
errdetail_internal("%s", msg))); \
} \
dblink_security_check(conn, rconn); \
PQsetClientEncoding(conn, GetDatabaseEncodingName()); \
if (PQclientEncoding(conn) != GetDatabaseEncoding()) \
PQsetClientEncoding(conn, GetDatabaseEncodingName()); \
freeconn = true; \
} \
} while (0)
@ -288,8 +289,9 @@ dblink_connect(PG_FUNCTION_ARGS)
/* check password actually used if not superuser */
dblink_security_check(conn, rconn);
/* attempt to set client encoding to match server encoding */
PQsetClientEncoding(conn, GetDatabaseEncodingName());
/* attempt to set client encoding to match server encoding, if needed */
if (PQclientEncoding(conn) != GetDatabaseEncoding())
PQsetClientEncoding(conn, GetDatabaseEncodingName());
if (connname)
{