Skip to content

Commit

Permalink
[opt](nereids) hbo fix pb
Browse files Browse the repository at this point in the history
  • Loading branch information
xzj7019 committed Dec 6, 2024
1 parent a05861e commit 5afa244
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
* HistoryBasedPlanStatisticsCalculator
*/
public class HistoryBasedPlanStatisticsCalculator extends StatsCalculator {
private final Supplier<HistoryBasedPlanStatisticsProvider> historyBasedPlanStatisticsProvider;
private final HistoryBasedPlanStatisticsProvider historyBasedPlanStatisticsProvider;
private final HistoryBasedStatisticsCacheManager historyBasedStatisticsCacheManager;
private final String queryId;
public HistoryBasedPlanStatisticsCalculator(GroupExpression groupExpression, boolean forbidUnknownColStats,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
import java.util.function.Supplier;

public class HistoryBasedPlanStatisticsTracker {
private final Supplier<HistoryBasedPlanStatisticsProvider> historyBasedPlanStatisticsProvider;
private final HistoryBasedPlanStatisticsProvider historyBasedPlanStatisticsProvider;
private final HistoryBasedStatisticsCacheManager historyBasedStatisticsCacheManager;
Map<PlanNodeWithHash, PlanStatisticsWithSourceInfo> planStatisticsMap = new HashMap<>();

Expand All @@ -67,14 +67,14 @@ public class HistoryBasedPlanStatisticsTracker {

public HistoryBasedPlanStatisticsTracker(
ConnectContext context,
Supplier<HistoryBasedPlanStatisticsProvider> historyBasedPlanStatisticsProvider,
HistoryBasedPlanStatisticsProvider historyBasedPlanStatisticsProvider,
HistoryBasedStatisticsCacheManager historyBasedStatisticsCacheManager) {
this.connectContext = context;
this.historyBasedPlanStatisticsProvider = historyBasedPlanStatisticsProvider;
this.historyBasedStatisticsCacheManager = historyBasedStatisticsCacheManager;
}

public Supplier<HistoryBasedPlanStatisticsProvider> getHistoryBasedPlanStatisticsProvider() {
public HistoryBasedPlanStatisticsProvider getHistoryBasedPlanStatisticsProvider() {
return this.historyBasedPlanStatisticsProvider;
}

Expand Down Expand Up @@ -153,7 +153,7 @@ public void updateStatistics() {
AuditEvent event = auditEventList.get(0);
Map<PlanNodeWithHash, PlanStatisticsWithSourceInfo> planStatistics = getQueryStats(event.queryId);
Map<PlanNodeWithHash, HistoricalPlanStatistics> historicalPlanStatisticsMap =
historyBasedPlanStatisticsProvider.get().getStats(
historyBasedPlanStatisticsProvider.getStats(
planStatistics.keySet().stream().collect(toImmutableList()), 1000);

Map<PlanNodeWithHash, HistoricalPlanStatistics> newPlanStatistics = planStatistics.entrySet().stream()
Expand All @@ -172,7 +172,7 @@ public void updateStatistics() {
}));

if (!newPlanStatistics.isEmpty()) {
historyBasedPlanStatisticsProvider.get().putStats(ImmutableMap.copyOf(newPlanStatistics));
historyBasedPlanStatisticsProvider.putStats(ImmutableMap.copyOf(newPlanStatistics));
}
historyBasedStatisticsCacheManager.invalidate(event.queryId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class HistoryBasedStatisticsCacheManager

public HistoryBasedStatisticsCacheManager() {}

public LoadingCache<PlanNodeWithHash, HistoricalPlanStatistics> getStatisticsCache(String queryId, Supplier<HistoryBasedPlanStatisticsProvider> historyBasedPlanStatisticsProvider, long timeoutInMilliSeconds)
public LoadingCache<PlanNodeWithHash, HistoricalPlanStatistics> getStatisticsCache(String queryId, HistoryBasedPlanStatisticsProvider historyBasedPlanStatisticsProvider, long timeoutInMilliSeconds)
{
return statisticsCache.computeIfAbsent(queryId, ignored -> CacheBuilder.newBuilder()
.build(new CacheLoader<PlanNodeWithHash, HistoricalPlanStatistics>()
Expand All @@ -61,7 +61,7 @@ public HistoricalPlanStatistics load(PlanNodeWithHash key)
@Override
public Map<PlanNodeWithHash, HistoricalPlanStatistics> loadAll(Iterable<? extends PlanNodeWithHash> keys)
{
Map<PlanNodeWithHash, HistoricalPlanStatistics> statistics = new HashMap<>(historyBasedPlanStatisticsProvider.get().getStats(
Map<PlanNodeWithHash, HistoricalPlanStatistics> statistics = new HashMap<>(historyBasedPlanStatisticsProvider.getStats(
ImmutableList.copyOf(keys), timeoutInMilliSeconds));
// loadAll excepts all keys to be written
for (PlanNodeWithHash key : keys) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public StmtExecutor(ConnectContext context, OriginStatement originStmt, boolean
this.context.getSessionVariable().getAutoProfileThresholdMs());
this.historyBasedPlanStatisticsTracker = new HistoryBasedPlanStatisticsTracker(
context,
(Supplier<HistoryBasedPlanStatisticsProvider>) new InMemoryHistoryBasedPlanStatisticsProvider(),
new InMemoryHistoryBasedPlanStatisticsProvider(),
new HistoryBasedStatisticsCacheManager());
this.statementContext.setHistoryBasedPlanStatisticsTracker(historyBasedPlanStatisticsTracker);
}
Expand Down Expand Up @@ -351,8 +351,7 @@ public StmtExecutor(ConnectContext ctx, StatementBase parsedStmt) {
context.getSessionVariable().getProfileLevel(),
context.getSessionVariable().getAutoProfileThresholdMs());
this.historyBasedPlanStatisticsTracker = new HistoryBasedPlanStatisticsTracker(
context,
(Supplier<HistoryBasedPlanStatisticsProvider>) new InMemoryHistoryBasedPlanStatisticsProvider(),
context, new InMemoryHistoryBasedPlanStatisticsProvider(),
new HistoryBasedStatisticsCacheManager());
this.statementContext.setHistoryBasedPlanStatisticsTracker(historyBasedPlanStatisticsTracker);
}
Expand Down

0 comments on commit 5afa244

Please sign in to comment.