From fd9b52575428d057b42b6b49c6640c6ec020f80e Mon Sep 17 00:00:00 2001 From: Florian Agsteiner Date: Mon, 28 Jan 2019 12:56:33 +0100 Subject: [PATCH] Setting logSlowQueries should not automatically enable profileSQL for all queries --- .../java/com/mysql/cj/protocol/a/NativeProtocol.java | 12 ++++++++++-- src/main/user-impl/java/com/mysql/cj/jdbc/StatementImpl.java | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/protocol-impl/java/com/mysql/cj/protocol/a/NativeProtocol.java b/src/main/protocol-impl/java/com/mysql/cj/protocol/a/NativeProtocol.java index eac18f51..64dbff19 100644 --- a/src/main/protocol-impl/java/com/mysql/cj/protocol/a/NativeProtocol.java +++ b/src/main/protocol-impl/java/com/mysql/cj/protocol/a/NativeProtocol.java @@ -1045,6 +1045,8 @@ public class NativeProtocol extends AbstractProtocol implem int resultSetId = rs.getResultId(); long eventDuration = queryEndTime - queryStartTime; + String eventCreationPoint = null; + if (queryWasSlow && !this.serverSession.queryWasSlow() /* don't log slow queries twice */) { StringBuilder mesgBuf = new StringBuilder(48 + profileQueryToLog.length()); @@ -1055,6 +1057,10 @@ public class NativeProtocol extends AbstractProtocol implem ProfilerEventHandler eventSink = getProfilerEventHandlerInstanceFunction.apply(); + if (eventCreationPoint == null) { + eventCreationPoint = LogUtils.findCallingClassAndMethod(new Throwable()); + } + eventSink.consumeEvent( new ProfilerEventImpl(ProfilerEvent.TYPE_SLOW_QUERY, "", catalog, threadId, queryId, resultSetId, System.currentTimeMillis(), eventDuration, this.queryTimingUnits, null, LogUtils.findCallingClassAndMethod(new Throwable()), mesgBuf.toString())); @@ -1069,11 +1075,13 @@ public class NativeProtocol extends AbstractProtocol implem } } - if (this.profileSQL || this.logSlowQueries) { + if (this.profileSQL) { ProfilerEventHandler eventSink = getProfilerEventHandlerInstanceFunction.apply(); - String eventCreationPoint = LogUtils.findCallingClassAndMethod(new Throwable()); + if (eventCreationPoint == null) { + eventCreationPoint = LogUtils.findCallingClassAndMethod(new Throwable()); + } if (this.logSlowQueries) { if (this.serverSession.noGoodIndexUsed()) { diff --git a/src/main/user-impl/java/com/mysql/cj/jdbc/StatementImpl.java b/src/main/user-impl/java/com/mysql/cj/jdbc/StatementImpl.java index 235eecf0..bd26b429 100644 --- a/src/main/user-impl/java/com/mysql/cj/jdbc/StatementImpl.java +++ b/src/main/user-impl/java/com/mysql/cj/jdbc/StatementImpl.java @@ -254,7 +254,7 @@ public class StatementImpl implements JdbcStatement { setFetchSize(defaultFetchSize); } - boolean profiling = this.profileSQL || this.useUsageAdvisor || this.logSlowQueries; + boolean profiling = this.profileSQL || this.useUsageAdvisor; if (profiling) { this.pointOfOrigin = LogUtils.findCallingClassAndMethod(new Throwable()); -- 2.16.2