]> granicus.if.org Git - postgresql/commitdiff
Fix performance regression in dblink connection speed.
authorJoe Conway <mail@joeconway.com>
Sun, 8 Dec 2013 00:59:35 +0000 (16:59 -0800)
committerJoe Conway <mail@joeconway.com>
Sun, 8 Dec 2013 00:59:35 +0000 (16:59 -0800)
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.

contrib/dblink/dblink.c

index 2cc7c8fefa13956674daee0a2e59a4b2cb1bbaf0..10a347fe5fbc48595ebe977b903e8eb1a13d97ad 100644 (file)
@@ -201,7 +201,8 @@ typedef struct remoteConnHashEnt
                                                         errdetail_internal("%s", msg))); \
                                } \
                                dblink_security_check(conn, rconn); \
-                               PQsetClientEncoding(conn, GetDatabaseEncodingName()); \
+                               if (PQclientEncoding(conn) != GetDatabaseEncoding()) \
+                                       PQsetClientEncoding(conn, GetDatabaseEncodingName()); \
                                freeconn = true; \
                        } \
        } while (0)
@@ -280,8 +281,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)
        {