Skip to content

Commit 7f4ef62

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 4104297 commit 7f4ef62

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
@@ -201,7 +201,8 @@ typedef struct remoteConnHashEnt
201201
errdetail_internal("%s", msg))); \
202202
} \
203203
dblink_security_check(conn, rconn); \
204-
PQsetClientEncoding(conn, GetDatabaseEncodingName()); \
204+
if (PQclientEncoding(conn) != GetDatabaseEncoding()) \
205+
PQsetClientEncoding(conn, GetDatabaseEncodingName()); \
205206
freeconn = true; \
206207
} \
207208
} while (0)
@@ -280,8 +281,9 @@ dblink_connect(PG_FUNCTION_ARGS)
280281
/* check password actually used if not superuser */
281282
dblink_security_check(conn, rconn);
282283

283-
/* attempt to set client encoding to match server encoding */
284-
PQsetClientEncoding(conn, GetDatabaseEncodingName());
284+
/* attempt to set client encoding to match server encoding, if needed */
285+
if (PQclientEncoding(conn) != GetDatabaseEncoding())
286+
PQsetClientEncoding(conn, GetDatabaseEncodingName());
285287

286288
if (connname)
287289
{

0 commit comments

Comments
 (0)