Skip to content

Commit 70165f2

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 ad910cc commit 70165f2

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
@@ -192,7 +192,8 @@ typedef struct remoteConnHashEnt
192192
errdetail_internal("%s", msg))); \
193193
} \
194194
dblink_security_check(conn, rconn); \
195-
PQsetClientEncoding(conn, GetDatabaseEncodingName()); \
195+
if (PQclientEncoding(conn) != GetDatabaseEncoding()) \
196+
PQsetClientEncoding(conn, GetDatabaseEncodingName()); \
196197
freeconn = true; \
197198
} \
198199
} while (0)
@@ -271,8 +272,9 @@ dblink_connect(PG_FUNCTION_ARGS)
271272
/* check password actually used if not superuser */
272273
dblink_security_check(conn, rconn);
273274

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

277279
if (connname)
278280
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy