Skip to content

Commit 9057adc

Browse files
committed
Fix performance regression in dblink connection speed.
Previous commit e5de601 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.
1 parent 36352ce commit 9057adc

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

contrib/dblink/dblink.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ typedef struct remoteConnHashEnt
193193
errdetail("%s", msg))); \
194194
} \
195195
dblink_security_check(conn, rconn); \
196-
PQsetClientEncoding(conn, GetDatabaseEncodingName()); \
196+
if (PQclientEncoding(conn) != GetDatabaseEncoding()) \
197+
PQsetClientEncoding(conn, GetDatabaseEncodingName()); \
197198
freeconn = true; \
198199
} \
199200
} while (0)
@@ -272,8 +273,9 @@ dblink_connect(PG_FUNCTION_ARGS)
272273
/* check password actually used if not superuser */
273274
dblink_security_check(conn, rconn);
274275

275-
/* attempt to set client encoding to match server encoding */
276-
PQsetClientEncoding(conn, GetDatabaseEncodingName());
276+
/* attempt to set client encoding to match server encoding, if needed */
277+
if (PQclientEncoding(conn) != GetDatabaseEncoding())
278+
PQsetClientEncoding(conn, GetDatabaseEncodingName());
277279

278280
if (connname)
279281
{

0 commit comments

Comments
 (0)