Skip to content

Commit d6ca510

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 54aa5ef commit d6ca510

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
@@ -209,7 +209,8 @@ typedef struct remoteConnHashEnt
209209
errdetail_internal("%s", msg))); \
210210
} \
211211
dblink_security_check(conn, rconn); \
212-
PQsetClientEncoding(conn, GetDatabaseEncodingName()); \
212+
if (PQclientEncoding(conn) != GetDatabaseEncoding()) \
213+
PQsetClientEncoding(conn, GetDatabaseEncodingName()); \
213214
freeconn = true; \
214215
} \
215216
} while (0)
@@ -288,8 +289,9 @@ dblink_connect(PG_FUNCTION_ARGS)
288289
/* check password actually used if not superuser */
289290
dblink_security_check(conn, rconn);
290291

291-
/* attempt to set client encoding to match server encoding */
292-
PQsetClientEncoding(conn, GetDatabaseEncodingName());
292+
/* attempt to set client encoding to match server encoding, if needed */
293+
if (PQclientEncoding(conn) != GetDatabaseEncoding())
294+
PQsetClientEncoding(conn, GetDatabaseEncodingName());
293295

294296
if (connname)
295297
{

0 commit comments

Comments
 (0)