From: Joe Conway Date: Sun, 8 Dec 2013 00:56:34 +0000 (-0800) Subject: Fix performance regression in dblink connection speed. X-Git-Tag: REL8_4_20~44 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6c8b16e30a2f8f32087fe5bf77213613bb8f9b21;p=postgresql Fix performance regression in dblink connection speed. Previous commit e5de601267d98c5d60df6de8d436685c7105d149 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. --- diff --git a/contrib/dblink/dblink.c b/contrib/dblink/dblink.c index cc8714dae6..a48949334d 100644 --- a/contrib/dblink/dblink.c +++ b/contrib/dblink/dblink.c @@ -191,7 +191,8 @@ typedef struct remoteConnHashEnt errdetail("%s", msg))); \ } \ dblink_security_check(conn, rconn); \ - PQsetClientEncoding(conn, GetDatabaseEncodingName()); \ + if (PQclientEncoding(conn) != GetDatabaseEncoding()) \ + PQsetClientEncoding(conn, GetDatabaseEncodingName()); \ freeconn = true; \ } \ } while (0) @@ -270,8 +271,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) {