diff --git a/fe/fe-core/src/main/java/org/apache/doris/common/NereidsSqlCacheManager.java b/fe/fe-core/src/main/java/org/apache/doris/common/NereidsSqlCacheManager.java index abb2487dc80866..6c4d59017099eb 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/common/NereidsSqlCacheManager.java +++ b/fe/fe-core/src/main/java/org/apache/doris/common/NereidsSqlCacheManager.java @@ -126,7 +126,7 @@ public void tryAddFeSqlCache(ConnectContext connectContext, String sql) { SqlCacheContext sqlCacheContext = sqlCacheContextOpt.get(); UserIdentity currentUserIdentity = connectContext.getCurrentUserIdentity(); - String key = sqlCacheContext.cacheKeyType == CacheKeyType.SQL + String key = sqlCacheContext.getCacheKeyType() == CacheKeyType.SQL ? currentUserIdentity.toString() + ":" + sql.trim() : currentUserIdentity.toString() + ":" + DebugUtil.printId(sqlCacheContext.getOrComputeCacheKeyMd5()); if (sqlCaches.getIfPresent(key) == null && sqlCacheContext.getOrComputeCacheKeyMd5() != null @@ -146,7 +146,7 @@ public void tryAddBeCache(ConnectContext connectContext, String sql, CacheAnalyz } SqlCacheContext sqlCacheContext = sqlCacheContextOpt.get(); UserIdentity currentUserIdentity = connectContext.getCurrentUserIdentity(); - String key = sqlCacheContext.cacheKeyType == CacheKeyType.SQL + String key = sqlCacheContext.getCacheKeyType() == CacheKeyType.SQL ? currentUserIdentity.toString() + ":" + sql.trim() : currentUserIdentity.toString() + ":" + DebugUtil.printId(sqlCacheContext.getOrComputeCacheKeyMd5()); if (sqlCaches.getIfPresent(key) == null && sqlCacheContext.getOrComputeCacheKeyMd5() != null) { @@ -187,7 +187,7 @@ public Optional tryParseSql(ConnectContext connectContext, Stri // already exist cache in the fe, but the variable is different to this query, // we should create another cache context in fe, use another cache key connectContext.getStatementContext() - .getSqlCacheContext().ifPresent(ctx -> ctx.cacheKeyType = CacheKeyType.MD5); + .getSqlCacheContext().ifPresent(ctx -> ctx.setCacheKeyType(CacheKeyType.MD5)); if (sqlCacheContextWithVariable != null) { return tryParseSqlWithoutCheckVariable( diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/SqlCacheContext.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/SqlCacheContext.java index 3c5d833fd28154..4cf2418d91e143 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/SqlCacheContext.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/SqlCacheContext.java @@ -86,7 +86,7 @@ public class SqlCacheContext { private volatile PUniqueId cacheKeyMd5; private volatile ResultSet resultSetInFe; - public volatile CacheKeyType cacheKeyType = CacheKeyType.SQL; + private volatile CacheKeyType cacheKeyType = CacheKeyType.SQL; public SqlCacheContext(UserIdentity userIdentity, TUniqueId queryId) { this.userIdentity = Objects.requireNonNull(userIdentity, "userIdentity cannot be null"); @@ -394,6 +394,14 @@ public void setResultSetInFe(ResultSet resultSetInFe) { this.resultSetInFe = resultSetInFe; } + public CacheKeyType getCacheKeyType() { + return cacheKeyType; + } + + public void setCacheKeyType(CacheKeyType cacheKeyType) { + this.cacheKeyType = cacheKeyType; + } + /** FullTableName */ @lombok.Data @lombok.AllArgsConstructor diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectProcessor.java b/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectProcessor.java index c1732855b7440a..7b0ef09a7444bb 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectProcessor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectProcessor.java @@ -239,7 +239,7 @@ public void executeQuery(MysqlCommand mysqlCommand, String originStmt) throws Ex Optional sqlCacheContext = ConnectContext.get() .getStatementContext().getSqlCacheContext(); if (sqlCacheContext.isPresent()) { - cacheKeyType = sqlCacheContext.get().cacheKeyType; + cacheKeyType = sqlCacheContext.get().getCacheKeyType(); } if (cachedStmts != null) { stmts = cachedStmts; @@ -321,7 +321,7 @@ public void executeQuery(MysqlCommand mysqlCommand, String originStmt) throws Ex if (cacheKeyType != null) { SqlCacheContext sqlCacheContext = executor.getContext().getStatementContext().getSqlCacheContext().get(); - sqlCacheContext.cacheKeyType = cacheKeyType; + sqlCacheContext.setCacheKeyType(cacheKeyType); } try {