From ecbc7faa7a089359cc5a7279ce9c925cb8efb9f6 Mon Sep 17 00:00:00 2001 From: Johno Crawford Date: Mon, 6 Nov 2017 11:23:42 +0100 Subject: [PATCH] Fix for #88021 high GC pressure when driver configured with serversideprepared statements. --- src/com/mysql/jdbc/ConnectionImpl.java | 37 ++++++++++++---------------------- 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/src/com/mysql/jdbc/ConnectionImpl.java b/src/com/mysql/jdbc/ConnectionImpl.java index 14758ce9..e0fe1441 100644 --- a/src/com/mysql/jdbc/ConnectionImpl.java +++ b/src/com/mysql/jdbc/ConnectionImpl.java @@ -190,18 +190,17 @@ public class ConnectionImpl extends ConnectionPropertiesImpl implements MySQLCon * names soon will, so current catalog is a (hidden) component of the name. */ static class CompoundCacheKey { - String componentOne; + final String componentOne; - String componentTwo; + final String componentTwo; - int hashCode; + final int hashCode; CompoundCacheKey(String partOne, String partTwo) { this.componentOne = partOne; this.componentTwo = partTwo; - // Handle first component (in most cases, currentCatalog being NULL.... - this.hashCode = (((this.componentOne != null) ? this.componentOne : "") + this.componentTwo).hashCode(); + this.hashCode = 31 * (componentOne != null ? componentOne.hashCode() : 0) + (componentTwo != null ? componentTwo.hashCode() : 0); } /* @@ -210,22 +209,15 @@ public class ConnectionImpl extends ConnectionPropertiesImpl implements MySQLCon * @see java.lang.Object#equals(java.lang.Object) */ @Override - public boolean equals(Object obj) { - if (obj instanceof CompoundCacheKey) { - CompoundCacheKey another = (CompoundCacheKey) obj; - - boolean firstPartEqual = false; - - if (this.componentOne == null) { - firstPartEqual = (another.componentOne == null); - } else { - firstPartEqual = this.componentOne.equals(another.componentOne); - } + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; - return (firstPartEqual && this.componentTwo.equals(another.componentTwo)); - } + CompoundCacheKey that = (CompoundCacheKey) o; - return false; + if (componentOne != null ? !componentOne.equals(that.componentOne) : that.componentOne != null) + return false; + return componentTwo != null ? componentTwo.equals(that.componentTwo) : that.componentTwo == null; } /* @@ -4277,11 +4269,8 @@ public class ConnectionImpl extends ConnectionPropertiesImpl implements MySQLCon } - private String makePreparedStatementCacheKey(String catalog, String query) { - StringBuilder key = new StringBuilder(); - key.append("/*").append(catalog).append("*/"); - key.append(query); - return key.toString(); + private CompoundCacheKey makePreparedStatementCacheKey(String catalog, String query) { + return new CompoundCacheKey(catalog, query); } public void recachePreparedStatement(ServerPreparedStatement pstmt) throws SQLException { -- 2.13.6