This is an automated email from the ASF dual-hosted git repository.
sanjeet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/master by this push:
new 6b3a1f6935 PHOENIX-7536 Capture Query parsing time for Read/Write path
(#2238)
6b3a1f6935 is described below
commit 6b3a1f69357901d1094e6bb0b563d3620db480a2
Author: Rahul Kumar <[email protected]>
AuthorDate: Wed Jul 23 20:00:05 2025 +0530
PHOENIX-7536 Capture Query parsing time for Read/Write path (#2238)
---------
Co-authored-by: Rahul Kumar
<[email protected]>
---
.../org/apache/phoenix/execute/MutationState.java | 23 ++++---
.../org/apache/phoenix/jdbc/PhoenixStatement.java | 13 ++++
.../org/apache/phoenix/monitoring/MetricType.java | 1 +
.../phoenix/monitoring/MutationMetricQueue.java | 15 ++++-
.../phoenix/monitoring/OverAllQueryMetrics.java | 11 ++++
.../phoenix/monitoring/BasePhoenixMetricsIT.java | 2 +-
.../phoenix/monitoring/PhoenixMetricsIT.java | 70 +++++++++++++++++++++-
.../monitoring/OverAllQueryMetricsTest.java | 18 +++---
.../monitoring/TableMetricsManagerTest.java | 24 ++++----
9 files changed, 145 insertions(+), 32 deletions(-)
diff --git
a/phoenix-core-client/src/main/java/org/apache/phoenix/execute/MutationState.java
b/phoenix-core-client/src/main/java/org/apache/phoenix/execute/MutationState.java
index e605936d55..13bdff10a4 100644
---
a/phoenix-core-client/src/main/java/org/apache/phoenix/execute/MutationState.java
+++
b/phoenix-core-client/src/main/java/org/apache/phoenix/execute/MutationState.java
@@ -181,6 +181,7 @@ public class MutationState implements SQLCloseable {
private Map<String, Long> timeInExecuteMutationMap = new HashMap<>();
private static boolean allUpsertsMutations = true;
private static boolean allDeletesMutations = true;
+ private long mutationQueryParsingTimeMS = 0;
private final boolean indexRegionObserverEnabledAllTables;
@@ -1678,14 +1679,17 @@ public class MutationState implements SQLCloseable {
mutationCommitTime = EnvironmentEdgeManager.currentTimeMillis() -
startTime;
GLOBAL_MUTATION_COMMIT_TIME.update(mutationCommitTime);
MutationMetric failureMutationMetrics = MutationMetric.EMPTY_METRIC;
+ long mutationQueryParsingTimeMS = this.mutationQueryParsingTimeMS;
if (!areAllBatchesSuccessful) {
- failureMutationMetrics =
updateMutationBatchFailureMetrics(currentMutationBatch,
- htableNameStr, numFailedMutations, table.isTransactional());
+ failureMutationMetrics =
+ updateMutationBatchFailureMetrics(currentMutationBatch,
htableNameStr,
+ numFailedMutations, table.isTransactional(),
mutationQueryParsingTimeMS);
}
MutationMetric committedMutationsMetric =
getCommittedMutationsMetric(totalMutationBytesObject,
mutationBatchList, numMutations,
- numFailedMutations, numFailedPhase3Mutations,
mutationCommitTime, totalBatchCount);
+ numFailedMutations, numFailedPhase3Mutations,
mutationCommitTime, totalBatchCount,
+ mutationQueryParsingTimeMS);
// Combine failure mutation metrics with committed ones for the
final picture
committedMutationsMetric.combineMetric(failureMutationMetrics);
mutationMetricQueue.addMetricsForTable(htableNameStr,
committedMutationsMetric);
@@ -1751,7 +1755,7 @@ public class MutationState implements SQLCloseable {
*/
public static MutationMetricQueue.MutationMetric
updateMutationBatchFailureMetrics(
List<Mutation> failedMutationBatch, String tableName, long
numFailedMutations,
- boolean isTransactional) {
+ boolean isTransactional, long mutationQueryParsingTimeMS) {
if (
failedMutationBatch == null || failedMutationBatch.isEmpty()
@@ -1788,7 +1792,7 @@ public class MutationState implements SQLCloseable {
// we don't use transactions
return new MutationMetricQueue.MutationMetric(0, 0, 0, 0, 0, 0,
totalNumFailedMutations, 0, 0,
0, 0, numUpsertMutationsInBatch, allUpsertsMutations ? 1 : 0,
numDeleteMutationsInBatch,
- allDeletesMutations ? 1 : 0, 0);
+ allDeletesMutations ? 1 : 0, 0, mutationQueryParsingTimeMS);
}
/**
@@ -1806,7 +1810,8 @@ public class MutationState implements SQLCloseable {
*/
static MutationMetric getCommittedMutationsMetric(MutationBytes
totalMutationBytesObject,
List<List<Mutation>> unsentMutationBatchList, long numMutations, long
numFailedMutations,
- long numFailedPhase3Mutations, long mutationCommitTime, long
mutationBatchCounter) {
+ long numFailedPhase3Mutations, long mutationCommitTime, long
mutationBatchCounter,
+ long mutationQueryParsingTimeMS) {
long committedUpsertMutationBytes =
totalMutationBytesObject == null ? 0 :
totalMutationBytesObject.getUpsertMutationBytes();
long committedAtomicUpsertMutationBytes = totalMutationBytesObject == null
@@ -1858,7 +1863,7 @@ public class MutationState implements SQLCloseable {
deleteMutationCommitTime, 0, // num failed mutations have been counted
already in
// updateMutationBatchFailureMetrics()
committedUpsertMutationCounter, committedDeleteMutationCounter,
committedTotalMutationBytes,
- numFailedPhase3Mutations, 0, 0, 0, 0, mutationBatchCounter);
+ numFailedPhase3Mutations, 0, 0, 0, 0, mutationBatchCounter,
mutationQueryParsingTimeMS);
}
private void filterIndexCheckerMutations(Map<TableInfo, List<Mutation>>
mutationMap,
@@ -2459,6 +2464,10 @@ public class MutationState implements SQLCloseable {
timeInExecuteMutationMap.put(tableName, timeSpent);
}
+ public void setMutationQueryParsingTime(long time) {
+ mutationQueryParsingTimeMS = time;
+ }
+
public void resetExecuteMutationTimeMap() {
timeInExecuteMutationMap.clear();
}
diff --git
a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java
b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java
index da5e8a9d59..4e4a34ae29 100644
---
a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java
+++
b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java
@@ -295,6 +295,7 @@ public class PhoenixStatement implements
PhoenixMonitoredStatement, SQLCloseable
// Caching per Statement
protected final Calendar localCalendar = Calendar.getInstance();
private boolean validateLastDdlTimestamp;
+ private long sqlQueryParsingTime = 0;
public PhoenixStatement(PhoenixConnection connection) {
this.connection = connection;
@@ -312,6 +313,14 @@ public class PhoenixStatement implements
PhoenixMonitoredStatement, SQLCloseable
QueryServicesOptions.DEFAULT_THREAD_TIMEOUT_MS);
}
+ private void setSqlQueryParsingTime(long time) {
+ this.sqlQueryParsingTime = time;
+ }
+
+ private long getSqlQueryParsingTime() {
+ return this.sqlQueryParsingTime;
+ }
+
public PhoenixResultSet newResultSet(ResultIterator iterator, RowProjector
projector,
StatementContext context) throws SQLException {
return new PhoenixResultSet(iterator, projector, context);
@@ -416,6 +425,7 @@ public class PhoenixStatement implements
PhoenixMonitoredStatement, SQLCloseable
context.getScan() != null ? context.getScan().toString() :
null);
}
overallQuerymetrics.startQuery();
+
overallQuerymetrics.setQueryParsingTimeMS(getSqlQueryParsingTime());
rs = newResultSet(resultIterator, plan.getProjector(),
plan.getContext());
// newResultset sets lastResultset
//
ExecutableShowCreateTable/ExecutableShowTablesStatement/ExecutableShowSchemasStatement
@@ -605,6 +615,7 @@ public class PhoenixStatement implements
PhoenixMonitoredStatement, SQLCloseable
throw new UpgradeRequiredException();
}
state = connection.getMutationState();
+ state.setMutationQueryParsingTime(getSqlQueryParsingTime());
isUpsert = stmt instanceof ExecutableUpsertStatement;
isDelete = stmt instanceof ExecutableDeleteStatement;
if (
@@ -2456,6 +2467,7 @@ public class PhoenixStatement implements
PhoenixMonitoredStatement, SQLCloseable
}
protected CompilableStatement parseStatement(String sql) throws SQLException
{
+ long startQueryParsingTime = EnvironmentEdgeManager.currentTimeMillis();
PhoenixStatementParser parser = null;
try {
parser = new PhoenixStatementParser(sql, new ExecutableNodeFactory());
@@ -2463,6 +2475,7 @@ public class PhoenixStatement implements
PhoenixMonitoredStatement, SQLCloseable
throw ClientUtil.parseServerException(e);
}
CompilableStatement statement = parser.parseStatement();
+ setSqlQueryParsingTime(EnvironmentEdgeManager.currentTimeMillis() -
startQueryParsingTime);
return statement;
}
diff --git
a/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/MetricType.java
b/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/MetricType.java
index 6c2b5c4d07..8ee8de6971 100644
---
a/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/MetricType.java
+++
b/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/MetricType.java
@@ -209,6 +209,7 @@ public enum MetricType {
QUERY_OPTIMIZER_TIME_MS("qot", "Time elapsed in query optimizer",
LogLevel.INFO, PLong.INSTANCE),
QUERY_RESULT_ITR_TIME_MS("qrt", "Time elapsed in query result iterator",
LogLevel.INFO,
PLong.INSTANCE),
+ SQL_QUERY_PARSING_TIME_MS("pt", "Time elapsed in query parsing",
LogLevel.OFF, PLong.INSTANCE),
OPEN_PHOENIX_CONNECTIONS_COUNTER("o", "Number of open phoenix connections",
LogLevel.OFF,
PLong.INSTANCE),
OPEN_INTERNAL_PHOENIX_CONNECTIONS_COUNTER("io", "Number of open internal
phoenix connections",
diff --git
a/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/MutationMetricQueue.java
b/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/MutationMetricQueue.java
index 7ab5bf7d8d..5329646675 100644
---
a/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/MutationMetricQueue.java
+++
b/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/MutationMetricQueue.java
@@ -29,6 +29,7 @@ import static
org.apache.phoenix.monitoring.MetricType.MUTATION_BATCH_FAILED_SIZ
import static org.apache.phoenix.monitoring.MetricType.MUTATION_BATCH_SIZE;
import static org.apache.phoenix.monitoring.MetricType.MUTATION_BYTES;
import static org.apache.phoenix.monitoring.MetricType.MUTATION_COMMIT_TIME;
+import static
org.apache.phoenix.monitoring.MetricType.SQL_QUERY_PARSING_TIME_MS;
import static
org.apache.phoenix.monitoring.MetricType.UPSERT_BATCH_FAILED_COUNTER;
import static
org.apache.phoenix.monitoring.MetricType.UPSERT_BATCH_FAILED_SIZE;
import static org.apache.phoenix.monitoring.MetricType.UPSERT_COMMIT_TIME;
@@ -113,6 +114,8 @@ public class MutationMetricQueue {
metric.getDeleteBatchFailedCounter().getValue());
publishedMetricsForTable.put(metric.getMutationBatchCounter().getMetricType(),
metric.getMutationBatchCounter().getValue());
+
publishedMetricsForTable.put(metric.getMutationQueryParsingTimeMS().getMetricType(),
+ metric.getMutationQueryParsingTimeMS().getValue());
}
return publishedMetrics;
}
@@ -154,6 +157,8 @@ public class MutationMetricQueue {
new CombinableMetricImpl(DELETE_BATCH_FAILED_SIZE);
private final CombinableMetric deleteBatchFailedCounter =
new CombinableMetricImpl(DELETE_BATCH_FAILED_COUNTER);
+ private final CombinableMetric mutationQueryParsingTimeMS =
+ new CombinableMetricImpl(SQL_QUERY_PARSING_TIME_MS);
private final CombinableMetric numOfIndexCommitFailMutations =
new CombinableMetricImpl(INDEX_COMMIT_FAILURE_SIZE);
@@ -162,14 +167,14 @@ public class MutationMetricQueue {
new CombinableMetricImpl(MUTATION_BATCH_COUNTER);
public static final MutationMetric EMPTY_METRIC =
- new MutationMetric(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
+ new MutationMetric(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
public MutationMetric(long numMutations, long upsertMutationsSizeBytes,
long deleteMutationsSizeBytes, long commitTimeForUpserts, long
commitTimeForAtomicUpserts,
long commitTimeForDeletes, long numFailedMutations, long
upsertMutationSqlCounterSuccess,
long deleteMutationSqlCounterSuccess, long totalMutationBytes, long
numOfPhase3Failed,
long upsertBatchFailedSize, long upsertBatchFailedCounter, long
deleteBatchFailedSize,
- long deleteBatchFailedCounter, long mutationBatchCounter) {
+ long deleteBatchFailedCounter, long mutationBatchCounter, long
mutationParsingTimeMS) {
this.numMutations.change(numMutations);
this.totalCommitTimeForUpserts.change(commitTimeForUpserts);
this.totalCommitTimeForAtomicUpserts.change(commitTimeForAtomicUpserts);
@@ -187,6 +192,7 @@ public class MutationMetricQueue {
this.deleteBatchFailedSize.change(deleteBatchFailedSize);
this.deleteBatchFailedCounter.change(deleteBatchFailedCounter);
this.mutationBatchCounter.change(mutationBatchCounter);
+ this.mutationQueryParsingTimeMS.change(mutationParsingTimeMS);
}
public CombinableMetric getTotalCommitTimeForUpserts() {
@@ -257,6 +263,10 @@ public class MutationMetricQueue {
return mutationBatchCounter;
}
+ public CombinableMetric getMutationQueryParsingTimeMS() {
+ return mutationQueryParsingTimeMS;
+ }
+
public void combineMetric(MutationMetric other) {
this.numMutations.combine(other.numMutations);
this.totalCommitTimeForUpserts.combine(other.totalCommitTimeForUpserts);
@@ -275,6 +285,7 @@ public class MutationMetricQueue {
this.deleteBatchFailedSize.combine(other.deleteBatchFailedSize);
this.deleteBatchFailedCounter.combine(other.deleteBatchFailedCounter);
this.mutationBatchCounter.combine(other.mutationBatchCounter);
+
this.mutationQueryParsingTimeMS.combine(other.mutationQueryParsingTimeMS);
}
}
diff --git
a/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/OverAllQueryMetrics.java
b/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/OverAllQueryMetrics.java
index 97d7fcf74d..101f01674a 100644
---
a/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/OverAllQueryMetrics.java
+++
b/phoenix-core-client/src/main/java/org/apache/phoenix/monitoring/OverAllQueryMetrics.java
@@ -29,6 +29,7 @@ import static
org.apache.phoenix.monitoring.MetricType.QUERY_SCAN_FAILED_COUNTER
import static
org.apache.phoenix.monitoring.MetricType.QUERY_SCAN_TIMEOUT_COUNTER;
import static org.apache.phoenix.monitoring.MetricType.QUERY_TIMEOUT_COUNTER;
import static org.apache.phoenix.monitoring.MetricType.RESULT_SET_TIME_MS;
+import static
org.apache.phoenix.monitoring.MetricType.SQL_QUERY_PARSING_TIME_MS;
import static org.apache.phoenix.monitoring.MetricType.WALL_CLOCK_TIME_MS;
import java.util.HashMap;
@@ -56,6 +57,7 @@ public class OverAllQueryMetrics {
private final CombinableMetric queryPointLookupFailed;
private final CombinableMetric queryScanFailed;
private final CombinableMetric cacheRefreshedDueToSplits;
+ private final CombinableMetric queryParsingTimeMS;
public OverAllQueryMetrics(boolean isRequestMetricsEnabled, LogLevel
connectionLogLevel) {
queryWatch = MetricUtil.getMetricsStopWatch(isRequestMetricsEnabled,
connectionLogLevel,
@@ -88,6 +90,8 @@ public class OverAllQueryMetrics {
QUERY_SCAN_FAILED_COUNTER);
cacheRefreshedDueToSplits =
MetricUtil.getCombinableMetric(isRequestMetricsEnabled,
connectionLogLevel, CACHE_REFRESH_SPLITS_COUNTER);
+ queryParsingTimeMS =
MetricUtil.getCombinableMetric(isRequestMetricsEnabled, connectionLogLevel,
+ SQL_QUERY_PARSING_TIME_MS);
}
public void updateNumParallelScans(long numParallelScans) {
@@ -170,6 +174,10 @@ public class OverAllQueryMetrics {
return resultSetTimeMS.getValue();
}
+ public void setQueryParsingTimeMS(long time) {
+ queryParsingTimeMS.set(time);
+ }
+
public Map<MetricType, Long> publish() {
Map<MetricType, Long> metricsForPublish = new HashMap<>();
metricsForPublish.put(numParallelScans.getMetricType(),
numParallelScans.getValue());
@@ -189,6 +197,7 @@ public class OverAllQueryMetrics {
metricsForPublish.put(queryScanFailed.getMetricType(),
queryScanFailed.getValue());
metricsForPublish.put(cacheRefreshedDueToSplits.getMetricType(),
cacheRefreshedDueToSplits.getValue());
+ metricsForPublish.put(queryParsingTimeMS.getMetricType(),
queryParsingTimeMS.getValue());
return metricsForPublish;
}
@@ -206,6 +215,7 @@ public class OverAllQueryMetrics {
queryPointLookupFailed.reset();
queryScanFailed.reset();
cacheRefreshedDueToSplits.reset();
+ queryParsingTimeMS.reset();
queryWatch.stop();
resultSetWatch.stop();
}
@@ -224,6 +234,7 @@ public class OverAllQueryMetrics {
queryCompilerTimeMS.combine(queryCompilerTimeMS);
queryOptimizerTimeMS.combine(queryOptimizerTimeMS);
queryResultItrSetTimeMS.combine(queryResultItrSetTimeMS);
+ queryParsingTimeMS.combine(metric.queryParsingTimeMS);
return this;
}
diff --git
a/phoenix-core/src/it/java/org/apache/phoenix/monitoring/BasePhoenixMetricsIT.java
b/phoenix-core/src/it/java/org/apache/phoenix/monitoring/BasePhoenixMetricsIT.java
index 99c51301b2..05538f5da4 100644
---
a/phoenix-core/src/it/java/org/apache/phoenix/monitoring/BasePhoenixMetricsIT.java
+++
b/phoenix-core/src/it/java/org/apache/phoenix/monitoring/BasePhoenixMetricsIT.java
@@ -115,7 +115,7 @@ public abstract class BasePhoenixMetricsIT extends BaseTest
{
assertEquals("Table names didn't match!", tableName, t);
Map<MetricType, Long> p = entry.getValue();
- assertEquals("There should have been seventeen metrics", 17, p.size());
+ assertEquals("There should have been eighteen metrics", 18, p.size());
boolean mutationBatchSizePresent = false;
boolean mutationCommitTimePresent = false;
diff --git
a/phoenix-core/src/it/java/org/apache/phoenix/monitoring/PhoenixMetricsIT.java
b/phoenix-core/src/it/java/org/apache/phoenix/monitoring/PhoenixMetricsIT.java
index 19d28a6ce9..0d6e1c5f8e 100644
---
a/phoenix-core/src/it/java/org/apache/phoenix/monitoring/PhoenixMetricsIT.java
+++
b/phoenix-core/src/it/java/org/apache/phoenix/monitoring/PhoenixMetricsIT.java
@@ -55,6 +55,7 @@ import static
org.apache.phoenix.monitoring.MetricType.QUERY_COMPILER_TIME_MS;
import static org.apache.phoenix.monitoring.MetricType.QUERY_OPTIMIZER_TIME_MS;
import static
org.apache.phoenix.monitoring.MetricType.QUERY_RESULT_ITR_TIME_MS;
import static org.apache.phoenix.monitoring.MetricType.QUERY_TIMEOUT_COUNTER;
+import static
org.apache.phoenix.monitoring.MetricType.SQL_QUERY_PARSING_TIME_MS;
import static org.apache.phoenix.monitoring.MetricType.TASK_END_TO_END_TIME;
import static org.apache.phoenix.monitoring.MetricType.TASK_EXECUTED_COUNTER;
import static org.apache.phoenix.monitoring.MetricType.TASK_EXECUTION_TIME;
@@ -132,8 +133,9 @@ public class PhoenixMetricsIT extends BasePhoenixMetricsIT {
"DELETE FROM %s WHERE A=? AND B=? AND C=? AND D=? AND G=FALSE";
private static final String DELETE_ALL_DML = "DELETE FROM %s";
- private static final List<MetricType> mutationMetricsToSkip =
Lists.newArrayList(
- MUTATION_COMMIT_TIME, UPSERT_COMMIT_TIME, DELETE_COMMIT_TIME,
MUTATION_BATCH_COUNTER);
+ private static final List<MetricType> mutationMetricsToSkip =
+ Lists.newArrayList(MUTATION_COMMIT_TIME, UPSERT_COMMIT_TIME,
DELETE_COMMIT_TIME,
+ MUTATION_BATCH_COUNTER, SQL_QUERY_PARSING_TIME_MS);
private static final List<MetricType> readMetricsToSkip =
Lists.newArrayList(TASK_QUEUE_WAIT_TIME,
TASK_EXECUTION_TIME, TASK_END_TO_END_TIME, COUNT_MILLS_BETWEEN_NEXTS);
private static final String CUSTOM_URL_STRING = "SESSION";
@@ -574,7 +576,7 @@ public class PhoenixMetricsIT extends BasePhoenixMetricsIT {
String t = entry.getKey();
assertEquals("Table names didn't match!", tableName, t);
Map<MetricType, Long> p = entry.getValue();
- assertEquals("There should have been seventeen metrics", 17, p.size());
+ assertEquals("There should have been eighteen metrics", 18, p.size());
boolean mutationBatchSizePresent = false;
boolean mutationCommitTimePresent = false;
boolean mutationBytesPresent = false;
@@ -1386,6 +1388,68 @@ public class PhoenixMetricsIT extends
BasePhoenixMetricsIT {
}
}
+ @Test
+ public void testQueryParsingTimeForUpsertAndSelect() throws Exception {
+ String tableName1 = generateUniqueName();
+ String tableName2 = generateUniqueName();
+ int sourceNumRows = 1;
+
+ Connection conn = DriverManager.getConnection(getUrl());
+ String ddl1 = "CREATE TABLE " + tableName1 + " (" + "ID INTEGER NOT NULL
PRIMARY KEY, "
+ + "CATEGORY VARCHAR(30), " + "REGION VARCHAR(30), " + "DISTRICT
VARCHAR(30)" + ")";
+ conn.createStatement().execute(ddl1);
+
+ String ddl2 = "CREATE TABLE " + tableName2 + " (" + "ID INTEGER NOT NULL
PRIMARY KEY, "
+ + "CATEGORY VARCHAR(30), " + "REGION VARCHAR(30), " + "DISTRICT
VARCHAR(30)" + ")";
+ conn.createStatement().execute(ddl2);
+
+ String upsert1 =
+ "UPSERT INTO " + tableName1 + " (ID, CATEGORY, REGION, DISTRICT) " +
"VALUES (?, ?, ?, ?)";
+
+ PreparedStatement pstmt1 = conn.prepareStatement(upsert1);
+ // Need to upsert at least 1 row to initialize Mutation metrics
+ // which further gets used in QueryParsingTime metrics.
+ for (int i = 0; i < sourceNumRows; i++) {
+ pstmt1.setInt(1, i);
+ pstmt1.setString(2, "CATEGORY_" + (i % 1));
+ pstmt1.setString(3, "REGION_" + (i % 1));
+ pstmt1.setString(4, "DISTRICT_" + (i % 1));
+ pstmt1.execute();
+ }
+ conn.commit();
+
+ // Creating a query with lots of IN CLAUSE to increase query parsing time
+ String whereStr =
+ " REGION IN ('REGION_0', 'REGION_1', 'REGION_2', 'REGION_3',
'REGION_4', 'REGION_5') "
+ + " AND CATEGORY IN ('CATEGORY_0', 'CATEGORY_1', 'CATEGORY_2',
'CATEGORY_3') "
+ + " AND DISTRICT IN ('DISTRICT_0', 'DISTRICT_1', 'DISTRICT_2',
'DISTRICT_3') ";
+
+ String whereCaluse = whereStr;
+ for (int i = 0; i < 50; i++) {
+ whereCaluse += "AND " + whereStr;
+ }
+
+ String queryStr =
+ " SELECT " + " ID, REGION" + " FROM " + tableName1 + " WHERE " +
whereCaluse;
+
+ PhoenixRuntime.resetMetrics(conn);
+ String upsertSelectQuery = "UPSERT INTO " + tableName2 + " " + queryStr;
+ conn = DriverManager.getConnection(getUrl());
+ PreparedStatement Sstmt = conn.prepareStatement(upsertSelectQuery);
+ Sstmt.executeUpdate();
+ conn.commit();
+
+ Map<String, Map<MetricType, Long>> mutationMetrics =
+ PhoenixRuntime.getWriteMetricInfoForMutationsSinceLastReset(conn);
+ long parsingTime =
mutationMetrics.get(tableName2).get(SQL_QUERY_PARSING_TIME_MS);
+ assertTrue("parsing time should be greater than zero", parsingTime > 0);
+ ResultSet rs = conn.createStatement().executeQuery(queryStr);
+ Map<MetricType, Long> overallReadMetrics =
PhoenixRuntime.getOverAllReadRequestMetricInfo(rs);
+ assertTrue("Query parsing time should be greater than zero",
+ overallReadMetrics.get(SQL_QUERY_PARSING_TIME_MS) > 0);
+ conn.close();
+ }
+
private static class GetConnectionCallable implements Callable<Connection> {
private final String url;
diff --git
a/phoenix-core/src/test/java/org/apache/phoenix/monitoring/OverAllQueryMetricsTest.java
b/phoenix-core/src/test/java/org/apache/phoenix/monitoring/OverAllQueryMetricsTest.java
index 3ce36d5a1b..89a1299d7e 100644
---
a/phoenix-core/src/test/java/org/apache/phoenix/monitoring/OverAllQueryMetricsTest.java
+++
b/phoenix-core/src/test/java/org/apache/phoenix/monitoring/OverAllQueryMetricsTest.java
@@ -26,6 +26,7 @@ import static
org.apache.phoenix.monitoring.MetricType.QUERY_OPTIMIZER_TIME_MS;
import static
org.apache.phoenix.monitoring.MetricType.QUERY_RESULT_ITR_TIME_MS;
import static org.apache.phoenix.monitoring.MetricType.QUERY_TIMEOUT_COUNTER;
import static org.apache.phoenix.monitoring.MetricType.RESULT_SET_TIME_MS;
+import static
org.apache.phoenix.monitoring.MetricType.SQL_QUERY_PARSING_TIME_MS;
import static org.apache.phoenix.monitoring.MetricType.WALL_CLOCK_TIME_MS;
import static org.junit.Assert.assertEquals;
@@ -108,20 +109,20 @@ public class OverAllQueryMetricsTest {
overAllQueryMetrics.startQuery();
overAllQueryMetrics.startResultSetWatch();
assertPublishedMetrics(overAllQueryMetrics.publish(), numParallelScans,
queryTimeouts,
- queryFailures, cacheRefreshesDueToSplits, 0L, delta, delta, delta);
+ queryFailures, cacheRefreshesDueToSplits, 0L, delta, delta, delta,
delta);
overAllQueryMetrics.endQuery();
overAllQueryMetrics.stopResultSetWatch();
// expect 2 * delta since we call both endQuery() and stopResultSetWatch()
assertPublishedMetrics(overAllQueryMetrics.publish(), numParallelScans,
queryTimeouts,
- queryFailures, cacheRefreshesDueToSplits, 2 * delta, delta, delta,
delta);
+ queryFailures, cacheRefreshesDueToSplits, 2 * delta, delta, delta,
delta, delta);
}
@Test
public void testReset() {
assertPublishedMetrics(overAllQueryMetrics.publish(), numParallelScans,
queryTimeouts,
- queryFailures, cacheRefreshesDueToSplits, 0L, delta, delta, delta);
+ queryFailures, cacheRefreshesDueToSplits, 0L, delta, delta, delta,
delta);
overAllQueryMetrics.reset();
- assertPublishedMetrics(overAllQueryMetrics.publish(), 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L);
+ assertPublishedMetrics(overAllQueryMetrics.publish(), 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L);
}
@Test
@@ -136,7 +137,8 @@ public class OverAllQueryMetricsTest {
OverAllQueryMetrics finalMetricObj =
this.overAllQueryMetrics.combine(otherMetrics);
assertPublishedMetrics(finalMetricObj.publish(), numParallelScans +
otherNumParallelScans,
queryTimeouts + otherQueryTimeouts, queryFailures + otherQueryFailures,
- cacheRefreshesDueToSplits + otherCacheRefreshes, 0L, 2 * delta, 2 *
delta, 2 * delta);
+ cacheRefreshesDueToSplits + otherCacheRefreshes, 0L, 2 * delta, 2 *
delta, 2 * delta,
+ 2 * delta);
}
@Test
@@ -164,13 +166,15 @@ public class OverAllQueryMetricsTest {
metricsObj.setQueryCompilerTimeMS(delta);
metricsObj.setQueryOptimizerTimeMS(delta);
metricsObj.setQueryResultItrTimeMS(delta);
+ metricsObj.setQueryParsingTimeMS(delta);
}
private void assertPublishedMetrics(final Map<MetricType, Long> metrics,
final long expectedNumParallelScans, final long expectedQueryTimeouts,
final long expectedQueryFailures, final long expectedCacheRefreshes,
final long expectedElapsedTime, final long expectedQueryCompilerTimeMS,
- final long expectedQueryOptimizerTimeMS, final long
expectedQueryResultItrSetTimeMS) {
+ final long expectedQueryOptimizerTimeMS, final long
expectedQueryResultItrSetTimeMS,
+ final long expectedQueryParsingTime) {
assertEquals(expectedNumParallelScans, (long)
metrics.get(NUM_PARALLEL_SCANS));
assertEquals(expectedQueryTimeouts, (long)
metrics.get(QUERY_TIMEOUT_COUNTER));
assertEquals(expectedQueryFailures, (long)
metrics.get(QUERY_FAILED_COUNTER));
@@ -180,6 +184,6 @@ public class OverAllQueryMetricsTest {
assertEquals(expectedQueryCompilerTimeMS, (long)
metrics.get(QUERY_COMPILER_TIME_MS));
assertEquals(expectedQueryOptimizerTimeMS, (long)
metrics.get(QUERY_OPTIMIZER_TIME_MS));
assertEquals(expectedQueryResultItrSetTimeMS, (long)
metrics.get(QUERY_RESULT_ITR_TIME_MS));
+ assertEquals(expectedQueryParsingTime, (long)
metrics.get(SQL_QUERY_PARSING_TIME_MS));
}
-
}
diff --git
a/phoenix-core/src/test/java/org/apache/phoenix/monitoring/TableMetricsManagerTest.java
b/phoenix-core/src/test/java/org/apache/phoenix/monitoring/TableMetricsManagerTest.java
index 63e6543fce..e667fb801d 100644
---
a/phoenix-core/src/test/java/org/apache/phoenix/monitoring/TableMetricsManagerTest.java
+++
b/phoenix-core/src/test/java/org/apache/phoenix/monitoring/TableMetricsManagerTest.java
@@ -247,37 +247,37 @@ public class TableMetricsManagerTest {
TableMetricsManager.updateLatencyHistogramForMutations(tableName, 1, true);
MutationMetricQueue.MutationMetric metric = new
MutationMetricQueue.MutationMetric(0L, 5L, 0L,
- 0L, 0L, 0L, 0L, 1L, 0L, 5L, 0L, 0L, 0L, 0L, 0L, 0L);
+ 0L, 0L, 0L, 0L, 1L, 0L, 5L, 0L, 0L, 0L, 0L, 0L, 0L, 0L);
TableMetricsManager.updateSizeHistogramMetricsForMutations(tableName,
metric.getTotalMutationsSizeBytes().getValue(), true);
TableMetricsManager.updateLatencyHistogramForMutations(tableName, 2, true);
metric = new MutationMetricQueue.MutationMetric(0L, 10L, 0L, 0L, 0L, 0L,
0L, 1L, 0L, 10L, 0L,
- 0L, 0L, 0L, 0L, 0L);
+ 0L, 0L, 0L, 0L, 0L, 0L);
TableMetricsManager.updateSizeHistogramMetricsForMutations(tableName,
metric.getTotalMutationsSizeBytes().getValue(), true);
TableMetricsManager.updateLatencyHistogramForMutations(tableName, 4, true);
metric = new MutationMetricQueue.MutationMetric(0L, 50L, 0L, 0L, 0L, 0L,
0L, 1L, 0L, 50L, 0L,
- 0L, 0L, 0L, 0L, 0L);
+ 0L, 0L, 0L, 0L, 0L, 0L);
TableMetricsManager.updateSizeHistogramMetricsForMutations(tableName,
metric.getTotalMutationsSizeBytes().getValue(), true);
TableMetricsManager.updateLatencyHistogramForMutations(tableName, 5, true);
metric = new MutationMetricQueue.MutationMetric(0L, 100L, 0L, 0L, 0L, 0L,
0L, 1L, 0L, 100L, 0L,
- 0L, 0L, 0L, 0L, 0L);
+ 0L, 0L, 0L, 0L, 0L, 0L);
TableMetricsManager.updateSizeHistogramMetricsForMutations(tableName,
metric.getTotalMutationsSizeBytes().getValue(), true);
TableMetricsManager.updateLatencyHistogramForMutations(tableName, 6, true);
metric = new MutationMetricQueue.MutationMetric(0L, 500L, 0L, 0L, 0L, 0L,
0L, 1L, 0L, 500L, 0L,
- 0L, 0L, 0L, 0L, 0L);
+ 0L, 0L, 0L, 0L, 0L, 0L);
TableMetricsManager.updateSizeHistogramMetricsForMutations(tableName,
metric.getTotalMutationsSizeBytes().getValue(), true);
TableMetricsManager.updateLatencyHistogramForMutations(tableName, 8, true);
metric = new MutationMetricQueue.MutationMetric(0L, 1000L, 0L, 0L, 0L, 0L,
0L, 1L, 0L, 1000L,
- 0L, 0L, 0L, 0L, 0L, 0L);
+ 0L, 0L, 0L, 0L, 0L, 0L, 0L);
TableMetricsManager.updateSizeHistogramMetricsForMutations(tableName,
metric.getTotalMutationsSizeBytes().getValue(), true);
@@ -317,37 +317,37 @@ public class TableMetricsManagerTest {
TableMetricsManager.updateLatencyHistogramForMutations(tableName, 1,
false);
MutationMetricQueue.MutationMetric metric = new
MutationMetricQueue.MutationMetric(0L, 0L, 5L,
- 0L, 0L, 0L, 0L, 0L, 1L, 5L, 0L, 0L, 0L, 0L, 0L, 0L);
+ 0L, 0L, 0L, 0L, 0L, 1L, 5L, 0L, 0L, 0L, 0L, 0L, 0L, 0L);
TableMetricsManager.updateSizeHistogramMetricsForMutations(tableName,
metric.getTotalMutationsSizeBytes().getValue(), false);
TableMetricsManager.updateLatencyHistogramForMutations(tableName, 2,
false);
metric = new MutationMetricQueue.MutationMetric(0L, 0L, 10L, 0L, 0L, 0L,
0L, 0L, 1L, 10L, 0L,
- 0L, 0L, 0L, 0L, 0L);
+ 0L, 0L, 0L, 0L, 0L, 0L);
TableMetricsManager.updateSizeHistogramMetricsForMutations(tableName,
metric.getTotalMutationsSizeBytes().getValue(), false);
TableMetricsManager.updateLatencyHistogramForMutations(tableName, 4,
false);
metric = new MutationMetricQueue.MutationMetric(0L, 0L, 50L, 0L, 0L, 0L,
0L, 0L, 1L, 50L, 0L,
- 0L, 0L, 0L, 0L, 0L);
+ 0L, 0L, 0L, 0L, 0L, 0L);
TableMetricsManager.updateSizeHistogramMetricsForMutations(tableName,
metric.getTotalMutationsSizeBytes().getValue(), false);
TableMetricsManager.updateLatencyHistogramForMutations(tableName, 5,
false);
metric = new MutationMetricQueue.MutationMetric(0L, 0L, 100L, 0L, 0L, 0L,
0L, 0L, 1L, 100L, 0L,
- 0L, 0L, 0L, 0L, 0L);
+ 0L, 0L, 0L, 0L, 0L, 0L);
TableMetricsManager.updateSizeHistogramMetricsForMutations(tableName,
metric.getTotalMutationsSizeBytes().getValue(), false);
TableMetricsManager.updateLatencyHistogramForMutations(tableName, 6,
false);
metric = new MutationMetricQueue.MutationMetric(0L, 0L, 500L, 0L, 0L, 0L,
0L, 0L, 1L, 500L, 0L,
- 0L, 0L, 0L, 0L, 0L);
+ 0L, 0L, 0L, 0L, 0L, 0L);
TableMetricsManager.updateSizeHistogramMetricsForMutations(tableName,
metric.getTotalMutationsSizeBytes().getValue(), false);
TableMetricsManager.updateLatencyHistogramForMutations(tableName, 8,
false);
metric = new MutationMetricQueue.MutationMetric(0L, 0L, 1000L, 0L, 0L, 0L,
0L, 0L, 1L, 1000L,
- 0L, 0L, 0L, 0L, 0L, 0L);
+ 0L, 0L, 0L, 0L, 0L, 0L, 0L);
TableMetricsManager.updateSizeHistogramMetricsForMutations(tableName,
metric.getTotalMutationsSizeBytes().getValue(), false);