From 36360ba846eda875bbc85c822ca02ada2cb8b4c2 Mon Sep 17 00:00:00 2001 From: qiye Date: Wed, 17 Nov 2021 14:38:00 +0800 Subject: [PATCH] [BUG] fix profile not working with sql_cache enabled (#7105) Fix profile not working in sql_cache enabled. It will thrown NullPointerException. The reason is that the Coordinator in init profile is null when cache is enable. Therefore, we should perform different profile processing in the case of cache hits and misses, so as to avoid the situation of null pointers. Fixed #7104 --- .../java/org/apache/doris/qe/StmtExecutor.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java index f43539936e..28042652e7 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java @@ -195,6 +195,13 @@ public class StmtExecutor implements ProfileWriter { private void initProfile(QueryPlannerProfile plannerProfile, boolean waiteBeReport) { long currentTimestamp = System.currentTimeMillis(); long totalTimeMs = currentTimestamp - context.getStartTime(); + RuntimeProfile queryProfile; + // when a query hits the sql cache, `coord` is null. + if (coord == null) { + queryProfile = new RuntimeProfile("Execution Profile " + DebugUtil.printId(context.queryId())); + } else { + queryProfile = coord.getQueryProfile(); + } if (profile == null) { profile = new RuntimeProfile("Query"); summaryProfile = new RuntimeProfile("Summary"); @@ -216,7 +223,7 @@ public class StmtExecutor implements ProfileWriter { plannerRuntimeProfile = new RuntimeProfile("Execution Summary"); summaryProfile.addChild(plannerRuntimeProfile); - profile.addChild(coord.getQueryProfile()); + profile.addChild(queryProfile); } else { summaryProfile.addInfoString(ProfileManager.END_TIME, waiteBeReport ? TimeUtils.longToTimeString(currentTimestamp) : "N/A"); @@ -227,8 +234,10 @@ public class StmtExecutor implements ProfileWriter { } plannerProfile.initRuntimeProfile(plannerRuntimeProfile); - coord.getQueryProfile().getCounterTotalTime().setValue(TimeUtils.getEstimatedTime(plannerProfile.getQueryBeginTime())); - coord.endProfile(waiteBeReport); + queryProfile.getCounterTotalTime().setValue(TimeUtils.getEstimatedTime(plannerProfile.getQueryBeginTime())); + if (coord != null) { + coord.endProfile(waiteBeReport); + } } public Planner planner() {